Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert 'Tip of the Day' window to Gtk.Template #1765

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions gramps/gui/glade/tipofday.glade
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<!-- Generated with glade 3.40.0 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkWindow" id="tipofday">
<template class="TipOfDay" parent="GtkWindow">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="hexpand">True</property>
Expand All @@ -11,13 +11,13 @@
<property name="title">window1</property>
<property name="gravity">center</property>
<child>
<object class="GtkBox" id="vbox126">
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<!-- n-columns=3 n-rows=3 -->
<object class="GtkGrid" id="grid1">
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="valign">start</property>
Expand Down Expand Up @@ -103,18 +103,19 @@
</packing>
</child>
<child>
<object class="GtkButtonBox" id="hbuttonbox47">
<object class="GtkButtonBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="layout-style">end</property>
<child>
<object class="GtkButton" id="next">
<object class="GtkButton">
<property name="label" translatable="yes">_Forward</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="can-default">True</property>
<property name="receives-default">True</property>
<property name="use-underline">True</property>
<signal name="clicked" handler="next_tip_cb"/>
</object>
<packing>
<property name="expand">False</property>
Expand All @@ -123,13 +124,14 @@
</packing>
</child>
<child>
<object class="GtkButton" id="close">
<object class="GtkButton">
<property name="label" translatable="yes">_Close</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="can-default">True</property>
<property name="receives-default">True</property>
<property name="use-underline">True</property>
<signal name="clicked" handler="close_cb"/>
</object>
<packing>
<property name="expand">False</property>
Expand All @@ -146,5 +148,5 @@
</child>
</object>
</child>
</object>
</template>
</interface>
41 changes: 19 additions & 22 deletions gramps/gui/tipofday.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
# GTK/GNOME modules
#
# -------------------------------------------------------------------------
from gi.repository import Gtk

# -------------------------------------------------------------------------
#
Expand All @@ -49,35 +50,31 @@
from gramps.gen.config import config
from .managedwindow import ManagedWindow
from .dialog import ErrorDialog
from .glade import Glade


# -------------------------------------------------------------------------
#
# Tip Display class
#
# -------------------------------------------------------------------------
class TipOfDay(ManagedWindow):
@Gtk.Template(filename=os.path.join(os.path.dirname(__file__), "glade/tipofday.glade"))
class TipOfDay(ManagedWindow, Gtk.Window):
__gtype_name__ = "TipOfDay"

title = Gtk.Template.Child()
tip = Gtk.Template.Child()
usetips = Gtk.Template.Child()
image = Gtk.Template.Child()

def __init__(self, uistate):
ManagedWindow.__init__(self, uistate, [], self)
Gtk.Window.__init__(self)

xml = Glade()
window = xml.toplevel
self.set_window(
window, xml.get_object("title"), _("Tip of the Day"), _("Tip of the Day")
)
self.set_window(self, self.title, _("Tip of the Day"), _("Tip of the Day"))
self.setup_configs("interface.tipofday", 550, 350)

self.tip = xml.get_object("tip")
self.use = xml.get_object("usetips")
self.use.set_active(config.get("behavior.use-tips"))
image = xml.get_object("image")
image.set_from_file(os.path.join(IMAGE_DIR, "splash.jpg"))

next = xml.get_object("next")
next.connect("clicked", self.next_tip_cb)
close = xml.get_object("close")
close.connect("clicked", self.close_cb)
self.usetips.set_active(config.get("behavior.use-tips"))
self.image.set_from_file(os.path.join(IMAGE_DIR, "splash.jpg"))

try:
tparser = TipParser()
Expand Down Expand Up @@ -106,17 +103,17 @@ def escape(self, text):
# Replace standalone > char
return text

@Gtk.Template.Callback()
def next_tip_cb(self, dummy=None):
tip_text = _(self.escape(self.tip_list[self.new_index[self.index]]))
newtext = ""
for line in tip_text.split("<br/>"):
newtext += line + "\n\n"
self.tip.set_text(newtext[:-2])
newtext = "\n\n".join(tip_text.split("<br/>"))
self.tip.set_text(newtext)
self.tip.set_use_markup(True)
self.index = (self.index + 1) % len(self.tip_list)

@Gtk.Template.Callback()
def close_cb(self, dummy=None):
config.set("behavior.use-tips", self.use.get_active())
config.set("behavior.use-tips", self.usetips.get_active())
self.close()

def build_menu_names(self, obj):
Expand Down