Step #2 some cleanup: Moved Gramplet class to gen/plug/_gramplet from DataView/GrampletView ; updated gramplets
svn: r13416
This commit is contained in:
parent
88de64e9a0
commit
6af2d2f30a
@ -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.
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -19,7 +19,7 @@
|
||||
# $Id: $
|
||||
#
|
||||
|
||||
from DataViews import Gramplet
|
||||
from gen.plug import Gramplet
|
||||
from BasicUtils import name_displayer
|
||||
from gettext import gettext as _
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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 _
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -23,7 +23,7 @@
|
||||
# GRAMPS modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from DataViews import Gramplet
|
||||
from gen.plug import Gramplet
|
||||
from TransUtils import sgettext as _
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
|
@ -22,7 +22,7 @@
|
||||
#
|
||||
from gettext import gettext as _
|
||||
|
||||
from DataViews import Gramplet
|
||||
from gen.plug import Gramplet
|
||||
import config
|
||||
|
||||
_YIELD_INTERVAL = 350
|
||||
|
@ -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 _
|
||||
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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("<b>%s Plugins</b>\n" % _(type))
|
||||
row_count = 1
|
||||
|
@ -30,7 +30,7 @@ import sys
|
||||
# GRAMPS modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from DataViews import Gramplet
|
||||
from gen.plug import Gramplet
|
||||
from TransUtils import sgettext as _
|
||||
import gen
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -23,7 +23,7 @@
|
||||
# GRAMPS modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from DataViews import Gramplet
|
||||
from gen.plug import Gramplet
|
||||
from TransUtils import sgettext as _
|
||||
import config
|
||||
|
||||
|
@ -23,7 +23,7 @@
|
||||
# GRAMPS modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from DataViews import Gramplet
|
||||
from gen.plug import Gramplet
|
||||
from TransUtils import sgettext as _
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
|
@ -23,7 +23,7 @@
|
||||
# GRAMPS modules
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
from DataViews import Gramplet
|
||||
from gen.plug import Gramplet
|
||||
from TransUtils import sgettext as _
|
||||
import config
|
||||
|
||||
|
@ -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 _
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user