From f5e53e53bca4c327ca4dc405dbd7983a6b899db8 Mon Sep 17 00:00:00 2001 From: SNoiraud Date: Wed, 31 Oct 2018 20:36:45 +0100 Subject: [PATCH] FR10850 V2: freeze/unfreeze button per gramplet Fixes #10850 This is the second method to avoid reloading gramplet automaticaly. --- gramps/gen/config.py | 1 + gramps/gen/plug/_gramplet.py | 35 ++++++++++++++-- gramps/gui/configure.py | 13 ++++++ gramps/gui/displaystate.py | 1 + gramps/gui/widgets/grampletbar.py | 66 ++++++++++++++++++++++++++++++- 5 files changed, 112 insertions(+), 4 deletions(-) diff --git a/gramps/gen/config.py b/gramps/gen/config.py index 12508ba13..7093e91ba 100644 --- a/gramps/gen/config.py +++ b/gramps/gen/config.py @@ -196,6 +196,7 @@ register('interface.view-categories', register('interface.filter', False) register('interface.fullscreen', False) register('interface.grampletbar-close', False) +register('interface.grampletbar-freeze', False) register('interface.ignore-gexiv2', False) register('interface.ignore-pil', False) register('interface.ignore-osmgpsmap', False) diff --git a/gramps/gen/plug/_gramplet.py b/gramps/gen/plug/_gramplet.py index 76b097224..3afc02716 100644 --- a/gramps/gen/plug/_gramplet.py +++ b/gramps/gen/plug/_gramplet.py @@ -291,17 +291,46 @@ class Gramplet: """ The main interface for running the :meth:`main` method. """ - from gi.repository import GLib if ((not self.active) and not self.gui.force_update): self.dirty = True if self.dbstate.is_open(): - #print " %s is not active" % self.gui.gname + #print(" %s is not active" % self.gui.gname) self.update_has_data() else: self.set_has_data(False) return - #print " %s is UPDATING" % self.gui.gname + #print(" %s is UPDATING" % self.gui.gname) + uva = self.uistate.viewmanager.active_page + # The dashboard has no sidebar or bottombar + if uva.bottombar: + for gramplets in [uva.bottombar.get_children()]: + for gramplet in gramplets: + for i in range(gramplet.pui.gui.pane.get_n_pages()): + child = gramplet.pui.gui.pane.get_nth_page(i) + label = gramplet.pui.gui.pane.get_tab_label(child) + act_grplet = (i == gramplet.pui.gui.pane.get_current_page()) + if (gramplet.title == child.get_title() and + gramplet.title == self.gui.title and + not label.get_freeze().get_active() and + act_grplet): + self._really_update() + for gramplets in [uva.sidebar.get_children()]: + for gramplet in gramplets: + for i in range(gramplet.pui.gui.pane.get_n_pages()): + child = gramplet.pui.gui.pane.get_nth_page(i) + label = gramplet.pui.gui.pane.get_tab_label(child) + act_grplet = (i == gramplet.pui.gui.pane.get_current_page()) + if (gramplet.title == child.get_title() and + gramplet.title == self.gui.title and + not label.get_freeze().get_active() and + act_grplet): + self._really_update() + else: + self._really_update() + + def _really_update(self): + from gi.repository import GLib self.dirty = False LOG.debug("gramplet updater: %s: running" % self.gui.title) if self._idle_id != 0: diff --git a/gramps/gui/configure.py b/gramps/gui/configure.py index b7c442db8..9257cd5cb 100644 --- a/gramps/gui/configure.py +++ b/gramps/gui/configure.py @@ -984,6 +984,12 @@ class GrampsPreferences(ConfigureDialog): """ self.uistate.emit('grampletbar-close-changed') + def cb_grampletbar_freeze(self, obj): + """ + Gramplet bar freeze/unfreeze button preference callback + """ + self.uistate.emit('grampletbar-freeze-changed') + def add_formats_panel(self, configdialog): row = 0 grid = Gtk.Grid() @@ -1185,6 +1191,13 @@ class GrampsPreferences(ConfigureDialog): row, 'interface.grampletbar-close', stop=3, extra_callback=self.cb_grampletbar_close) row += 1 + + # Gramplet bar freeze button: + self.add_checkbox(grid, + _("Enable freeze/unfreeze for the active gramplet"), + row, 'interface.grampletbar-freeze', stop=3, + extra_callback=self.cb_grampletbar_freeze) + row += 1 return _('Display'), grid def auto_title_changed(self, obj): diff --git a/gramps/gui/displaystate.py b/gramps/gui/displaystate.py index 758f9a824..e5517aaaa 100644 --- a/gramps/gui/displaystate.py +++ b/gramps/gui/displaystate.py @@ -398,6 +398,7 @@ class DisplayState(Callback): 'nameformat-changed' : None, 'placeformat-changed' : None, 'grampletbar-close-changed' : None, + 'grampletbar-freeze-changed' : None, 'update-available' : (list, ), 'autobackup' : None, } diff --git a/gramps/gui/widgets/grampletbar.py b/gramps/gui/widgets/grampletbar.py index b5cae4bb8..5df8da752 100644 --- a/gramps/gui/widgets/grampletbar.py +++ b/gramps/gui/widgets/grampletbar.py @@ -142,6 +142,7 @@ class GrampletBar(Gtk.Notebook): self.set_current_page(config_settings[1]) uistate.connect('grampletbar-close-changed', self.cb_close_changed) + uistate.connect('grampletbar-freeze-changed', self.cb_freeze_changed) # Connect after gramplets added to prevent making them active self.connect('switch-page', self.__switch_page) @@ -389,6 +390,11 @@ class GrampletBar(Gtk.Notebook): else: # just a function; always show yes it has data tablabel.set_has_data(True) + if config.get('interface.grampletbar-freeze'): + tablabel.use_freeze(True) + else: + tablabel.use_freeze(False) + if config.get('interface.grampletbar-close'): tablabel.use_close(True) else: @@ -404,6 +410,14 @@ class GrampletBar(Gtk.Notebook): tablabel = self.get_tab_label(gramplet) tablabel.use_close(config.get('interface.grampletbar-close')) + def cb_freeze_changed(self): + """ + Freeze/unfreeze button preference changed. + """ + for gramplet in self.get_children(): + tablabel = self.get_tab_label(gramplet) + tablabel.use_freeze(config.get('interface.grampletbar-freeze')) + def __delete_clicked(self, button, gramplet): """ Called when the delete button is clicked. @@ -476,6 +490,16 @@ class GrampletBar(Gtk.Notebook): gramplet.detached_window.close() gramplet.detached_window = None + def __freeze_clicked(self, button): + """ + Called when the freeze/unfreeze button is clicked. + """ + for gramplet in self.get_children(): + if gramplet and gramplet.pui: + if gramplet.pui.active: + if not self.freeze: + gramplet.pui.main() + def __button_clicked(self, button): """ Called when the drop-down button is clicked. @@ -601,6 +625,7 @@ class TabGramplet(Gtk.ScrolledWindow, GuiGramplet): self.add(self.textview) self.show_all() self.track = [] + self.pane = pane def get_title(self): return self.title @@ -721,6 +746,11 @@ class TabLabel(Gtk.Box): self.label.set_tooltip_text(gramplet.tname) self.label.show() + self.freezebtn = Gtk.ToggleButton() + self.freezebtn.connect("toggled", self.update_freeze, gramplet) + self.freezebtn.set_active(False) + self.update_freeze(self.freezebtn, gramplet) + self.closebtn = Gtk.Button() image = Gtk.Image() image.set_from_icon_name('window-close', Gtk.IconSize.MENU) @@ -729,6 +759,7 @@ class TabLabel(Gtk.Box): self.closebtn.set_relief(Gtk.ReliefStyle.NONE) self.pack_start(self.label, True, True, 0) + self.pack_start(self.freezebtn, False, False, 0) self.pack_end(self.closebtn, False, False, 0) def set_has_data(self, has_data): @@ -741,9 +772,42 @@ class TabLabel(Gtk.Box): else: self.label.set_text(self.text) + def update_freeze(self, obj, gramplet): + """ + Display the correct icon for the button according to user + gramplet preference. + """ + child = obj.get_child() + if child: + obj.remove(child) + image = Gtk.Image() + if obj.get_active(): + image.set_from_icon_name('gramps-lock', Gtk.IconSize.MENU) + obj.set_tooltip_text(_('Gramplet update is freezed')) + else: + image.set_from_icon_name('gramps-unlock', Gtk.IconSize.MENU) + obj.set_tooltip_text(_('Gramplet update is allowed')) + image.show() + obj.add(image) + + def get_freeze(self): + """ + return the freeze button + """ + return self.freezebtn + + def use_freeze(self, use_freeze): + """ + Display the close button according to user preference. + """ + if use_freeze: + self.freezebtn.show() + else: + self.freezebtn.hide() + def use_close(self, use_close): """ - Display the cose button according to user preference. + Display the close button according to user preference. """ if use_close: self.closebtn.show()