From c2de30e2de115619ef65c43f7fd1ec12c8552876 Mon Sep 17 00:00:00 2001 From: Nick Hall Date: Mon, 4 Jun 2012 22:49:01 +0000 Subject: [PATCH] GEPS008: Remove deprecated Assistant class svn: r19757 --- src/Assistant.py | 352 ---------------- src/gui/logger/_errorreportassistant.py | 526 ++++++++++++++---------- src/plugins/tool/MediaManager.py | 428 +++++++++++-------- 3 files changed, 573 insertions(+), 733 deletions(-) delete mode 100644 src/Assistant.py diff --git a/src/Assistant.py b/src/Assistant.py deleted file mode 100644 index 78580d571..000000000 --- a/src/Assistant.py +++ /dev/null @@ -1,352 +0,0 @@ -# -# Gramps - a GTK+/GNOME based genealogy program -# -# Copyright (C) 2000-2006 Donald N. Allingham -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -# - -# $Id$ - -#------------------------------------------------------------------------- -# -# Standard python modules -# -#------------------------------------------------------------------------- -from gen.ggettext import gettext as _ -import os - -#------------------------------------------------------------------------- -# -# GTK modules -# -#------------------------------------------------------------------------- -import gtk -import gobject - -#------------------------------------------------------------------------- -# -# Gramps modules -# -#------------------------------------------------------------------------- -import const -import ManagedWindow - -#------------------------------------------------------------------------- -# -# Constants -# -#------------------------------------------------------------------------- -_gramps_png = os.path.join(const.IMAGE_DIR, "gramps.png") -_splash_jpg = os.path.join(const.IMAGE_DIR, "splash.jpg") -_format = '%s' - -#------------------------------------------------------------------------- -# -# Assistant class -# -#------------------------------------------------------------------------- -class Assistant(gtk.Object, ManagedWindow.ManagedWindow): - """ A tabbed dialog box used to implement Assistant interfaces. - Deprecated. Please use gtk.Assistant class from now on. - See eg. example use in ExportAssistant - """ - - __gproperties__ = {} - - __gsignals__ = { - 'page-changed' : (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, - (gobject.TYPE_INT, )), - 'before-page-next' : (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, - (gobject.TYPE_INT, )), - 'after-page-next' : (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, - (gobject.TYPE_INT, )), - 'before-page-back' : (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, - (gobject.TYPE_INT, )), - 'after-page-back' : (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, - (gobject.TYPE_INT, )), - 'complete' : (gobject.SIGNAL_RUN_LAST, - gobject.TYPE_NONE, - ()) - } - - def __init__(self, uistate, parent_class, complete, top_title=''): - gobject.GObject.__init__(self) - - self.top_title = top_title - if uistate: - ManagedWindow.ManagedWindow.__init__(self, uistate, [], - parent_class) - else: - self.uistate = None - - self.complete = complete - self.fg_color = gtk.gdk.color_parse('#7d684a') - self.bg_color = gtk.gdk.color_parse('#e1dbc5') - self.logo = gtk.gdk.pixbuf_new_from_file(_gramps_png) - self.splash = gtk.gdk.pixbuf_new_from_file(_splash_jpg) - - self.current_page = -1 - - if uistate: - self.set_window(gtk.Window(), None, self.top_title) - else: - self.window = gtk.Window() - self.close = self.destroy - - titlebox = gtk.HBox() - self.title_text = [] - - self.title = gtk.Label('') - self.title.set_alignment(0, 0.5) - self.title.set_use_markup(True) - - titlebox.pack_start(self.title, True) - image = gtk.Image() - image.set_from_file(_gramps_png) - titlebox.pack_end(image, False) - - self.notebook = gtk.Notebook() - self.notebook.set_show_border(False) - self.notebook.set_show_tabs(False) - - vbox = gtk.VBox(spacing=6) - vbox.set_border_width(6) - hbox = gtk.HButtonBox() - hbox.set_spacing(6) - hbox.set_layout(gtk.BUTTONBOX_END) - - self.cancel = gtk.Button(stock=gtk.STOCK_CANCEL) - self.cancel.connect('clicked', self.close) - self.back = gtk.Button(stock=gtk.STOCK_GO_BACK) - self.back.set_sensitive(False) - self.back.connect('clicked', self.back_clicked) - self.next = gtk.Button(stock=gtk.STOCK_GO_FORWARD) - self.next.connect('clicked', self.next_clicked) - self.ok = gtk.Button(stock=gtk.STOCK_OK) - self.ok.connect('clicked', self.next_clicked) - self.ok.set_sensitive(False) - - hbox.add(self.cancel) - hbox.add(self.back) - hbox.add(self.next) - hbox.add(self.ok) - - vbox.pack_start(titlebox, False) - vbox.pack_start(self.notebook, True) - vbox.pack_start(hbox, False) - - self.window.add(vbox) - - def build_menu_names(self, obj): - return (self.top_title, None) - - def set_busy_cursor(self, value): - if value: - self.window.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH)) - self.window.set_sensitive(0) - else: - self.window.window.set_cursor(None) - self.window.set_sensitive(1) - - while gtk.events_pending(): - gtk.main_iteration() - - def destroy(self, *obj): - self.window.emit('delete-event', None) - self.window.destroy() - - def do_get_property(self, prop): - """Return the gproperty's value.""" - raise AttributeError, 'unknown property %s' % prop.name - - def do_set_property(self, prop, value): - """Set the property of writable properties.""" - raise AttributeError, 'unknown or read only property %s' % prop.name - - def get_number_of_pages(self): - return self.notebook.get_n_pages() - - def update_title(self): - self.title.set_label(self.title_text[self.current_page]) - self.title.set_use_markup(True) - - def set_buttons(self): - max_page = self.notebook.get_n_pages() - if self.current_page == max_page-2: - self.next.show() - self.back.show() - self.cancel.show() - self.ok.set_sensitive(True) - self.next.set_sensitive(False) - self.back.set_sensitive(True) - elif self.current_page == max_page-1: - self.next.hide() - self.back.hide() - self.cancel.hide() - elif self.current_page == 0: - self.next.show() - self.back.show() - self.cancel.show() - self.back.set_sensitive(False) - self.next.set_sensitive(True) - self.ok.set_sensitive(False) - else: - self.next.show() - self.back.show() - self.back.set_sensitive(True) - self.next.set_sensitive(True) - self.ok.set_sensitive(False) - self.cancel.show() - - def back_clicked(self, obj): - self.emit('before-page-back', self.notebook.get_current_page()) - self.current_page -= 1 - self.notebook.set_current_page(self.current_page) - self.update_title() - self.set_buttons() - - self.emit('after-page-back', self.notebook.get_current_page()) - self.emit('page-changed', self.notebook.get_current_page()) - - def next_clicked(self, obj): - self.emit('before-page-next', self.notebook.get_current_page()) - if self.current_page == self.notebook.get_n_pages()-1: - self.emit('complete') - self.complete() - self.close() - else: - self.current_page += 1 - self.notebook.set_current_page(self.current_page) - self.update_title() - self.set_buttons() - - self.emit('after-page-next', self.notebook.get_current_page()) - self.emit('page-changed', self.notebook.get_current_page()) - - def add_text_page(self, title, text): - """ - Add page with Gramps logo and given text and title. - Usually, first page (introduction) and last page (conclusion) - use this method. - """ - hbox = self.prepare_text_page(text) - return self.add_page(title, hbox) - - def insert_text_page(self, title, text, position): - """ - Add page with Gramps logo and given text and title. - Usually, first page (introduction) and last page (conclusion) - use this method. - """ - hbox = self.prepare_text_page(text) - return self.insert_page(title, hbox, position) - - def prepare_text_page(self, text): - hbox = gtk.HBox(spacing=12) - image = gtk.Image() - image.set_from_file(_splash_jpg) - hbox.pack_start(image, False) - label = gtk.Label(text) - label.set_line_wrap(True) - label.set_use_markup(True) - hbox.add(label) - hbox.show_all() - return hbox - - def add_page(self, title, child): - """ - Add page with the title and child widget. - Return index number of the new page. - """ - self.title_text.append(_format % title) - return self.notebook.append_page(child) - - def insert_page(self, title, child, position): - """ - Insert page at a given position. - Returns index number of the new page. - """ - self.title_text.insert(position, _format % title) - return self.notebook.insert_page(child, None, position) - - def remove_page(self, position): - """ - Remove page from a given position. - """ - self.title_text.pop(position) - self.notebook.remove_page(position) - - def show(self): - self.window.show_all() - self.current_page = 0 - self.notebook.set_current_page(self.current_page) - self.update_title() - self.set_buttons() - self.emit('page-changed', self.notebook.get_current_page()) - if self.uistate: - ManagedWindow.ManagedWindow.show(self) - -if gtk.pygtk_version < (2, 8, 0): - gobject.type_register(Assistant) - -if __name__ == "__main__": - - def complete(): - gtk.main_quit() - - def make_label(table, val, y, x1, x2, x3, x4): - label = gtk.Label(val) - label.set_alignment(0, 0.5) - text = gtk.Entry() - table.attach(label, x1, x2, y, y+1, gtk.SHRINK|gtk.FILL) - table.attach(text, x3, x4, y, y+1, gtk.EXPAND|gtk.FILL) - return text - - a = Assistant(complete) - a.add_text_page('Getting started', - 'Welcome to Gramps, the Genealogical Research ' - 'and Analysis Management Programming System.\n' - 'Several options and information need to be gathered ' - 'before Gramps is ready to be used. Any of this ' - 'information can be changed in the future in the ' - 'Preferences dialog under the Settings menu.') - - box = gtk.VBox() - box.set_spacing(12) - table = gtk.Table(8, 4) - table.set_row_spacings(6) - table.set_col_spacings(6) - - make_label(table, _('Name:'), 0, 0, 1, 1, 4) - make_label(table, _('Address:'), 1, 0, 1, 1, 4) - make_label(table, _('City:'), 2, 0, 1, 1, 2) - make_label(table, _('State/Province:'), 2, 2, 3, 3, 4) - make_label(table, _('Country:'), 3, 0, 1, 1, 2) - make_label(table, _('ZIP/Postal code:'), 3, 2, 3, 3, 4) - make_label(table, _('Phone:'), 4, 0, 1, 1, 4) - make_label(table, _('Email:'), 5, 0, 1, 1, 4) - box.add(table) - a.add_page('Researcher information', box) - - a.add_text_page('Conclusion title', 'Very long conclusion text here') - a.show() - - gtk.main() diff --git a/src/gui/logger/_errorreportassistant.py b/src/gui/logger/_errorreportassistant.py index 1fbb3d0b9..3b5272489 100644 --- a/src/gui/logger/_errorreportassistant.py +++ b/src/gui/logger/_errorreportassistant.py @@ -2,6 +2,7 @@ # Gramps - a GTK+/GNOME based genealogy program # # Copyright (C) 2000-2007 Donald N. Allingham +# Copyright (C) 2012 Nick Hall # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -20,11 +21,13 @@ # $Id$ +#------------------------------------------------------------------------- +# +# Python modules +# +#------------------------------------------------------------------------- from gen.ggettext import gettext as _ -import Assistant -import const import gtk -import pygtk import gobject import cairo import sys, os @@ -34,10 +37,36 @@ if config.get('preferences.use-bsddb3'): import bsddb3 as bsddb else: import bsddb + +#------------------------------------------------------------------------- +# +# Gramps modules +# +#------------------------------------------------------------------------- +import const +import GrampsDisplay -class ErrorReportAssistant(object): +#------------------------------------------------------------------------- +# +# Constants +# +#------------------------------------------------------------------------- +GRAMPS_PNG = os.path.join(const.IMAGE_DIR, "gramps.png") +SPLASH_JPG = os.path.join(const.IMAGE_DIR, "splash.jpg") + +#------------------------------------------------------------------------- +# +# ErrorReportAssistant +# +#------------------------------------------------------------------------- +class ErrorReportAssistant(gtk.Assistant): + """ + Give the user an opportunity to report an error on the Gramps bug + reporting system. + """ + def __init__(self, error_detail, rotate_handler, ownthread=False): + gtk.Assistant.__init__(self) - def __init__(self,error_detail,rotate_handler, ownthread=False): self._error_detail = error_detail self._rotate_handler = rotate_handler @@ -45,64 +74,48 @@ class ErrorReportAssistant(object): self._user_information_text_buffer = None self._error_details_text_buffer = None self._final_report_text_buffer = None - - self.w = Assistant.Assistant(None,None,self.complete) - #connect our extra close to close by x, and close by cancel click - self.w.window.connect('delete-event', self.close) - self.w.cancel.connect('clicked', self.close) - self.w.add_text_page( - _('Report a bug'), - _("This is the Bug Reporting Assistant. It will "\ - "help you to make a bug report to the Gramps "\ - "developers that will be as detailed as possible.\n\n"\ - "The assistant will ask you a few questions and will "\ - "gather some information about the error that has "\ - "occured and the operating environment. "\ - "At the end of the assistant you will be asked to "\ - "file a bug report on the Gramps bug tracking system. "\ - "The assistant will place the bug report on the clip board so "\ - "that you can paste it into the form on the bug tracking "\ - "website and review exactly what information you want to include.")) + self.logo = gtk.gdk.pixbuf_new_from_file(GRAMPS_PNG) + self.splash = gtk.gdk.pixbuf_new_from_file(SPLASH_JPG) + self.set_title(_("Error Report Assistant")) + self.connect('close', self.close) + self.connect('cancel', self.close) + self.connect('prepare', self.prepare) - self.w.add_page(_("Report a bug: Step 1 of 5"), self.build_page1()) - self.w.add_page(_("Report a bug: Step 2 of 5"), self.build_page2()) - self.w.add_page(_("Report a bug: Step 3 of 5"), self.build_page3()) - - page4 = self.build_page4() - self.w.add_page(_("Report a bug: Step 4 of 5"), page4) - self.cb = {4:self.page4_update} - self.w.add_page(_("Report a bug: Step 5 of 5"), self.build_page5()) + #create the assistant pages + self.create_page_intro() + self.build_page1() + self.build_page2() + self.build_page3() + self.build_page4() + self.build_page5() + self.create_page_summary() + self.show_all() - self.w.add_text_page( - _('Complete'), - _('Gramps is an Open Source project. Its success ' - 'depends on its users. User feedback is important. ' - 'Thank you for taking the time to submit a bug report.')) - - self.w.connect('page-changed',self.on_page_changed) - - self.w.show() - self.ownthread = ownthread if self.ownthread: gtk.main() def close(self, *obj): + """ + Close the assistant. + """ + self.hide() if self.ownthread: gtk.main_quit() - - def on_page_changed(self, obj,page,data=None): - if page in self.cb: - self.cb[page]() - - def complete(self): - if self.ownthread: - #stop the thread we started - gtk.main_quit() + + def prepare(self, assistant, page): + """ + Prepare pages prior to display. + """ + self.page4_update() + self.set_page_complete(page, True) def _copy_to_clipboard(self, obj=None): + """ + Copy the bug report to the clipboard. + """ clipboard = gtk.Clipboard() clipboard.set_text( self._final_report_text_buffer.get_text( @@ -116,7 +129,9 @@ class ErrorReportAssistant(object): self._final_report_text_buffer.get_end_iter())) def _start_email_client(self, obj=None): - import GrampsDisplay + """ + Start an email client to send the report. + """ GrampsDisplay.url('mailto:gramps-bugs@lists.sourceforge.net?subject=' '"bug report"&body="%s"' \ % self._final_report_text_buffer.get_text( @@ -124,10 +139,15 @@ class ErrorReportAssistant(object): self._final_report_text_buffer.get_end_iter())) def _start_gramps_bts_in_browser(self, obj=None): - import GrampsDisplay + """ + Start a web browser to report the bug. + """ GrampsDisplay.url('http://bugs.gramps-project.org/bug_report_page.php') def _get_sys_information(self): + """ + Get relevant system information. + """ if hasattr(os, "uname"): operatingsystem = os.uname()[0] distribution = os.uname()[2] @@ -156,74 +176,132 @@ class ErrorReportAssistant(object): gobject.pygobject_version, cairo.version_info) - def _reset_error_details_text_buffer(self, obj=None): + def _reset_error_details(self, obj=None): + """ + Reset the error details buffer to its original contents. + """ self._error_details_text_buffer.set_text( "\n".join(self._rotate_handler.get_formatted_log( self._error_detail.get_record())) + self._error_detail.get_formatted_log()) - def _clear_error_details_text_buffer(self, obj=None): + def _clear_error_details(self, obj=None): + """ + Clear the error details buffer. + """ self._error_details_text_buffer.delete( self._error_details_text_buffer.get_start_iter(), self._error_details_text_buffer.get_end_iter()) - def _reset_sys_information_text_buffer(self, obj=None): + def _reset_sys_information(self, obj=None): + """ + Reset the system information buffer to its original contents. + """ self._sys_information_text_buffer.set_text( self._get_sys_information()) - def _clear_sys_information_text_buffer(self, obj=None): + def _clear_sys_information(self, obj=None): + """ + Clear the system information buffer. + """ self._sys_information_text_buffer.delete( self._sys_information_text_buffer.get_start_iter(), self._sys_information_text_buffer.get_end_iter()) - def _clear_user_information_text_buffer(self, obj=None): + def _clear_user_information(self, obj=None): + """ + Clear the user information buffer. + """ self._user_information_text_buffer.delete( self._user_information_text_buffer.get_start_iter(), self._user_information_text_buffer.get_end_iter()) + def create_page_intro(self): + """ + Create the introduction page. + """ + label = gtk.Label(self.get_intro_text()) + label.set_line_wrap(True) + + # Using set_page_side_image causes window sizing problems, so put the + # image in the main page instead. + image = gtk.Image() + image.set_from_file(SPLASH_JPG) + + hbox = gtk.HBox() + hbox.pack_start(image, False, False, 0) + hbox.pack_start(label, True, True, 0) + + page = hbox + + page.show_all() + self.append_page(page) + self.set_page_header_image(page, self.logo) + #self.set_page_side_image(page, self.splash) + self.set_page_title(page, _('Report a bug')) + self.set_page_type(page, gtk.ASSISTANT_PAGE_INTRO) + + def get_intro_text(self): + """ + Return the text of the introduction page. + """ + return _("This is the Bug Reporting Assistant. It will " + "help you to make a bug report to the Gramps " + "developers that will be as detailed as possible.\n\n" + "The assistant will ask you a few questions and will " + "gather some information about the error that has " + "occured and the operating environment. " + "At the end of the assistant you will be asked to " + "file a bug report on the Gramps bug tracking system. " + "The assistant will place the bug report on the clip board so " + "that you can paste it into the form on the bug tracking " + "website and review exactly what information you want to " + "include.") def build_page1(self): - label = gtk.Label(_("If you can see that there is any personal "\ - "information included in the error please remove it.")) - label.set_alignment(0.01,0.5) + """ + Build the error details page. + """ + label = gtk.Label(_("If you can see that there is any personal " + "information included in the error please remove " + "it.")) + label.set_alignment(0.01, 0.5) label.set_padding(0, 4) label.set_line_wrap(True) - sw = gtk.ScrolledWindow() - sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + swin = gtk.ScrolledWindow() + swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) textview = gtk.TextView() self._error_details_text_buffer = textview.get_buffer() - self._reset_error_details_text_buffer() + self._reset_error_details() - sw.add(textview) - sw.show() - textview.show() + swin.add(textview) sw_frame = gtk.Frame() - sw_frame.add(sw) + sw_frame.add(swin) reset = gtk.Button("Reset") - reset.connect('clicked', self._reset_error_details_text_buffer) + reset.connect('clicked', self._reset_error_details) clear = gtk.Button("Clear") - clear.connect('clicked', self._clear_error_details_text_buffer) + clear.connect('clicked', self._clear_error_details) button_box = gtk.HButtonBox() button_box.set_border_width(6) button_box.set_spacing(6) button_box.set_layout(gtk.BUTTONBOX_END) - button_box.pack_end(reset,False,False) - button_box.pack_end(clear,False,False) + button_box.pack_end(reset, False, False) + button_box.pack_end(clear, False, False) error_details_box = gtk.VBox() - error_details_box.pack_start(label,False,False) - error_details_box.pack_start(sw_frame,True,True) - error_details_box.pack_start(button_box,False,False) + error_details_box.pack_start(label, False, False) + error_details_box.pack_start(sw_frame, True, True) + error_details_box.pack_start(button_box, False, False) - error_details_align = gtk.Alignment(0,0,1,1) - error_details_align.set_padding(0,0,11,0) + error_details_align = gtk.Alignment(0, 0, 1, 1) + error_details_align.set_padding(0, 0, 11, 0) error_details_align.add(error_details_box) error_details_frame = gtk.Frame() @@ -233,50 +311,56 @@ class ErrorReportAssistant(object): error_details_frame.add(error_details_align) - side_label = gtk.Label(_("This is the detailed Gramps error information, don't worry if you "\ - "do not understand it. You "\ - "will have the opportunity to add further detail about the error "\ + side_label = gtk.Label(_("This is the detailed Gramps error " + "information, don't worry if you do not " + "understand it. You will have the opportunity " + "to add further detail about the error " "in the following pages of the assistant.")) side_label.set_line_wrap(True) side_label.set_size_request(124, -1) box = gtk.HBox() - - box.pack_start(side_label,False,False,5) - + box.pack_start(side_label, False, False, 5) box.pack_start(error_details_frame) - box.show_all() - return box + page = box + + page.show_all() + self.append_page(page) + self.set_page_header_image(page, self.logo) + self.set_page_title(page, _("Report a bug: Step 1 of 5")) + self.set_page_type(page, gtk.ASSISTANT_PAGE_CONTENT) def build_page2(self): - label = gtk.Label(_("Please check the information below and correct anything that "\ - "you know to be wrong or remove anything that you would rather not "\ - "have included in the bug report.")) - label.set_alignment(0.01,0.5) + """ + Build the system information page. + """ + label = gtk.Label(_("Please check the information below and correct " + "anything that you know to be wrong or remove " + "anything that you would rather not have included " + "in the bug report.")) + label.set_alignment(0.01, 0.5) label.set_padding(0, 4) label.set_line_wrap(True) - sw = gtk.ScrolledWindow() - sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + swin = gtk.ScrolledWindow() + swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) textview = gtk.TextView() self._sys_information_text_buffer = textview.get_buffer() - self._reset_sys_information_text_buffer() + self._reset_sys_information() - sw.add(textview) - sw.show() - textview.show() + swin.add(textview) sw_frame = gtk.Frame() - sw_frame.add(sw) + sw_frame.add(swin) reset = gtk.Button("Reset") - reset.connect('clicked', self._reset_sys_information_text_buffer) + reset.connect('clicked', self._reset_sys_information) clear = gtk.Button("Clear") - clear.connect('clicked', self._clear_sys_information_text_buffer) + clear.connect('clicked', self._clear_sys_information) button_box = gtk.HButtonBox() @@ -284,16 +368,16 @@ class ErrorReportAssistant(object): button_box.set_spacing(6) button_box.set_layout(gtk.BUTTONBOX_END) - button_box.pack_end(reset,False,False) - button_box.pack_end(clear,False,False) + button_box.pack_end(reset, False, False) + button_box.pack_end(clear, False, False) sys_information_box = gtk.VBox() - sys_information_box.pack_start(label,False,False) - sys_information_box.pack_start(sw_frame,True,True) - sys_information_box.pack_start(button_box,False,False) + sys_information_box.pack_start(label, False, False) + sys_information_box.pack_start(sw_frame, True, True) + sys_information_box.pack_start(button_box, False, False) - sys_information_align = gtk.Alignment(0,0,1,1) - sys_information_align.set_padding(0,0,11,0) + sys_information_align = gtk.Alignment(0, 0, 1, 1) + sys_information_align.set_padding(0, 0, 11, 0) sys_information_align.add(sys_information_box) sys_information_frame = gtk.Frame() @@ -303,59 +387,65 @@ class ErrorReportAssistant(object): sys_information_frame.add(sys_information_align) - side_label = gtk.Label(_("This is the information about your system that "\ - "will help the developers to fix the bug.")) + side_label = gtk.Label(_("This is the information about your system " + "that will help the developers to fix the " + "bug.")) side_label.set_line_wrap(True) side_label.set_size_request(124, -1) box = gtk.HBox() - - box.pack_start(side_label,False,False,5) - + box.pack_start(side_label, False, False, 5) box.pack_start(sys_information_frame) - box.show_all() - return box + page = box + + page.show_all() + self.append_page(page) + self.set_page_header_image(page, self.logo) + self.set_page_title(page, _("Report a bug: Step 2 of 5")) + self.set_page_type(page, gtk.ASSISTANT_PAGE_CONTENT) def build_page3(self): - label = gtk.Label(_("Please provide as much information as you can "\ - "about what you were doing when the error occured. ")) - label.set_alignment(0.01,0.5) + """ + Build the further information page. + """ + label = gtk.Label(_("Please provide as much information as you can " + "about what you were doing when the error " + "occured.")) + label.set_alignment(0.01, 0.5) label.set_padding(0, 4) label.set_line_wrap(True) - sw = gtk.ScrolledWindow() - sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + swin = gtk.ScrolledWindow() + swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) textview = gtk.TextView() self._user_information_text_buffer = textview.get_buffer() - sw.add(textview) - sw.show() - textview.show() + swin.add(textview) sw_frame = gtk.Frame() - sw_frame.add(sw) + sw_frame.add(swin) clear = gtk.Button("Clear") - clear.connect('clicked',self._clear_user_information_text_buffer) + clear.connect('clicked', self._clear_user_information) button_box = gtk.HButtonBox() button_box.set_border_width(6) button_box.set_spacing(6) button_box.set_layout(gtk.BUTTONBOX_END) - button_box.pack_end(clear,False,False) + button_box.pack_end(clear, False, False) user_information_box = gtk.VBox() - user_information_box.pack_start(label,False,False) - user_information_box.pack_start(sw_frame,True,True) - user_information_box.pack_start(button_box,False,False) + user_information_box.pack_start(label, False, False) + user_information_box.pack_start(sw_frame, True, True) + user_information_box.pack_start(button_box, False, False) - user_information_align = gtk.Alignment(0,0,1,1) - user_information_align.set_padding(0,0,11,0) + user_information_align = gtk.Alignment(0, 0, 1, 1) + user_information_align.set_padding(0, 0, 11, 0) user_information_align.add(user_information_box) user_information_frame = gtk.Frame() @@ -365,33 +455,39 @@ class ErrorReportAssistant(object): user_information_frame.add(user_information_align) - side_label = gtk.Label(_("This is your opportunity to describe what you were "\ - "doing when the error occured.")) + side_label = gtk.Label(_("This is your opportunity to describe what " + "you were doing when the error occured.")) side_label.set_line_wrap(True) side_label.set_size_request(124, -1) box = gtk.HBox() - - box.pack_start(side_label,False,False,5) - + box.pack_start(side_label, False, False, 5) box.pack_start(user_information_frame) - box.show_all() - return box + page = box + page.show_all() + self.append_page(page) + self.set_page_header_image(page, self.logo) + self.set_page_title(page, _("Report a bug: Step 3 of 5")) + self.set_page_type(page, gtk.ASSISTANT_PAGE_CONTENT) def build_page4(self): - label = gtk.Label(_("Please check that the information is correct, do not worry if you "\ - "don't understand the detail of the error information. Just make sure "\ - "that it does not contain anything that you do not want to be sent "\ - "to the developers.")) - label.set_alignment(0.01,0.5) + """ + Build the bug report summary page. + """ + label = gtk.Label(_("Please check that the information is correct, " + "do not worry if you don't understand the detail " + "of the error information. Just make sure that it " + "does not contain anything that you do not want " + "to be sent to the developers.")) + label.set_alignment(0.01, 0.5) label.set_padding(0, 4) label.set_line_wrap(True) - sw = gtk.ScrolledWindow() - sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) + swin = gtk.ScrolledWindow() + swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) textview = gtk.TextView() textview.set_editable(False) @@ -399,19 +495,17 @@ class ErrorReportAssistant(object): self._final_report_text_buffer = textview.get_buffer() - sw.add(textview) - sw.show() - textview.show() + swin.add(textview) sw_frame = gtk.Frame() - sw_frame.add(sw) + sw_frame.add(swin) summary_box = gtk.VBox() - summary_box.pack_start(label,False,False) - summary_box.pack_start(sw_frame,True,True) + summary_box.pack_start(label, False, False) + summary_box.pack_start(sw_frame, True, True) - summary_align = gtk.Alignment(0,0,1,1) - summary_align.set_padding(0,0,11,0) + summary_align = gtk.Alignment(0, 0, 1, 1) + summary_align.set_padding(0, 0, 11, 0) summary_align.add(summary_box) summary_frame = gtk.Frame() @@ -421,98 +515,86 @@ class ErrorReportAssistant(object): summary_frame.add(summary_align) -# side_label = gtk.Label(_("This is the completed bug report. The next page "\ -# "of the assistant will help you to send the report "\ -# "to the bug report mailing list.")) - - side_label = gtk.Label(_("This is the completed bug report. The next page "\ - "of the assistant will help you to file a bug "\ - " on the Gramps bug tracking system website.")) + side_label = gtk.Label(_("This is the completed bug report. The next " + "page of the assistant will help you to file " + "a bug on the Gramps bug tracking system " + "website.")) side_label.set_line_wrap(True) side_label.set_size_request(124, -1) box = gtk.HBox() - - box.pack_start(side_label,False,False,5) - + box.pack_start(side_label, False, False, 5) box.pack_start(summary_frame) - box.show_all() - return box + page = box + + page.show_all() + self.append_page(page) + self.set_page_header_image(page, self.logo) + self.set_page_title(page, _("Report a bug: Step 4 of 5")) + self.set_page_type(page, gtk.ASSISTANT_PAGE_CONTENT) def build_page5(self): -# label = gtk.Label( -# "%s %s" % -# (_("Use one of the two methods below to send the "\ -# "bug report to the GRAMPS bug reporting mailing "\ -# "list at "), -# "gramps-bugs@lists.sourceforge.net.")) + """ + Build the send bug report page. + """ label = gtk.Label( "%s %s" % (_("Use the two buttons below to first copy the bug report to the " "clipboard and then open a webbrowser to file a bug report at "), "http://bugs.gramps-project.org/bug_report_page.php.")) - label.set_alignment(0.01,0.5) + label.set_alignment(0.01, 0.5) label.set_padding(0, 4) label.set_line_wrap(True) label.set_use_markup(True) -# url_label = gtk.Label(_("If your email client is configured correctly you may be able "\ -# "to use this button to start it with the bug report ready to send. "\ -# "(This will probably only work if you are running Gnome)")) url_label = gtk.Label(_("Use this button to start a web browser and " "file a bug report on the Gramps bug tracking " "system.")) - url_label.set_alignment(0.01,0.5) + url_label.set_alignment(0.01, 0.5) url_label.set_padding(0, 4) url_label.set_line_wrap(True) url_button = gtk.Button("File bug report") -# url_button = gtk.Button("Start email client") -# url_button.connect('clicked', self._start_email_client) url_button.connect('clicked', self._start_gramps_bts_in_browser) url_button_vbox = gtk.VBox() - url_button_vbox.pack_start(url_button,True,False) + url_button_vbox.pack_start(url_button, True, False) url_box = gtk.HBox() - url_box.pack_start(url_label,True,True) - url_box.pack_start(url_button_vbox,False,False) + url_box.pack_start(url_label, True, True) + url_box.pack_start(url_button_vbox, False, False) - url_align = gtk.Alignment(0,0,1,1) - url_align.set_padding(0,0,11,0) + url_align = gtk.Alignment(0, 0, 1, 1) + url_align.set_padding(0, 0, 11, 0) url_align.add(url_box) url_frame = gtk.Frame() url_frame.add(url_align) -# clip_label = gtk.Label(_("If your email program fails to start you can use this button " -# "to copy the bug report onto the clipboard. Then start your " -# "email client, paste the report and send it to the address " -# "above.")) clip_label = gtk.Label(_("Use this button " "to copy the bug report onto the clipboard. " "Then go to the bug tracking website by using " "the button below, paste the report and click " "submit report")) - clip_label.set_alignment(0.01,0.5) + clip_label.set_alignment(0.01, 0.5) clip_label.set_padding(0, 4) clip_label.set_line_wrap(True) clip_button = gtk.Button("Copy to clipboard") clip_button.connect('clicked', self._copy_to_clipboard) clip_button_vbox = gtk.VBox() - clip_button_vbox.pack_start(clip_button,True,False) + clip_button_vbox.pack_start(clip_button, True, False) clip_box = gtk.HBox() - clip_box.pack_start(clip_label,True,True) - clip_box.pack_start(clip_button_vbox,False,False) + clip_box.pack_start(clip_label, True, True) + clip_box.pack_start(clip_button_vbox, False, False) - clip_align = gtk.Alignment(0,0,1,1) - clip_align.set_padding(0,0,11,0) + clip_align = gtk.Alignment(0, 0, 1, 1) + clip_align.set_padding(0, 0, 11, 0) clip_align.add(clip_box) clip_frame = gtk.Frame() @@ -520,14 +602,12 @@ class ErrorReportAssistant(object): inner_box = gtk.VBox() - inner_box.pack_start(label,False,False) -# inner_box.pack_start(url_frame,False,False) -# inner_box.pack_start(clip_frame,False,False) - inner_box.pack_start(clip_frame,False,False) - inner_box.pack_start(url_frame,False,False) + inner_box.pack_start(label, False, False) + inner_box.pack_start(clip_frame, False, False) + inner_box.pack_start(url_frame, False, False) - inner_align = gtk.Alignment(0,0,1,1) - inner_align.set_padding(0,0,11,0) + inner_align = gtk.Alignment(0, 0, 1, 1) + inner_align.set_padding(0, 0, 11, 0) inner_align.add(inner_box) outer_frame = gtk.Frame() @@ -537,28 +617,58 @@ class ErrorReportAssistant(object): outer_frame.add(inner_align) -# side_label = gtk.Label(_("This is the final step. Use the buttons on this " -# "page to transfer the bug report to your email client.")) - - side_label = gtk.Label(_("This is the final step. Use the buttons on this " - "page to start a web browser and file a bug " - "report on the Gramps bug tracking system.")) + side_label = gtk.Label(_("This is the final step. Use the buttons on " + "this page to start a web browser and file a " + "bug report on the Gramps bug tracking " + "system.")) side_label.set_line_wrap(True) side_label.set_size_request(124, -1) box = gtk.HBox() - - box.pack_start(side_label,False,False,5) - + box.pack_start(side_label, False, False, 5) box.pack_start(outer_frame) - box.show_all() - return box + page = box + page.show_all() + self.append_page(page) + self.set_page_header_image(page, self.logo) + self.set_page_title(page, _("Report a bug: Step 5 of 5")) + self.set_page_type(page, gtk.ASSISTANT_PAGE_CONTENT) + + def create_page_summary(self): + """ + Create the summary page. + """ + text = _('Gramps is an Open Source project. Its success ' + 'depends on its users. User feedback is important. ' + 'Thank you for taking the time to submit a bug report.') + label = gtk.Label(text) + label.set_line_wrap(True) + + # Using set_page_side_image causes window sizing problems, so put the + # image in the main page instead. + image = gtk.Image() + image.set_from_file(SPLASH_JPG) + + hbox = gtk.HBox() + hbox.pack_start(image, False, False, 0) + hbox.pack_start(label, True, True, 0) + + page = hbox + + page.show_all() + self.append_page(page) + self.set_page_header_image(page, self.logo) + #self.set_page_side_image(page, self.splash) + self.set_page_title(page, _('Complete')) + self.set_page_type(page, gtk.ASSISTANT_PAGE_SUMMARY) def page4_update(self): - + """ + Update the contents of page 4 with any changes made. + """ self._final_report_text_buffer.set_text( "User Information: \n" + "===================\n\n" + diff --git a/src/plugins/tool/MediaManager.py b/src/plugins/tool/MediaManager.py index 95fc1d6b5..1162cbf01 100644 --- a/src/plugins/tool/MediaManager.py +++ b/src/plugins/tool/MediaManager.py @@ -5,6 +5,7 @@ # Copyright (C) 2008 B. Malengier # Copyright (C) 2008 Brian G. Matherly # Copyright (C) 2010 Jakim Friant +# Copyright (C) 2012 Nick Hall # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -50,8 +51,6 @@ import gobject #------------------------------------------------------------------------ import const import GrampsDisplay -import Assistant -import Errors from gen.lib import MediaObject from gen.db import DbTxn from gen.updatecallback import UpdateCallback @@ -67,6 +66,8 @@ import gen.mime #------------------------------------------------------------------------- WIKI_HELP_PAGE = '%s_-_Tools' % const.URL_MANUAL_PAGE WIKI_HELP_SEC = _('manual|Media_Manager...') +GRAMPS_PNG = os.path.join(const.IMAGE_DIR, "gramps.png") +SPLASH_JPG = os.path.join(const.IMAGE_DIR, "splash.jpg") #------------------------------------------------------------------------- # @@ -81,40 +82,145 @@ class MediaMan(tool.Tool): self.uistate = uistate self.callback = uistate.pulse_progressbar + self.batch_ops = [] self.build_batch_ops() - self.batch_settings = None - self.settings_page = None - try: - self.w = Assistant.Assistant(uistate,self.__class__,self.complete, - _("Media Manager")) - except Errors.WindowActiveError: - return + self.assistant = gtk.Assistant() + self.logo = gtk.gdk.pixbuf_new_from_file(GRAMPS_PNG) + self.splash = gtk.gdk.pixbuf_new_from_file(SPLASH_JPG) - self.welcome_page = self.w.add_text_page(_('Gramps Media Manager'), - self.get_info_text()) - self.selection_page = self.w.add_page(_('Selecting operation'), - self.build_selection_page()) - self.confirm_page = self.w.add_text_page('','') - self.conclusion_page = self.w.add_text_page('','') + self.assistant.set_title(_('Gramps Media Manager')) + self.assistant.connect('close', self.close) + self.assistant.connect('cancel', self.close) + self.assistant.connect('apply', self.run) + self.assistant.connect('prepare', self.prepare) + self.assistant.set_forward_page_func(self.forward_page) - self.w.connect('before-page-next',self.on_before_page_next) + intro = IntroductionPage() + self.add_page(intro, gtk.ASSISTANT_PAGE_INTRO, _('Introduction')) + self.selection = SelectionPage(self.batch_ops) + self.add_page(self.selection, gtk.ASSISTANT_PAGE_CONTENT, + _('Selection')) + self.settings = SettingsPage(self.batch_ops, self.assistant) + self.add_page(self.settings, gtk.ASSISTANT_PAGE_CONTENT) + self.confirmation = ConfirmationPage(self.batch_ops) + self.add_page(self.confirmation, gtk.ASSISTANT_PAGE_CONFIRM, + _('Final confirmation')) + self.conclusion = ConclusionPage(self.assistant) + self.add_page(self.conclusion, gtk.ASSISTANT_PAGE_SUMMARY) + + self.assistant.show() - self.w.show() + def close(self, assistant): + """ + Close the assistant. + """ + self.assistant.hide() - def complete(self): - pass + def forward_page(self, page): + """ + Specify the next page to be displayed. + """ + if page == 1: # selection page + index = self.selection.get_index() + if self.settings.prepare(index): + return page + 1 + else: + return page + 2 + else: + return page + 1 - def on_before_page_next(self, obj,page,data=None): - if page == self.selection_page: - self.build_settings_page() - elif page == self.settings_page: - self.build_confirmation() - elif page == self.confirm_page: - success = self.run() - self.build_conclusion(success) + def prepare(self, assistant, page): + """ + Run page preparation code. + """ + if self.assistant.get_current_page() == 3: + index = self.selection.get_index() + self.confirmation.prepare(index) + self.assistant.set_page_complete(page, True) - def get_info_text(self): + def add_page(self, page, page_type, title=''): + """ + Add a page to the assistant. + """ + page.show_all() + self.assistant.append_page(page) + self.assistant.set_page_header_image(page, self.logo) + self.assistant.set_page_title(page, title) + self.assistant.set_page_type(page, page_type) + + def on_help_clicked(self, obj): + """ + Display the relevant portion of Gramps manual. + """ + GrampsDisplay.help(webpage=WIKI_HELP_PAGE, section=WIKI_HELP_SEC) + + def build_batch_ops(self): + """ + Define the batch operations available. + """ + batches_to_use = [ + PathChange, + Convert2Abs, + Convert2Rel, + ImagesNotIncluded, + ] + + for batch_class in batches_to_use: + self.batch_ops.append(batch_class(self.db, self.callback)) + + def run(self, assistant): + """ + Run selected batch op with selected settings. + """ + index = self.selection.get_index() + self.pre_run() + success = self.batch_ops[index].run_tool() + self.conclusion.set_result(success) + self.post_run() + + def pre_run(self): + """ + Code to run prior to the batch op. + """ + self.uistate.set_busy_cursor(1) + self.uistate.progress.show() + + def post_run(self): + """ + Code to run after to the batch op. + """ + self.uistate.set_busy_cursor(0) + self.uistate.progress.hide() + +#------------------------------------------------------------------------ +# +# Assistant pages +# +#------------------------------------------------------------------------ +class IntroductionPage(gtk.HBox): + """ + A page containing introductory text. + """ + def __init__(self): + gtk.HBox.__init__(self) + + # Using set_page_side_image causes window sizing problems, so put the + # image in the main page instead. + image = gtk.Image() + image.set_from_file(SPLASH_JPG) + + label = gtk.Label(self.__get_intro_text()) + label.set_line_wrap(True) + label.set_use_markup(True) + + self.pack_start(image, False, False, 0) + self.pack_start(label, True, True, 0) + + def __get_intro_text(self): + """ + Return the introductory text. + """ return _("This tool allows batch operations on media objects " "stored in Gramps. " "An important distinction must be made between a Gramps " @@ -134,181 +240,154 @@ class MediaMan(tool.Tool): "Gramps. Then you can adjust the paths using this tool so " "that the media objects store the correct file locations.") - def build_selection_page(self): - """ - Build a page with the radio buttons for every available batch op. - """ +class SelectionPage(gtk.VBox): + """ + A page with the radio buttons for every available batch op. + """ + def __init__(self, batch_ops): + gtk.VBox.__init__(self) + self.batch_op_buttons = [] - box = gtk.VBox() - box.set_spacing(12) + self.set_spacing(12) - table = gtk.Table(2*len(self.batch_ops),2) + table = gtk.Table(2 * len(batch_ops), 2) table.set_row_spacings(6) table.set_col_spacings(6) group = None - for ix in range(len(self.batch_ops)): - title = self.batch_ops[ix].title - description= self.batch_ops[ix].description + for index in range(len(batch_ops)): + title = batch_ops[index].title + description = batch_ops[index].description - button = gtk.RadioButton(group,title) + button = gtk.RadioButton(group, title) button.set_tooltip_text(description) if not group: group = button self.batch_op_buttons.append(button) - table.attach(button,0,2,2*ix,2*ix+1,yoptions=0) + table.attach(button, 0, 2, 2 * index, 2 * index + 1, yoptions=0) - box.add(table) - return box + self.add(table) - def on_help_clicked(self, obj): - """Display the relevant portion of GRAMPS manual""" - GrampsDisplay.help(webpage=WIKI_HELP_PAGE, section=WIKI_HELP_SEC) - - def build_batch_ops(self): - self.batch_ops = [] - batches_to_use = [ - PathChange, - Convert2Abs, - Convert2Rel, - ImagesNotIncluded, - ] - - for batch_class in batches_to_use: - self.batch_ops.append(batch_class(self.db,self.callback)) - - def get_selected_op_index(self): + def get_index(self): """ Query the selection radiobuttons and return the index number of the selected batch op. """ - for ix in range(len(self.batch_op_buttons)): - button = self.batch_op_buttons[ix] + for index in range(len(self.batch_op_buttons)): + button = self.batch_op_buttons[index] if button.get_active(): - return ix + return index else: return 0 - - def build_settings_page(self): - """ - Build an extra page with the settings specific for the chosen batch-op. - If there's already an entry for this batch-op then do nothing, - otherwise add a page. - If the chosen batch-op does not have settings then remove the - settings page that is already there (from previous user passes - through the assistant). +class SettingsPage(gtk.VBox): + """ + An extra page with the settings specific for the chosen batch-op. + """ + def __init__(self, batch_ops, assistant): + gtk.VBox.__init__(self) + self.assistant = assistant + self.batch_ops = batch_ops + + def prepare(self, index): """ - ix = self.get_selected_op_index() - config = self.batch_ops[ix].build_config() + Build the settings for the batch op. + """ + config = self.batch_ops[index].build_config() if config: - if ix == self.batch_settings: - return - elif self.batch_settings: - self.w.remove_page(self.settings_page) - self.settings_page = None - self.confirm_page -= 1 - self.conclusion_page -= 1 - self.batch_settings = None - self.build_confirmation() - title,box = config - self.settings_page = self.w.insert_page(title,box, - self.selection_page+1) - self.confirm_page += 1 - self.conclusion_page += 1 - self.batch_settings = ix - box.show_all() + title, contents = config + self.assistant.set_page_title(self, title) + map(self.remove, self.get_children()) + self.pack_start(contents) + self.show_all() + return True else: - if self.batch_settings is not None: - self.w.remove_page(self.settings_page) - self.settings_page = None - self.confirm_page -= 1 - self.conclusion_page -= 1 - self.batch_settings = None - self.build_confirmation() + return False - def build_confirmation(self): - """ - Build the confirmation page. +class ConfirmationPage(gtk.VBox): + """ + A page to display the summary of the proposed action, as well as the + list of affected paths. + """ + def __init__(self, batch_ops): + gtk.VBox.__init__(self) - This should query the selected settings and present the summary - of the proposed action, as well as the list of affected paths. - """ + self.batch_ops = batch_ops - ix = self.get_selected_op_index() - confirm_text = self.batch_ops[ix].build_confirm_text() - path_list = self.batch_ops[ix].build_path_list() + self.set_spacing(12) + self.set_border_width(12) - box = gtk.VBox() - box.set_spacing(12) - box.set_border_width(12) - - label1 = gtk.Label(confirm_text) - label1.set_line_wrap(True) - label1.set_use_markup(True) - label1.set_alignment(0,0.5) - box.pack_start(label1,expand=False) + self.confirm = gtk.Label() + self.confirm.set_line_wrap(True) + self.confirm.set_use_markup(True) + self.confirm.set_alignment(0, 0.5) + self.pack_start(self.confirm, expand=False) scrolled_window = gtk.ScrolledWindow() - scrolled_window.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_AUTOMATIC) + scrolled_window.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC) scrolled_window.set_shadow_type(gtk.SHADOW_IN) tree = gtk.TreeView() - model = gtk.ListStore(gobject.TYPE_STRING) - tree.set_model(model) + self.path_model = gtk.ListStore(gobject.TYPE_STRING) + tree.set_model(self.path_model) tree_view_column = gtk.TreeViewColumn(_('Affected path'), - gtk.CellRendererText(),text=0) + gtk.CellRendererText(), text=0) tree_view_column.set_sort_column_id(0) tree.append_column(tree_view_column) - for path in path_list: - model.append(row=[path]) scrolled_window.add(tree) - box.pack_start(scrolled_window,expand=True,fill=True) + self.pack_start(scrolled_window, expand=True, fill=True) - label3 = gtk.Label(_('Press OK to proceed, Cancel to abort, ' + label3 = gtk.Label(_('Press Apply to proceed, Cancel to abort, ' 'or Back to revisit your options.')) - box.pack_start(label3,expand=False) - box.show_all() + self.pack_start(label3, expand=False) - self.w.remove_page(self.confirm_page) - self.confirm_page = self.w.insert_page(_('Final confirmation'), - box,self.confirm_page) + def prepare(self, index): + """ + Display a list of changes to be made. + """ + confirm_text = self.batch_ops[index].build_confirm_text() + path_list = self.batch_ops[index].build_path_list() - def run(self): - """ - Run selected batch op with selected settings. - """ - ix = self.get_selected_op_index() - self.pre_run() - success = self.batch_ops[ix].run_tool() - self.post_run() - return success + self.confirm.set_text(confirm_text) + + self.path_model.clear() + for path in path_list: + self.path_model.append(row=[path]) + +class ConclusionPage(gtk.HBox): + """ + A page to display the summary of the proposed action, as well as the + list of affected paths. + """ + def __init__(self, assistant): + gtk.HBox.__init__(self) + + self.assistant = assistant + + # Using set_page_side_image causes window sizing problems, so put the + # image in the main page instead. + image = gtk.Image() + image.set_from_file(SPLASH_JPG) + + self.label = gtk.Label() + self.label.set_line_wrap(True) + + self.pack_start(image, False, False, 0) + self.pack_start(self.label, True, True, 0) - def pre_run(self): - self.uistate.set_busy_cursor(1) - self.w.set_busy_cursor(1) - self.uistate.progress.show() - - def post_run(self): - self.uistate.set_busy_cursor(0) - self.w.set_busy_cursor(0) - self.uistate.progress.hide() - - def build_conclusion(self,success): + def set_result(self, success): if success: - conclusion_title = _('Operation successfully finished.') + conclusion_title = _('Operation successfully finished') conclusion_text = _( 'The operation you requested has finished successfully. ' - 'You may press OK button now to continue.') + 'You may press Close now to continue.') else: - conclusion_title = _('Operation failed'), + conclusion_title = _('Operation failed') conclusion_text = _( 'There was an error while performing the requested ' 'operation. You may try starting the tool again.') - self.w.remove_page(self.conclusion_page) - self.conclusion_page = self.w.insert_text_page(conclusion_title, - conclusion_text, - self.conclusion_page) + self.label.set_text(conclusion_text) + self.assistant.set_page_title(self, conclusion_title) #------------------------------------------------------------------------ # @@ -322,8 +401,8 @@ class BatchOp(UpdateCallback): title = 'Untitled operation' description = 'This operation needs to be described' - def __init__(self,db,callback): - UpdateCallback.__init__(self,callback) + def __init__(self, db, callback): + UpdateCallback.__init__(self, callback) self.db = db self.prepared = False @@ -392,7 +471,6 @@ class BatchOp(UpdateCallback): def _prepare(self): print "This method needs to be written." print "Preparing BatchOp tool... done." - pass #------------------------------------------------------------------------ # Simple op to replace substrings in the paths @@ -410,39 +488,43 @@ class PathChange(BatchOp): box = gtk.VBox() box.set_spacing(12) - table = gtk.Table(2,2) + table = gtk.Table(2, 2) table.set_row_spacings(6) table.set_col_spacings(6) self.from_entry = gtk.Entry() - table.attach(self.from_entry,1,2,0,1,yoptions=0) + table.attach(self.from_entry, 1, 2, 0, 1, yoptions=0) from_label = gtk.Label(_('_Replace:')) from_label.set_use_underline(True) - from_label.set_alignment(0,0.5) + from_label.set_alignment(0, 0.5) from_label.set_mnemonic_widget(self.from_entry) - table.attach(from_label,0,1,0,1,xoptions=0,yoptions=0) + table.attach(from_label, 0, 1, 0, 1, xoptions=0, yoptions=0) self.to_entry = gtk.Entry() - table.attach(self.to_entry,1,2,1,2,yoptions=0) + table.attach(self.to_entry, 1, 2, 1, 2, yoptions=0) to_label = gtk.Label(_('_With:')) to_label.set_use_underline(True) - to_label.set_alignment(0,0.5) + to_label.set_alignment(0, 0.5) to_label.set_mnemonic_widget(self.to_entry) - table.attach(to_label,0,1,1,2,xoptions=0,yoptions=0) + table.attach(to_label, 0, 1, 1, 2, xoptions=0, yoptions=0) box.add(table) - return (title,box) + return (title, box) def build_confirm_text(self): from_text = unicode(self.from_entry.get_text()) to_text = unicode(self.to_entry.get_text()) text = _( 'The following action is to be performed:\n\n' - 'Operation:\t%(title)s\nReplace:\t\t%(src_fname)s\nWith:\t\t%(dest_fname)s') % { - 'title' : self.title.replace('_',''), 'src_fname' : from_text, 'dest_fname' : to_text } + 'Operation:\t%(title)s\n' + 'Replace:\t\t%(src_fname)s\n' + 'With:\t\t%(dest_fname)s') % { + 'title' : self.title.replace('_',''), + 'src_fname' : from_text, + 'dest_fname' : to_text } return text def _prepare(self): @@ -467,9 +549,9 @@ class PathChange(BatchOp): to_text = unicode(self.to_entry.get_text()) for handle in self.handle_list: obj = self.db.get_object_from_handle(handle) - new_path = obj.get_path().replace(from_text,to_text) + new_path = obj.get_path().replace(from_text, to_text) obj.set_path(new_path) - self.db.commit_media_object(obj,self.trans) + self.db.commit_media_object(obj, self.trans) self.update() return True @@ -503,7 +585,7 @@ class Convert2Abs(BatchOp): obj = self.db.get_object_from_handle(handle) new_path = media_path_full(self.db, obj.path) obj.set_path(new_path) - self.db.commit_media_object(obj,self.trans) + self.db.commit_media_object(obj, self.trans) self.update() return True @@ -540,7 +622,7 @@ class Convert2Rel(BatchOp): obj = self.db.get_object_from_handle(handle) new_path = relative_path(obj.path, base_dir) obj.set_path(new_path) - self.db.commit_media_object(obj,self.trans) + self.db.commit_media_object(obj, self.trans) self.update() return True @@ -620,5 +702,5 @@ class MediaManOptions(tool.ToolOptions): Defines options and provides handling interface. """ - def __init__(self, name,person_id=None): - tool.ToolOptions.__init__(self, name,person_id) + def __init__(self, name, person_id=None): + tool.ToolOptions.__init__(self, name, person_id)