From b03579428bd4ce3f9bf7d61dba7f7afbe5e293f1 Mon Sep 17 00:00:00 2001 From: Paul Franklin Date: Mon, 19 Sep 2016 13:42:03 -0700 Subject: [PATCH] enable the main window to remember its position on the screen The genealogy -- as it were -- of this patch started with https://gramps-project.org/bugs/view.php?id=5357 which was a feature request for the clipboard to remember its location on the screen, its placement, its position. The p.r. https://github.com/gramps-project/gramps/pull/58 was a prototype implementation, but it also had the main window remembering its location. Then p.r. 58 turned into https://github.com/gramps-project/gramps/pull/60/ -- but later both of those were closed, never committed. Since I really wanted the main window to be able to remember its position, I have extracted the relevant code. I also modified it along the way, e.g. renaming some variables. So all the credit should go to Sam Manzi, the originator of those two pull requests, and thus the code in this commit. However, any problems are due to me, my changes -- not Sam. --- gramps/gen/config.py | 2 ++ gramps/gui/managedwindow.py | 2 ++ gramps/gui/viewmanager.py | 7 +++++++ 3 files changed, 11 insertions(+) diff --git a/gramps/gen/config.py b/gramps/gen/config.py index a6efe7191..074cef3ac 100644 --- a/gramps/gen/config.py +++ b/gramps/gen/config.py @@ -224,6 +224,8 @@ register('interface.lds-width', 600) register('interface.location-height', 250) register('interface.location-width', 600) register('interface.main-window-height', 500) +register('interface.main-window-horiz-position', 15) +register('interface.main-window-vert-position', 10) register('interface.main-window-width', 775) register('interface.mapservice', 'OpenStreetMap') register('interface.media-height', 450) diff --git a/gramps/gui/managedwindow.py b/gramps/gui/managedwindow.py index 786026ef1..71ef2aea3 100644 --- a/gramps/gui/managedwindow.py +++ b/gramps/gui/managedwindow.py @@ -527,6 +527,7 @@ class ManagedWindow: """ Set the dimensions of the window """ + # self.width_key is set in the subclass, typically in its _local_init if self.width_key is not None: width = config.get(self.width_key) height = config.get(self.height_key) @@ -536,6 +537,7 @@ class ManagedWindow: """ Save the dimensions of the window to the config file """ + # self.width_key is set in the subclass, typically in its _local_init if self.width_key is not None: (width, height) = self.window.get_size() config.set(self.width_key, width) diff --git a/gramps/gui/viewmanager.py b/gramps/gui/viewmanager.py index 6a3422833..5a5ea1941 100644 --- a/gramps/gui/viewmanager.py +++ b/gramps/gui/viewmanager.py @@ -356,10 +356,13 @@ class ViewManager(CLIManager): """ width = config.get('interface.main-window-width') height = config.get('interface.main-window-height') + horiz_position = config.get('interface.main-window-horiz-position') + vert_position = config.get('interface.main-window-vert-position') self.window = Gtk.Window() self.window.set_icon_from_file(ICON) self.window.set_default_size(width, height) + self.window.move(horiz_position, vert_position) vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL) self.window.add(vbox) @@ -758,6 +761,10 @@ class ViewManager(CLIManager): (width, height) = self.window.get_size() config.set('interface.main-window-width', width) config.set('interface.main-window-height', height) + # save the current window position + (horiz_position, vert_position) = self.window.get_position() + config.set('interface.main-window-horiz-position', horiz_position) + config.set('interface.main-window-vert-position', vert_position) config.save() Gtk.main_quit()