diff --git a/ChangeLog b/ChangeLog index 6e8338222..3f07330aa 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2005-12-28 Don Allingham + * src/GnomeMime.py: GNOME based mime handling + * src/PythonMime.py: Python based mime handling + * src/AddMedia.py: gnome code isolation + * src/DisplayState.py: gnome code isolation + * src/EditPerson.py: gnome code isolation + * src/EditRepository.py: gnome code isolation + * src/GnomeMime.py: gnome code isolation + * src/GrampsDisplay.py: gnome code isolation + * src/GrampsMime.py: gnome code isolation + * src/ImageSelect.py: gnome code isolation + * src/ImgManip.py: gnome code isolation + * src/PluginMgr.py: toolbar/menu support + * src/Plugins.py: toolbar/menu support + * src/RepositoryRefEdit.py: gnome code isolation + * src/SelectObject.py: gnome code isolation + * src/Utils.py: gnome code isolation + * src/ViewManager.py: toolbar/menu support, gnome code isolation + * src/GrampsDb/_GrampsBSDDB.py: unified messaging + * src/GrampsDb/_ReadGedcom.py: unified messaging + * src/plugins/WriteFtree.py: gnome code isolation + 2005-12-25 Don Allingham * src/Bookmarks.py: remove debugging statements * src/DisplayState.py: remove extra rebuild request diff --git a/src/AddMedia.py b/src/AddMedia.py index bca7fb1d7..3e6f5f549 100644 --- a/src/AddMedia.py +++ b/src/AddMedia.py @@ -162,7 +162,7 @@ class AddMediaObject: if mtype and mtype.startswith("image"): image = RelImage.scale_image(filename,const.thumbScale) else: - image = Utils.find_mime_type_pixbuf(mtype) + image = GrampsMime.find_mime_type_pixbuf(mtype) self.image.set_from_pixbuf(image) def run(self): diff --git a/src/DisplayState.py b/src/DisplayState.py index 1b4b24bf1..03a83d88c 100644 --- a/src/DisplayState.py +++ b/src/DisplayState.py @@ -43,6 +43,7 @@ import gtk import GrampsDb import GrampsKeys import NameDisplay +import GrampsMime #------------------------------------------------------------------------- # @@ -352,10 +353,6 @@ _rct_btm = '' import RecentFiles import os -try: - from gnomevfs import get_mime_type -except: - from gnome.vfs import get_mime_type class RecentDocsMenu: def __init__(self,uimanager, state, fileopen): @@ -393,7 +390,7 @@ class RecentDocsMenu: for item in rfiles: try: filename = os.path.basename(item.get_path()).replace('_','__') - filetype = get_mime_type(item.get_path()) + filetype = GrampsMime.get_type(item.get_path()) action_id = "RecentMenu%d" % count f.write('' % action_id) actions.append((action_id,None,filename,None,None, diff --git a/src/EditPerson.py b/src/EditPerson.py index 0ee67542b..2d713e4cb 100644 --- a/src/EditPerson.py +++ b/src/EditPerson.py @@ -41,7 +41,6 @@ from cgi import escape import gtk import gtk.glade import gobject -import gnome import gtk.gdk #------------------------------------------------------------------------- @@ -502,7 +501,7 @@ class EditPerson(DisplayState.ManagedWindow): if mtype[0:5] == "image": image = ImgManip.get_thumbnail_image(obj.get_path()) else: - image = Utils.find_mime_type_pixbuf(mtype) + image = GrampsMime.find_mime_type_pixbuf(mtype) if not image: image = gtk.gdk.pixbuf_new_from_file(const.icon) return image diff --git a/src/EditRepository.py b/src/EditRepository.py index d57b8a27d..f519674c3 100644 --- a/src/EditRepository.py +++ b/src/EditRepository.py @@ -35,7 +35,6 @@ from gettext import gettext as _ import gobject import gtk.glade import gtk.gdk -import gnome #------------------------------------------------------------------------- # @@ -50,6 +49,7 @@ import RelLib import NameDisplay import AutoComp import RepositoryRefEdit +import GrampsDisplay #------------------------------------------------------------------------- # @@ -418,7 +418,7 @@ class EditRepository: def on_help_clicked(self,obj): """Display the relevant portion of GRAMPS manual""" - gnome.help_display('gramps-manual','adv-src') + GrampsDisplay.help('adv-src') def close(self,obj): self.close_child_windows() diff --git a/src/GnomeMime.py b/src/GnomeMime.py new file mode 100644 index 000000000..b797f4237 --- /dev/null +++ b/src/GnomeMime.py @@ -0,0 +1,80 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2004 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 +# + +try: + from gnomevfs import mime_get_short_list_applications, mime_get_description, get_mime_type +except: + from gnome.vfs import mime_get_short_list_applications, mime_get_description, get_mime_type + +from gettext import gettext as _ + +def get_application(type): + """Returns the application command and application name of the + specified mime type""" + try: + applist = mime_get_short_list_applications(type) + if applist: + prog = applist[0] + return (prog[2],prog[1]) + else: + return None + except: + return None + +def get_description(type): + """Returns the description of the specfied mime type""" + try: + return mime_get_description(type) + except: + return _("unknown") + +def get_type(file): + """Returns the mime type of the specified file""" + try: + return get_mime_type(file) + except: + return _('unknown') + +def mime_type_is_defined(type): + """"Return True if a description for a mime type exists""" + try: + mime_get_description(type) + return True + except: + return False + +_icon_theme = gtk.icon_theme_get_default() + +def find_mime_type_pixbuf(mime_type): + try: + icontmp = mime_type.replace('/','-') + newicon = "gnome-mime-%s" % icontmp + try: + return _icon_theme.load_icon(newicon,48,0) + except: + icontmp = mime_type.split('/')[0] + try: + newicon = "gnome-mime-%s" % icontmp + return _icon_theme.load_icon(newicon,48,0) + except: + return gtk.gdk.pixbuf_new_from_file(const.icon) + except: + return gtk.gdk.pixbuf_new_from_file(const.icon) + diff --git a/src/GrampsDb/_GrampsBSDDB.py b/src/GrampsDb/_GrampsBSDDB.py index d620a6a75..df4bc936d 100644 --- a/src/GrampsDb/_GrampsBSDDB.py +++ b/src/GrampsDb/_GrampsBSDDB.py @@ -179,6 +179,8 @@ class GrampsBSDDB(GrampsDbBase): self.readonly = mode == "r" + callback(0.25) + self.env = db.DBEnv() self.env.set_cachesize(0,0x2000000) # 2MB flags = db.DB_CREATE|db.DB_INIT_MPOOL|db.DB_PRIVATE @@ -275,7 +277,6 @@ class GrampsBSDDB(GrampsDbBase): "reference_map_referenced_map", db.DB_BTREE, flags=openflags) - if not self.readonly: self.person_map.associate(self.surnames, find_surname, openflags) self.person_map.associate(self.id_trans, find_idmap, openflags) @@ -298,6 +299,8 @@ class GrampsBSDDB(GrampsDbBase): self.undodb = db.DB() self.undodb.open(self.undolog, db.DB_RECNO, db.DB_CREATE) + callback(0.5) + self.metadata = self.dbopen(name, "meta") self.bookmarks = self.metadata.get('bookmarks') self.family_event_names = sets.Set(self.metadata.get('fevent_names',[])) diff --git a/src/GrampsDb/_ReadGedcom.py b/src/GrampsDb/_ReadGedcom.py index 8f1d3c71c..02b8c6f0c 100644 --- a/src/GrampsDb/_ReadGedcom.py +++ b/src/GrampsDb/_ReadGedcom.py @@ -164,7 +164,7 @@ def importData(database, filename, cb=None, use_trans=True): f.close() if not gramps and ansel: - glade_file = "%s/gedcomimport.glade" % os.path.dirname(__file__) + glade_file = "%s/../gedcomimport.glade" % os.path.dirname(__file__) top = gtk.glade.XML(glade_file,'encoding','gramps') code = top.get_widget('codeset') code.set_active(0) @@ -180,9 +180,9 @@ def importData(database, filename, cb=None, use_trans=True): def import2(database, filename, cb, codeset, use_trans): # add some checking here - glade_file = "%s/gedcomimport.glade" % os.path.dirname(__file__) + glade_file = "%s/../gedcomimport.glade" % os.path.dirname(__file__) if not os.path.isfile(glade_file): - glade_file = "plugins/gedcomimport.glade" + glade_file = "../gedcomimport.glade" statusTop = gtk.glade.XML(glade_file,"status","gramps") status_window = statusTop.get_widget("status") diff --git a/src/GrampsDisplay.py b/src/GrampsDisplay.py index ef78cf15e..f6cad714e 100644 --- a/src/GrampsDisplay.py +++ b/src/GrampsDisplay.py @@ -18,18 +18,19 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -import gnome import gobject from QuestionDialog import ErrorDialog def help(target): try: + import gnome gnome.help_display('gramps-manual',target) except gobject.GError, msg: url('http://gramps-project.org/gramps-manual/gramps-manual-en/index.html') def url(target): try: + import gnome gnome.url_show(target) except gobject.GError, msg: run_browser(target) diff --git a/src/GrampsMime.py b/src/GrampsMime.py index 6b7ac4bb4..78074272a 100644 --- a/src/GrampsMime.py +++ b/src/GrampsMime.py @@ -19,43 +19,6 @@ # try: - from gnomevfs import mime_get_short_list_applications, mime_get_description, get_mime_type + from GnomeMime import * except: - from gnome.vfs import mime_get_short_list_applications, mime_get_description, get_mime_type - -from gettext import gettext as _ - -def get_application(type): - """Returns the application command and application name of the - specified mime type""" - try: - applist = mime_get_short_list_applications(type) - if applist: - prog = applist[0] - return (prog[2],prog[1]) - else: - return None - except: - return None - -def get_description(type): - """Returns the description of the specfied mime type""" - try: - return mime_get_description(type) - except: - return _("unknown") - -def get_type(file): - """Returns the mime type of the specified file""" - try: - return get_mime_type(file) - except: - return _('unknown') - -def mime_type_is_defined(type): - """"Return True if a description for a mime type exists""" - try: - mime_get_description(type) - return True - except: - return False + from PythonMime import * diff --git a/src/ImageSelect.py b/src/ImageSelect.py index 932afb74d..50c41f55e 100644 --- a/src/ImageSelect.py +++ b/src/ImageSelect.py @@ -169,7 +169,7 @@ class ImageSelect: image = RelImage.scale_image(filename,const.thumbScale) self.image.set_from_pixbuf(image) else: - i = Utils.find_mime_type_pixbuf(mtype) + i = GrampsMime.find_mime_type_pixbuf(mtype) self.image.set_from_pixbuf(i) def on_savephoto_clicked(self): @@ -754,7 +754,7 @@ class LocalMediaProperties: self.change_dialog.get_widget("path").set_text(fname) - mt = Utils.get_mime_description(mtype) + mt = GrampsMime.get_description(mtype) if mt: self.change_dialog.get_widget("type").set_text(mt) else: @@ -1055,7 +1055,7 @@ class GlobalMediaProperties(DisplayState.ManagedWindow): if mtype: pb = ImgManip.get_thumbnail_image(self.obj.get_path(),mtype) self.pixmap.set_from_pixbuf(pb) - descr = Utils.get_mime_description(mtype) + descr = GrampsMime.get_description(mtype) if descr: self.change_dialog.get_widget("type").set_text(descr) else: diff --git a/src/ImgManip.py b/src/ImgManip.py index 21fd3a0ab..898b78d39 100644 --- a/src/ImgManip.py +++ b/src/ImgManip.py @@ -25,6 +25,7 @@ import md5 import gtk import gobject +import GrampsMime import GrampsKeys import Utils @@ -152,7 +153,7 @@ def get_thumbnail_image(path,mtype=None): return gtk.gdk.pixbuf_new_from_file(filename) except (gobject.GError, OSError): if mtype: - return Utils.find_mime_type_pixbuf(mtype) + return GrampsMime.find_mime_type_pixbuf(mtype) else: return gtk.gdk.pixbuf_new_from_file(os.path.join(const.dataDir,"document.png")) diff --git a/src/PluginMgr.py b/src/PluginMgr.py index 30710db15..e1ffa2727 100644 --- a/src/PluginMgr.py +++ b/src/PluginMgr.py @@ -95,7 +95,7 @@ def load_plugins(direct): is done in this routine to register the tasks.""" global _success_list,attempt_list,loaddir_list,failmsg_list - + # if the directory does not exist, do nothing if not os.path.isdir(direct): return True @@ -263,7 +263,6 @@ def register_report( The low-level functions (starting with '_') should not be used on their own. Instead, this function will call them as needed. """ - import Report (junk,standalone_task) = divmod(modes,2**Report.MODE_GUI) if standalone_task: @@ -302,6 +301,7 @@ def _register_standalone(report_class, options_class, translated_name, del_index = i if del_index != -1: del report_list[del_index] + report_list.append((report_class, options_class, translated_name, category, name, description, status, author_name, author_email, unsupported)) diff --git a/src/Plugins.py b/src/Plugins.py index 017591463..de33bf398 100644 --- a/src/Plugins.py +++ b/src/Plugins.py @@ -89,7 +89,6 @@ class PluginDialog(DisplayState.ManagedWindow): hand side of the dailog box.""" self.active = state.active - self.update = None self.imap = {} self.msg = msg self.content = content @@ -161,12 +160,12 @@ class PluginDialog(DisplayState.ManagedWindow): (item_class,options_class,title,category,name) = self.item if self.content == REPORTS: - Report.report(self.db,self.active, + Report.report(self.state.db,self.state.active, item_class,options_class,title,name,category) else: - Tool.gui_tool(self.db,self.active, + Tool.gui_tool(self.state.db,self.state.active, item_class,options_class,title,name,category, - self.update,self.parent) + self.state.db.request_rebuild,self.parent) def on_node_selected(self,obj): """Updates the informational display on the right hand side of @@ -285,16 +284,16 @@ class ToolPlugins(PluginDialog): """Displays the dialog box that allows the user to select the tool that is desired.""" - def __init__(self,parent,db,active,update): + def __init__(self,dbstate,uistate,track): """Display the dialog box, and build up the list of available reports. This is used to build the selection tree on the left hand side of the dailog box.""" PluginDialog.__init__( self, - parent, - db, - active, + dbstate, + uistate, + track, PluginMgr.tool_list, Tool.tool_categories, _("Tool Selection"), @@ -302,28 +301,24 @@ class ToolPlugins(PluginDialog): _("_Run"), _("Run selected tool"), TOOLS) - self.update = update #------------------------------------------------------------------------- # # PluginStatus # #------------------------------------------------------------------------- -status_up = None -parent_window = None -class PluginStatus: +class PluginStatus(DisplayState.ManagedWindow): """Displays a dialog showing the status of loaded plugins""" - def __init__(self,parent_class=None): - global status_up, parent_window - if status_up: - status_up.close(None) - if parent_class: - parent_window = parent_class.topWindow - status_up = self + def __init__(self,state,uistate,track): import cStringIO + DisplayState.ManagedWindow.__init__(self, uistate, [], None) + if self.already_exist: + return + self.state = state + self.uistate = uistate self.glade = gtk.glade.XML(const.pluginsFile,"plugstat","gramps") self.window = self.glade.get_widget("plugstat") @@ -341,9 +336,6 @@ class PluginStatus: 'on_plugstat_delete_event' : self.on_delete, }) - if parent_window: - self.window.set_transient_for(parent_window) - info = cStringIO.StringIO() if len(PluginMgr.expect_list) + len(PluginMgr.failmsg_list) == 0: @@ -366,11 +358,10 @@ class PluginStatus: window.get_buffer().set_text(info.read()) def on_delete(self,obj1,obj2): - status_up = None + pass def close(self,obj): self.window.destroy() - status_up = None def help(self,obj): """Display the GRAMPS manual""" diff --git a/src/PythonMime.py b/src/PythonMime.py new file mode 100644 index 000000000..ac9f443ff --- /dev/null +++ b/src/PythonMime.py @@ -0,0 +1,64 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2004 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 +# + +import mimetypes +import const +from gettext import gettext as _ + +_type_map = { + 'application/x-gramps' : 'GRAMPS database', + 'application/x-gramps-xml' : 'GRAMPS XML database', + 'application/x-gedcom' : 'GEDCOM database', + 'application/x-gramps-package': 'GRAMPS package', + 'image/jpeg' : 'JPEG image', + 'application/pdf' : 'PDF document', + 'text/rtf' : 'Rich Text File', +} + +mimetypes.add_type('application/x-gramps','.grdb') +mimetypes.add_type('application/x-gramps','.GRDB') +mimetypes.add_type('application/x-gramps-xml','.gramps') +mimetypes.add_type('application/x-gramps-xml','.GRAMPS') +mimetypes.add_type('application/x-gedcom','.ged') +mimetypes.add_type('application/x-gedcom','.GED') + +def get_application(mime_type): + """Returns the application command and application name of the + specified mime type""" + return None + +def get_description(mime_type): + """Returns the description of the specfied mime type""" + return _type_map.get(mime_type,_("unknown")) + +def get_type(filename): + """Returns the mime type of the specified file""" + value = mimetypes.guess_type(filename) + if value: + return value[0] + else: + return _('unknown') + +def mime_type_is_defined(mime_type): + """"Return True if a description for a mime type exists""" + return _type_map.has_key(mime_type) + +def find_mime_type_pixbuf(mime_type): + return gtk.gdk.pixbuf_new_from_file(const.icon) diff --git a/src/RepositoryRefEdit.py b/src/RepositoryRefEdit.py index af90c9898..fbcd645a4 100644 --- a/src/RepositoryRefEdit.py +++ b/src/RepositoryRefEdit.py @@ -34,7 +34,6 @@ from gettext import gettext as _ #------------------------------------------------------------------------- import gtk import gtk.glade -import gnome from gtk.gdk import ACTION_COPY, BUTTON1_MASK, INTERP_BILINEAR, pixbuf_new_from_file from gobject import TYPE_PYOBJECT import cPickle as pickle @@ -51,7 +50,7 @@ import Date import DateEdit import DateHandler import AutoComp - +import GrampsDisplay #------------------------------------------------------------------------- # @@ -218,7 +217,7 @@ class RepositoryRefEdit(RepositoryRefEditBase): def on_help_clicked(self,obj): """Display the relevant portion of GRAMPS manual""" - gnome.help_display('gramps-manual','adv-si') + GrampsDisplay.help('adv-si') def set_button(self): if self.active_repos: @@ -355,7 +354,7 @@ class RepositoryRefSourceEdit(RepositoryRefEditBase): def on_help_clicked(self,obj): """Display the relevant portion of GRAMPS manual""" - gnome.help_display('gramps-manual','adv-si') + GrampsDisplay.help('adv-si') def set_button(self): if self.active_source: diff --git a/src/SelectObject.py b/src/SelectObject.py index e0e99c3c9..6ff8e2dfe 100644 --- a/src/SelectObject.py +++ b/src/SelectObject.py @@ -58,6 +58,7 @@ import const import Utils import ListModel import ImgManip +import GrampsMime #------------------------------------------------------------------------- # @@ -100,7 +101,7 @@ class SelectObject: for key in self.db.get_media_object_handles(): obj = self.db.get_object_from_handle(key) title = obj.get_description() - the_type = Utils.get_mime_description(obj.get_mime_type()) + the_type = GramspMime.get_description(obj.get_mime_type()) path = obj.get_path() self.object_model.add([title,obj.get_gramps_id(),the_type,path],key) @@ -119,7 +120,7 @@ class SelectObject: if the_type and the_type[0:5] == "image": image = ImgManip.get_thumbnail_image(path,the_type) else: - image = Utils.find_mime_type_pixbuf(the_type) + image = GrampsMime.find_mime_type_pixbuf(the_type) self.preview.set_from_pixbuf(image) self.object_handle.set_text(obj.get_gramps_id()) diff --git a/src/Utils.py b/src/Utils.py index 32385e004..a7a8af638 100644 --- a/src/Utils.py +++ b/src/Utils.py @@ -505,30 +505,6 @@ def view_photo(photo): if os.fork() == 0: os.execvp(args[0],args) -_icon_theme = gtk.icon_theme_get_default() - -def find_mime_type_pixbuf(mime_type): - try: - icontmp = mime_type.replace('/','-') - newicon = "gnome-mime-%s" % icontmp - try: - return _icon_theme.load_icon(newicon,48,0) - except: - icontmp = mime_type.split('/')[0] - try: - newicon = "gnome-mime-%s" % icontmp - return _icon_theme.load_icon(newicon,48,0) - except: - return gtk.gdk.pixbuf_new_from_file(const.icon) - except: - return gtk.gdk.pixbuf_new_from_file(const.icon) - -def get_mime_description(mime_type): - try: - return GrampsMime.get_description(mime_type) - except: - return '' - def find_file( filename): # try the filename we got try: diff --git a/src/ViewManager.py b/src/ViewManager.py index 26960943c..fd72c45f1 100644 --- a/src/ViewManager.py +++ b/src/ViewManager.py @@ -28,6 +28,7 @@ from gettext import gettext as _ from bsddb import db import os +from cStringIO import StringIO #------------------------------------------------------------------------- # @@ -35,11 +36,6 @@ import os # #------------------------------------------------------------------------- import gtk -import gnome -try: - from gnomevfs import get_mime_type -except: - from gnome.vfs import get_mime_type #------------------------------------------------------------------------- # @@ -47,9 +43,9 @@ except: # #------------------------------------------------------------------------- import DisplayState -import DbPrompter import const import PluginMgr +import Plugins import GrampsKeys import GrampsDb import GrampsCfg @@ -63,6 +59,9 @@ import TipOfDay import Bookmarks import RecentFiles import NameDisplay +import Tool +import Report +import GrampsMime #------------------------------------------------------------------------- # @@ -124,6 +123,7 @@ uidefault = ''' + @@ -206,7 +206,8 @@ class ViewManager: person_nav = Navigation.PersonNavigation(self.uistate) self.navigation_type[PageView.NAVIGATION_PERSON] = (person_nav,None) - self.recent_manager = DisplayState.RecentDocsMenu(self.uimanager,self.state,self.read_file) + self.recent_manager = DisplayState.RecentDocsMenu(self.uimanager,self.state, + self.read_file) self.recent_manager.build() self.window.show() @@ -214,6 +215,22 @@ class ViewManager: self.create_pages() self.change_page(None,None) self.actiongroup.set_visible(False) + self.fileactions.set_sensitive(False) + self.load_plugins() + self.build_tools_menu() + self.build_report_menu() + self.fileactions.set_sensitive(True) + + def load_plugins(self): + self.uistate.status_text(_('Loading document formats...')) + error = PluginMgr.load_plugins(const.docgenDir) + error |= PluginMgr.load_plugins(os.path.expanduser("~/.gramps/docgen")) + self.uistate.status_text(_('Loading plugins...')) + error |= PluginMgr.load_plugins(const.pluginsDir) + error |= PluginMgr.load_plugins(os.path.expanduser("~/.gramps/plugins")) + if GrampsKeys.get_pop_plugin_status() and error: + Plugins.PluginStatus(self) + self.uistate.push_message(_('Ready')) def quit(self,obj=None): self.state.db.close() @@ -238,6 +255,7 @@ class ViewManager: self.actiongroup = gtk.ActionGroup('MainWindow') self.fileactions = gtk.ActionGroup('FileWindow') + self.fileactions.add_actions([ ('FileMenu', None, '_File'), ('New', gtk.STOCK_NEW, '_New', "n", None, self.new_activate), @@ -252,6 +270,7 @@ class ViewManager: ('MailingLists', None, _('GRAMPS _mailing lists'), None, None, self.mailing_lists_activate), ('ReportBug', None, _('_Report a bug'), None, None, self.report_bug_activate), ('About', gtk.STOCK_ABOUT, '_About', None, None, self.about), + ('PluginStatus', None, '_Plugin status', None, None, self.plugin_status), ('FAQ', None, '_FAQ', None, None, self.faq_activate), ('UserManual', gtk.STOCK_HELP, '_User Manual', 'F1', None, self.manual_activate), ('TipOfDay', None, 'Tip of the day', None, None, self.tip_of_day_activate), @@ -268,7 +287,7 @@ class ViewManager: ('ScratchPad', gtk.STOCK_PASTE, '_ScratchPad', None, None, self.scratchpad), ('Import', gtk.STOCK_CONVERT, '_Import', None, None, self.import_data), ('Reports', gtk.STOCK_DND_MULTIPLE, '_Reports', None, None, self.reports_clicked), - ('Tools', gtk.STOCK_EXECUTE, '_Tools'), + ('Tools', gtk.STOCK_EXECUTE, '_Tools', None, None, self.tools_clicked), ('EditMenu', None, '_Edit'), ('GoMenu', None, '_Go'), ('BookMenu', None, '_Bookmarks'), @@ -290,25 +309,25 @@ class ViewManager: self.uimanager.insert_action_group(self.actiongroup,1) def home_page_activate(self,obj): - gnome.url_show( const.url_homepage) + GrampsDisplay.url(const.url_homepage) def mailing_lists_activate(self,obj): - gnome.url_show( const.url_mailinglist) + GrampsDisplay.url( const.url_mailinglist) def report_bug_activate(self,obj): - gnome.url_show( const.url_bugtracker) + GrampsDisplay.url( const.url_bugtracker) def manual_activate(self,obj): """Display the GRAMPS manual""" try: - gnome.help_display('gramps-manual','index') + GrampsDisplay.help('index') except gobject.GError, msg: ErrorDialog(_("Could not open help"),str(msg)) def faq_activate(self,obj): """Display FAQ""" try: - gnome.help_display('gramps-manual','faq') + GrampsDisplay.help('faq') except gobject.GError, msg: ErrorDialog(_("Could not open help"),str(msg)) @@ -316,6 +335,10 @@ class ViewManager: """Display Tip of the day""" TipOfDay.TipOfDay(self.uistate) + def plugin_status(self,obj): + """Display Tip of the day""" + Plugins.PluginStatus(self.state,self.uistate,[]) + def about(self,obj): about = gtk.AboutDialog() about.set_name(const.program_name) @@ -481,7 +504,7 @@ class ViewManager: return False filetype = type_selector.get_value() if filetype == 'auto': - filetype = get_mime_type(filename) + filetype = GrampsMime.get_type(filename) (the_path,the_file) = os.path.split(filename) choose.destroy() if filetype in [const.app_gramps,const.app_gramps_xml, @@ -674,8 +697,10 @@ class ViewManager: return True def load_database(self,name,callback=None,mode="w"): - if not self.state.db.load(name,callback,mode): + self.progress.show() + if not self.state.db.load(name,self.pulse_progressbar,mode): return False + self.progress.hide() return self.post_load(name,callback) def post_load(self,name,callback=None): @@ -732,6 +757,10 @@ class ViewManager: def reports_clicked(self,obj): import Plugins Plugins.ReportPlugins(self.state,self.uistate,[]) + + def tools_clicked(self,obj): + import Plugins + Plugins.ToolPlugins(self.state,self.uistate,[]) def find_initial_person(self): person = self.state.db.get_default_person() @@ -748,6 +777,8 @@ class ViewManager: def pulse_progressbar(self,value): self.progress.set_fraction(value) + while gtk.events_pending(): + gtk.main_iteration() def import_data(self,obj): choose = gtk.FileChooserDialog(_('GRAMPS: Import database'), @@ -799,7 +830,7 @@ class ViewManager: filetype = type_selector.get_value() if filetype == 'auto': try: - filetype = get_mime_type(filename) + filetype = GrampsMime.get_type(filename) except RuntimeError,msg: QuestionDialog.ErrorDialog( _("Could not open file: %s") % filename, @@ -808,8 +839,10 @@ class ViewManager: if filetype == const.app_gramps: choose.destroy() - GrampsDb.gramps_db_reader_factory(filetype)(self.state.db,filename) + self.progress.show() + GrampsDb.gramps_db_reader_factory(filetype)(self.state.db,filename,self.pulse_progressbar) self.parent.import_tool_callback() + self.progress.hide() return True elif filetype == const.app_gramps_xml: choose.destroy() @@ -836,6 +869,85 @@ class ViewManager: choose.destroy() return False + + def build_tools_menu(self): + self.toolactions = gtk.ActionGroup('ToolWindow') + (ui,actions) = self.build_plugin_menu('ToolsMenu', + PluginMgr.tool_list, + Tool.tool_categories, + make_tool_callback) + self.toolactions.add_actions(actions) + self.uistate.uimanager.add_ui_from_string(ui) + self.uimanager.insert_action_group(self.toolactions,1) + + def build_report_menu(self): + self.reportactions = gtk.ActionGroup('ReportWindow') + (ui,actions) = self.build_plugin_menu('ReportsMenu', + PluginMgr.report_list, + Report.standalone_categories, + make_report_callback) + self.reportactions.add_actions(actions) + self.uistate.uimanager.add_ui_from_string(ui) + self.uimanager.insert_action_group(self.reportactions,1) + + def build_plugin_menu(self,text,item_list,categories,func): + actions = [] + f = StringIO() + f.write('' % text) + + menu = gtk.Menu() + menu.show() + + hash_data = {} + for item in item_list: + if item[9]: + category = Plugins.UNSUPPORTED + else: + category = categories[item[3]] + if hash_data.has_key(category): + hash_data[category].append( + (item[0],item[1],item[2],item[4],item[3])) + else: + hash_data[category] = [ + (item[0],item[1],item[2],item[4],item[3])] + + # Sort categories, skipping the unsupported + catlist = [item for item in hash_data.keys() if item != Plugins.UNSUPPORTED] + catlist.sort() + for key in catlist: + new_key = key.replace(' ','-') + f.write('' % new_key) + actions.append((new_key,None,key)) + lst = hash_data[key] + lst.sort(by_menu_name) + for name in lst: + new_key = name[2].replace(' ','-') + f.write('' % new_key) + actions.append((new_key,None,name[2],None,None, + func(name,self.state))) + f.write('') + + # If there are any unsupported items we add separator + # and the unsupported category at the end of the menu + if hash_data.has_key(Plugins.UNSUPPORTED): + f.write('') + f.write('' % Plugins.UNSUPPORTED) + actions.append((Plugins.UNSUPPORTED,None,Plugins.UNSUPPORTED)) + lst = hash_data[key] + lst.sort(by_menu_name) + for name in lst: + new_key = name[2].replace(' ','-') + f.write('' % new_key) + actions.append((new_key,None,name[2],None,None, + func(name,self.state))) + f.write('') + + f.write('') + return (f.getvalue(),actions) + +def by_menu_name(a,b): + return cmp(a[2],b[2]) + def add_all_files_filter(chooser): """ Add an all-permitting filter to the file chooser dialog. @@ -883,6 +995,15 @@ def add_gedcom_filter(chooser): mime_filter.add_mime_type(const.app_gedcom) chooser.add_filter(mime_filter) +def make_report_callback(lst,dbstate): + return lambda x: Report.report(dbstate.db,dbstate.active, + lst[0],lst[1],lst[2],lst[3],lst[4]) + +def make_tool_callback(lst,dbstate): + return lambda x: Tool.gui_tool(dbstate.db,dbstate.active, + lst[0],lst[1],lst[2],lst[3],lst[4], + dbstate.db.request_rebuild,None) + #------------------------------------------------------------------------- # # Format selectors and filters diff --git a/src/plugins/WriteFtree.py b/src/plugins/WriteFtree.py index 1b7ae948e..ad7b4915e 100644 --- a/src/plugins/WriteFtree.py +++ b/src/plugins/WriteFtree.py @@ -38,7 +38,6 @@ from gettext import gettext as _ #------------------------------------------------------------------------- import gtk import gtk.glade -import gnome #------------------------------------------------------------------------- #