set up a window's initial configuration easier (size, etc.; see 9795)

This commit is contained in:
Paul Franklin 2016-12-04 13:27:25 -08:00
parent e75a45748f
commit 6495240859
5 changed files with 30 additions and 26 deletions

View File

@ -187,20 +187,12 @@ register('interface.address-height', 450)
register('interface.address-width', 650)
register('interface.attribute-height', 350)
register('interface.attribute-width', 600)
register('interface.book-selector-height', 600)
register('interface.book-selector-horiz-position', 100)
register('interface.book-selector-vert-position', 200)
register('interface.book-selector-width', 700)
register('interface.child-ref-height', 450)
register('interface.child-ref-width', 600)
register('interface.citation-height', 450)
register('interface.citation-sel-height', 450)
register('interface.citation-sel-width', 600)
register('interface.citation-width', 600)
register('interface.clipboard-height', 300)
register('interface.clipboard-horiz-position', 100)
register('interface.clipboard-vert-position', 200)
register('interface.clipboard-width', 300)
register('interface.dont-ask', False)
register('interface.view-categories',
["Dashboard", "People", "Relationships", "Families",

View File

@ -1383,15 +1383,9 @@ class ClipboardWindow(ManagedWindow):
self.database_changed(self.dbstate.db)
self.dbstate.connect('database-changed', self.database_changed)
self.width_key = 'interface.clipboard-width'
self.height_key = 'interface.clipboard-height'
self.horiz_position_key = 'interface.clipboard-horiz-position'
self.vert_position_key = 'interface.clipboard-vert-position'
self.top = Glade()
self.set_window(self.top.toplevel, None, None, msg=_("Clipboard"))
self._set_size()
self._set_position()
self.setup_configs('interface.clipboard', 500, 300, 100, 200)
self.clear_all_btn = self.top.get_object("btn_clear_all")
self.clear_btn = self.top.get_object("btn_clear")

View File

@ -5,8 +5,6 @@
<object class="GtkDialog" id="clipboard">
<property name="can_focus">False</property>
<property name="title" translatable="yes">Clipboard</property>
<property name="default_width">500</property>
<property name="default_height">300</property>
<property name="type_hint">dialog</property>
<child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1">

View File

@ -569,7 +569,7 @@ class ManagedWindow:
"""
Set the dimensions of the window
"""
# self.width_key is set in the subclass, typically in its _local_init
# self.width_key is set in the subclass (or in setup_configs)
if self.width_key is not None:
width = config.get(self.width_key)
height = config.get(self.height_key)
@ -579,7 +579,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
# self.width_key is set in the subclass (or in setup_configs)
if self.width_key is not None:
(width, height) = self.window.get_size()
config.set(self.width_key, width)
@ -590,7 +590,7 @@ class ManagedWindow:
"""
Set the position of the window
"""
# self.horiz_position_key is set in the subclass
# self.horiz_position_key is set in the subclass (or in setup_configs)
if self.horiz_position_key is not None:
horiz_position = config.get(self.horiz_position_key)
vert_position = config.get(self.vert_position_key)
@ -600,12 +600,37 @@ class ManagedWindow:
"""
Save the window's position to the config file
"""
# self.horiz_position_key is set in the subclass (or in setup_configs)
if self.horiz_position_key is not None:
(horiz_position, vert_position) = self.window.get_position()
config.set(self.horiz_position_key, horiz_position)
config.set(self.vert_position_key, vert_position)
config.save()
def setup_configs(self, config_base,
default_width, default_height,
default_horiz_position, default_vert_position):
"""
Helper method to setup the window's configuration settings
@param config_base: the common config name, e.g. 'interface.clipboard'
@type config_base: str
@param default_width, default_height: the default width and height
@type default_width, default_height: int
@param default_horiz_position, default_vert_position: the defaults
@type default_horiz_position, default_vert_position: int
"""
self.width_key = config_base + '-width'
self.height_key = config_base + '-height'
self.horiz_position_key = config_base + '-horiz-position'
self.vert_position_key = config_base + '-vert-position'
config.register(self.width_key, default_width)
config.register(self.height_key, default_height)
config.register(self.horiz_position_key, default_horiz_position)
config.register(self.vert_position_key, default_vert_position)
self._set_size()
self._set_position()
def track_ref_for_deletion(self, ref):
"""
Record references of instance variables that need to be removed

View File

@ -329,12 +329,7 @@ class BookSelector(ManagedWindow):
title_label = self.xml.get_object('title')
self.set_window(window, title_label, self.title)
self.height_key = 'interface.book-selector-height'
self.width_key = 'interface.book-selector-width'
self._set_size()
self.horiz_position_key = 'interface.book-selector-horiz-position'
self.vert_position_key = 'interface.book-selector-vert-position'
self._set_position()
self.setup_configs('interface.book-selector', 700, 600, 100, 200)
window.show()
self.xml.connect_signals({
"on_add_clicked" : self.on_add_clicked,