2007-08-19 02:43:30 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
|
|
|
# Copyright (C) 2004-2007 Donald N. Allingham
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2009-08-08 21:14:46 +05:30
|
|
|
# Contribution 2009 by Brad Crittenden <brad [AT] bradcrittenden.net>
|
2007-08-19 02:43:30 +05:30
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
|
|
|
# Written by B.Malengier
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
from gettext import gettext as _
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# set up logging
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import logging
|
|
|
|
log = logging.getLogger(".ExportAssistant")
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gtk
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
|
|
|
import const
|
2009-10-08 06:42:51 +05:30
|
|
|
import config
|
2009-10-25 19:22:29 +05:30
|
|
|
from gui.pluginmanager import GuiPluginManager
|
2007-08-19 02:43:30 +05:30
|
|
|
import Utils
|
|
|
|
import ManagedWindow
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-09-08 11:24:02 +05:30
|
|
|
_gramps_png = os.path.join(const.IMAGE_DIR,"gramps.png")
|
|
|
|
_splash_jpg = os.path.join(const.IMAGE_DIR,"splash.jpg")
|
2007-08-19 02:43:30 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# ExportAssistant
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
2007-08-21 04:11:50 +05:30
|
|
|
_ExportAssistant_pages = {
|
|
|
|
'intro' : 0,
|
|
|
|
'exporttypes' : 1,
|
|
|
|
'options' : 2,
|
|
|
|
'fileselect' : 3,
|
|
|
|
'confirm' : 4,
|
|
|
|
'summary' : 5,
|
|
|
|
}
|
|
|
|
|
2007-08-19 02:43:30 +05:30
|
|
|
class ExportAssistant(gtk.Assistant, ManagedWindow.ManagedWindow) :
|
|
|
|
"""
|
|
|
|
This class creates a GTK assistant to guide the user through the various
|
2008-01-17 03:12:05 +05:30
|
|
|
Save as/Export options.
|
|
|
|
|
|
|
|
The overall goal is to keep things simple by presenting few choice options
|
|
|
|
on each assistant page.
|
|
|
|
|
|
|
|
The export formats and options are obtained from the plugins.
|
2007-08-19 02:43:30 +05:30
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
__gsignals__ = {"apply": "override", "cancel": "override",
|
|
|
|
"close": "override", "prepare": "override"}
|
|
|
|
|
|
|
|
def __init__(self,dbstate,uistate):
|
|
|
|
"""
|
2008-01-17 03:12:05 +05:30
|
|
|
Set up the assistant, and build all the possible assistant pages.
|
|
|
|
|
2007-08-19 02:43:30 +05:30
|
|
|
Some page elements are left empty, since their contents depends
|
|
|
|
on the user choices and on the success of the attempted save.
|
|
|
|
|
|
|
|
"""
|
|
|
|
self.dbstate = dbstate
|
|
|
|
self.uistate = uistate
|
|
|
|
|
2007-08-31 03:19:46 +05:30
|
|
|
self.writestarted = False
|
|
|
|
|
2009-08-08 21:14:46 +05:30
|
|
|
#set up Assistant
|
2007-08-19 02:43:30 +05:30
|
|
|
gtk.Assistant.__init__(self)
|
2008-01-18 15:28:50 +05:30
|
|
|
##workaround around bug http://bugzilla.gnome.org/show_bug.cgi?id=56070
|
2008-01-18 15:32:20 +05:30
|
|
|
self.forward_button = None
|
2008-01-18 15:28:50 +05:30
|
|
|
gtk.Assistant.forall(self, self.get_forward_button)
|
|
|
|
## end
|
2007-08-19 02:43:30 +05:30
|
|
|
|
|
|
|
#set up ManagedWindow
|
|
|
|
self.top_title = _("Export Assistant")
|
|
|
|
ManagedWindow.ManagedWindow.__init__(self,uistate,[],
|
|
|
|
self.__class__)
|
|
|
|
self.set_window(self, None, self.top_title, isWindow=True)
|
2007-08-21 04:11:50 +05:30
|
|
|
|
|
|
|
#set up callback method for the export plugins
|
2007-08-31 03:19:46 +05:30
|
|
|
self.callback = self.pulse_progressbar
|
2007-08-19 02:43:30 +05:30
|
|
|
|
|
|
|
if self.dbstate.active:
|
|
|
|
self.person = self.dbstate.get_active_person()
|
|
|
|
else:
|
|
|
|
self.person = self.dbstate.db.find_initial_person()
|
|
|
|
|
|
|
|
self.logo = gtk.gdk.pixbuf_new_from_file(_gramps_png)
|
|
|
|
self.splash = gtk.gdk.pixbuf_new_from_file(_splash_jpg)
|
|
|
|
|
2009-10-25 19:22:29 +05:30
|
|
|
pmgr = GuiPluginManager.get_instance()
|
2008-11-04 09:42:51 +05:30
|
|
|
self.__exporters = pmgr.get_export_plugins()
|
2007-08-19 02:43:30 +05:30
|
|
|
|
2007-08-21 04:11:50 +05:30
|
|
|
self.__previous_page = -1
|
2007-08-19 02:43:30 +05:30
|
|
|
|
|
|
|
#create the assistant pages
|
|
|
|
self.create_page_intro()
|
|
|
|
self.create_page_exporttypes()
|
|
|
|
self.create_page_options()
|
|
|
|
self.create_page_fileselect()
|
|
|
|
self.create_page_confirm()
|
2007-08-31 03:19:46 +05:30
|
|
|
#no progress page, looks ugly, and user needs to hit forward at end!
|
2007-08-19 02:43:30 +05:30
|
|
|
self.create_page_summary()
|
|
|
|
|
2009-08-08 21:14:46 +05:30
|
|
|
self.option_box_instance = None
|
2007-08-23 17:28:36 +05:30
|
|
|
#we need our own forward function as options page must not always be shown
|
|
|
|
self.set_forward_page_func(self.forward_func, None)
|
|
|
|
|
2007-08-19 02:43:30 +05:30
|
|
|
#ManagedWindow show method
|
|
|
|
ManagedWindow.ManagedWindow.show(self)
|
2008-01-18 15:28:50 +05:30
|
|
|
|
|
|
|
def get_forward_button(self, arg):
|
|
|
|
if isinstance(arg, gtk.HBox):
|
|
|
|
arg.forall(self._forward_btn)
|
|
|
|
|
|
|
|
def _forward_btn(self, arg):
|
|
|
|
if isinstance(arg, gtk.Button) and arg.get_label() == 'gtk-go-forward':
|
|
|
|
self.forward_button = arg
|
|
|
|
|
2008-02-24 19:25:55 +05:30
|
|
|
def build_menu_names(self, obj):
|
2008-01-17 03:12:05 +05:30
|
|
|
"""Override ManagedWindow method."""
|
2007-08-19 02:43:30 +05:30
|
|
|
return (self.top_title, None)
|
|
|
|
|
|
|
|
def create_page_intro(self):
|
2008-01-17 03:12:05 +05:30
|
|
|
"""Create the introduction page."""
|
2007-08-19 02:43:30 +05:30
|
|
|
label = gtk.Label(self.get_intro_text())
|
|
|
|
label.set_line_wrap(True)
|
|
|
|
label.set_use_markup(True)
|
|
|
|
|
|
|
|
page = label
|
|
|
|
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, _('Saving your data'))
|
|
|
|
self.set_page_complete(page, True)
|
|
|
|
self.set_page_type(page, gtk.ASSISTANT_PAGE_INTRO)
|
|
|
|
|
|
|
|
def create_page_exporttypes(self):
|
2008-01-17 03:12:05 +05:30
|
|
|
"""Create the export type page.
|
|
|
|
|
|
|
|
A Title label.
|
2007-08-19 02:43:30 +05:30
|
|
|
A table of format radio buttons and their descriptions.
|
2008-01-17 03:12:05 +05:30
|
|
|
|
|
|
|
"""
|
2007-08-19 02:43:30 +05:30
|
|
|
self.format_buttons = []
|
|
|
|
|
|
|
|
box = gtk.VBox()
|
|
|
|
box.set_border_width(12)
|
|
|
|
box.set_spacing(12)
|
|
|
|
|
2008-11-04 09:42:51 +05:30
|
|
|
table = gtk.Table(2*len(self.__exporters),2)
|
2007-08-19 02:43:30 +05:30
|
|
|
table.set_row_spacings(6)
|
|
|
|
table.set_col_spacings(6)
|
|
|
|
|
|
|
|
group = None
|
2009-10-08 06:42:51 +05:30
|
|
|
recent_type = config.get('behavior.recent-export-type')
|
2007-08-25 20:01:14 +05:30
|
|
|
|
2008-11-04 09:42:51 +05:30
|
|
|
for ix in range(len(self.__exporters)):
|
|
|
|
title = self.__exporters[ix].get_name()
|
|
|
|
description= self.__exporters[ix].get_description()
|
2007-08-19 02:43:30 +05:30
|
|
|
|
|
|
|
button = gtk.RadioButton(group,title)
|
2009-10-08 01:31:39 +05:30
|
|
|
button.set_tooltip_text(description)
|
2007-08-19 02:43:30 +05:30
|
|
|
if not group:
|
|
|
|
group = button
|
|
|
|
self.format_buttons.append(button)
|
2009-10-08 01:31:39 +05:30
|
|
|
table.attach(button, 0, 2, 2*ix, 2*ix+1)
|
2007-08-25 20:01:14 +05:30
|
|
|
if ix == recent_type :
|
|
|
|
button.set_active(True)
|
2007-08-19 02:43:30 +05:30
|
|
|
|
|
|
|
box.add(table)
|
|
|
|
|
|
|
|
page = box
|
|
|
|
|
|
|
|
page.show_all()
|
|
|
|
|
|
|
|
self.append_page(page)
|
|
|
|
self.set_page_header_image(page, self.logo)
|
2007-08-25 10:33:23 +05:30
|
|
|
self.set_page_title(page, _('Choose the output format'))
|
2007-08-23 17:28:36 +05:30
|
|
|
|
2007-08-19 02:43:30 +05:30
|
|
|
self.set_page_type(page, gtk.ASSISTANT_PAGE_CONTENT)
|
2007-08-21 04:11:50 +05:30
|
|
|
|
|
|
|
|
2007-08-19 02:43:30 +05:30
|
|
|
def create_page_options(self):
|
2007-08-21 04:11:50 +05:30
|
|
|
# as we do not know yet what to show, we create an empty page
|
|
|
|
page = gtk.VBox()
|
|
|
|
page.set_border_width(12)
|
|
|
|
page.set_spacing(12)
|
|
|
|
|
|
|
|
page.show_all()
|
|
|
|
|
|
|
|
self.append_page(page)
|
|
|
|
self.set_page_header_image(page, self.logo)
|
|
|
|
self.set_page_complete(page, False)
|
|
|
|
self.set_page_type(page, gtk.ASSISTANT_PAGE_CONTENT)
|
|
|
|
|
|
|
|
def forward_func(self, pagenumber, data):
|
2008-01-17 03:12:05 +05:30
|
|
|
"""This function is called on forward press.
|
|
|
|
|
2007-08-21 04:11:50 +05:30
|
|
|
Normally, go to next page, however, before options,
|
|
|
|
we decide if options to show
|
2008-01-17 03:12:05 +05:30
|
|
|
"""
|
2007-08-21 04:11:50 +05:30
|
|
|
if pagenumber == _ExportAssistant_pages['exporttypes'] :
|
|
|
|
#decide if options need to be shown:
|
|
|
|
ix = self.get_selected_format_index()
|
2008-11-04 09:42:51 +05:30
|
|
|
if self.__exporters[ix].get_config():
|
2007-08-21 04:11:50 +05:30
|
|
|
return pagenumber + 1
|
|
|
|
else :
|
|
|
|
# no options needed
|
|
|
|
return pagenumber + 2
|
|
|
|
else :
|
|
|
|
return pagenumber + 1
|
|
|
|
|
|
|
|
def create_options(self):
|
2008-01-17 03:12:05 +05:30
|
|
|
"""This method gets the option page, and fills it with the options."""
|
2007-08-21 04:11:50 +05:30
|
|
|
option = self.get_selected_format_index()
|
|
|
|
vbox = self.get_nth_page(_ExportAssistant_pages['options'])
|
2008-11-04 09:42:51 +05:30
|
|
|
(config_title, config_box_class) = self.__exporters[option].get_config()
|
|
|
|
self.set_page_title(vbox, config_title)
|
2007-08-21 04:11:50 +05:30
|
|
|
# remove present content of the vbox
|
|
|
|
vbox.foreach(vbox.remove)
|
|
|
|
# add new content
|
2008-11-04 09:42:51 +05:30
|
|
|
if config_box_class:
|
|
|
|
self.option_box_instance = config_box_class(self.person)
|
2009-08-08 21:14:46 +05:30
|
|
|
box = self.option_box_instance.get_option_box()
|
|
|
|
vbox.add(box)
|
2008-11-04 09:42:51 +05:30
|
|
|
else:
|
|
|
|
self.option_box_instance = None
|
2007-08-21 04:11:50 +05:30
|
|
|
vbox.show_all()
|
|
|
|
|
|
|
|
# We silently assume all options lead to accepted behavior
|
|
|
|
self.set_page_complete(vbox, True)
|
2007-08-19 02:43:30 +05:30
|
|
|
|
|
|
|
def create_page_fileselect(self):
|
|
|
|
self.chooser = gtk.FileChooserWidget(gtk.FILE_CHOOSER_ACTION_SAVE)
|
|
|
|
#add border
|
|
|
|
self.chooser.set_border_width(12)
|
|
|
|
#global files, ask before overwrite
|
|
|
|
self.chooser.set_local_only(False)
|
|
|
|
self.chooser.set_do_overwrite_confirmation(True)
|
|
|
|
|
2007-08-23 17:28:36 +05:30
|
|
|
#created, folder and name not set
|
|
|
|
self.folder_is_set = False
|
2007-08-19 02:43:30 +05:30
|
|
|
|
|
|
|
#connect changes in filechooser with check to mark page complete
|
|
|
|
self.chooser.connect("selection-changed", self.check_fileselect)
|
|
|
|
self.chooser.connect("key-release-event", self.check_fileselect)
|
|
|
|
#first selection does not give a selection-changed event, grab the button
|
|
|
|
self.chooser.connect("button-release-event", self.check_fileselect)
|
|
|
|
#Note, we can induce an exotic error, delete filename,
|
|
|
|
# do not release button, click forward. We expect user not to do this
|
|
|
|
# In case he does, recheck on confirmation page!
|
|
|
|
|
|
|
|
self.chooser.show_all()
|
|
|
|
page = self.chooser
|
|
|
|
|
|
|
|
self.append_page(page)
|
|
|
|
self.set_page_header_image(page, self.logo)
|
|
|
|
self.set_page_title(page, _('Select Save File'))
|
|
|
|
#see if page can be set as complete :
|
|
|
|
self.check_fileselect(page)
|
|
|
|
self.set_page_type(page, gtk.ASSISTANT_PAGE_CONTENT)
|
|
|
|
|
2008-01-21 17:51:57 +05:30
|
|
|
def check_fileselect(self, filechooser, event=None, show=True):
|
2008-01-17 03:12:05 +05:30
|
|
|
"""Given a filechooser, determine if it can be marked complete in
|
|
|
|
the Assistant.
|
|
|
|
|
2008-01-21 17:51:57 +05:30
|
|
|
Used as normal callback and event callback. For callback, we will have
|
|
|
|
show=True
|
2008-01-17 03:12:05 +05:30
|
|
|
"""
|
2007-08-19 02:43:30 +05:30
|
|
|
filename = filechooser.get_filename()
|
|
|
|
folder = filechooser.get_current_folder()
|
|
|
|
#the file must be valid, not a folder, and folder must be valid
|
|
|
|
if filename and filename.strip and Utils.find_folder(filename) == '' \
|
|
|
|
and folder and Utils.find_folder(folder):
|
|
|
|
#this page of the assistant is complete
|
|
|
|
self.set_page_complete(filechooser, True)
|
2008-01-21 17:51:57 +05:30
|
|
|
##workaround around bug http://bugzilla.gnome.org/show_bug.cgi?id=56070
|
|
|
|
if self.forward_button and show:
|
|
|
|
self.forward_button.hide()
|
|
|
|
self.forward_button.show()
|
|
|
|
## end
|
2007-08-19 02:43:30 +05:30
|
|
|
|
|
|
|
else :
|
|
|
|
self.set_page_complete(filechooser, False)
|
|
|
|
|
|
|
|
def create_page_confirm(self):
|
2007-08-21 04:11:50 +05:30
|
|
|
# Construct confirm page
|
|
|
|
label = gtk.Label()
|
|
|
|
label.set_line_wrap(True)
|
|
|
|
label.set_use_markup(True)
|
|
|
|
label.show()
|
|
|
|
|
|
|
|
page = label
|
|
|
|
self.append_page(page)
|
|
|
|
self.set_page_header_image(page, self.logo)
|
|
|
|
self.set_page_title(page, _('Final confirmation'))
|
|
|
|
self.set_page_type(page, gtk.ASSISTANT_PAGE_CONFIRM)
|
|
|
|
self.set_page_complete(page, True)
|
2007-08-31 03:19:46 +05:30
|
|
|
|
2007-08-19 02:43:30 +05:30
|
|
|
def create_page_summary(self):
|
|
|
|
# Construct summary page
|
|
|
|
# As this is the last page needs to be of page_type
|
|
|
|
# gtk.ASSISTANT_PAGE_CONFIRM or gtk.ASSISTANT_PAGE_SUMMARY
|
2007-08-31 03:19:46 +05:30
|
|
|
page = gtk.Alignment(xalign=0.5, yalign=0.5, xscale=0,
|
|
|
|
yscale=0)
|
|
|
|
vbox = gtk.VBox()
|
|
|
|
vbox.set_border_width(12)
|
|
|
|
vbox.set_spacing(6)
|
|
|
|
self.labelsum = gtk.Label(_("Please wait while your data is selected and exported"))
|
|
|
|
self.labelsum.set_line_wrap(True)
|
|
|
|
self.labelsum.set_use_markup(True)
|
|
|
|
vbox.pack_start(self.labelsum, expand=True)
|
|
|
|
|
|
|
|
self.progressbar = gtk.ProgressBar()
|
|
|
|
vbox.pack_start(self.progressbar, expand=True)
|
|
|
|
|
|
|
|
page.add(vbox)
|
|
|
|
page.show_all()
|
2007-08-19 02:43:30 +05:30
|
|
|
|
|
|
|
self.append_page(page)
|
|
|
|
self.set_page_header_image(page, self.logo)
|
|
|
|
self.set_page_title(page, _('Summary'))
|
|
|
|
self.set_page_side_image(page, self.splash)
|
2007-08-31 03:19:46 +05:30
|
|
|
self.set_page_complete(page, False)
|
2007-08-19 02:43:30 +05:30
|
|
|
self.set_page_type(page, gtk.ASSISTANT_PAGE_SUMMARY)
|
|
|
|
|
|
|
|
|
|
|
|
def do_apply(self):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def do_cancel(self):
|
2007-08-31 03:19:46 +05:30
|
|
|
if self.writestarted :
|
|
|
|
return True
|
|
|
|
else :
|
|
|
|
self.close()
|
2007-08-19 02:43:30 +05:30
|
|
|
|
|
|
|
def do_close(self):
|
2007-08-31 03:19:46 +05:30
|
|
|
if self.writestarted :
|
|
|
|
return True
|
|
|
|
else :
|
|
|
|
self.close()
|
2007-08-19 02:43:30 +05:30
|
|
|
|
|
|
|
def do_prepare(self, page):
|
2008-01-17 03:12:05 +05:30
|
|
|
"""
|
2007-08-21 04:11:50 +05:30
|
|
|
The "prepare" signal is emitted when a new page is set as the
|
|
|
|
assistant's current page, but before making the new page visible.
|
2008-01-17 03:12:05 +05:30
|
|
|
|
2009-06-25 03:26:07 +05:30
|
|
|
:param page: the new page to prepare for display.
|
2008-01-17 03:12:05 +05:30
|
|
|
|
|
|
|
"""
|
2007-08-21 04:11:50 +05:30
|
|
|
#determine if we go backward or forward
|
2007-08-19 02:43:30 +05:30
|
|
|
page_number = self.get_current_page()
|
2007-08-21 04:11:50 +05:30
|
|
|
assert page == self.get_nth_page(page_number)
|
|
|
|
if page_number <= self.__previous_page :
|
|
|
|
back = True
|
|
|
|
else :
|
|
|
|
back = False
|
2007-08-19 02:43:30 +05:30
|
|
|
|
2007-08-21 04:11:50 +05:30
|
|
|
if back :
|
2007-08-23 17:28:36 +05:30
|
|
|
#when moving backward, show page as it was,
|
|
|
|
#page we come from is set incomplete so as to disallow user jumping
|
|
|
|
# to last page after backward move
|
|
|
|
self.set_page_complete(self.get_nth_page(self.__previous_page),
|
|
|
|
False)
|
2007-08-21 04:11:50 +05:30
|
|
|
|
|
|
|
elif page_number == _ExportAssistant_pages['options'] :
|
|
|
|
self.create_options()
|
2007-08-23 17:28:36 +05:30
|
|
|
self.set_page_complete(page, True)
|
2008-01-18 15:28:50 +05:30
|
|
|
##workaround around bug http://bugzilla.gnome.org/show_bug.cgi?id=56070
|
|
|
|
if self.forward_button:
|
|
|
|
self.forward_button.hide()
|
|
|
|
self.forward_button.show()
|
|
|
|
## end
|
2007-08-21 04:11:50 +05:30
|
|
|
elif page == self.chooser :
|
|
|
|
# next page is the file chooser, reset filename, keep folder where user was
|
|
|
|
folder, name = self.suggest_filename()
|
2007-08-23 17:28:36 +05:30
|
|
|
if self.folder_is_set :
|
|
|
|
page.set_current_name(name)
|
|
|
|
else :
|
|
|
|
page.set_current_name(name)
|
|
|
|
page.set_current_folder(folder)
|
|
|
|
self.folder_is_set = True
|
2007-08-21 04:11:50 +05:30
|
|
|
# see if page is complete with above
|
2008-01-21 17:51:57 +05:30
|
|
|
self.check_fileselect(page, show=True)
|
2007-08-19 02:43:30 +05:30
|
|
|
|
2007-08-21 04:11:50 +05:30
|
|
|
elif self.get_page_type(page) == gtk.ASSISTANT_PAGE_CONFIRM :
|
|
|
|
# The confirm page with apply button
|
|
|
|
# Present user with what will happen
|
|
|
|
ix = self.get_selected_format_index()
|
2008-11-04 09:42:51 +05:30
|
|
|
format = self.__exporters[ix].get_name()
|
2007-08-21 04:11:50 +05:30
|
|
|
|
2007-08-23 17:28:36 +05:30
|
|
|
#Allow for exotic error: file is still not correct
|
2008-01-21 17:51:57 +05:30
|
|
|
self.check_fileselect(self.chooser, show=False)
|
2007-08-23 17:28:36 +05:30
|
|
|
if self.get_page_complete(self.chooser) :
|
2009-02-24 10:11:23 +05:30
|
|
|
filename = Utils.get_unicode_path(self.chooser.get_filename())
|
2007-08-23 17:28:36 +05:30
|
|
|
name = os.path.split(filename)[1]
|
|
|
|
folder = os.path.split(filename)[0]
|
|
|
|
confirm_text = _(
|
2007-08-21 04:11:50 +05:30
|
|
|
'The data will be saved as follows:\n\n'
|
|
|
|
'Format:\t%s\nName:\t%s\nFolder:\t%s\n\n'
|
|
|
|
'Press Apply to proceed, Back to revisit '
|
2009-03-14 16:24:02 +05:30
|
|
|
'your options, or Cancel to abort') % (format.replace("_",""), name, folder)
|
2007-08-23 17:28:36 +05:30
|
|
|
self.set_page_complete(page, True)
|
|
|
|
else :
|
|
|
|
confirm_text = _(
|
|
|
|
'The selected file and folder to save to '
|
|
|
|
'cannot be created or found.\n\n'
|
|
|
|
'Press Back to return and select a valid filename.'
|
|
|
|
)
|
|
|
|
self.set_page_complete(page, False)
|
|
|
|
|
2007-08-21 04:11:50 +05:30
|
|
|
page.set_label(confirm_text)
|
|
|
|
|
2007-08-19 02:43:30 +05:30
|
|
|
elif self.get_page_type(page) == gtk.ASSISTANT_PAGE_SUMMARY :
|
2007-08-21 04:11:50 +05:30
|
|
|
# The summary page
|
|
|
|
# Lock page, show progress bar
|
2007-08-31 03:19:46 +05:30
|
|
|
self.pre_save(page)
|
2007-08-21 04:11:50 +05:30
|
|
|
# save
|
2008-01-15 16:17:25 +05:30
|
|
|
success = self.save()
|
2007-08-21 04:11:50 +05:30
|
|
|
# Unlock page
|
|
|
|
self.post_save()
|
|
|
|
|
|
|
|
#update the label and title
|
2008-01-17 03:12:05 +05:30
|
|
|
if success:
|
2007-08-19 02:43:30 +05:30
|
|
|
conclusion_title = _('Your data has been saved')
|
|
|
|
conclusion_text = _(
|
|
|
|
'The copy of your data has been '
|
2007-08-21 04:11:50 +05:30
|
|
|
'successfully saved. You may press Close button '
|
2007-08-19 02:43:30 +05:30
|
|
|
'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. ')
|
|
|
|
#add test, what is dir
|
2008-09-06 13:39:49 +05:30
|
|
|
conclusion_text += '\n\n' + _('Filename: %s') %self.chooser.get_filename()
|
2007-08-19 02:43:30 +05:30
|
|
|
else:
|
2008-01-15 16:17:25 +05:30
|
|
|
conclusion_title = _('Saving failed')
|
2007-08-19 02:43:30 +05:30
|
|
|
conclusion_text = _(
|
|
|
|
'There was an error while saving your data. '
|
|
|
|
'You may try starting the export again.\n\n'
|
|
|
|
'Note: your currently opened database is safe. '
|
|
|
|
'It was only '
|
|
|
|
'a copy of your data that failed to save.')
|
2007-08-31 03:19:46 +05:30
|
|
|
self.labelsum.set_label(conclusion_text)
|
2007-08-19 02:43:30 +05:30
|
|
|
self.set_page_title(page, conclusion_title)
|
2007-08-23 17:28:36 +05:30
|
|
|
self.set_page_complete(page, True)
|
|
|
|
else :
|
|
|
|
#whatever other page, if we show it, it is complete to
|
|
|
|
self.set_page_complete(page, True)
|
2008-01-22 14:30:40 +05:30
|
|
|
if page_number == _ExportAssistant_pages['exporttypes'] :
|
|
|
|
##workaround around bug http://bugzilla.gnome.org/show_bug.cgi?id=56070
|
|
|
|
if self.forward_button:
|
|
|
|
self.forward_button.hide()
|
|
|
|
self.forward_button.show()
|
|
|
|
## end
|
|
|
|
|
2007-08-23 17:28:36 +05:30
|
|
|
#remember previous page for next time
|
|
|
|
self.__previous_page = page_number
|
2007-08-19 02:43:30 +05:30
|
|
|
|
|
|
|
def close(self, *obj) :
|
|
|
|
#clean up ManagedWindow menu, then destroy window, bring forward parent
|
2007-08-31 03:19:46 +05:30
|
|
|
|
2007-08-19 02:43:30 +05:30
|
|
|
ManagedWindow.ManagedWindow.close(self,*obj)
|
2008-11-04 09:42:51 +05:30
|
|
|
|
2007-08-19 02:43:30 +05:30
|
|
|
def get_intro_text(self):
|
|
|
|
return _('Under normal circumstances, GRAMPS does not require you '
|
|
|
|
'to directly save your changes. All changes you make are '
|
|
|
|
'immediately saved to the database.\n\n'
|
|
|
|
'This process will help you save a copy of your data '
|
|
|
|
'in any of the several formats supported by GRAMPS. '
|
|
|
|
'This can be used to make a copy of your data, backup '
|
|
|
|
'your data, or convert it to a format that will allow '
|
|
|
|
'you to transfer it to a different program.\n\n'
|
|
|
|
'If you change your mind during this process, you '
|
|
|
|
'can safely press the Cancel button at any time and your '
|
|
|
|
'present database will still be intact.')
|
|
|
|
|
|
|
|
def get_selected_format_index(self):
|
|
|
|
"""
|
2008-01-17 03:12:05 +05:30
|
|
|
Query the format radiobuttons and return the index number of the
|
|
|
|
selected one.
|
|
|
|
|
2007-08-19 02:43:30 +05:30
|
|
|
"""
|
|
|
|
for ix in range(len(self.format_buttons)):
|
|
|
|
button = self.format_buttons[ix]
|
|
|
|
if button.get_active():
|
|
|
|
return ix
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def suggest_filename(self):
|
2008-01-17 03:12:05 +05:30
|
|
|
"""Prepare suggested filename and set it in the file chooser."""
|
2007-08-19 02:43:30 +05:30
|
|
|
ix = self.get_selected_format_index()
|
2008-11-04 09:42:51 +05:30
|
|
|
ext = self.__exporters[ix].get_extension()
|
2007-08-19 02:43:30 +05:30
|
|
|
|
|
|
|
# Suggested folder: try last export, then last import, then home.
|
2009-10-08 06:42:51 +05:30
|
|
|
default_dir = config.get('paths.recent-export-dir')
|
2007-08-19 02:43:30 +05:30
|
|
|
if len(default_dir)<=1:
|
2009-10-08 06:42:51 +05:30
|
|
|
default_dir = config.get('paths.recent-import-dir')
|
2007-08-19 02:43:30 +05:30
|
|
|
if len(default_dir)<=1:
|
2007-09-08 11:24:02 +05:30
|
|
|
default_dir = const.USER_HOME
|
2007-08-19 02:43:30 +05:30
|
|
|
|
|
|
|
if ext == 'gramps':
|
|
|
|
new_filename = os.path.join(default_dir,'data.gramps')
|
|
|
|
elif ext == 'burn':
|
|
|
|
new_filename = os.path.basename(self.dbstate.db.get_save_path())
|
|
|
|
else:
|
|
|
|
new_filename = Utils.get_new_filename(ext,default_dir)
|
|
|
|
return (default_dir, os.path.split(new_filename)[1])
|
2007-08-21 04:11:50 +05:30
|
|
|
|
|
|
|
def save(self):
|
|
|
|
"""
|
2008-01-17 03:12:05 +05:30
|
|
|
Perform the actual Save As/Export operation.
|
|
|
|
|
2007-08-21 04:11:50 +05:30
|
|
|
Depending on the success status, set the text for the final page.
|
2008-01-17 03:12:05 +05:30
|
|
|
|
2007-08-21 04:11:50 +05:30
|
|
|
"""
|
2009-02-24 10:11:23 +05:30
|
|
|
filename = Utils.get_unicode_path(self.chooser.get_filename())
|
2009-10-08 06:42:51 +05:30
|
|
|
config.set('paths.recent-export-dir', os.path.split(filename)[0])
|
2007-08-21 04:11:50 +05:30
|
|
|
ix = self.get_selected_format_index()
|
2009-10-08 06:42:51 +05:30
|
|
|
config.set('behavior.recent-export-type', ix)
|
2008-11-04 09:42:51 +05:30
|
|
|
export_function = self.__exporters[ix].get_export_function()
|
|
|
|
success = export_function(self.dbstate.db,
|
|
|
|
filename,
|
|
|
|
self.option_box_instance,
|
|
|
|
self.callback)
|
2007-08-21 04:11:50 +05:30
|
|
|
return success
|
|
|
|
|
2007-08-31 03:19:46 +05:30
|
|
|
def pre_save(self,page):
|
2009-08-08 21:14:46 +05:30
|
|
|
#as all is locked, show the page, which assistant normally only does
|
2007-08-31 03:19:46 +05:30
|
|
|
# after prepare signal!
|
|
|
|
self.writestarted = True
|
|
|
|
page.set_child_visible(True)
|
|
|
|
self.show_all()
|
|
|
|
|
2007-08-21 04:11:50 +05:30
|
|
|
self.uistate.set_busy_cursor(1)
|
|
|
|
self.set_busy_cursor(1)
|
|
|
|
|
|
|
|
def post_save(self):
|
|
|
|
self.uistate.set_busy_cursor(0)
|
|
|
|
self.set_busy_cursor(0)
|
2007-08-31 03:19:46 +05:30
|
|
|
self.progressbar.hide()
|
|
|
|
self.writestarted = False
|
2007-08-21 04:11:50 +05:30
|
|
|
|
|
|
|
def set_busy_cursor(self,value):
|
2008-01-17 03:12:05 +05:30
|
|
|
"""Set or unset the busy cursor while saving data.
|
|
|
|
|
2007-08-21 04:11:50 +05:30
|
|
|
Note : self.window is the gtk.Assistant gtk.Window, not
|
|
|
|
a part of ManagedWindow
|
2008-01-17 03:12:05 +05:30
|
|
|
|
|
|
|
"""
|
2007-08-21 04:11:50 +05:30
|
|
|
if value:
|
|
|
|
self.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH))
|
2007-08-31 03:19:46 +05:30
|
|
|
#self.set_sensitive(0)
|
2007-08-21 04:11:50 +05:30
|
|
|
else:
|
|
|
|
self.window.set_cursor(None)
|
2007-08-31 03:19:46 +05:30
|
|
|
#self.set_sensitive(1)
|
2007-08-21 04:11:50 +05:30
|
|
|
|
|
|
|
while gtk.events_pending():
|
|
|
|
gtk.main_iteration()
|
2007-08-31 03:19:46 +05:30
|
|
|
|
2007-08-31 19:56:59 +05:30
|
|
|
def pulse_progressbar(self, value, text=None):
|
2007-08-31 03:19:46 +05:30
|
|
|
self.progressbar.set_fraction(min(value/100.0, 1.0))
|
2007-08-31 19:56:59 +05:30
|
|
|
if text:
|
|
|
|
self.progressbar.set_text("%s: %d%%" % (text, value))
|
|
|
|
else:
|
|
|
|
self.progressbar.set_text("%d%%" % value)
|
2007-08-31 03:19:46 +05:30
|
|
|
while gtk.events_pending():
|
|
|
|
gtk.main_iteration()
|
2007-08-19 02:43:30 +05:30
|
|
|
|
|
|
|
|
|
|
|
|