diff --git a/src/DataViews/GrampletView.py b/src/DataViews/GrampletView.py index 709f44145..f1017cceb 100644 --- a/src/DataViews/GrampletView.py +++ b/src/DataViews/GrampletView.py @@ -275,325 +275,6 @@ class GrampletWindow(ManagedWindow.ManagedWindow): #------------------------------------------------------------------------ -class Gramplet(object): - """ - Base class for non-graphical gramplet code. - """ - def __init__(self, gui): - """ - Internal constructor for non-graphical gramplets. - """ - self._idle_id = 0 - self._pause = False - self._generator = None - self._need_to_update = False - self.option_dict = {} - self.option_order = [] - # links to each other: - self.gui = gui # plugin gramplet has link to gui - gui.pui = self # gui has link to plugin ui - self.dbstate = gui.dbstate - self.uistate = gui.uistate - self.init() - self.on_load() - self.build_options() - self.dbstate.connect('database-changed', self._db_changed) - self.dbstate.connect('active-changed', self._active_changed) - self.gui.textview.connect('button-press-event', - self.gui.on_button_press) - self.gui.textview.connect('motion-notify-event', - self.gui.on_motion) - if self.dbstate.active: # already changed - self._db_changed(self.dbstate.db) - self._active_changed(self.dbstate.active.handle) - - def init(self): # once, constructor - """ - External constructor for developers to put their initialization - code. Designed to be overridden. - """ - pass - - def build_options(self): - """ - External constructor for developers to put code for building - options. - """ - pass - - def main(self): # return false finishes - """ - The main place for the gramplet's code. This is a generator. - Generator which will be run in the background, through update(). - """ - if debug: print "%s dummy" % self.gui.title - yield False - - def on_load(self): - """ - Gramplets should override this to take care of loading previously - their special data. - """ - pass - - def on_save(self): - """ - Gramplets should override this to take care of saving their - special data. - """ - if debug: print ("on_save: '%s'" % self.gui.title) - return - - def active_changed(self, handle): - """ - Developers should put their code that occurs when the active - person is changed. - """ - pass - - def _active_changed(self, handle): - """ - Private code that updates the GUI when active_person is changed. - """ - self.uistate.push_message(self.gui.dbstate, - _("Gramplet %s is running") % self.gui.title) - self.active_changed(handle) - - def db_changed(self): - """ - Method executed when the database is changed. - """ - if debug: print "%s is connecting" % self.gui.title - pass - - def link(self, text, link_type, data, size=None, tooltip=None): - """ - Creates a clickable link in the textview area. - """ - self.gui.link(text, link_type, data, size, tooltip) - - # Shortcuts to the gui functionality: - - def set_tooltip(self, tip): - """ - Sets the tooltip for this gramplet. - """ - self.gui.tooltip = tip - - def get_text(self): - """ - Returns the current text of the textview. - """ - return self.gui.get_text() - - def insert_text(self, text): - """ - Insert the given text in the textview at the cursor. - """ - self.gui.insert_text(text) - - def render_text(self, text): - """ - Render the given text, given that set_use_markup is on. - """ - self.gui.render_text(text) - - def clear_text(self): - """ - Clear all of the text from the textview. - """ - self.gui.clear_text() - - def set_text(self, text, scroll_to='start'): - """ - Clear and set the text to the given text. Additionally, move the - cursor to the position given. Positions are: - 'start': start of textview - 'end': end of textview - 'begin': begin of line, before setting the text. - """ - self.gui.set_text(text, scroll_to) - - def append_text(self, text, scroll_to="end"): - """ - Append the text to the textview. Additionally, move the - cursor to the position given. Positions are: - 'start': start of textview - 'end': end of textview - 'begin': begin of line, before setting the text. - """ - self.gui.append_text(text, scroll_to) - - def set_use_markup(self, value): - """ - Allows the use of render_text to show markup. - """ - self.gui.set_use_markup(value) - - def set_wrap(self, value): - """ - Set the textview to wrap or not. - """ - self.gui.scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC, - gtk.POLICY_AUTOMATIC) - # gtk.WRAP_NONE, gtk.WRAP_CHAR, gtk.WRAP_WORD or gtk.WRAP_WORD_CHAR. - if value in [True, 1]: - self.gui.textview.set_wrap_mode(gtk.WRAP_WORD) - elif value in [False, 0, None]: - self.gui.textview.set_wrap_mode(gtk.WRAP_NONE) - elif value in ["char"]: - self.gui.textview.set_wrap_mode(gtk.WRAP_CHAR) - elif value in ["word char"]: - self.gui.textview.set_wrap_mode(gtk.WRAP_WORD_CHAR) - else: - raise Exception("Unknown wrap mode: '%s': use 0,1,'char' or 'word char')" % value) - - def no_wrap(self): - """ - The view in gramplet should not wrap. DEPRICATED: use set_wrap instead. - """ - self.set_wrap(False) - - # Other functions of the gramplet: - - def load_data_to_text(self, pos=0): - """ - Load information from the data portion of the saved - Gramplet to the textview. - """ - if len(self.gui.data) >= pos + 1: - text = self.gui.data[pos] - text = text.replace("\\n", chr(10)) - self.set_text(text, 'end') - - def save_text_to_data(self): - """ - Save the textview to the data portion of a saved gramplet. - """ - text = self.get_text() - text = text.replace(chr(10), "\\n") - self.gui.data.append(text) - - def update(self, *args): - """ - The main interface for running the main method. - """ - if (self.gui.state in ["closed", "minimized"] and - not self.gui.force_update): return - if self._idle_id != 0: - if debug: print "%s interrupt!" % self.gui.title - self.interrupt() - if debug: print "%s creating generator" % self.gui.title - self._generator = self.main() - if debug: print "%s adding to gobject" % self.gui.title - self._pause = False - self._idle_id = gobject.idle_add(self._updater, - priority=gobject.PRIORITY_LOW - 10) - - def _updater(self): - """ - Runs the generator. - """ - if debug: print "%s _updater" % self.gui.title - if not isinstance(self._generator, types.GeneratorType): - self._idle_id = 0 - return False - try: - retval = self._generator.next() - if not retval: - self._idle_id = 0 - if self._pause: - return False - return retval - except StopIteration: - self._idle_id = 0 - return False - except Exception, e: - print "Gramplet gave an error" - traceback.print_exc() - print "Continuing after gramplet error..." - self._idle_id = 0 - return False - - def pause(self, *args): - """ - Pause the main method. - """ - self._pause = True - - def resume(self, *args): - """ - Resume the main method that has previously paused. - """ - self._pause = False - self._idle_id = gobject.idle_add(self._updater, - priority=gobject.PRIORITY_LOW - 10) - - def update_all(self, *args): - """ - Force the main loop to run right now (as opposed to running in background). - """ - self._generator = self.main() - if isinstance(self._generator, types.GeneratorType): - for step in self._generator: - pass - - def interrupt(self, *args): - """ - Force the generator to stop running. - """ - self._pause = True - if self._idle_id == 0: - if debug: print "%s removing from gobject" % self.gui.title - gobject.source_remove(self._idle_id) - self._idle_id = 0 - - def _db_changed(self, db): - """ - Internal method for handling items that should happen when the - database changes. This will push a message to the GUI status bar. - """ - if debug: print "%s is _connecting" % self.gui.title - self.uistate.push_message(self.dbstate, - _("Gramplet %s is running") % self.gui.title) - self.dbstate.db = db - self.gui.dbstate.db = db - self.db_changed() - self.update() - - def get_option_widget(self, label): - """ - Retrieve an option's widget by its label text. - """ - return self.option_dict[label][0] - - def get_option(self, label): - """ - Retireve an option by its label text. - """ - return self.option_dict[label][1] - - def add_option(self, option): - """ - Add an option to the GUI gramplet. - """ - from PluginUtils import make_gui_option - #tooltips, dbstate, uistate, track - widget, label = make_gui_option( - option, self.dbstate, self.uistate,None) - self.option_dict.update({option.get_label(): (widget, option)}) - self.option_order.append(option.get_label()) - - def save_update_options(self, obj): - """ - Save a gramplet's options to file. - """ - self.save_options() - self.update() - - def save_options(self): - pass - class GuiGramplet(object): """ Class that handles the plugin interfaces for the GrampletView. diff --git a/src/DataViews/__init__.py b/src/DataViews/__init__.py index a75e52646..12a8405a4 100644 --- a/src/DataViews/__init__.py +++ b/src/DataViews/__init__.py @@ -23,7 +23,7 @@ Package init for the DataViews package. """ -from GrampletView import GrampletView, Gramplet +from GrampletView import GrampletView from PersonView import PersonView from RelationView import RelationshipView from FamilyList import FamilyListView diff --git a/src/gen/plug/__init__.py b/src/gen/plug/__init__.py index cd7079836..93db307d4 100644 --- a/src/gen/plug/__init__.py +++ b/src/gen/plug/__init__.py @@ -34,6 +34,7 @@ from _manager import BasePluginManager from _import import ImportPlugin from _export import ExportPlugin from _docgenplugin import DocGenPlugin +from _gramplet import Gramplet from utils import * __all__ = [ "docbackend", "docgen", "menu", Plugin, PluginData, diff --git a/src/plugins/gramplet/AgeOnDateGramplet.py b/src/plugins/gramplet/AgeOnDateGramplet.py index 04a262abd..6061984ef 100644 --- a/src/plugins/gramplet/AgeOnDateGramplet.py +++ b/src/plugins/gramplet/AgeOnDateGramplet.py @@ -34,7 +34,7 @@ on a particular date. # GRAMPS modules # #------------------------------------------------------------------------ -from DataViews import Gramplet +from gen.plug import Gramplet from TransUtils import sgettext as _ import DateHandler from QuickReports import run_quick_report_by_name diff --git a/src/plugins/gramplet/AgeStats.py b/src/plugins/gramplet/AgeStats.py index 72c54f209..31ae5930f 100644 --- a/src/plugins/gramplet/AgeStats.py +++ b/src/plugins/gramplet/AgeStats.py @@ -26,7 +26,7 @@ This Gramplet shows textual distributions of age breakdowns of various types. import locale -from DataViews import Gramplet +from gen.plug import Gramplet from gettext import gettext as _ import gen.lib diff --git a/src/plugins/gramplet/AttributesGramplet.py b/src/plugins/gramplet/AttributesGramplet.py index eb7780a6f..594381455 100644 --- a/src/plugins/gramplet/AttributesGramplet.py +++ b/src/plugins/gramplet/AttributesGramplet.py @@ -19,7 +19,7 @@ # $Id: $ # -from DataViews import Gramplet +from gen.plug import Gramplet from BasicUtils import name_displayer from gettext import gettext as _ diff --git a/src/plugins/gramplet/CalendarGramplet.py b/src/plugins/gramplet/CalendarGramplet.py index 565dfe961..61845d449 100644 --- a/src/plugins/gramplet/CalendarGramplet.py +++ b/src/plugins/gramplet/CalendarGramplet.py @@ -23,7 +23,7 @@ # GRAMPS modules # #------------------------------------------------------------------------ -from DataViews import Gramplet +from gen.plug import Gramplet from TransUtils import sgettext as _ from QuickReports import run_quick_report_by_name import gen.lib diff --git a/src/plugins/gramplet/DataEntryGramplet.py b/src/plugins/gramplet/DataEntryGramplet.py index 0d92d66a6..41a879def 100644 --- a/src/plugins/gramplet/DataEntryGramplet.py +++ b/src/plugins/gramplet/DataEntryGramplet.py @@ -23,7 +23,7 @@ # GRAMPS modules # #------------------------------------------------------------------------ -from DataViews import Gramplet +from gen.plug import Gramplet from BasicUtils import name_displayer from ReportBase import ReportUtils import DateHandler diff --git a/src/plugins/gramplet/DeepConnections.py b/src/plugins/gramplet/DeepConnections.py index 00c183a36..2755b627e 100644 --- a/src/plugins/gramplet/DeepConnections.py +++ b/src/plugins/gramplet/DeepConnections.py @@ -35,7 +35,7 @@ import gtk #------------------------------------------------------------------------ from gen.lib import EventType, FamilyRelType from BasicUtils import name_displayer -from DataViews import Gramplet +from gen.plug import Gramplet from TransUtils import sgettext as _ #------------------------------------------------------------------------ diff --git a/src/plugins/gramplet/DescendGramplet.py b/src/plugins/gramplet/DescendGramplet.py index fbf00112f..4d130848f 100644 --- a/src/plugins/gramplet/DescendGramplet.py +++ b/src/plugins/gramplet/DescendGramplet.py @@ -36,7 +36,7 @@ from gettext import gettext as _ # GRAMPS modules # #------------------------------------------------------------------------ -from DataViews import Gramplet +from gen.plug import Gramplet from ReportBase import ReportUtils from BasicUtils import name_displayer import DateHandler diff --git a/src/plugins/gramplet/FanChartGramplet.py b/src/plugins/gramplet/FanChartGramplet.py index 1a68b4e07..3eb73acd3 100644 --- a/src/plugins/gramplet/FanChartGramplet.py +++ b/src/plugins/gramplet/FanChartGramplet.py @@ -54,7 +54,7 @@ if gtk.pygtk_version < (2,3,93): #------------------------------------------------------------------------- from BasicUtils import name_displayer from gettext import gettext as _ -from DataViews import Gramplet +from gen.plug import Gramplet from DataViews.PedigreeView import (find_children, find_parents, find_witnessed_people, FormattingHelper) import gen.lib diff --git a/src/plugins/gramplet/FaqGramplet.py b/src/plugins/gramplet/FaqGramplet.py index cc0249dd7..76a53afd3 100644 --- a/src/plugins/gramplet/FaqGramplet.py +++ b/src/plugins/gramplet/FaqGramplet.py @@ -23,7 +23,7 @@ # GRAMPS modules # #------------------------------------------------------------------------ -from DataViews import Gramplet +from gen.plug import Gramplet from TransUtils import sgettext as _ #------------------------------------------------------------------------ diff --git a/src/plugins/gramplet/GivenNameGramplet.py b/src/plugins/gramplet/GivenNameGramplet.py index dc8ba9962..ec0cdefe1 100644 --- a/src/plugins/gramplet/GivenNameGramplet.py +++ b/src/plugins/gramplet/GivenNameGramplet.py @@ -22,7 +22,7 @@ # from gettext import gettext as _ -from DataViews import Gramplet +from gen.plug import Gramplet import config _YIELD_INTERVAL = 350 diff --git a/src/plugins/gramplet/HeadlineNewsGramplet.py b/src/plugins/gramplet/HeadlineNewsGramplet.py index e4f57fd49..6ca48322a 100644 --- a/src/plugins/gramplet/HeadlineNewsGramplet.py +++ b/src/plugins/gramplet/HeadlineNewsGramplet.py @@ -45,7 +45,7 @@ import re # GRAMPS modules # #------------------------------------------------------------------------ -from DataViews import Gramplet +from gen.plug import Gramplet from const import URL_WIKISTRING from TransUtils import sgettext as _ diff --git a/src/plugins/gramplet/NoteGramplet.py b/src/plugins/gramplet/NoteGramplet.py index f76de2526..ba102b8ca 100644 --- a/src/plugins/gramplet/NoteGramplet.py +++ b/src/plugins/gramplet/NoteGramplet.py @@ -31,7 +31,7 @@ import pango # GRAMPS modules # #------------------------------------------------------------------------ -from DataViews import Gramplet +from gen.plug import Gramplet from BasicUtils import name_displayer from TransUtils import sgettext as _ from const import GLADE_FILE diff --git a/src/plugins/gramplet/PedigreeGramplet.py b/src/plugins/gramplet/PedigreeGramplet.py index 3376fd4b4..149e6382e 100644 --- a/src/plugins/gramplet/PedigreeGramplet.py +++ b/src/plugins/gramplet/PedigreeGramplet.py @@ -31,7 +31,7 @@ import locale # GRAMPS modules # #------------------------------------------------------------------------ -from DataViews import Gramplet +from gen.plug import Gramplet from TransUtils import sgettext as _ from gettext import ngettext from BasicUtils import name_displayer diff --git a/src/plugins/gramplet/PluginManagerGramplet.py b/src/plugins/gramplet/PluginManagerGramplet.py index 0f1ac6ad9..ab590ff9c 100644 --- a/src/plugins/gramplet/PluginManagerGramplet.py +++ b/src/plugins/gramplet/PluginManagerGramplet.py @@ -30,8 +30,7 @@ import urllib # GRAMPS modules # #------------------------------------------------------------------------ -from DataViews import Gramplet -from DataViews.GrampletView import AVAILABLE_GRAMPLETS +from gen.plug import Gramplet from TransUtils import sgettext as _ #------------------------------------------------------------------------ @@ -79,7 +78,7 @@ class PluginManagerGramplet(Gramplet): for row in rows: types[row[1]] = 1 self.set_text("") - # name, type, ver, desc, gver, use, rating, contact, download + # name, type, ver, desc, use, rating, contact, download for type in types: self.render_text("%s Plugins\n" % _(type)) row_count = 1 diff --git a/src/plugins/gramplet/PythonGramplet.py b/src/plugins/gramplet/PythonGramplet.py index 7c0e98c0c..b5f40cee7 100644 --- a/src/plugins/gramplet/PythonGramplet.py +++ b/src/plugins/gramplet/PythonGramplet.py @@ -30,7 +30,7 @@ import sys # GRAMPS modules # #------------------------------------------------------------------------ -from DataViews import Gramplet +from gen.plug import Gramplet from TransUtils import sgettext as _ import gen diff --git a/src/plugins/gramplet/QuickViewGramplet.py b/src/plugins/gramplet/QuickViewGramplet.py index 6923b65b9..ddcf2f969 100644 --- a/src/plugins/gramplet/QuickViewGramplet.py +++ b/src/plugins/gramplet/QuickViewGramplet.py @@ -30,7 +30,7 @@ # GRAMPS modules # #------------------------------------------------------------------------ -from DataViews import Gramplet +from gen.plug import Gramplet from TransUtils import sgettext as _ from QuickReports import run_quick_report_by_name, get_quick_report_list from gen.plug import (CATEGORY_QR_PERSON, CATEGORY_QR_FAMILY, diff --git a/src/plugins/gramplet/RelativeGramplet.py b/src/plugins/gramplet/RelativeGramplet.py index 0e219ed88..a96314f7b 100644 --- a/src/plugins/gramplet/RelativeGramplet.py +++ b/src/plugins/gramplet/RelativeGramplet.py @@ -23,7 +23,7 @@ # GRAMPS modules # #------------------------------------------------------------------------ -from DataViews import Gramplet +from gen.plug import Gramplet from TransUtils import sgettext as _ from BasicUtils import name_displayer diff --git a/src/plugins/gramplet/SessionLogGramplet.py b/src/plugins/gramplet/SessionLogGramplet.py index f45d9f538..44aa6f898 100644 --- a/src/plugins/gramplet/SessionLogGramplet.py +++ b/src/plugins/gramplet/SessionLogGramplet.py @@ -23,7 +23,7 @@ # GRAMPS modules # #------------------------------------------------------------------------ -from DataViews import Gramplet +from gen.plug import Gramplet from TransUtils import sgettext as _ from BasicUtils import name_displayer diff --git a/src/plugins/gramplet/StatsGramplet.py b/src/plugins/gramplet/StatsGramplet.py index bb1a5e2df..e02c8d517 100644 --- a/src/plugins/gramplet/StatsGramplet.py +++ b/src/plugins/gramplet/StatsGramplet.py @@ -30,7 +30,7 @@ import posixpath # GRAMPS modules # #------------------------------------------------------------------------ -from DataViews import Gramplet +from gen.plug import Gramplet from TransUtils import sgettext as _ from Utils import media_path_full import DateHandler diff --git a/src/plugins/gramplet/SurnameCloudGramplet.py b/src/plugins/gramplet/SurnameCloudGramplet.py index 6384b07cc..6af1c6b69 100644 --- a/src/plugins/gramplet/SurnameCloudGramplet.py +++ b/src/plugins/gramplet/SurnameCloudGramplet.py @@ -23,7 +23,7 @@ # GRAMPS modules # #------------------------------------------------------------------------ -from DataViews import Gramplet +from gen.plug import Gramplet from TransUtils import sgettext as _ import config diff --git a/src/plugins/gramplet/ToDoGramplet.py b/src/plugins/gramplet/ToDoGramplet.py index c4cf363d6..8e7094890 100644 --- a/src/plugins/gramplet/ToDoGramplet.py +++ b/src/plugins/gramplet/ToDoGramplet.py @@ -23,7 +23,7 @@ # GRAMPS modules # #------------------------------------------------------------------------ -from DataViews import Gramplet +from gen.plug import Gramplet from TransUtils import sgettext as _ #------------------------------------------------------------------------ diff --git a/src/plugins/gramplet/TopSurnamesGramplet.py b/src/plugins/gramplet/TopSurnamesGramplet.py index 92b0f7c55..73f7d1138 100644 --- a/src/plugins/gramplet/TopSurnamesGramplet.py +++ b/src/plugins/gramplet/TopSurnamesGramplet.py @@ -23,7 +23,7 @@ # GRAMPS modules # #------------------------------------------------------------------------ -from DataViews import Gramplet +from gen.plug import Gramplet from TransUtils import sgettext as _ import config diff --git a/src/plugins/gramplet/WhatsNext.py b/src/plugins/gramplet/WhatsNext.py index 7a467c040..2bb3aaa7e 100644 --- a/src/plugins/gramplet/WhatsNext.py +++ b/src/plugins/gramplet/WhatsNext.py @@ -27,8 +27,8 @@ # #------------------------------------------------------------------------ from gen.lib import EventType, FamilyRelType, MarkerType +from gen.plug import Gramplet from BasicUtils import name_displayer -from DataViews import Gramplet from ReportBase import ReportUtils from TransUtils import sgettext as _