diff --git a/src/DataViews/GrampletView.py b/src/DataViews/GrampletView.py index 9d87e7bc9..306552c20 100644 --- a/src/DataViews/GrampletView.py +++ b/src/DataViews/GrampletView.py @@ -49,7 +49,7 @@ import const import PageView import ManagedWindow import ConfigParser -import Utils +from gui.utils import add_menuitem from QuickReports import run_quick_report_by_name import GrampsDisplay from glade import Glade @@ -1585,7 +1585,7 @@ class GrampletView(PageView.PersonNavView): in AVAILABLE_GRAMPLETS] names.sort() for name in names: - Utils.add_menuitem(qr_menu, name, + add_menuitem(qr_menu, name, None, self.add_gramplet) self.uistate.uimanager.get_widget('/Popup/AddGramplet').set_submenu(qr_menu) rg_menu = self.uistate.uimanager.get_widget('/Popup/RestoreGramplet') @@ -1602,7 +1602,7 @@ class GrampletView(PageView.PersonNavView): if len(names) > 0: qr_menu = gtk.Menu() for name in names: - Utils.add_menuitem(qr_menu, name, + add_menuitem(qr_menu, name, None, self.restore_gramplet) self.uistate.uimanager.get_widget('/Popup/RestoreGramplet').set_submenu(qr_menu) if menu: diff --git a/src/DataViews/PersonView.py b/src/DataViews/PersonView.py index cb160863e..d629d6bec 100644 --- a/src/DataViews/PersonView.py +++ b/src/DataViews/PersonView.py @@ -51,6 +51,7 @@ from DisplayModels import PeopleModel import PageView from BasicUtils import name_displayer import Utils +from gui.utils import add_menuitem from QuestionDialog import ErrorDialog, QuestionDialog import TreeTips import Errors @@ -856,7 +857,7 @@ class PersonView(PageView.PersonNavView): if len(reportactions) > 1 : qr_menu = gtk.Menu() for action in reportactions[1:] : - Utils.add_menuitem(qr_menu, action[2], None, action[5]) + add_menuitem(qr_menu, action[2], None, action[5]) self.uistate.uimanager.get_widget('/Popup/QuickReport').\ set_submenu(qr_menu) if menu: diff --git a/src/DataViews/PlaceView.py b/src/DataViews/PlaceView.py index 55de8ae6d..fd6144ad1 100644 --- a/src/DataViews/PlaceView.py +++ b/src/DataViews/PlaceView.py @@ -46,7 +46,7 @@ import gtk import gen.lib import PageView import DisplayModels -import Utils +from gui.utils import add_menuitem import Errors import Bookmarks import Config @@ -195,7 +195,7 @@ class PlaceView(PageView.ListView): servlist = PluginManager.get_instance().get_mapservice_list() for i, service in zip(range(len(servlist)), servlist): key = service[2].replace(' ', '-') - Utils.add_menuitem(menu, service[1], None, + add_menuitem(menu, service[1], None, make_callback(self.set_mapservice, key)) self.mapservicedata[key] = (service[0], service[2], service[3]) diff --git a/src/Editors/_EditPerson.py b/src/Editors/_EditPerson.py index 71b3fda9f..d861c32c8 100644 --- a/src/Editors/_EditPerson.py +++ b/src/Editors/_EditPerson.py @@ -48,6 +48,7 @@ import gtk #------------------------------------------------------------------------- import const import Utils +from gui.utils import add_menuitem import Mime import gen.lib import widgets @@ -496,8 +497,8 @@ class EditPerson(EditPrimary): menu.set_title(_("Media Object")) obj = self.db.get_object_from_handle(photo.get_reference_handle()) if obj: - Utils.add_menuitem(menu, _("View"), photo, self._popup_view_photo) - Utils.add_menuitem(menu, _("Edit Object Properties"), photo, + add_menuitem(menu, _("View"), photo, self._popup_view_photo) + add_menuitem(menu, _("Edit Object Properties"), photo, self._popup_change_description) menu.popup(None, None, None, event.button, event.time) diff --git a/src/Filters/_GenericFilter.py b/src/Filters/_GenericFilter.py index 8bcaff6c9..6e6b484f4 100644 --- a/src/Filters/_GenericFilter.py +++ b/src/Filters/_GenericFilter.py @@ -197,7 +197,8 @@ class GenericFilter(object): def check(self, db, handle): return self.get_check_func()(db, [handle]) - # progress is optional. If present it must be an instance of Utils.ProgressMeter + # progress is optional. If present it must be an instance of + # gui.utils.ProgressMeter def apply(self, db, id_list=None, progress=None): m = self.get_check_func() for rule in self.flist: diff --git a/src/GrampsCfg.py b/src/GrampsCfg.py index 5f60f0c32..6eb52c1d3 100644 --- a/src/GrampsCfg.py +++ b/src/GrampsCfg.py @@ -56,15 +56,6 @@ from QuestionDialog import ErrorDialog, QuestionDialog2 from Errors import NameDisplayError from glade import Glade -geopresent = True -try: - import DataViews.GeoView -except: - geopresent = False -#experimental feature, don't show in release -if not const.VERSION.find('SVN') == -1: - gepresent = False - #------------------------------------------------------------------------- # # Constants @@ -84,34 +75,6 @@ COL_NAME = 1 COL_FMT = 2 COL_EXPL = 3 -def set_calendar_date_format(): - format_list = DateHandler.get_date_formats() - DateHandler.set_format(Config.get_date_format(format_list)) - -def get_researcher(): - import gen.lib - - n = Config.get(Config.RESEARCHER_NAME) - a = Config.get(Config.RESEARCHER_ADDR) - c = Config.get(Config.RESEARCHER_CITY) - s = Config.get(Config.RESEARCHER_STATE) - ct = Config.get(Config.RESEARCHER_COUNTRY) - p = Config.get(Config.RESEARCHER_POSTAL) - ph = Config.get(Config.RESEARCHER_PHONE) - e = Config.get(Config.RESEARCHER_EMAIL) - - owner = gen.lib.Researcher() - owner.set_name(n) - owner.set_address(a) - owner.set_city(c) - owner.set_state(s) - owner.set_country(ct) - owner.set_postal_code(p) - owner.set_phone(ph) - owner.set_email(e) - - return owner - #------------------------------------------------------------------------- # # @@ -188,7 +151,8 @@ class GrampsPreferences(ManagedWindow.ManagedWindow): MarkupLabel(_('Researcher'))) panel.append_page(self.add_color_panel(), MarkupLabel(_('Marker Colors'))) - if geopresent: + import DataViews + if DataViews.geopresent: panel.append_page(self.add_geoview_panel(), MarkupLabel(_('Internet Maps'))) self.window.show_all() diff --git a/src/PageView.py b/src/PageView.py index cd48df69b..1707ba5f4 100644 --- a/src/PageView.py +++ b/src/PageView.py @@ -50,6 +50,7 @@ import Bookmarks import Errors from Filters import SearchBar import Utils +from gui.utils import add_menuitem import const from widgets.menutoolbuttonaction import MenuToolButtonAction @@ -1041,7 +1042,7 @@ class ListView(BookMarkView): if len(reportactions) > 1 : qr_menu = gtk.Menu() for action in reportactions[1:] : - Utils.add_menuitem(qr_menu, action[2], None, action[5]) + add_menuitem(qr_menu, action[2], None, action[5]) self.uistate.uimanager.get_widget('/Popup/QuickReport').\ set_submenu(qr_menu) if menu: diff --git a/src/PluginUtils/_GuiOptions.py b/src/PluginUtils/_GuiOptions.py index 982de6aa5..fbe32c5b7 100644 --- a/src/PluginUtils/_GuiOptions.py +++ b/src/PluginUtils/_GuiOptions.py @@ -47,6 +47,7 @@ import gobject # #------------------------------------------------------------------------- import Utils +from gui.utils import ProgressMeter import widgets import ManagedWindow from QuestionDialog import OptionDialog @@ -107,7 +108,7 @@ class LastNameDialog(ManagedWindow.ManagedWindow): # build up the list of surnames, keeping track of the count for each # name (this can be a lengthy process, so by passing in the # dictionary we can be certain we only do this once) - progress = Utils.ProgressMeter(_('Finding Surnames')) + progress = ProgressMeter(_('Finding Surnames')) progress.set_pass(_('Finding surnames'), database.get_number_of_people()) for person_handle in database.get_person_handles(False): diff --git a/src/PluginUtils/_PluginWindows.py b/src/PluginUtils/_PluginWindows.py index 5378a5542..ee55b070c 100644 --- a/src/PluginUtils/_PluginWindows.py +++ b/src/PluginUtils/_PluginWindows.py @@ -347,7 +347,7 @@ class ToolManagedWindowBase(ManagedWindow.ManagedWindow): buffer.set_text("") def pre_run(self): - from Utils import ProgressMeter + from gui.utils import ProgressMeter self.progress = ProgressMeter(self.get_title()) def run(self): diff --git a/src/ReportBase/_GraphvizReportDialog.py b/src/ReportBase/_GraphvizReportDialog.py index b21b92e5b..be62886c4 100644 --- a/src/ReportBase/_GraphvizReportDialog.py +++ b/src/ReportBase/_GraphvizReportDialog.py @@ -48,6 +48,7 @@ import gobject # #------------------------------------------------------------------------------- import Utils +from gui.utils import ProgressMeter from gen.plug.docgen import BaseDoc, GVDoc import Config from ReportBase import CATEGORY_GRAPHVIZ @@ -123,9 +124,9 @@ def _run_long_process_in_thread(func, header): @return: nothing """ - pbar = Utils.ProgressMeter(_('Processing File')) + pbar = ProgressMeter(_('Processing File')) pbar.set_pass(total=40, - mode=Utils.ProgressMeter.MODE_ACTIVITY, + mode=ProgressMeter.MODE_ACTIVITY, header=header) sys_thread = threading.Thread(target=func) diff --git a/src/Utils.py b/src/Utils.py index 3120cbfb8..f91e1a8f0 100644 --- a/src/Utils.py +++ b/src/Utils.py @@ -213,48 +213,6 @@ def family_upper_name(family, db): name = mother.get_primary_name().get_upper_name() return name -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def redraw_list(dlist, clist, func): - clist.clear() - - index = 0 - for obj in dlist: - col = 0 - node = clist.append() - for data in func(obj): - clist.set_value(node, col, data) - col = col + 1 - index = index + 1 - return index - -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def delete_selected(obj, dlist): - sel = obj.get_selection() - model, node = sel.get_selected() - if node: - index = model.get_path(node)[0] - del dlist[index] - return 1 - -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def add_menuitem(menu, msg, obj, func): - item = gtk.MenuItem(msg) - item.set_data('o', obj) - item.connect("activate", func) - item.show() - menu.append(item) #------------------------------------------------------------------------- # @@ -334,55 +292,6 @@ def get_unicode_path(path): else: return unicode(path,sys.getfilesystemencoding()) -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def build_string_optmenu(mapping, start_val): - index = 0 - start_index = 0 - keys = mapping.keys() - keys.sort() - myMenu = gtk.Menu() - - for key in keys: - if key == "default": - menuitem = gtk.MenuItem(_("default")) - else: - menuitem = gtk.MenuItem(key) - menuitem.set_data("d", mapping[key]) - menuitem.set_data("l", key) - menuitem.show() - myMenu.append(menuitem) - if key == start_val: - start_index = index - index = index + 1 - - if start_index: - myMenu.set_active(start_index) - return myMenu - - -#------------------------------------------------------------------------- -# -# -# -#------------------------------------------------------------------------- -def build_columns(tree, list): - cnum = 0 - for name in list: - renderer = gtk.CellRendererText() - renderer.set_fixed_height_from_font(1) - column = gtk.TreeViewColumn(name[0], renderer, text=cnum) - column.set_min_width(name[1]) - if name[2] >= 0: - column.set_sort_column_id(name[2]) - if name[0] == '': - column.set_clickable(True) - column.set_visible(False) - cnum = cnum + 1 - tree.append_column(column) #------------------------------------------------------------------------- # @@ -447,69 +356,6 @@ def search_for(name): if os.access(fname, os.X_OK) and not os.path.isdir(fname): return 1 return 0 - -#------------------------------------------------------------------------- -# -# Change label appearance -# -#------------------------------------------------------------------------- -def bold_label(label, widget=None): - if label.__class__ == gtk.Label: - text = unicode(label.get_text()) - text = text.replace('', '') - text = text.replace('', '') - label.set_text("%s" % text ) - label.set_use_markup(True) - else: - clist = label.get_children() - text = unicode(clist[1].get_text()) - text = text.replace('', '') - text = text.replace('', '') - clist[0].show() - clist[1].set_text("%s" % text ) - clist[1].set_use_markup(True) - if widget: - widget.window.set_cursor(None) - -def unbold_label(label, widget=None): - if label.__class__ == gtk.Label: - text = unicode(label.get_text()) - text = text.replace('', '') - text = text.replace('', '') - text = text.replace('', '') - text = text.replace('', '') - label.set_text(text) - label.set_use_markup(False) - else: - clist = label.get_children() - text = unicode(clist[1].get_text()) - text = text.replace('', '') - text = text.replace('', '') - text = text.replace('', '') - text = text.replace('', '') - clist[0].hide() - clist[1].set_text(text) - clist[1].set_use_markup(False) - if widget: - widget.window.set_cursor(None) - -def temp_label(label, widget=None): - if label.__class__ == gtk.Label: - text = unicode(label.get_text()) - text = text.replace('', '') - text = text.replace('', '') - label.set_text("%s" % text ) - label.set_use_markup(True) - else: - clist = label.get_children() - text = unicode(clist[1].get_text()) - text = text.replace('', '') - text = text.replace('', '') - clist[0].hide() - clist[1].set_text("%s" % text ) - clist[1].set_use_markup(True) - if widget: - widget.window.set_cursor(gtk.gdk.Cursor(gtk.gdk.WATCH)) #------------------------------------------------------------------------- # @@ -965,153 +811,6 @@ def media_path_full(db, filename): return filename mpath = media_path(db) return os.path.join(mpath, filename) - - -class ProgressMeter(object): - """ - Progress meter class for GRAMPS. - - The progress meter has two modes: - - MODE_FRACTION is used when you know the number of steps that will be taken. - Set the total number of steps, and then call step() that many times. - The progress bar will progress from left to right. - - MODE_ACTIVITY is used when you don't know the number of steps that will be - taken. Set up the total number of steps for the bar to get from one end of - the bar to the other. Then, call step() as many times as you want. The bar - will move from left to right until you stop calling step. - """ - - MODE_FRACTION = 0 - MODE_ACTIVITY = 1 - - def __init__(self, title, header=''): - """ - Specify the title and the current pass header. - """ - self.__mode = ProgressMeter.MODE_FRACTION - self.__pbar_max = 100.0 - self.__pbar_index = 0.0 - self.__old_val = -1 - - self.__dialog = gtk.Dialog() - self.__dialog.connect('delete_event', self.__warn) - self.__dialog.set_has_separator(False) - self.__dialog.set_title(title) - self.__dialog.set_border_width(12) - self.__dialog.vbox.set_spacing(10) - self.__dialog.vbox.set_border_width(24) - self.__dialog.set_size_request(350, 125) - - tlbl = gtk.Label('%s' % title) - tlbl.set_use_markup(True) - self.__dialog.vbox.add(tlbl) - - self.__lbl = gtk.Label(header) - self.__lbl.set_use_markup(True) - self.__dialog.vbox.add(self.__lbl) - - self.__pbar = gtk.ProgressBar() - self.__dialog.vbox.add(self.__pbar) - - self.__dialog.show_all() - if header == '': - self.__lbl.hide() - - def set_pass(self, header="", total=100, mode=MODE_FRACTION): - """ - Reset for another pass. Provide a new header and define number - of steps to be used. - """ - self.__mode = mode - self.__pbar_max = total - self.__pbar_index = 0.0 - - self.__lbl.set_text(header) - if header == '': - self.__lbl.hide() - else: - self.__lbl.show() - - if self.__mode is ProgressMeter.MODE_FRACTION: - self.__pbar.set_fraction(0.0) - else: # ProgressMeter.MODE_ACTIVITY - self.__pbar.set_pulse_step(1.0/self.__pbar_max) - - while gtk.events_pending(): - gtk.main_iteration() - - def step(self): - """Click the progress bar over to the next value. Be paranoid - and insure that it doesn't go over 100%.""" - - if self.__mode is ProgressMeter.MODE_FRACTION: - self.__pbar_index = self.__pbar_index + 1.0 - - if self.__pbar_index > self.__pbar_max: - self.__pbar_index = self.__pbar_max - - try: - val = int(100*self.__pbar_index/self.__pbar_max) - except ZeroDivisionError: - val = 0 - - if val != self.__old_val: - self.__pbar.set_text("%d%%" % val) - self.__pbar.set_fraction(val/100.0) - self.__old_val = val - else: # ProgressMeter.MODE_ACTIVITY - self.__pbar.pulse() - - while gtk.events_pending(): - gtk.main_iteration() - - def __warn(self, *obj): - """ - Don't let the user close the progress dialog. - """ - WarningDialog( - _("Attempt to force closing the dialog"), - _("Please do not force closing this important dialog."), - self.__dialog) - return True - - def close(self): - """ - Close the progress meter - """ - self.__dialog.destroy() - -def open_file_with_default_application( file_path ): - """ - Launch a program to open an arbitrary file. The file will be opened using - whatever program is configured on the host as the default program for that - type of file. - - @param file_path: The path to the file to be opened. - Example: "c:\foo.txt" - @type file_path: string - @return: nothing - """ - norm_path = os.path.normpath( file_path ) - - if not os.path.exists(norm_path): - ErrorDialog(_("Error Opening File"), _("File does not exist")) - return - - if os.sys.platform == 'win32': - try: - os.startfile(norm_path) - except WindowsError, msg: - ErrorDialog(_("Error Opening File"), str(msg)) - else: - search = os.environ['PATH'].split(':') - for lpath in search: - prog = os.path.join(lpath, 'xdg-open') - if os.path.isfile(prog): - os.spawnvpe(os.P_NOWAIT, prog, [prog, norm_path], os.environ) - return def profile(func, *args): import hotshot.stats @@ -1176,4 +875,33 @@ def get_translations(): trans = TRANS_TO_KEY.keys() trans.sort(lambda a,b: -cmp(len(a), len(b))) return trans + +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +def get_researcher(): + import gen.lib + import Config + n = Config.get(Config.RESEARCHER_NAME) + a = Config.get(Config.RESEARCHER_ADDR) + c = Config.get(Config.RESEARCHER_CITY) + s = Config.get(Config.RESEARCHER_STATE) + ct = Config.get(Config.RESEARCHER_COUNTRY) + p = Config.get(Config.RESEARCHER_POSTAL) + ph = Config.get(Config.RESEARCHER_PHONE) + e = Config.get(Config.RESEARCHER_EMAIL) + + owner = gen.lib.Researcher() + owner.set_name(n) + owner.set_address(a) + owner.set_city(c) + owner.set_state(s) + owner.set_country(ct) + owner.set_postal_code(p) + owner.set_phone(ph) + owner.set_email(e) + + return owner diff --git a/src/cli/__init__.py b/src/cli/__init__.py index c719604bb..f430d5009 100644 --- a/src/cli/__init__.py +++ b/src/cli/__init__.py @@ -23,7 +23,4 @@ Package init for the cli package. """ -from grampscli import startcli, CLIDbLoader, CLIManager -from argparser import ArgParser -from arghandler import ArgHandler -from clidbman import CLIDbManager +# DO NOT IMPORT METHODS/CLASSES FROM src/gui HERE ! Only __all__ diff --git a/src/cli/arghandler.py b/src/cli/arghandler.py index 091cfe2ca..ec49711b3 100644 --- a/src/cli/arghandler.py +++ b/src/cli/arghandler.py @@ -439,7 +439,7 @@ class ArgHandler(object): pmgr = PluginManager.get_instance() if action == 'check': import Check - checker = Check.CheckIntegrity(self.dbstate.db, None, None) + checker = Check.CheckIntegrity(self.dbstate, None, None) checker.check_for_broken_family_links() checker.cleanup_missing_photos(1) checker.check_parent_relationships() @@ -448,6 +448,7 @@ class ArgHandler(object): if errs: checker.report(1) elif action == 'summary': + ## FIXME, this is broken, Summary no longer has build_report ! import Summary text = Summary.build_report(self.dbstate.db, None) print text diff --git a/src/cli/grampscli.py b/src/cli/grampscli.py index a11475ab5..36be53723 100644 --- a/src/cli/grampscli.py +++ b/src/cli/grampscli.py @@ -53,7 +53,7 @@ import DbState from gen.db import (GrampsDBDir, FileVersionDeclineToUpgrade) import gen.db.exceptions from gen.plug import PluginManager -import GrampsCfg +from Utils import get_researcher import RecentFiles #------------------------------------------------------------------------- @@ -251,7 +251,7 @@ class CLIManager(object): # apply preferred researcher if loaded file has none res = self.dbstate.db.get_researcher() - owner = GrampsCfg.get_researcher() + owner = get_researcher() if res.get_name() == "" and owner.get_name() != "": self.dbstate.db.set_researcher(owner) diff --git a/src/gramps.py b/src/gramps.py index 58c1df5b6..a92955b32 100644 --- a/src/gramps.py +++ b/src/gramps.py @@ -159,18 +159,18 @@ def run(): #we start with parsing the arguments to determine if we have a cli or a # gui session - from cli import ArgParser + from cli.argparser import ArgParser argpars = ArgParser(sys.argv) if argpars.need_gui(): #A GUI is needed, set it up - from gui import startgtkloop + from gui.grampsgui import startgtkloop startgtkloop(error, argpars) else: #CLI use of GRAMPS argpars.print_help() - from cli import startcli + from cli.grampscli import startcli startcli(error, argpars) run() diff --git a/src/gui/Makefile.am b/src/gui/Makefile.am index bc17f7e6f..49b6faa81 100644 --- a/src/gui/Makefile.am +++ b/src/gui/Makefile.am @@ -13,6 +13,7 @@ pkgdata_PYTHON = \ dbloader.py \ dbman.py \ grampsgui.py \ + utilsgui.py \ viewmanager.py pkgpyexecdir = @pkgpyexecdir@/gui diff --git a/src/gui/__init__.py b/src/gui/__init__.py index 9431b8141..f6cd55766 100644 --- a/src/gui/__init__.py +++ b/src/gui/__init__.py @@ -24,9 +24,6 @@ Package init for the gui package. """ -from grampsgui import startgtkloop -from viewmanager import ViewManager -from dbman import DbManager -from dbloader import DbLoader +# DO NOT IMPORT METHODS/CLASSES FROM src/gui HERE ! Only __all__ __all__ = [ "views" ] diff --git a/src/gui/utilsgui.py b/src/gui/utilsgui.py new file mode 100644 index 000000000..ba8ad7ba3 --- /dev/null +++ b/src/gui/utilsgui.py @@ -0,0 +1,222 @@ +# +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2000-2007 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: Utils.py 12603 2009-05-31 14:59:56Z bmcage $ + +""" +Utility functions that depend on GUI components or for GUI components +""" + +#------------------------------------------------------------------------- +# +# Standard python modules +# +#------------------------------------------------------------------------- +import os +from gettext import gettext as _ + +#------------------------------------------------------------------------- +# +# GNOME/GTK +# +#------------------------------------------------------------------------- +import gtk + +#------------------------------------------------------------------------- +# +# Gramps modules +# +#------------------------------------------------------------------------- +import gen.lib +import Errors +from QuestionDialog import WarningDialog, ErrorDialog + +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +def add_menuitem(menu, msg, obj, func): + """ + add a menuitem to menu with label msg, which activates func, and has data + obj + """ + item = gtk.MenuItem(msg) + item.set_data('o', obj) + item.connect("activate", func) + item.show() + menu.append(item) + +#------------------------------------------------------------------------- +# +# Progress meter class +# +#------------------------------------------------------------------------- + +class ProgressMeter(object): + """ + Progress meter class for GRAMPS. + + The progress meter has two modes: + + MODE_FRACTION is used when you know the number of steps that will be taken. + Set the total number of steps, and then call step() that many times. + The progress bar will progress from left to right. + + MODE_ACTIVITY is used when you don't know the number of steps that will be + taken. Set up the total number of steps for the bar to get from one end of + the bar to the other. Then, call step() as many times as you want. The bar + will move from left to right until you stop calling step. + """ + + MODE_FRACTION = 0 + MODE_ACTIVITY = 1 + + def __init__(self, title, header=''): + """ + Specify the title and the current pass header. + """ + self.__mode = ProgressMeter.MODE_FRACTION + self.__pbar_max = 100.0 + self.__pbar_index = 0.0 + self.__old_val = -1 + + self.__dialog = gtk.Dialog() + self.__dialog.connect('delete_event', self.__warn) + self.__dialog.set_has_separator(False) + self.__dialog.set_title(title) + self.__dialog.set_border_width(12) + self.__dialog.vbox.set_spacing(10) + self.__dialog.vbox.set_border_width(24) + self.__dialog.set_size_request(350, 125) + + tlbl = gtk.Label('%s' % title) + tlbl.set_use_markup(True) + self.__dialog.vbox.add(tlbl) + + self.__lbl = gtk.Label(header) + self.__lbl.set_use_markup(True) + self.__dialog.vbox.add(self.__lbl) + + self.__pbar = gtk.ProgressBar() + self.__dialog.vbox.add(self.__pbar) + + self.__dialog.show_all() + if header == '': + self.__lbl.hide() + + def set_pass(self, header="", total=100, mode=MODE_FRACTION): + """ + Reset for another pass. Provide a new header and define number + of steps to be used. + """ + self.__mode = mode + self.__pbar_max = total + self.__pbar_index = 0.0 + + self.__lbl.set_text(header) + if header == '': + self.__lbl.hide() + else: + self.__lbl.show() + + if self.__mode is ProgressMeter.MODE_FRACTION: + self.__pbar.set_fraction(0.0) + else: # ProgressMeter.MODE_ACTIVITY + self.__pbar.set_pulse_step(1.0/self.__pbar_max) + + while gtk.events_pending(): + gtk.main_iteration() + + def step(self): + """Click the progress bar over to the next value. Be paranoid + and insure that it doesn't go over 100%.""" + + if self.__mode is ProgressMeter.MODE_FRACTION: + self.__pbar_index = self.__pbar_index + 1.0 + + if self.__pbar_index > self.__pbar_max: + self.__pbar_index = self.__pbar_max + + try: + val = int(100*self.__pbar_index/self.__pbar_max) + except ZeroDivisionError: + val = 0 + + if val != self.__old_val: + self.__pbar.set_text("%d%%" % val) + self.__pbar.set_fraction(val/100.0) + self.__old_val = val + else: # ProgressMeter.MODE_ACTIVITY + self.__pbar.pulse() + + while gtk.events_pending(): + gtk.main_iteration() + + def __warn(self, *obj): + """ + Don't let the user close the progress dialog. + """ + WarningDialog( + _("Attempt to force closing the dialog"), + _("Please do not force closing this important dialog."), + self.__dialog) + return True + + def close(self): + """ + Close the progress meter + """ + self.__dialog.destroy() + +#------------------------------------------------------------------------- +# +# +# +#------------------------------------------------------------------------- +def open_file_with_default_application( file_path ): + """ + Launch a program to open an arbitrary file. The file will be opened using + whatever program is configured on the host as the default program for that + type of file. + + @param file_path: The path to the file to be opened. + Example: "c:\foo.txt" + @type file_path: string + @return: nothing + """ + norm_path = os.path.normpath( file_path ) + + if not os.path.exists(norm_path): + ErrorDialog(_("Error Opening File"), _("File does not exist")) + return + + if os.sys.platform == 'win32': + try: + os.startfile(norm_path) + except WindowsError, msg: + ErrorDialog(_("Error Opening File"), str(msg)) + else: + search = os.environ['PATH'].split(':') + for lpath in search: + prog = os.path.join(lpath, 'xdg-open') + if os.path.isfile(prog): + os.spawnvpe(os.P_NOWAIT, prog, [prog, norm_path], os.environ) + return diff --git a/src/gui/viewmanager.py b/src/gui/viewmanager.py index 07eb8cdc6..6560da90f 100644 --- a/src/gui/viewmanager.py +++ b/src/gui/viewmanager.py @@ -55,7 +55,7 @@ import gtk # GRAMPS modules # #------------------------------------------------------------------------- -from cli import CLIManager +from cli.grampscli import CLIManager from PluginUtils import Tool, PluginWindows, \ ReportPluginDialog, ToolPluginDialog import ReportBase diff --git a/src/plugins/drawreport/Calendar.py b/src/plugins/drawreport/Calendar.py index d273005c5..dec996e40 100644 --- a/src/plugins/drawreport/Calendar.py +++ b/src/plugins/drawreport/Calendar.py @@ -45,8 +45,8 @@ from gen.plug.menu import BooleanOption, StringOption, NumberOption, \ EnumeratedListOption, FilterOption, PersonOption import GrampsLocale import gen.lib -from Utils import probably_alive, ProgressMeter - +from Utils import probably_alive +from gui.utils import ProgressMeter import libholiday from libholiday import g2iso diff --git a/src/plugins/drawreport/StatisticsChart.py b/src/plugins/drawreport/StatisticsChart.py index 031322e93..3b3ce3256 100644 --- a/src/plugins/drawreport/StatisticsChart.py +++ b/src/plugins/drawreport/StatisticsChart.py @@ -51,7 +51,7 @@ from gen.plug.menu import BooleanOption, NumberOption, EnumeratedListOption, \ FilterOption, PersonOption from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_DRAW import DateHandler -from Utils import ProgressMeter +from gui.utils import ProgressMeter #------------------------------------------------------------------------ # diff --git a/src/plugins/drawreport/TimeLine.py b/src/plugins/drawreport/TimeLine.py index c11b17a26..b4e227222 100644 --- a/src/plugins/drawreport/TimeLine.py +++ b/src/plugins/drawreport/TimeLine.py @@ -46,7 +46,8 @@ from gen.plug.docgen import (FontStyle, ParagraphStyle, GraphicsStyle, import Sort from QuestionDialog import ErrorDialog from BasicUtils import name_displayer -from Utils import probably_alive, ProgressMeter +from Utils import probably_alive +from gui.utils import ProgressMeter import gen.lib #------------------------------------------------------------------------ diff --git a/src/plugins/export/ExportSql.py b/src/plugins/export/ExportSql.py index d1a5409b1..18a81dc51 100644 --- a/src/plugins/export/ExportSql.py +++ b/src/plugins/export/ExportSql.py @@ -35,7 +35,7 @@ import re import gen.lib from gen.plug import PluginManager, ExportPlugin import DateHandler -from Utils import ProgressMeter +from gui.utils import ProgressMeter import ExportOptions def makeDB(db): diff --git a/src/plugins/graph/GVFamilyLines.py b/src/plugins/graph/GVFamilyLines.py index 696da72e1..5aa15366c 100644 --- a/src/plugins/graph/GVFamilyLines.py +++ b/src/plugins/graph/GVFamilyLines.py @@ -48,6 +48,7 @@ log = logging.getLogger(".FamilyLines") #------------------------------------------------------------------------ import gen.lib import Utils +from gui.utils import ProgressMeter import ThumbNails from DateHandler import displayer as _dd from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_GRAPHVIZ @@ -394,7 +395,7 @@ class FamilyLinesReport(Report): from the database is going to be output into the report """ - self.progress = Utils.ProgressMeter(_('Generating Family Lines'), + self.progress = ProgressMeter(_('Generating Family Lines'), _('Starting')) # starting with the people of interest, we then add parents: diff --git a/src/plugins/import/ImportCsv.py b/src/plugins/import/ImportCsv.py index 25cce5e13..74d4399b3 100644 --- a/src/plugins/import/ImportCsv.py +++ b/src/plugins/import/ImportCsv.py @@ -54,7 +54,7 @@ from QuestionDialog import ErrorDialog from DateHandler import parser as _dp from gen.plug import PluginManager, ImportPlugin from Utils import gender as gender_map -from Utils import ProgressMeter +from gui.utils import ProgressMeter from Utils import create_id #------------------------------------------------------------------------- diff --git a/src/plugins/import/ImportProGen.py b/src/plugins/import/ImportProGen.py index ffe2e6b2a..a90c124c5 100644 --- a/src/plugins/import/ImportProGen.py +++ b/src/plugins/import/ImportProGen.py @@ -48,6 +48,7 @@ log = logging.getLogger('.ImportProGen') # #------------------------------------------------------------------------- import Utils +from gui.utils import ProgressMeter import gen.lib from QuestionDialog import ErrorDialog from gen.plug import PluginManager, ImportPlugin @@ -488,7 +489,7 @@ class ProgenParser(object): self.skeys = {} # Caching source handles def parse_progen_file(self): - self.progress = Utils.ProgressMeter(_("Import from Pro-Gen"), '') + self.progress = ProgressMeter(_("Import from Pro-Gen"), '') self.def_ = PG30_Def(self.fname) #print self.def_.diag() diff --git a/src/plugins/textreport/BirthdayReport.py b/src/plugins/textreport/BirthdayReport.py index 1135ef44b..855f03c24 100644 --- a/src/plugins/textreport/BirthdayReport.py +++ b/src/plugins/textreport/BirthdayReport.py @@ -45,7 +45,8 @@ from gen.plug.menu import BooleanOption, StringOption, NumberOption, \ EnumeratedListOption, FilterOption, PersonOption import GrampsLocale from gen.lib import NameType, EventType, Name, Date, Person -from Utils import probably_alive, ProgressMeter +from Utils import probably_alive +from gui.utils import ProgressMeter import libholiday diff --git a/src/plugins/tool/ChangeNames.py b/src/plugins/tool/ChangeNames.py index cbe1a0b0a..9ad2a879f 100644 --- a/src/plugins/tool/ChangeNames.py +++ b/src/plugins/tool/ChangeNames.py @@ -37,7 +37,7 @@ import gtk # #------------------------------------------------------------------------- import const -import Utils +from gui.utils import ProgressMeter import GrampsDisplay import ManagedWindow @@ -81,7 +81,7 @@ class ChangeNames(Tool.BatchTool, ManagedWindow.ManagedWindow): if self.fail: return - self.progress = Utils.ProgressMeter(_('Checking Family Names'),'') + self.progress = ProgressMeter(_('Checking Family Names'),'') self.progress.set_pass(_('Searching family names'), len(self.db.get_surname_list())) self.name_list = [] diff --git a/src/plugins/tool/ChangeTypes.py b/src/plugins/tool/ChangeTypes.py index 80c59e9cb..f5e21ade0 100644 --- a/src/plugins/tool/ChangeTypes.py +++ b/src/plugins/tool/ChangeTypes.py @@ -36,7 +36,7 @@ from gettext import ngettext # GRAMPS modules # #------------------------------------------------------------------------ -import Utils +from gui.utils import ProgressMeter import locale import ManagedWindow import AutoComp @@ -113,7 +113,7 @@ class ChangeTypes(Tool.BatchTool, ManagedWindow.ManagedWindow): self.trans = self.db.transaction_begin("",batch=True) self.db.disable_signals() if not cli: - progress = Utils.ProgressMeter(_('Analyzing Events'),'') + progress = ProgressMeter(_('Analyzing Events'),'') progress.set_pass('',self.db.get_number_of_events()) for event_handle in self.db.get_event_handles(): diff --git a/src/plugins/tool/Check.py b/src/plugins/tool/Check.py index 230f26f18..af5c80c3e 100644 --- a/src/plugins/tool/Check.py +++ b/src/plugins/tool/Check.py @@ -58,6 +58,7 @@ import gtk #------------------------------------------------------------------------- import gen.lib import Utils +from gui.utils import ProgressMeter #import const import ManagedWindow @@ -243,7 +244,7 @@ class CheckIntegrity(object): 'repos' : [], 'notes' : [], } - self.progress = Utils.ProgressMeter(_('Checking Database'),'') + self.progress = ProgressMeter(_('Checking Database'),'') def family_errors(self): return len(self.broken_parent_links) + \ diff --git a/src/plugins/tool/DateParserDisplayTest.py b/src/plugins/tool/DateParserDisplayTest.py index 00de508a2..fa7f52126 100644 --- a/src/plugins/tool/DateParserDisplayTest.py +++ b/src/plugins/tool/DateParserDisplayTest.py @@ -45,7 +45,7 @@ from gettext import gettext as _ import gen.lib from PluginUtils import Tool from gen.plug import PluginManager -import Utils +from gui.utils import ProgressMeter from QuestionDialog import QuestionDialog from DateHandler import parser as _dp from DateHandler import displayer as _dd @@ -68,7 +68,7 @@ class DateParserDisplayTest(Tool.Tool): def run_tool(self): - self.progress = Utils.ProgressMeter(_('Running Date Test'),'') + self.progress = ProgressMeter(_('Running Date Test'),'') self.progress.set_pass(_('Generating dates'), 4) dates = [] diff --git a/src/plugins/tool/EventCmp.py b/src/plugins/tool/EventCmp.py index ad84888e0..af36b2b91 100644 --- a/src/plugins/tool/EventCmp.py +++ b/src/plugins/tool/EventCmp.py @@ -45,6 +45,7 @@ import gtk from Filters import GenericFilter, build_filter_model, Rules import Sort import Utils +from gui.utils import ProgressMeter from docgen import ODSTab import const import Errors @@ -171,7 +172,7 @@ class EventComparison(Tool.Tool,ManagedWindow.ManagedWindow): def on_apply_clicked(self, obj): cfilter = self.filter_menu[self.filters.get_active()][1] - progress_bar = Utils.ProgressMeter(_('Comparing events'),'') + progress_bar = ProgressMeter(_('Comparing events'),'') progress_bar.set_pass(_('Selecting people'),1) plist = cfilter.apply(self.db, @@ -288,7 +289,7 @@ class DisplayChart(ManagedWindow.ManagedWindow): self.progress_bar.close() def build_row_data(self): - self.progress_bar = Utils.ProgressMeter(_('Comparing Events'),'') + self.progress_bar = ProgressMeter(_('Comparing Events'),'') self.progress_bar.set_pass(_('Building data'),len(self.my_list)) for individual_id in self.my_list: individual = self.db.get_person_from_handle(individual_id) diff --git a/src/plugins/tool/ExtractCity.py b/src/plugins/tool/ExtractCity.py index 7c20b88c8..0e3a278b4 100644 --- a/src/plugins/tool/ExtractCity.py +++ b/src/plugins/tool/ExtractCity.py @@ -50,7 +50,7 @@ import GrampsDisplay from PluginUtils import Tool from gen.plug import PluginManager -import Utils +from gui.utils import ProgressMeter from glade import Glade CITY_STATE_ZIP = re.compile("((\w|\s)+)\s*,\s*((\w|\s)+)\s*(,\s*((\d|-)+))", re.UNICODE) @@ -428,7 +428,7 @@ class ExtractCity(Tool.BatchTool, ManagedWindow.ManagedWindow): Performs the actual extraction of information """ - self.progress = Utils.ProgressMeter(_('Checking Place Titles'), '') + self.progress = ProgressMeter(_('Checking Place Titles'), '') self.progress.set_pass(_('Looking for place fields'), len(self.db.get_place_handles())) diff --git a/src/plugins/tool/FindDupes.py b/src/plugins/tool/FindDupes.py index a15cb1ef2..1b04addba 100644 --- a/src/plugins/tool/FindDupes.py +++ b/src/plugins/tool/FindDupes.py @@ -37,7 +37,7 @@ import gtk #------------------------------------------------------------------------- import const import gen.lib -import Utils +from gui.utils import ProgressMeter import soundex from BasicUtils import name_displayer from QuestionDialog import OkDialog @@ -180,7 +180,7 @@ class Merge(Tool.Tool,ManagedWindow.ManagedWindow): pass def find_potentials(self,thresh): - self.progress = Utils.ProgressMeter(_('Find Duplicates'), + self.progress = ProgressMeter(_('Find Duplicates'), _('Looking for duplicate people')) index = 0 diff --git a/src/plugins/tool/NotRelated.py b/src/plugins/tool/NotRelated.py index bca37ea30..7944e84f5 100644 --- a/src/plugins/tool/NotRelated.py +++ b/src/plugins/tool/NotRelated.py @@ -43,7 +43,7 @@ from ReportBase import ReportUtils from PluginUtils import Tool from Editors import EditPerson, EditFamily import ManagedWindow -import Utils +from gui.utils import ProgressMeter import GrampsDisplay from TransUtils import sgettext as _ from glade import Glade @@ -96,7 +96,7 @@ class NotRelated(Tool.ActivePersonTool, ManagedWindow.ManagedWindow) : # start the progress indicator - self.progress = Utils.ProgressMeter(self.title,_('Starting')) + self.progress = ProgressMeter(self.title,_('Starting')) # setup the columns self.model = gtk.TreeStore( @@ -226,7 +226,7 @@ class NotRelated(Tool.ActivePersonTool, ManagedWindow.ManagedWindow) : # if more than 1 person is selected, use a progress indicator if rows > 1: - progress = Utils.ProgressMeter(self.title,_('Starting')) + progress = ProgressMeter(self.title,_('Starting')) progress.set_pass(_('Setting marker for %d people') % rows, rows) # start the db transaction diff --git a/src/plugins/tool/OwnerEditor.py b/src/plugins/tool/OwnerEditor.py index e0778fea8..6e9dcbf7c 100644 --- a/src/plugins/tool/OwnerEditor.py +++ b/src/plugins/tool/OwnerEditor.py @@ -37,7 +37,7 @@ import gtk #------------------------------------------------------------------------- import const import Config -import GrampsCfg +from Utils import get_researcher import GrampsDisplay from widgets import MonitoredEntry import ManagedWindow @@ -159,7 +159,7 @@ class OwnerEditor(Tool.Tool, ManagedWindow.ManagedWindow): def on_menu_activate(self, menuitem): """Copies the owner information from/to the preferences""" if menuitem.name == 'copy_from_preferences_to_db': - self.owner.set_from(GrampsCfg.get_researcher()) + self.owner.set_from(get_researcher()) for entry in self.entries: entry.update() diff --git a/src/plugins/tool/PatchNames.py b/src/plugins/tool/PatchNames.py index 9df3b8320..ba20f0edb 100644 --- a/src/plugins/tool/PatchNames.py +++ b/src/plugins/tool/PatchNames.py @@ -44,7 +44,7 @@ import gobject # #------------------------------------------------------------------------- import const -import Utils +from gui.utils import ProgressMeter from PluginUtils import Tool from gen.plug import PluginManager from QuestionDialog import OkDialog @@ -117,7 +117,7 @@ class PatchNames(Tool.BatchTool, ManagedWindow.ManagedWindow): self.prefix1_list = [] self.prefix2_list = [] - self.progress = Utils.ProgressMeter( + self.progress = ProgressMeter( _('Extracting Information from Names'), '') self.progress.set_pass(_('Analyzing names'), self.db.get_number_of_people()) diff --git a/src/plugins/tool/ReorderIds.py b/src/plugins/tool/ReorderIds.py index ebd2fb2e4..b0aefb5fb 100644 --- a/src/plugins/tool/ReorderIds.py +++ b/src/plugins/tool/ReorderIds.py @@ -39,7 +39,7 @@ from gettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------ -import Utils +from gui.utils import ProgressMeter import gen.lib from PluginUtils import Tool from gen.plug import PluginManager @@ -60,7 +60,7 @@ class ReorderIds(Tool.BatchTool): db = dbstate.db self.uistate = uistate if uistate: - self.progress = Utils.ProgressMeter(_('Reordering GRAMPS IDs'),'') + self.progress = ProgressMeter(_('Reordering GRAMPS IDs'),'') else: print "Reordering GRAMPS IDs..." diff --git a/src/plugins/webreport/NarrativeWeb.py b/src/plugins/webreport/NarrativeWeb.py index e4c91b54e..17c7439c3 100644 --- a/src/plugins/webreport/NarrativeWeb.py +++ b/src/plugins/webreport/NarrativeWeb.py @@ -79,7 +79,6 @@ log = logging.getLogger(".WebPage") from gen.lib import UrlType, EventType, Person, date, Date, ChildRefType, \ FamilyRelType, NameType, Name import const -from GrampsCfg import get_researcher import Sort from gen.plug import PluginManager from gen.plug.menu import PersonOption, NumberOption, StringOption, \ @@ -88,6 +87,7 @@ from gen.plug.menu import PersonOption, NumberOption, StringOption, \ from ReportBase import (Report, ReportUtils, MenuReportOptions, CATEGORY_WEB, Bibliography, CSS_FILES ) import Utils +from gui.utils import ProgressMeter import ThumbNails import ImgManip import Mime @@ -198,7 +198,7 @@ class BasePage(object): self.page_title = "" - self.author = get_researcher().get_name() + self.author = Utils.get_researcher().get_name() if self.author: self.author = self.author.replace(',,,', '') self.up = False @@ -2326,7 +2326,7 @@ class ContactPage(BasePage): if contactimg: summaryarea += contactimg - r = get_researcher() + r = Utils.get_researcher() with Html('div', id='researcher') as researcher: summaryarea += researcher @@ -3682,7 +3682,7 @@ class NavWebReport(Report): value) return - self.progress = Utils.ProgressMeter(_("Narrated Web Site Report"), '') + self.progress = ProgressMeter(_("Narrated Web Site Report"), '') # Build the person list ind_list = self.build_person_list() diff --git a/src/plugins/webreport/WebCal.py b/src/plugins/webreport/WebCal.py index 7c7c7c4e3..f26e15a99 100644 --- a/src/plugins/webreport/WebCal.py +++ b/src/plugins/webreport/WebCal.py @@ -54,7 +54,6 @@ log = logging.getLogger(".WebPage") #------------------------------------------------------------------------ from gen.lib import date, Date, Name, Person, NameType, EventType import const -from GrampsCfg import get_researcher from gen.plug import PluginManager from ReportBase import Report, ReportUtils, MenuReportOptions, CATEGORY_WEB, \ CSS_FILES @@ -63,7 +62,8 @@ from gen.plug.menu import BooleanOption, NumberOption, StringOption, \ DestinationOption import GrampsLocale from QuestionDialog import WarningDialog -from Utils import probably_alive, ProgressMeter, xml_lang +from Utils import probably_alive, xml_lang, get_researcher +from gui.utils import ProgressMeter from DateHandler import displayer as _dd from BasicUtils import name_displayer as _nd