9795: remember the last location of windows [style dialogs]

This commit is contained in:
Paul Franklin 2017-02-02 19:22:55 -08:00
parent 94716cc20f
commit 1ae88d9aed
5 changed files with 71 additions and 45 deletions

View File

@ -36,7 +36,7 @@ from ..docgen import StyleSheetList
# StyleOption class # StyleOption class
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class StyleOption(EnumeratedListOption): class StyleOption(EnumeratedListOption): # TODO this is likely dead code
""" """
This class describes an option that allows the use to select a style sheet. This class describes an option that allows the use to select a style sheet.
""" """

View File

@ -90,7 +90,7 @@
<property name="can_default">True</property> <property name="can_default">True</property>
<property name="receives_default">False</property> <property name="receives_default">False</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<signal name="clicked" handler="destroy_passed_object" object="editor" swapped="yes"/> <signal name="clicked" handler="on_cancel_style_clicked" object="editor" swapped="yes"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -1705,8 +1705,6 @@
</object> </object>
<object class="GtkDialog" id="styles"> <object class="GtkDialog" id="styles">
<property name="can_focus">False</property> <property name="can_focus">False</property>
<property name="default_width">400</property>
<property name="default_height">300</property>
<property name="type_hint">dialog</property> <property name="type_hint">dialog</property>
<child internal-child="vbox"> <child internal-child="vbox">
<object class="GtkBox" id="dialog-vbox1"> <object class="GtkBox" id="dialog-vbox1">
@ -1727,6 +1725,7 @@
<property name="can_default">True</property> <property name="can_default">True</property>
<property name="receives_default">False</property> <property name="receives_default">False</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<signal name="clicked" handler="on_cancel_clicked" object="styles" swapped="yes"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>

View File

@ -1790,7 +1790,7 @@ class GuiDestinationOption(Gtk.Box):
# GuiStyleOption class # GuiStyleOption class
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
class GuiStyleOption(GuiEnumeratedListOption): class GuiStyleOption(GuiEnumeratedListOption): # TODO this is likely dead code
""" """
This class displays a StyleOption. This class displays a StyleOption.
""" """
@ -1808,6 +1808,8 @@ class GuiStyleOption(GuiEnumeratedListOption):
self.__button.connect('clicked', self.__on_style_edit_clicked) self.__button.connect('clicked', self.__on_style_edit_clicked)
self.pack_end(self.__button, False, False) self.pack_end(self.__button, False, False)
self.uistate = uistate
self.track = track
def __on_style_edit_clicked(self, *obj): def __on_style_edit_clicked(self, *obj):
"""The user has clicked on the 'Edit Styles' button. Create a """The user has clicked on the 'Edit Styles' button. Create a
@ -1817,7 +1819,7 @@ class GuiStyleOption(GuiEnumeratedListOption):
from .report._styleeditor import StyleListDisplay from .report._styleeditor import StyleListDisplay
style_list = StyleSheetList(self.__option.get_style_file(), style_list = StyleSheetList(self.__option.get_style_file(),
self.__option.get_default_style()) self.__option.get_default_style())
StyleListDisplay(style_list, None, None) StyleListDisplay(style_list, self.uistate, self.track)
new_items = [] new_items = []
for style_name in style_list.get_style_names(): for style_name in style_list.get_style_names():

View File

@ -588,8 +588,8 @@ class ReportDialog(ManagedWindow):
style sheet editor object and let them play. When they are style sheet editor object and let them play. When they are
done, the previous routine will be called to update the dialog done, the previous routine will be called to update the dialog
menu for selecting a style.""" menu for selecting a style."""
StyleListDisplay(self.style_sheet_list, self.build_style_menu, StyleListDisplay(self.style_sheet_list, self.uistate, self.track,
self.window) callback=self.build_style_menu)
#---------------------------------------------------------------------- #----------------------------------------------------------------------
# #

View File

@ -55,63 +55,73 @@ from gramps.gen.plug.docgen import (StyleSheet, FONT_SERIF, FONT_SANS_SERIF,
PARA_ALIGN_JUSTIFY, ParagraphStyle, TableStyle, TableCellStyle, PARA_ALIGN_JUSTIFY, ParagraphStyle, TableStyle, TableCellStyle,
GraphicsStyle) GraphicsStyle)
from ...listmodel import ListModel from ...listmodel import ListModel
from ...managedwindow import set_titles from ...managedwindow import ManagedWindow
from ...glade import Glade from ...glade import Glade
from ...dialog import ErrorDialog
#------------------------------------------------------------------------ #------------------------------------------------------------------------
# #
# StyleListDisplay class # StyleListDisplay class
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
class StyleListDisplay: class StyleListDisplay(ManagedWindow):
""" """
Shows the available paragraph/font styles. Allows the user to select, Shows the available paragraph/font styles. Allows the user to select,
add, edit, and delete styles from a StyleSheet. add, edit, and delete styles from a StyleSheetList.
""" """
def __init__(self, stylesheetlist, callback, parent_window): def __init__(self, stylesheetlist, uistate, track, callback=None):
""" """
Create a StyleListDisplay object that displays the styles in the Create a StyleListDisplay object that displays the styles in the
StyleSheet. StyleSheetList.
stylesheetlist - styles that can be editied stylesheetlist - styles for editing: a :class:`.StyleSheetList` instance
callback - task called with an object has been added. callback - task called when an object has been added.
""" """
ManagedWindow.__init__(self, uistate, track, self.__class__, modal=True)
# the self.window.run() below makes Gtk make it modal, so any change
# to the previous line's "modal" would require that line to be changed
self.callback = callback self.callback = callback
self.sheetlist = stylesheetlist self.sheetlist = stylesheetlist
self.parent_window = parent_window
self.top = Glade(toplevel='styles') self.top = Glade(toplevel='styles')
self.window = self.top.toplevel self.set_window(self.top.toplevel, self.top.get_object('title'),
_('Document Styles'))
set_titles(self.window, self.top.get_object('title'), self.setup_configs('interface.stylelistdisplay', 400, 300)
_('Document Styles')) self.show()
self.top.connect_signals({ self.top.connect_signals({
"destroy_passed_object" : self.__close,
"on_ok_clicked" : self.on_ok_clicked, "on_ok_clicked" : self.on_ok_clicked,
"on_add_clicked" : self.on_add_clicked, "on_add_clicked" : self.on_add_clicked,
"on_delete_clicked" : self.on_delete_clicked, "on_delete_clicked" : self.on_delete_clicked,
"on_button_press" : self.on_button_press, "on_button_press" : self.on_button_press,
"on_edit_clicked" : self.on_edit_clicked, "on_edit_clicked" : self.on_edit_clicked,
"on_cancel_clicked" : self.__cancel,
"on_cancel_style_clicked" : dummy_callback,
"on_save_style_clicked" : dummy_callback, "on_save_style_clicked" : dummy_callback,
}) })
self.list = ListModel(self.top.get_object("list"), self.list = ListModel(self.top.get_object("list"),
[(_('Style'), -1, 10)], ) [(_('Style'), -1, 10)], )
self.redraw() self.redraw()
if parent_window: # the self.window.run() makes Gtk make it modal, so any change to that
self.window.set_transient_for(parent_window) # line would require the ManagedWindow.__init__ to be changed also
self.window.run() self.window.run()
self.window.destroy() if self.opened:
self.close()
def __close(self, obj): def build_menu_names(self, obj): # meaningless while it's modal
self.top.destroy() """Override :class:`.ManagedWindow` method."""
return (_('Document Styles'), ' ')
def __cancel(self, obj):
pass
def redraw(self): def redraw(self):
"""Redraws the list of styles that are current available""" """Redraws the list of styles that are currently available"""
self.list.model.clear() self.list.model.clear()
self.list.add([_("default")]) self.list.add([_("default")])
@ -124,22 +134,21 @@ class StyleListDisplay:
index += 1 index += 1
def on_add_clicked(self, obj): def on_add_clicked(self, obj):
"""Called with the ADD button is clicked. Invokes the StyleEditor to """Called when the ADD button is clicked. Invokes the StyleEditor to
create a new style""" create a new style"""
style = self.sheetlist.get_style_sheet("default") style = self.sheetlist.get_style_sheet("default")
StyleEditor(_("New Style"), style, self) StyleEditor(_("New Style"), style, self)
def on_ok_clicked(self, obj): def on_ok_clicked(self, obj):
"""Called with the OK button is clicked; Calls the callback task, """Called when the OK button is clicked; Calls the callback task,
then saves the stylesheet.""" then saves the stylesheet."""
if self.callback is not None: if self.callback is not None:
self.callback() self.callback()
try: try:
self.sheetlist.save() self.sheetlist.save()
except IOError as msg: except IOError as msg:
from ...dialog import ErrorDialog
ErrorDialog(_("Error saving stylesheet"), str(msg), ErrorDialog(_("Error saving stylesheet"), str(msg),
parent=self.parent_window) parent=self.window)
except: except:
log.error("Failed to save stylesheet", exc_info=True) log.error("Failed to save stylesheet", exc_info=True)
@ -149,11 +158,13 @@ class StyleListDisplay:
def on_edit_clicked(self, obj): def on_edit_clicked(self, obj):
""" """
Called with the EDIT button is clicked. Called when the EDIT button is clicked.
Calls the StyleEditor to edit the selected style. Calls the StyleEditor to edit the selected style.
""" """
store, node = self.list.selection.get_selected() store, node = self.list.selection.get_selected()
if not node: if not node:
ErrorDialog(_("Missing information"), _("Select a style"),
parent=self.window)
return return
name = str(self.list.model.get_value(node, 0)) name = str(self.list.model.get_value(node, 0))
@ -166,6 +177,8 @@ class StyleListDisplay:
"""Deletes the selected style.""" """Deletes the selected style."""
store, node = self.list.selection.get_selected() store, node = self.list.selection.get_selected()
if not node: if not node:
ErrorDialog(_("Missing information"), _("Select a style"),
parent=self.window)
return return
name = str(self.list.model.get_value(node, 0)) name = str(self.list.model.get_value(node, 0))
if name == _('default'): # the default style cannot be removed if name == _('default'): # the default style cannot be removed
@ -178,7 +191,7 @@ class StyleListDisplay:
# StyleEditor class # StyleEditor class
# #
#------------------------------------------------------------------------ #------------------------------------------------------------------------
class StyleEditor: class StyleEditor(ManagedWindow):
""" """
Edits the current style definition. Presents a dialog allowing the values Edits the current style definition. Presents a dialog allowing the values
of the paragraphs in the style to be altered. of the paragraphs in the style to be altered.
@ -189,20 +202,30 @@ class StyleEditor:
Create the StyleEditor. Create the StyleEditor.
name - name of the style that is to be edited name - name of the style that is to be edited
style - style object that is to be edited style - style object to be edited: a :class:`.StyleSheet` instance
parent - StyleListDisplay object that called the editor parent - StyleListDisplay object that called the editor
""" """
ManagedWindow.__init__(self, parent.uistate, parent.track,
self.__class__, modal=True)
# the self.window.run() below makes Gtk make it modal, so any change
# to the previous line's "modal" would require that line to be changed
self.current_style = None self.current_style = None
self.current_name = None self.current_name = None
self.style = StyleSheet(style) self.style = StyleSheet(style)
self.parent = parent self.parent = parent
self.top = Glade(toplevel='editor') self.top = Glade(toplevel='editor')
self.window = self.top.toplevel self.set_window(self.top.toplevel, self.top.get_object('title'),
_('Style editor'))
self.setup_configs('interface.styleeditor', 550, 610)
self.show()
self.top.connect_signals({ self.top.connect_signals({
"on_save_style_clicked" : self.on_save_style_clicked, "on_save_style_clicked" : self.on_save_style_clicked,
"destroy_passed_object" : self.__close, "on_cancel_style_clicked" : self.__cancel,
"on_cancel_clicked" : dummy_callback,
"on_ok_clicked" : dummy_callback, "on_ok_clicked" : dummy_callback,
"on_add_clicked" : dummy_callback, "on_add_clicked" : dummy_callback,
"on_delete_clicked" : dummy_callback, "on_delete_clicked" : dummy_callback,
@ -226,8 +249,6 @@ class StyleEditor:
self.line_style.pack_start(renderer_text, True) self.line_style.pack_start(renderer_text, True)
self.line_style.add_attribute(renderer_text, "text", 1) self.line_style.add_attribute(renderer_text, "text", 1)
set_titles(self.window, self.top.get_object('title'),
_('Style editor'))
self.top.get_object("label6").set_text(_("point size|pt")) self.top.get_object("label6").set_text(_("point size|pt"))
titles = [(_('Style'), 0, 130)] titles = [(_('Style'), 0, 130)]
@ -261,13 +282,18 @@ class StyleEditor:
self.plist.add([d_name], self.style.get_draw_style(d_name)) self.plist.add([d_name], self.style.get_draw_style(d_name))
self.plist.select_row(0) self.plist.select_row(0)
if self.parent: # the self.window.run() makes Gtk make it modal, so any change to that
self.window.set_transient_for(parent.window) # line would require the ManagedWindow.__init__ to be changed also
self.window.run() self.window.run()
self.window.destroy() if self.opened:
self.close()
def __close(self, obj): def build_menu_names(self, obj): # meaningless while it's modal
self.window.destroy() """Override :class:`.ManagedWindow` method."""
return (_('Style editor'), None)
def __cancel(self, obj):
pass
def show_pages(self, show_pages): def show_pages(self, show_pages):
""" """
@ -525,7 +551,6 @@ class StyleEditor:
self.style.set_name(name) self.style.set_name(name)
self.parent.sheetlist.set_style_sheet(name, self.style) self.parent.sheetlist.set_style_sheet(name, self.style)
self.parent.redraw() self.parent.redraw()
self.window.destroy()
def change_display(self, obj): def change_display(self, obj):
""" """