From 064ec90db064f8e032edda32152b6fcacdb35167 Mon Sep 17 00:00:00 2001 From: prculley Date: Wed, 8 Feb 2017 16:19:45 -0600 Subject: [PATCH] Fix Glade file loading to avoid loading and leaving extra toplevels Also deals with problems caused by fix; sometimes do need to load some other toplevel objects. In some cases, it was easier to remove unused toplevel objects from glade files. --- gramps/gui/editors/filtereditor.py | 2 +- gramps/gui/glade.py | 35 +++++++++--- gramps/gui/glade/book.glade | 9 ++-- gramps/gui/managedwindow.py | 4 +- gramps/gui/plug/report/_bookdialog.py | 4 +- gramps/gui/plug/report/_styleeditor.py | 7 ++- gramps/plugins/tool/eventcmp.py | 4 +- gramps/plugins/tool/finddupes.glade | 69 +----------------------- gramps/plugins/tool/finddupes.py | 2 +- gramps/plugins/tool/mergecitations.glade | 69 +----------------------- gramps/plugins/tool/mergecitations.py | 2 +- gramps/plugins/tool/verify.py | 15 +++--- 12 files changed, 59 insertions(+), 163 deletions(-) diff --git a/gramps/gui/editors/filtereditor.py b/gramps/gui/editors/filtereditor.py index 29948dc07..222378cb1 100644 --- a/gramps/gui/editors/filtereditor.py +++ b/gramps/gui/editors/filtereditor.py @@ -804,7 +804,7 @@ class EditFilter(ManagedWindow): self.filterdb = filterdb self.selection_callback = selection_callback - self.define_glade('define_filter', RULE_GLADE) + self.define_glade('define_filter', RULE_GLADE, also_load=["model1"]) self.set_window( self.get_widget('define_filter'), diff --git a/gramps/gui/glade.py b/gramps/gui/glade.py index fe99f9c4e..b6985dea7 100644 --- a/gramps/gui/glade.py +++ b/gramps/gui/glade.py @@ -59,22 +59,37 @@ class Glade(Gtk.Builder): """ __slots__ = ['__toplevel', '__filename', '__dirname'] - def __init__(self, filename=None, dirname=None, toplevel=None): + def __init__(self, filename=None, dirname=None, toplevel=None, + also_load=[]): """ Class Constructor: Returns a new instance of the Glade class - :type filename: string + :type filename: string or None :param filename: The name of the glade file to be used. Defaults to None - :type dirname: string + :type dirname: string or None :param dirname: The directory to search for the glade file. Defaults to None which will cause a search for the file in the default directory followed by the directory of the calling module. - :type toplevel: toplevel + :type toplevel: string or None :param toplevel: The toplevel object to search for in the glade file. Defaults to None, which will cause a search for a toplevel - matching the file name. + matching the supplied name. + :type also_load: list of strings + :param also_load: Additional toplevel objects to load from the glade + file. These are typically liststore or other objects + needed to operate the toplevel object. + Defaults to [] (empty list), which will not load + additional objects. :rtype: object reference :returns: reference to the newly-created Glade instance + + This operates in two modes; when no toplevel parameter is supplied, + the entire Glade file is loaded. It is the responsibility of the user + to make sure ALL toplevel objects are destroyed. + + When a toplevel parameter is supplied, only that object and any + additional objects requested in the also_load parameter are loaded. + The user only has to destroy the requested toplevel objects. """ Gtk.Builder.__init__(self) self.set_translation_domain(glocale.get_localedomain()) @@ -120,14 +135,18 @@ class Glade(Gtk.Builder): # try to build Gtk objects from glade file. Let exceptions happen - self.add_from_file(path) self.__dirname, self.__filename = os.path.split(path) # try to find the toplevel widget - if toplevel: # toplevel is given + # toplevel is given + if toplevel: + loadlist = [toplevel] + also_load + self.add_objects_from_file(path, loadlist) self.__toplevel = self.get_object(toplevel) - else: # toplevel not given + # toplevel not given + else: + self.add_from_file(path) # first, use filename as possible toplevel widget name self.__toplevel = self.get_object(filename.rpartition('.')[0]) diff --git a/gramps/gui/glade/book.glade b/gramps/gui/glade/book.glade index c4a6cd766..bab136662 100644 --- a/gramps/gui/glade/book.glade +++ b/gramps/gui/glade/book.glade @@ -1,5 +1,5 @@ - + @@ -507,6 +507,7 @@ 300 False normal + True @@ -525,7 +526,7 @@ True False True - + False @@ -541,7 +542,7 @@ True False True - + False @@ -557,7 +558,7 @@ True False True - + False diff --git a/gramps/gui/managedwindow.py b/gramps/gui/managedwindow.py index 7bd190b42..8f195c5c5 100644 --- a/gramps/gui/managedwindow.py +++ b/gramps/gui/managedwindow.py @@ -518,11 +518,11 @@ class ManagedWindow: def build_window_key(self, obj): return id(obj) - def define_glade(self, top_module, glade_file=None): + def define_glade(self, top_module, glade_file=None, also_load=[]): if glade_file is None: raise TypeError("ManagedWindow.define_glade: no glade file") glade_file = GLADE_FILE - self._gladeobj = Glade(glade_file, None, top_module) + self._gladeobj = Glade(glade_file, None, top_module, also_load) return self._gladeobj def get_widget(self, name): diff --git a/gramps/gui/plug/report/_bookdialog.py b/gramps/gui/plug/report/_bookdialog.py index 03fcda839..146f43de5 100644 --- a/gramps/gui/plug/report/_bookdialog.py +++ b/gramps/gui/plug/report/_bookdialog.py @@ -158,7 +158,7 @@ class BookListDisplay: self.booklist = booklist self.dosave = dosave - self.xml = Glade('book.glade') + self.xml = Glade('book.glade', toplevel='book') self.top = self.xml.toplevel self.unsaved_changes = False @@ -233,7 +233,7 @@ class BookListDisplay: self.unsaved_changes = True self.top.run() - def on_booklist_cancel_clicked(self, obj): + def on_booklist_cancel_clicked(self, *obj): """ cancel the booklist dialog """ if self.unsaved_changes: qqq = QuestionDialog2( diff --git a/gramps/gui/plug/report/_styleeditor.py b/gramps/gui/plug/report/_styleeditor.py index a4eb7b89f..43da76edc 100644 --- a/gramps/gui/plug/report/_styleeditor.py +++ b/gramps/gui/plug/report/_styleeditor.py @@ -216,7 +216,12 @@ class StyleEditor(ManagedWindow): self.style = StyleSheet(style) self.parent = parent - self.top = Glade(toplevel='editor') + self.top = Glade( + toplevel='editor', + also_load=[ + "adjustment1", "adjustment2", "adjustment3", "adjustment4", + "adjustment5", "adjustment6", "adjustment7", "adjustment8", + "adjustment9", "adjustment10", "adjustment11"]) self.set_window(self.top.toplevel, self.top.get_object('title'), _('Style editor')) self.setup_configs('interface.styleeditor', 550, 610) diff --git a/gramps/plugins/tool/eventcmp.py b/gramps/plugins/tool/eventcmp.py index 23666941a..95f492cc2 100644 --- a/gramps/plugins/tool/eventcmp.py +++ b/gramps/plugins/tool/eventcmp.py @@ -124,7 +124,7 @@ class EventComparison(tool.Tool,ManagedWindow): ManagedWindow.__init__(self, uistate, [], self) self.qual = 0 - self.filterDialog = Glade(toplevel="filters") + self.filterDialog = Glade(toplevel="filters", also_load=["liststore1"]) self.filterDialog.connect_signals({ "on_apply_clicked" : self.on_apply_clicked, "on_editor_clicked" : self.filter_editor_clicked, @@ -230,7 +230,7 @@ class EventComparisonResults(ManagedWindow): self.row_data = [] self.save_form = None - self.topDialog = Glade() + self.topDialog = Glade(toplevel="eventcmp") self.topDialog.connect_signals({ "on_write_table" : self.on_write_table, "destroy_passed_object" : self.close, diff --git a/gramps/plugins/tool/finddupes.glade b/gramps/plugins/tool/finddupes.glade index 5aae1108e..4708de52f 100644 --- a/gramps/plugins/tool/finddupes.glade +++ b/gramps/plugins/tool/finddupes.glade @@ -146,10 +146,11 @@ True True False + center 12 True True - center + 0.5 True True @@ -334,70 +335,4 @@ button13 - - False - True - - - True - False - 12 - vertical - - - True - False - center - - - False - False - 6 - 0 - - - - - True - False - 10 - 10 - Please be patient. This may take a while. - center - True - - - False - False - 20 - 1 - - - - - True - False - - - True - False - 0.10000000149 - - - True - True - 20 - 0 - - - - - False - False - 2 - - - - - diff --git a/gramps/plugins/tool/finddupes.py b/gramps/plugins/tool/finddupes.py index c570f6332..4bc63cf25 100644 --- a/gramps/plugins/tool/finddupes.py +++ b/gramps/plugins/tool/finddupes.py @@ -103,7 +103,7 @@ class DuplicatePeopleTool(tool.Tool, ManagedWindow): self.update = callback self.use_soundex = 1 - top = Glade() + top = Glade(toplevel="finddupes", also_load=["liststore1"]) # retrieve options threshold = self.options.handler.options_dict['threshold'] diff --git a/gramps/plugins/tool/mergecitations.glade b/gramps/plugins/tool/mergecitations.glade index 170422ffb..e07e8c979 100644 --- a/gramps/plugins/tool/mergecitations.glade +++ b/gramps/plugins/tool/mergecitations.glade @@ -146,10 +146,11 @@ True True False + center 12 True True - center + 0.5 True True @@ -199,70 +200,4 @@ button14 - - False - True - - - True - False - 12 - vertical - - - True - False - center - - - False - False - 6 - 0 - - - - - True - False - 10 - 10 - Please be patient. This may take a while. - center - True - - - False - False - 20 - 1 - - - - - True - False - - - True - False - 0.10000000149 - - - True - True - 20 - 0 - - - - - False - False - 2 - - - - - diff --git a/gramps/plugins/tool/mergecitations.py b/gramps/plugins/tool/mergecitations.py index f3567a4b0..b2fb27de6 100644 --- a/gramps/plugins/tool/mergecitations.py +++ b/gramps/plugins/tool/mergecitations.py @@ -106,7 +106,7 @@ class MergeCitations(tool.BatchTool,ManagedWindow): def run(self): - top = Glade(toplevel="mergecitations") + top = Glade(toplevel="mergecitations", also_load=["liststore1"]) # retrieve options fields = self.options.handler.options_dict['fields'] diff --git a/gramps/plugins/tool/verify.py b/gramps/plugins/tool/verify.py index 1b6c58ae9..4dde32ca9 100644 --- a/gramps/plugins/tool/verify.py +++ b/gramps/plugins/tool/verify.py @@ -364,7 +364,8 @@ class Verify(tool.Tool, ManagedWindow, UpdateCallback): o_dict[option] = self.top.get_object(option).get_value_as_int() try: - self.v_r = VerifyResults(self.dbstate, self.uistate, self.track) + self.v_r = VerifyResults(self.dbstate, self.uistate, self.track, + self.top) self.add_results = self.v_r.add_results self.v_r.load_ignored(self.db.full_name) except WindowActiveError: @@ -493,7 +494,7 @@ class VerifyResults(ManagedWindow): TRUE_COL = 8 SHOW_COL = 9 - def __init__(self, dbstate, uistate, track): + def __init__(self, dbstate, uistate, track, glade): """ initialize things """ self.title = _('Data Verification Results') @@ -501,8 +502,8 @@ class VerifyResults(ManagedWindow): self.dbstate = dbstate self._set_filename() - self.top = Glade(toplevel="verify_result") - window = self.top.toplevel + self.top = glade + window = self.top.get_object("verify_result") self.set_window(window, self.top.get_object('title2'), self.title) self.setup_configs('interface.verifyresults', 500, 300) @@ -724,13 +725,13 @@ class VerifyResults(ManagedWindow): if the_type == 'Person': try: person = self.dbstate.db.get_person_from_handle(handle) - EditPerson(self.dbstate, self.uistate, [], person) + EditPerson(self.dbstate, self.uistate, self.track, person) except WindowActiveError: pass elif the_type == 'Family': try: family = self.dbstate.db.get_family_from_handle(handle) - EditFamily(self.dbstate, self.uistate, [], family) + EditFamily(self.dbstate, self.uistate, self.track, family) except WindowActiveError: pass @@ -759,7 +760,7 @@ class VerifyResults(ManagedWindow): def build_menu_names(self, obj): """ build the menu names """ - return (self.title, None) + return (self.title, self.title) #------------------------------------------------------------------------ #