* src/Assistant.py: More changes, still needs work.

* src/Exporter.py: More changes, still needs work.


svn: r5709
This commit is contained in:
Alex Roitman 2006-01-11 01:26:17 +00:00
parent df94a019fe
commit 4637e596cd
3 changed files with 110 additions and 107 deletions

View File

@ -12,6 +12,9 @@
* src/ViewManager.py: Add handler for Export; add hot keys for * src/ViewManager.py: Add handler for Export; add hot keys for
import and export. import and export.
* src/Assistant.py: More changes, still needs work.
* src/Exporter.py: More changes, still needs work.
2006-01-09 Don Allingham <don@gramps-project.org> 2006-01-09 Don Allingham <don@gramps-project.org>
* relation.svg: Relationship view icon * relation.svg: Relationship view icon
* media.svg: Relationship view icon * media.svg: Relationship view icon

View File

@ -94,6 +94,7 @@ class Assistant(gtk.Object):
self.current_page = 0 self.current_page = 0
self.max_page = 1 self.max_page = 1
self.conclusion_set = False
self.window = gtk.Window() self.window = gtk.Window()
titlebox = gtk.HBox() titlebox = gtk.HBox()
@ -103,7 +104,6 @@ class Assistant(gtk.Object):
self.title = gtk.Label(self.title_text[0]) self.title = gtk.Label(self.title_text[0])
self.title.set_alignment(0,0.5) self.title.set_alignment(0,0.5)
self.title.set_use_markup(True) self.title.set_use_markup(True)
self.conclude_text = "No finish text specified"
titlebox.pack_start(self.title,True) titlebox.pack_start(self.title,True)
image = gtk.Image() image = gtk.Image()
@ -150,9 +150,11 @@ class Assistant(gtk.Object):
"""Set the property of writable properties.""" """Set the property of writable properties."""
raise AttributeError, 'unknown or read only property %s' % prop.name raise AttributeError, 'unknown or read only property %s' % prop.name
def update_title(self): def update_title(self):
try:
self.title.set_label(self.title_text[self.current_page]) self.title.set_label(self.title_text[self.current_page])
except IndexError:
pass
self.title.set_use_markup(True) self.title.set_use_markup(True)
def set_buttons(self): def set_buttons(self):
@ -217,29 +219,44 @@ class Assistant(gtk.Object):
self.notebook.append_page(hbox) self.notebook.append_page(hbox)
def set_conclusion(self,title,text): def set_conclusion(self,title,text):
self.conclude_text = 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)
hbox.add(label)
hbox.show_all()
if self.conclusion_set:
self.notebook.remove_page(-1)
self.title_text.pop(-1)
self.notebook.append_page(hbox)
self.title_text.append(_format % title)
self.conclusion_set = True
def add_page(self, title, child): def add_page(self, title, child):
self.title_text.append(_format % title) self.title_text.append(_format % title)
self.notebook.append_page(child) self.notebook.append_page(child)
self.max_page += 1 self.max_page += 1
def insert_page(self, title, child, position=-1):
self.title_text.insert(position,_format % title)
self.notebook.insert_page(child,None,position)
self.max_page += 1
def remove_page(self,position):
self.title_text.pop(position)
self.notebook.remove_page(position)
self.max_page -= 1
def get_number_of_pages(self):
return self.max_page
def show(self): def show(self):
self.title_text.append(_format % _('Finished'))
hbox = gtk.HBox(spacing=12)
image = gtk.Image()
image.set_from_file(_splash_jpg)
hbox.pack_start(image,False)
label = gtk.Label(self.conclude_text)
label.set_line_wrap(True)
hbox.add(label)
self.notebook.append_page(hbox)
self.window.show_all() self.window.show_all()
self.notebook.set_current_page(0) self.notebook.set_current_page(0)
self.emit('page-changed',self.notebook.get_current_page()) self.emit('page-changed',self.notebook.get_current_page())
def destroy(self): def destroy(self):
self.window.destroy() self.window.destroy()
@ -283,6 +300,8 @@ if __name__ == "__main__":
make_label(table,_('Email:'),5,0,1,1,4) make_label(table,_('Email:'),5,0,1,1,4)
box.add(table) box.add(table)
a.add_page('Researcher information',box) a.add_page('Researcher information',box)
a.set_conclusion('aaa','bbb')
a.show() a.show()
gtk.main() gtk.main()

View File

@ -49,7 +49,8 @@ import QuestionDialog
import GrampsKeys import GrampsKeys
import GrampsDisplay import GrampsDisplay
import Assistant import Assistant
print "0"
from GrampsDb import gramps_db_writer_factory
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
# #
# Exporter # Exporter
@ -83,31 +84,38 @@ class Exporter:
self.build_exports() self.build_exports()
self.confirm_label = gtk.Label() self.confirm_label = gtk.Label()
self.extra_pages = [] self.format_option = None
self.w = Assistant.Assistant(_('Saving your data'),None) self.w = Assistant.Assistant(_('Saving your data'),self.complete)
self.w.set_intro(self.get_intro_text()) self.w.set_intro(self.get_intro_text())
title,box = self.build_format_page() title1,box1 = self.build_format_page()
self.w.add_page(title,box) self.w.add_page(title1,box1)
self.format_page = 1
title,box = self.build_file_sel_page() title2,box2 = self.build_file_sel_page()
self.w.add_page(title,box) self.w.add_page(title2,box2)
self.file_sel_page = self.w.get_number_of_pages()
title,box = self.build_confirm_page() title3,box3 = self.build_confirm_page()
self.w.add_page(title,box) self.w.add_page(title3,box3)
title,text=self.get_conclusion_text() self.w.connect('before-page-next',self.on_before_page_next)
self.w.set_conclusion(title,text)
self.w.show() self.w.show()
def close(self,obj,obj2=None): def complete(self):
""" pass
Close and delete handler.
""" def on_before_page_next(self,obj,page,data=None):
self.w.destroy() if page == self.format_page:
self.build_options()
self.suggest_filename()
elif page == self.file_sel_page-1:
self.build_confirm_label()
elif page == self.file_sel_page:
self.success = self.save()
def help(self,obj): def help(self,obj):
""" """
@ -139,11 +147,9 @@ class Exporter:
box = gtk.VBox() box = gtk.VBox()
box.set_spacing(12) box.set_spacing(12)
box.add(self.confirm_label) box.add(self.confirm_label)
#p.connect('prepare',self.build_confirm_label)
#p.connect('next',self.save)
return (page_title,box) return (page_title,box)
def build_confirm_label(self,obj,obj2): def build_confirm_label(self):
""" """
Build the text of the confirmation label. This should query Build the text of the confirmation label. This should query
the selected options (format, filename) and present the summary the selected options (format, filename) and present the summary
@ -158,11 +164,12 @@ class Exporter:
self.confirm_label.set_text( self.confirm_label.set_text(
_('The data will be saved as follows:\n\n' _('The data will be saved as follows:\n\n'
'Format:\t%s\nName:\t%s\nFolder:\t%s\n\n' 'Format:\t%s\nName:\t%s\nFolder:\t%s\n\n'
'Press Forward to proceed, Cancel to abort, or Back to ' 'Press OK to proceed, Cancel to abort, or Back to '
'revisit your options.') % (format, name, folder)) 'revisit your options.') % (format, name, folder))
self.confirm_label.set_line_wrap(True) self.confirm_label.set_line_wrap(True)
self.confirm_label.show_all()
def save(self,obj,obj2): def save(self):
""" """
Perform the actual Save As/Export operation. Perform the actual Save As/Export operation.
Depending on the success status, set the text for the final page. Depending on the success status, set the text for the final page.
@ -171,44 +178,31 @@ class Exporter:
GrampsKeys.save_last_export_dir(os.path.split(filename)[0]) GrampsKeys.save_last_export_dir(os.path.split(filename)[0])
ix = self.get_selected_format_index() ix = self.get_selected_format_index()
if self.exports[ix][3]: if self.exports[ix][3]:
success = self.exports[ix][0](self.parent.db,filename,self.person, success = self.exports[ix][0](self.dbstate.db,
filename,self.person,
self.option_box_instance) self.option_box_instance)
else: else:
success = self.exports[ix][0](self.parent.db,filename,self.person) success = self.exports[ix][0](self.dbstate.db,
filename,self.person)
if success: if success:
self.last_page.set_title(_('Your data has been saved')) conclusion_title = _('Your data has been saved')
self.last_page.set_text(_('The copy of your data has been ' conclusion_text = _(
'successfully saved. You may press Apply button ' 'The copy of your data has been '
'now to continue.\n\n'
'Note: the database currently opened in your GRAMPS '
'window is NOT the file you have just saved. '
'Future editing of the currently opened database will '
'not alter the copy you have just made. '))
else:
self.last_page.set_title(_('Saving failed'))
self.last_page.set_text()
def get_conclusion_text(self,success=False):
if success:
return (
_('Your data has been saved'),
_('The copy of your data has been '
'successfully saved. You may press Apply button ' 'successfully saved. You may press Apply button '
'now to continue.\n\n' 'now to continue.\n\n'
'Note: the database currently opened in your GRAMPS ' 'Note: the database currently opened in your GRAMPS '
'window is NOT the file you have just saved. ' 'window is NOT the file you have just saved. '
'Future editing of the currently opened database will ' 'Future editing of the currently opened database will '
'not alter the copy you have just made. ') 'not alter the copy you have just made. ')
)
else: else:
return ( conclusion_title = _('Saving failed'),
_('Saving failed'), conclusion_text = _(
_('There was an error while saving your data. ' 'There was an error while saving your data. '
'Please go back and try again.\n\n' 'You may try starting the export again.\n\n'
'Note: your currently opened database is safe. ' 'Note: your currently opened database is safe. '
'It was only ' 'It was only '
'a copy of your data that failed to save.') 'a copy of your data that failed to save.')
) self.w.set_conclusion(conclusion_title,conclusion_text)
def build_format_page(self): def build_format_page(self):
""" """
@ -241,46 +235,35 @@ class Exporter:
tip.set_tip(button,description) tip.set_tip(button,description)
box.add(table) box.add(table)
#box.show_all()
#p.connect('next',self.build_options)
return (page_title,box) return (page_title,box)
def build_options(self,obj,obj2): def build_options(self):
""" """
Build an extra page with the options specific for the chosen format. Build an extra page with the options specific for the chosen format.
If there's already a page (or pages) for this format in If there's already an entry for this format in self.extra_pages then
self.empty_pages then do nothing, otherwise add a page. do nothing, otherwise add a page.
If the chosen format does not have options then remove all If the chosen format does not have options then remove all
extra pages that are already there (from previous user passes extra pages that are already there (from previous user passes
through the druid). through the assistant).
""" """
ix = self.get_selected_format_index() ix = self.get_selected_format_index()
if self.exports[ix][3]: if self.exports[ix][3]:
title = self.exports[ix][3][0] if ix == self.format_option:
for (ep_ix,ep) in self.extra_pages:
if ep_ix == ix:
return return
else: elif self.format_option:
ep.destroy() self.w.remove_page(self.format_page+1)
self.extra_pages.remove((ep_ix,ep)) self.format_option = None
title = self.exports[ix][3][0]
option_box_class = self.exports[ix][3][1] option_box_class = self.exports[ix][3][1]
self.option_box_instance = option_box_class(self.person) self.option_box_instance = option_box_class(self.person)
box = self.option_box_instance.get_option_box()
p = DruidPageStandard() self.w.insert_page(title,box,self.format_page+1)
p.set_title(title) self.format_option = ix
p.set_title_foreground(self.fg_color) box.show_all()
p.set_background(self.bg_color) elif self.format_option:
p.set_logo(self.logo) self.w.remove_page(self.format_page+1)
p.append_item("",self.option_box_instance.get_option_box(),"") self.format_option = None
self.extra_pages.append((ix,p))
self.d.insert_page(self.file_sel_page,p)
p.show_all()
else:
for (ep_ix,ep) in self.extra_pages:
ep.destroy()
self.extra_pages = []
def build_file_sel_page(self): def build_file_sel_page(self):
""" """
@ -294,14 +277,12 @@ class Exporter:
box.set_spacing(12) box.set_spacing(12)
box.add(self.chooser) box.add(self.chooser)
# Dirty hack to enable proper EXPAND and FILL properties of the chooser # Dirty hack to enable proper EXPAND/FILL properties of the chooser
box.set_child_packing(self.chooser,1,1,0,gtk.PACK_START) box.set_child_packing(self.chooser,1,1,0,gtk.PACK_START)
#gradnparent = parent.get_parent()
#gradnparent.set_child_packing(parent,1,1,0,gtk.PACK_START)
#p.connect('prepare',self.suggest_filename)
return (page_title,box) return (page_title,box)
def suggest_filename(self,obj,obj2): def suggest_filename(self):
""" """
Prepare suggested filename and set it in the file chooser. Prepare suggested filename and set it in the file chooser.
""" """
@ -318,7 +299,7 @@ class Exporter:
if ext == 'gramps': if ext == 'gramps':
new_filename = os.path.expanduser(default_dir + 'data.gramps') new_filename = os.path.expanduser(default_dir + 'data.gramps')
elif ext == 'burn': elif ext == 'burn':
new_filename = os.path.basename(self.parent.db.get_save_path()) new_filename = os.path.basename(self.dbstate.db.get_save_path())
else: else:
new_filename = Utils.get_new_filename(ext,default_dir) new_filename = Utils.get_new_filename(ext,default_dir)
self.chooser.set_current_folder(default_dir) self.chooser.set_current_folder(default_dir)
@ -343,7 +324,7 @@ class Exporter:
In the future, filter and other options may be added. In the future, filter and other options may be added.
""" """
try: try:
GrampsDb.gramps_db_writer_factory(const.app_gramps)(database,filename,person) gramps_db_writer_factory(const.app_gramps)(database,filename,person)
return 1 return 1
except IOError, msg: except IOError, msg:
QuestionDialog.ErrorDialog( _("Could not write file: %s") % filename, QuestionDialog.ErrorDialog( _("Could not write file: %s") % filename,