Skip to content

Commit 9283b07

Browse files
authored
Geps044 replace deprecated Gtk.UIManager and associate APIs (#171)
with newer versions.
1 parent c6f84d5 commit 9283b07

File tree

4 files changed

+456
-197
lines changed

4 files changed

+456
-197
lines changed

GraphView/graphview.py

Lines changed: 106 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -159,19 +159,15 @@ def __init__(self, pdata, dbstate, uistate, nav_group=0):
159159
# dict {handle, tooltip_str} of tooltips in markup format
160160
self.tags_tooltips = {}
161161

162-
self.additional_uis.append(self.additional_ui())
162+
self.additional_uis.append(self.additional_ui)
163163
self.define_print_actions()
164164

165165
def define_print_actions(self):
166166
"""
167167
Associate the print button to the PrintView action.
168168
"""
169-
self._add_action('PrintView', 'document-print', _("_Print..."),
170-
accel="<PRIMARY>P",
171-
tip=_("Save the dot file for a later print.\n"
172-
"This will save a .gv file and a svg file.\n"
173-
"You must select a .gv file"),
174-
callback=self.printview)
169+
self._add_action('PrintView', self.printview, "<PRIMARY>P")
170+
self._add_action('PRIMARY-J', self.jump, '<PRIMARY>J')
175171

176172
def _connect_db_signals(self):
177173
"""
@@ -223,39 +219,96 @@ def build_tree(self):
223219
"""
224220
pass
225221

226-
def additional_ui(self):
227-
"""
228-
Specifies the UIManager XML code that defines the menus and buttons
229-
associated with the interface.
230-
"""
231-
return '''<ui>
232-
<menubar name="MenuBar">
233-
<menu action="GoMenu">
234-
<placeholder name="CommonGo">
235-
<menuitem action="Back"/>
236-
<menuitem action="Forward"/>
237-
<separator/>
238-
<menuitem action="HomePerson"/>
239-
<separator/>
240-
</placeholder>
241-
</menu>
242-
<menu action="EditMenu">
243-
<placeholder name="CommonEdit">
244-
<menuitem action="PrintView"/>
245-
</placeholder>
246-
</menu>
247-
</menubar>
248-
<toolbar name="ToolBar">
249-
<placeholder name="CommonNavigation">
250-
<toolitem action="Back"/>
251-
<toolitem action="Forward"/>
252-
<toolitem action="HomePerson"/>
253-
</placeholder>
254-
<placeholder name="CommonEdit">
255-
<toolitem action="PrintView"/>
256-
</placeholder>
257-
</toolbar>
258-
</ui>'''
222+
additional_ui = [ # Defines the UI string for UIManager
223+
'''
224+
<placeholder id="CommonGo">
225+
<section>
226+
<item>
227+
<attribute name="action">win.Back</attribute>
228+
<attribute name="label" translatable="yes">_Back</attribute>
229+
</item>
230+
<item>
231+
<attribute name="action">win.Forward</attribute>
232+
<attribute name="label" translatable="yes">_Forward</attribute>
233+
</item>
234+
</section>
235+
<section>
236+
<item>
237+
<attribute name="action">win.HomePerson</attribute>
238+
<attribute name="label" translatable="yes">_Home</attribute>
239+
</item>
240+
</section>
241+
</placeholder>
242+
''',
243+
'''
244+
<section id='CommonEdit' groups='RW'>
245+
<item>
246+
<attribute name="action">win.PrintView</attribute>
247+
<attribute name="label" translatable="yes">_Print...</attribute>
248+
</item>
249+
</section>
250+
''', # Following are the Toolbar items
251+
'''
252+
<placeholder id='CommonNavigation'>
253+
<child groups='RO'>
254+
<object class="GtkToolButton">
255+
<property name="icon-name">go-previous</property>
256+
<property name="action-name">win.Back</property>
257+
<property name="tooltip_text" translatable="yes">'''
258+
'''Go to the previous object in the history</property>
259+
<property name="label" translatable="yes">_Back</property>
260+
<property name="use-underline">True</property>
261+
</object>
262+
<packing>
263+
<property name="homogeneous">False</property>
264+
</packing>
265+
</child>
266+
<child groups='RO'>
267+
<object class="GtkToolButton">
268+
<property name="icon-name">go-next</property>
269+
<property name="action-name">win.Forward</property>
270+
<property name="tooltip_text" translatable="yes">'''
271+
'''Go to the next object in the history</property>
272+
<property name="label" translatable="yes">_Forward</property>
273+
<property name="use-underline">True</property>
274+
</object>
275+
<packing>
276+
<property name="homogeneous">False</property>
277+
</packing>
278+
</child>
279+
<child groups='RO'>
280+
<object class="GtkToolButton">
281+
<property name="icon-name">go-home</property>
282+
<property name="action-name">win.HomePerson</property>
283+
<property name="tooltip_text" translatable="yes">'''
284+
'''Go to the default person</property>
285+
<property name="label" translatable="yes">_Home</property>
286+
<property name="use-underline">True</property>
287+
</object>
288+
<packing>
289+
<property name="homogeneous">False</property>
290+
</packing>
291+
</child>
292+
</placeholder>
293+
''',
294+
'''
295+
<placeholder id='BarCommonEdit'>
296+
<child groups='RO'>
297+
<object class="GtkToolButton">
298+
<property name="icon-name">document-print</property>
299+
<property name="action-name">win.PrintView</property>
300+
<property name="tooltip_text" translatable="yes">"Save the dot file '''
301+
'''for a later print.\nThis will save a .gv file and a svg file.\n'''
302+
'''You must select a .gv file"</property>
303+
<property name="label" translatable="yes">_Print...</property>
304+
<property name="use-underline">True</property>
305+
</object>
306+
<packing>
307+
<property name="homogeneous">False</property>
308+
</packing>
309+
</child>
310+
</placeholder>
311+
''']
259312

260313
def navigation_type(self):
261314
"""
@@ -503,20 +556,19 @@ def animation_config_panel(self, configdialog):
503556
# Printing functionalities
504557
#
505558
#-------------------------------------------------------------------------
506-
def printview(self, obj):
559+
def printview(self, *obj):
507560
"""
508561
Save the dot file for a later printing with an appropriate tool.
509562
"""
510563
# ask for the dot file name
511564
filter1 = Gtk.FileFilter()
512565
filter1.set_name("dot files")
513566
filter1.add_pattern("*.gv")
514-
dot = Gtk.FileChooserDialog(
515-
_("Select a dot file name"),
516-
action=Gtk.FileChooserAction.SAVE,
517-
buttons=(_('_Cancel'), Gtk.ResponseType.CANCEL,
518-
_('_Apply'), Gtk.ResponseType.OK),
519-
parent=self.uistate.window)
567+
dot = Gtk.FileChooserDialog(title=_("Select a dot file name"),
568+
action=Gtk.FileChooserAction.SAVE,
569+
transient_for=self.uistate.window)
570+
dot.add_button(_('_Cancel'), Gtk.ResponseType.CANCEL)
571+
dot.add_button(_('_Apply'), Gtk.ResponseType.OK)
520572
mpath = config.get('paths.report-directory')
521573
dot.set_current_folder(os.path.dirname(mpath))
522574
dot.set_filter(filter1)
@@ -588,9 +640,11 @@ def __init__(self, view, dbstate, uistate):
588640

589641
scrolled_win.add(self.canvas)
590642

591-
self.vbox = Gtk.Box(False, 4, orientation=Gtk.Orientation.VERTICAL)
643+
self.vbox = Gtk.Box(homogeneous=False, spacing=4,
644+
orientation=Gtk.Orientation.VERTICAL)
592645
self.vbox.set_border_width(4)
593-
hbox = Gtk.Box(False, 4, orientation=Gtk.Orientation.HORIZONTAL)
646+
hbox = Gtk.Box(homogeneous=False, spacing=4,
647+
orientation=Gtk.Orientation.HORIZONTAL)
594648
self.vbox.pack_start(hbox, False, False, 0)
595649

596650
# add zoom-in button
@@ -640,7 +694,7 @@ def __init__(self, view, dbstate, uistate):
640694

641695
# add spinners for quick generations change
642696
box = Gtk.Box(orientation=Gtk.Orientation.HORIZONTAL)
643-
box.pack_start(Gtk.Label('↑'), False, False, 1)
697+
box.pack_start(Gtk.Label(label='↑'), False, False, 1)
644698
self.ancestors_spinner = Gtk.SpinButton.new_with_range(0, 50, 1)
645699
self.ancestors_spinner.set_tooltip_text(_('Ancestor generations'))
646700
self.ancestors_spinner.set_value(
@@ -649,7 +703,7 @@ def __init__(self, view, dbstate, uistate):
649703
self.set_ancestors_generations)
650704
box.pack_start(self.ancestors_spinner, False, False, 1)
651705

652-
box.pack_start(Gtk.Label('↓'), False, False, 1)
706+
box.pack_start(Gtk.Label(label='↓'), False, False, 1)
653707
self.descendants_spinner = Gtk.SpinButton.new_with_range(1, 50, 1)
654708
self.descendants_spinner.set_tooltip_text(_('Descendant generations'))
655709
self.descendants_spinner.set_value(
@@ -2574,6 +2628,7 @@ def get_person_label(self, person):
25742628
label = ""
25752629
line_delimiter = '\\n'
25762630

2631+
25772632
# If we have an image, then start an HTML table.
25782633
# Remember to close the table afterwards!
25792634
#

0 commit comments

Comments
 (0)