From ded3b12080229c0a98f3ddce796846c225fbb05f Mon Sep 17 00:00:00 2001 From: Benny Malengier Date: Tue, 7 May 2013 12:37:00 +0000 Subject: [PATCH] 6659: Justified paragraph layout does not work in "Custom Book Text" in book report svn: r22191 --- gramps/gui/plug/_guioptions.py | 1 + gramps/gui/plug/report/_bookdialog.py | 38 +++++++++++++++++++-- gramps/gui/plug/report/_reportdialog.py | 23 ++++++++++--- gramps/plugins/textreport/custombooktext.py | 18 +++++----- 4 files changed, 64 insertions(+), 16 deletions(-) diff --git a/gramps/gui/plug/_guioptions.py b/gramps/gui/plug/_guioptions.py index 228c7cb5b..35a56a7f7 100644 --- a/gramps/gui/plug/_guioptions.py +++ b/gramps/gui/plug/_guioptions.py @@ -366,6 +366,7 @@ class GuiTextOption(Gtk.ScrolledWindow): gtext.set_size_request(-1, 70) gtext.get_buffer().set_text("\n".join(value)) gtext.set_editable(1) + gtext.set_wrap_mode(Gtk.WrapMode.WORD_CHAR) self.add(gtext) self.__buff = gtext.get_buffer() diff --git a/gramps/gui/plug/report/_bookdialog.py b/gramps/gui/plug/report/_bookdialog.py index e6b0e7763..4a355e3e9 100644 --- a/gramps/gui/plug/report/_bookdialog.py +++ b/gramps/gui/plug/report/_bookdialog.py @@ -88,6 +88,8 @@ from gramps.gen.display.name import displayer as _nd #------------------------------------------------------------------------ _UNSUPPORTED = _("Unsupported") +_RETURN = Gdk.keyval_from_name("Return") +_KP_ENTER = Gdk.keyval_from_name("KP_Enter") #------------------------------------------------------------------------ # # Private Functions @@ -239,8 +241,10 @@ class BookListDisplay(object): "on_save_clicked" : self.do_nothing, "on_clear_clicked" : self.do_nothing }) - - self.blist = ListModel(self.xml.get_object("list"), [('Name',-1,10)],) + self.guilistbooks = self.xml.get_object('list') + self.guilistbooks.connect('button-press-event', self.on_button_press) + self.guilistbooks.connect('key-press-event', self.on_key_pressed) + self.blist = ListModel(self.guilistbooks, [('Name',-1,10)],) self.redraw() self.selection = None @@ -294,7 +298,35 @@ class BookListDisplay(object): return else: self.top.run() - + + def on_button_press(self, obj, event): + """ + Checks for a double click event. In the list, we want to + treat a double click as if it was OK button press. + """ + if event.type == Gdk.EventType._2BUTTON_PRESS and event.button == 1: + store, the_iter = self.blist.get_selected() + if not the_iter: + return False + self.on_booklist_ok_clicked(obj) + #emit OK response on dialog to close it automatically + self.top.response(-5) + return True + return False + + def on_key_pressed(self, obj, event): + """ + Handles the return key being pressed on list. If the key is pressed, + the Edit button handler is called + """ + if event.type == Gdk.EventType.KEY_PRESS: + if event.keyval in (_RETURN, _KP_ENTER): + self.on_booklist_ok_clicked(obj) + #emit OK response on dialog to close it automatically + self.top.response(-5) + return True + return False + def do_nothing(self, object): pass diff --git a/gramps/gui/plug/report/_reportdialog.py b/gramps/gui/plug/report/_reportdialog.py index a36ff1d49..24a521c90 100644 --- a/gramps/gui/plug/report/_reportdialog.py +++ b/gramps/gui/plug/report/_reportdialog.py @@ -194,13 +194,23 @@ class ReportDialog(ManagedWindow): self.notebook = Gtk.Notebook() self.notebook.set_scrollable(True) self.notebook.set_border_width(6) - self.window.vbox.add(self.notebook) + try: + #assume a vbox or hbox + self.window.vbox.pack_start(self.notebook, expand=True, fill=True, padding=0) + except: + #general container instead: + self.window.vbox.add(self.notebook) self.setup_report_options_frame() self.setup_other_frames() self.notebook.set_current_page(0) - self.window.vbox.add(self.tbl) + try: + #assume a vbox or hbox + self.window.vbox.pack_start(self.tbl, expand=True, fill=True, padding=0) + except: + #general container instead: + self.window.vbox.add(self.tbl) self.show() def get_title(self): @@ -293,7 +303,7 @@ class ReportDialog(ManagedWindow): label = Gtk.Label(label='%s' % self.report_name) label.set_use_markup(True) - self.window.vbox.pack_start(label, True, True, self.border_pad) + self.window.vbox.pack_start(label, False, False, self.border_pad) def setup_style_frame(self): """Set up the style frame of the dialog. This function relies @@ -376,6 +386,7 @@ class ReportDialog(ManagedWindow): row += 1 def setup_other_frames(self): + from gramps.gui.plug._guioptions import GuiTextOption for key in self.frame_names: flist = self.frames[key] table = Gtk.Table(3, len(flist)) @@ -393,7 +404,11 @@ class ReportDialog(ManagedWindow): text_widget.set_alignment(0.0, 0.5) table.attach(text_widget, 1, 2, row, row+1, Gtk.AttachOptions.SHRINK|Gtk.AttachOptions.FILL, Gtk.AttachOptions.SHRINK) - table.attach(widget, 2, 3, row, row+1, + if isinstance(widget, GuiTextOption): + table.attach(widget, 2, 3, row, row+1, + yoptions=Gtk.AttachOptions.EXPAND|Gtk.AttachOptions.FILL) + else: + table.attach(widget, 2, 3, row, row+1, yoptions=Gtk.AttachOptions.SHRINK) else: table.attach(widget, 2, 3, row, row+1, diff --git a/gramps/plugins/textreport/custombooktext.py b/gramps/plugins/textreport/custombooktext.py index 1df27f8da..5e5ca5654 100644 --- a/gramps/plugins/textreport/custombooktext.py +++ b/gramps/plugins/textreport/custombooktext.py @@ -128,41 +128,41 @@ class CustomTextOptions(MenuReportOptions): top = TextOption(_("Initial Text"), [""] ) top.set_help(_("Text to display at the top.")) - menu.add_option(category_name,"top",top) + menu.add_option(category_name, "top", top) mid = TextOption(_("Middle Text"), [""] ) mid.set_help(_("Text to display in the middle")) - menu.add_option(category_name,"mid",mid) + menu.add_option(category_name, "mid", mid) bot = TextOption(_("Final Text"), [""] ) bot.set_help(_("Text to display last.")) - menu.add_option(category_name,"bot",bot) + menu.add_option(category_name, "bot", bot) def make_default_style(self,default_style): """Make the default output style for the Custom Text report.""" font = FontStyle() - font.set(face=FONT_SANS_SERIF,size=12,bold=0,italic=0) + font.set(face=FONT_SANS_SERIF, size=12, bold=0, italic=0) para = ParagraphStyle() para.set_font(font) para.set_alignment(PARA_ALIGN_CENTER) para.set(pad=0.5) para.set_description(_('The style used for the first portion of the custom text.')) - default_style.add_paragraph_style("CBT-Initial",para) + default_style.add_paragraph_style("CBT-Initial", para) font = FontStyle() - font.set(face=FONT_SANS_SERIF,size=12,bold=0,italic=0) + font.set(face=FONT_SANS_SERIF, size=12, bold=0, italic=0) para = ParagraphStyle() para.set_font(font) para.set(pad=0.5) para.set_alignment(PARA_ALIGN_CENTER) para.set_description(_('The style used for the middle portion of the custom text.')) - default_style.add_paragraph_style("CBT-Middle",para) + default_style.add_paragraph_style("CBT-Middle", para) font = FontStyle() - font.set(face=FONT_SANS_SERIF,size=12,bold=0,italic=0) + font.set(face=FONT_SANS_SERIF, size=12, bold=0, italic=0) para = ParagraphStyle() para.set_font(font) para.set_alignment(PARA_ALIGN_CENTER) para.set(pad=0.5) para.set_description(_('The style used for the last portion of the custom text.')) - default_style.add_paragraph_style("CBT-Final",para) + default_style.add_paragraph_style("CBT-Final", para)