diff --git a/gramps/gui/dbman.py b/gramps/gui/dbman.py index ab0c2eba4..7d366cfff 100644 --- a/gramps/gui/dbman.py +++ b/gramps/gui/dbman.py @@ -113,12 +113,11 @@ RCS_BUTTON = {True : _('_Extract'), False : _('_Archive')} class Information(ManagedWindow): - def __init__(self, uistate, data, parent): - super().__init__(uistate, [], self) + def __init__(self, uistate, data, track): + super().__init__(uistate, track, self, modal=True) self.window = Gtk.Dialog() self.set_window(self.window, None, _("Database Information")) self.setup_configs('interface.information', 600, 400) - self.window.set_modal(True) self.ok = self.window.add_button(_('_OK'), Gtk.ResponseType.OK) self.ok.connect('clicked', self.on_ok_clicked) s = Gtk.ScrolledWindow() @@ -132,8 +131,6 @@ class Information(ManagedWindow): model.add((key, str(value),), key) s.add(treeview) self.window.vbox.pack_start(s, True, True, 0) - if parent: - self.window.set_transient_for(parent) self.show() def on_ok_clicked(self, obj): @@ -142,7 +139,8 @@ class Information(ManagedWindow): def build_menu_names(self, obj): return (_('Database Information'), None) -class DbManager(CLIDbManager): + +class DbManager(CLIDbManager, ManagedWindow): """ Database Manager. Opens a database manager window that allows users to create, rename, delete and open databases. @@ -162,14 +160,13 @@ class DbManager(CLIDbManager): Create the top level window from the glade description, and extracts the GTK widgets that are needed. """ - self.uistate = uistate + window_id = self + ManagedWindow.__init__(self, uistate, [], window_id, modal=True) CLIDbManager.__init__(self, dbstate) self.glade = Glade(toplevel='dbmanager') self.top = self.glade.toplevel + self.set_window(self.top, None, None) self.viewmanager = viewmanager - self.parent = parent - if parent: - self.top.set_transient_for(parent) for attr in ['connect', 'cancel', 'new', 'remove', 'info', 'dblist', 'rename', 'convert', 'repair', 'rcs', @@ -191,10 +188,17 @@ class DbManager(CLIDbManager): self.before_change = "" self.after_change = "" self._select_default() - self.user = User(error=ErrorDialog, parent=self.parent, + self.user = User(error=ErrorDialog, parent=parent, callback=self.uistate.pulse_progressbar, uistate=self.uistate) + def build_menu_names(self, obj): + ''' This window can have children, but they are modal so no submenu + is visible''' + submenu_label = " " + menu_label = _('Family Trees') + return (menu_label, submenu_label) + def _select_default(self): """ Select the current, or latest, tree. @@ -458,6 +462,7 @@ class DbManager(CLIDbManager): Runs the dialog, returning None if nothing has been chosen, or the path and name if something has been selected """ + self.show() while True: value = self.top.run() if value == Gtk.ResponseType.OK: @@ -856,7 +861,7 @@ class DbManager(CLIDbManager): dirname = store[node][1] # if this is open, get info from there, otherwise, temp open? summary = self.get_dbdir_summary(dirname, name) - Information(self.uistate, summary, parent=self.top) + Information(self.uistate, summary, track=self.track) def __repair_db(self, obj): """ diff --git a/gramps/gui/managedwindow.py b/gramps/gui/managedwindow.py index 2b9cfca88..1f784b4aa 100644 --- a/gramps/gui/managedwindow.py +++ b/gramps/gui/managedwindow.py @@ -344,8 +344,16 @@ class ManagedWindow: window_id, modal=False) # Proceed with the class. + window = Gtk.Dialog() # Some Gtk window object to manage + self.set_window(window, None, None) # See set_window def below ... + def build_menu_names(self, obj): + ''' Define menu labels. If your ManagedWindow can have + ManagedWindow children, you must include a submenu_label + string; However, if modal, that string is never seen and can + be ' '. + ''' submenu_label = None # This window cannot have children menu_label = 'Menu label for this window' return (menu_label, submenu_label) @@ -368,8 +376,20 @@ class ManagedWindow: If a modal window is used and has children, its and any child 'track' parameters must properly be set to the parents 'self.track'. Only one modal window can be supported by Gtk without potentially - hiding of a modal window while it has focus. So don't use direct - non managed Gtk windows as children and set them modal. + hiding of a modal window while it has focus. So don't use + non-managed Gtk windows as children and set them modal. + + If you use the 'Gtk.Dialog.run()' within your ManagedWindow, Gtk makes + the dialog modal. Accordingly you MUST also set the ManagedWindow + modal for proper operation of any child windows. + + You must use 'self.show()' in order for your ManagedWindow to work + properly, this in turn calls the Gtk.Window.show_all() for you. + + The ManagedWindow uses 'track' to properly do a + Gtk.Window.set_transient_for() for you; you don't have to do it + yourself. If you need a 'parent=' to call an unmanaged window, + self.window is available. """ window_key = self.build_window_key(obj) @@ -431,6 +451,7 @@ class ManagedWindow: :param title: a label widget in which to write the title, else None if not needed :param text: text to use as title of window and in title param + can also be None if Glade defines title :param msg: if not None, use msg as title of window instead of text :param isWindow: {if isWindow than self is the window (so self inherits from Gtk.Window and @@ -514,6 +535,9 @@ class ManagedWindow: def modal_call(self, after_ok_func=None): """ + This is deprecated; use the 'modal=True' on the ManagedWindow + initialization for new work. + Method to do modal run of the ManagedWindow. Connect the OK button to a method that checks if all is ok, Do not call close, close is called here. @@ -676,6 +700,6 @@ def set_titles(window, title, text, msg=None): title.set_use_markup(True) if msg: window.set_title('%s - Gramps' % msg) - else: + elif text: window.set_title('%s - Gramps' % text) window.set_icon_from_file(ICON)