Cleanup separation between gui and non-gui; moved toolip to set_tooltip
svn: r11582
This commit is contained in:
parent
1746064f8a
commit
4704f01093
@ -133,9 +133,7 @@ def make_requested_gramplet(viewpage, name, opts, dbstate, uistate):
|
||||
if opts.get("content", None):
|
||||
opts["content"](gui)
|
||||
# now that we have user code, set the tooltips
|
||||
msg = None
|
||||
if gui.pui:
|
||||
msg = gui.pui.tooltip
|
||||
msg = gui.tooltip
|
||||
if msg is None:
|
||||
msg = _("Drag Properties Button to move and click it for setup")
|
||||
if msg:
|
||||
@ -215,12 +213,8 @@ class Gramplet(object):
|
||||
self._idle_id = 0
|
||||
self._generator = None
|
||||
self._need_to_update = False
|
||||
self._tags = []
|
||||
self.option_dict = {}
|
||||
self.option_order = []
|
||||
self.tooltip = None
|
||||
self.link_cursor = gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)
|
||||
self.standard_cursor = gtk.gdk.Cursor(gtk.gdk.XTERM)
|
||||
# links to each other:
|
||||
self.gui = gui # plugin gramplet has link to gui
|
||||
gui.pui = self # gui has link to plugin ui
|
||||
@ -231,9 +225,9 @@ class Gramplet(object):
|
||||
self.dbstate.connect('database-changed', self._db_changed)
|
||||
self.dbstate.connect('active-changed', self.active_changed)
|
||||
self.gui.textview.connect('button-press-event',
|
||||
self.on_button_press)
|
||||
self.gui.on_button_press)
|
||||
self.gui.textview.connect('motion-notify-event',
|
||||
self.on_motion)
|
||||
self.gui.on_motion)
|
||||
if self.dbstate.active: # already changed
|
||||
self._db_changed(self.dbstate.db)
|
||||
self.active_changed(self.dbstate.active.handle)
|
||||
@ -273,26 +267,14 @@ class Gramplet(object):
|
||||
if debug: print "%s is connecting" % self.gui.title
|
||||
pass
|
||||
|
||||
def link_region(self, start, stop, link_type, url):
|
||||
link_data = (LinkTag(self.gui.buffer), link_type, url, url)
|
||||
self._tags.append(link_data)
|
||||
self.gui.buffer.apply_tag(link_data[0], start, stop)
|
||||
|
||||
def link(self, text, link_type, data, size=None, tooltip=None):
|
||||
buffer = self.gui.buffer
|
||||
iter = buffer.get_end_iter()
|
||||
offset = buffer.get_char_count()
|
||||
self.append_text(text)
|
||||
start = buffer.get_iter_at_offset(offset)
|
||||
end = buffer.get_end_iter()
|
||||
link_data = (LinkTag(buffer), link_type, data, tooltip)
|
||||
if size:
|
||||
link_data[0].set_property("size-points", size)
|
||||
self._tags.append(link_data)
|
||||
buffer.apply_tag(link_data[0], start, end)
|
||||
self.gui.link(text, link_type, data, size, tooltip)
|
||||
|
||||
# Shortcuts to the gui functionality:
|
||||
|
||||
def set_tooltip(self, tip):
|
||||
self.gui.tooltip = tip
|
||||
|
||||
def get_text(self):
|
||||
return self.gui.get_text()
|
||||
|
||||
@ -386,129 +368,6 @@ class Gramplet(object):
|
||||
self._idle_id = 0
|
||||
return False
|
||||
|
||||
def on_motion(self, view, event):
|
||||
buffer_location = view.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT,
|
||||
int(event.x),
|
||||
int(event.y))
|
||||
iter = view.get_iter_at_location(*buffer_location)
|
||||
cursor = self.standard_cursor
|
||||
ttip = None
|
||||
for (tag, link_type, handle, tooltip) in self._tags:
|
||||
if iter.has_tag(tag):
|
||||
tag.set_property('underline', pango.UNDERLINE_SINGLE)
|
||||
cursor = self.link_cursor
|
||||
ttip = tooltip
|
||||
else:
|
||||
tag.set_property('underline', pango.UNDERLINE_NONE)
|
||||
view.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(cursor)
|
||||
if self.gui.tooltips:
|
||||
if ttip:
|
||||
self.gui.tooltips.set_tip(self.gui.scrolledwindow,
|
||||
ttip)
|
||||
else:
|
||||
self.gui.tooltips.set_tip(self.gui.scrolledwindow,
|
||||
self.gui.tooltips_text)
|
||||
return False # handle event further, if necessary
|
||||
|
||||
def on_button_press(self, view, event):
|
||||
buffer_location = view.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT,
|
||||
int(event.x),
|
||||
int(event.y))
|
||||
iter = view.get_iter_at_location(*buffer_location)
|
||||
for (tag, link_type, handle, tooltip) in self._tags:
|
||||
if iter.has_tag(tag):
|
||||
if link_type == 'Person':
|
||||
person = self.dbstate.db.get_person_from_handle(handle)
|
||||
if person is not None:
|
||||
if event.button == 1: # left mouse
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS: # double
|
||||
try:
|
||||
from Editors import EditPerson
|
||||
EditPerson(self.gui.dbstate,
|
||||
self.gui.uistate,
|
||||
[], person)
|
||||
return True # handled event
|
||||
except Errors.WindowActiveError:
|
||||
pass
|
||||
elif event.type == gtk.gdk.BUTTON_PRESS: # single click
|
||||
self.gui.dbstate.change_active_person(person)
|
||||
return True # handled event
|
||||
elif event.button == 3: # right mouse
|
||||
#FIXME: add a popup menu with options
|
||||
try:
|
||||
from Editors import EditPerson
|
||||
EditPerson(self.gui.dbstate,
|
||||
self.gui.uistate,
|
||||
[], person)
|
||||
return True # handled event
|
||||
except Errors.WindowActiveError:
|
||||
pass
|
||||
elif link_type == 'Surname':
|
||||
if event.button == 1: # left mouse
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS: # double
|
||||
run_quick_report_by_name(self.gui.dbstate,
|
||||
self.gui.uistate,
|
||||
'samesurnames',
|
||||
handle)
|
||||
return True
|
||||
elif link_type == 'Given':
|
||||
if event.button == 1: # left mouse
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS: # double
|
||||
run_quick_report_by_name(self.gui.dbstate,
|
||||
self.gui.uistate,
|
||||
'samegivens_misc',
|
||||
handle)
|
||||
return True
|
||||
elif link_type == 'Filter':
|
||||
if event.button == 1: # left mouse
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS: # double
|
||||
run_quick_report_by_name(self.gui.dbstate,
|
||||
self.gui.uistate,
|
||||
'filterbyname',
|
||||
handle)
|
||||
return True
|
||||
elif link_type == 'URL':
|
||||
if event.button == 1: # left mouse
|
||||
GrampsDisplay.url(handle)
|
||||
return True
|
||||
elif link_type == 'WIKI':
|
||||
if event.button == 1: # left mouse
|
||||
GrampsDisplay.help(handle.replace(" ", "_"))
|
||||
return True
|
||||
elif link_type == 'Family':
|
||||
family = self.dbstate.db.get_family_from_handle(handle)
|
||||
if family is not None:
|
||||
if event.button == 1: # left mouse
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS: # double
|
||||
try:
|
||||
from Editors import EditFamily
|
||||
EditFamily(self.gui.dbstate,
|
||||
self.gui.uistate,
|
||||
[], family)
|
||||
return True # handled event
|
||||
except Errors.WindowActiveError:
|
||||
pass
|
||||
elif event.button == 3: # right mouse
|
||||
#FIXME: add a popup menu with options
|
||||
try:
|
||||
from Editors import EditFamily
|
||||
EditFamily(self.gui.dbstate,
|
||||
self.gui.uistate,
|
||||
[], family)
|
||||
return True # handled event
|
||||
except Errors.WindowActiveError:
|
||||
pass
|
||||
elif link_type == 'PersonList':
|
||||
if event.button == 1: # left mouse
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS: # double
|
||||
run_quick_report_by_name(self.gui.dbstate,
|
||||
self.gui.uistate,
|
||||
'filterbyname',
|
||||
'list of people',
|
||||
handles=handle)
|
||||
return True
|
||||
return False # did not handle event
|
||||
|
||||
def get_option_widget(self, label):
|
||||
return self.option_dict[label][0]
|
||||
|
||||
@ -546,6 +405,9 @@ class GuiGramplet:
|
||||
self.uistate = uistate
|
||||
self.title = title
|
||||
self.force_update = False
|
||||
self._tags = []
|
||||
self.link_cursor = gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)
|
||||
self.standard_cursor = gtk.gdk.Cursor(gtk.gdk.XTERM)
|
||||
########## Set defaults
|
||||
self.name = kwargs.get("name", "Unnamed Gramplet")
|
||||
self.tname = kwargs.get("tname", "Unnamed Gramplet")
|
||||
@ -560,7 +422,8 @@ class GuiGramplet:
|
||||
##########
|
||||
self.use_markup = False
|
||||
self.pui = None # user code
|
||||
self.tooltips = None
|
||||
self.tooltip = None # text
|
||||
self.tooltips = None # gtk tooltip widget
|
||||
self.tooltips_text = None
|
||||
self.xml = glade.XML(const.GLADE_FILE, 'gvgramplet', "gramps")
|
||||
self.mainframe = self.xml.get_widget('gvgramplet')
|
||||
@ -763,13 +626,18 @@ class GuiGramplet:
|
||||
stop = self.buffer.get_iter_at_offset(b + offset)
|
||||
if "href" in attributes:
|
||||
url = attributes["href"]
|
||||
self.pui.link_region(start, stop, "URL", url) # tooltip?
|
||||
self.link_region(start, stop, "URL", url) # tooltip?
|
||||
elif "wiki" in attributes:
|
||||
url = attributes["wiki"]
|
||||
self.pui.link_region(start, stop, "WIKI", url) # tooltip?
|
||||
self.link_region(start, stop, "WIKI", url) # tooltip?
|
||||
else:
|
||||
print "warning: no url on link: '%s'" % text[start, stop]
|
||||
|
||||
def link_region(self, start, stop, link_type, url):
|
||||
link_data = (LinkTag(self.buffer), link_type, url, url)
|
||||
self._tags.append(link_data)
|
||||
self.buffer.apply_tag(link_data[0], start, stop)
|
||||
|
||||
def set_use_markup(self, value):
|
||||
if self.use_markup == value: return
|
||||
self.use_markup = value
|
||||
@ -815,6 +683,142 @@ class GuiGramplet:
|
||||
topbox.show_all()
|
||||
save_button.connect('clicked', self.pui.save_update_options)
|
||||
|
||||
def link(self, text, link_type, data, size=None, tooltip=None):
|
||||
buffer = self.buffer
|
||||
iter = buffer.get_end_iter()
|
||||
offset = buffer.get_char_count()
|
||||
self.append_text(text)
|
||||
start = buffer.get_iter_at_offset(offset)
|
||||
end = buffer.get_end_iter()
|
||||
link_data = (LinkTag(buffer), link_type, data, tooltip)
|
||||
if size:
|
||||
link_data[0].set_property("size-points", size)
|
||||
self._tags.append(link_data)
|
||||
buffer.apply_tag(link_data[0], start, end)
|
||||
|
||||
def on_motion(self, view, event):
|
||||
buffer_location = view.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT,
|
||||
int(event.x),
|
||||
int(event.y))
|
||||
iter = view.get_iter_at_location(*buffer_location)
|
||||
cursor = self.standard_cursor
|
||||
ttip = None
|
||||
for (tag, link_type, handle, tooltip) in self._tags:
|
||||
if iter.has_tag(tag):
|
||||
tag.set_property('underline', pango.UNDERLINE_SINGLE)
|
||||
cursor = self.link_cursor
|
||||
ttip = tooltip
|
||||
else:
|
||||
tag.set_property('underline', pango.UNDERLINE_NONE)
|
||||
view.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(cursor)
|
||||
if self.tooltips:
|
||||
if ttip:
|
||||
self.tooltips.set_tip(self.scrolledwindow,
|
||||
ttip)
|
||||
else:
|
||||
self.tooltips.set_tip(self.scrolledwindow,
|
||||
self.tooltips_text)
|
||||
return False # handle event further, if necessary
|
||||
|
||||
def on_button_press(self, view, event):
|
||||
buffer_location = view.window_to_buffer_coords(gtk.TEXT_WINDOW_TEXT,
|
||||
int(event.x),
|
||||
int(event.y))
|
||||
iter = view.get_iter_at_location(*buffer_location)
|
||||
for (tag, link_type, handle, tooltip) in self._tags:
|
||||
if iter.has_tag(tag):
|
||||
if link_type == 'Person':
|
||||
person = self.dbstate.db.get_person_from_handle(handle)
|
||||
if person is not None:
|
||||
if event.button == 1: # left mouse
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS: # double
|
||||
try:
|
||||
from Editors import EditPerson
|
||||
EditPerson(self.dbstate,
|
||||
self.uistate,
|
||||
[], person)
|
||||
return True # handled event
|
||||
except Errors.WindowActiveError:
|
||||
pass
|
||||
elif event.type == gtk.gdk.BUTTON_PRESS: # single click
|
||||
self.dbstate.change_active_person(person)
|
||||
return True # handled event
|
||||
elif event.button == 3: # right mouse
|
||||
#FIXME: add a popup menu with options
|
||||
try:
|
||||
from Editors import EditPerson
|
||||
EditPerson(self.dbstate,
|
||||
self.uistate,
|
||||
[], person)
|
||||
return True # handled event
|
||||
except Errors.WindowActiveError:
|
||||
pass
|
||||
elif link_type == 'Surname':
|
||||
if event.button == 1: # left mouse
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS: # double
|
||||
run_quick_report_by_name(self.dbstate,
|
||||
self.uistate,
|
||||
'samesurnames',
|
||||
handle)
|
||||
return True
|
||||
elif link_type == 'Given':
|
||||
if event.button == 1: # left mouse
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS: # double
|
||||
run_quick_report_by_name(self.dbstate,
|
||||
self.uistate,
|
||||
'samegivens_misc',
|
||||
handle)
|
||||
return True
|
||||
elif link_type == 'Filter':
|
||||
if event.button == 1: # left mouse
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS: # double
|
||||
run_quick_report_by_name(self.dbstate,
|
||||
self.uistate,
|
||||
'filterbyname',
|
||||
handle)
|
||||
return True
|
||||
elif link_type == 'URL':
|
||||
if event.button == 1: # left mouse
|
||||
GrampsDisplay.url(handle)
|
||||
return True
|
||||
elif link_type == 'WIKI':
|
||||
if event.button == 1: # left mouse
|
||||
GrampsDisplay.help(handle.replace(" ", "_"))
|
||||
return True
|
||||
elif link_type == 'Family':
|
||||
family = self.dbstate.db.get_family_from_handle(handle)
|
||||
if family is not None:
|
||||
if event.button == 1: # left mouse
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS: # double
|
||||
try:
|
||||
from Editors import EditFamily
|
||||
EditFamily(self.dbstate,
|
||||
self.uistate,
|
||||
[], family)
|
||||
return True # handled event
|
||||
except Errors.WindowActiveError:
|
||||
pass
|
||||
elif event.button == 3: # right mouse
|
||||
#FIXME: add a popup menu with options
|
||||
try:
|
||||
from Editors import EditFamily
|
||||
EditFamily(self.dbstate,
|
||||
self.uistate,
|
||||
[], family)
|
||||
return True # handled event
|
||||
except Errors.WindowActiveError:
|
||||
pass
|
||||
elif link_type == 'PersonList':
|
||||
if event.button == 1: # left mouse
|
||||
if event.type == gtk.gdk._2BUTTON_PRESS: # double
|
||||
run_quick_report_by_name(self.dbstate,
|
||||
self.uistate,
|
||||
'filterbyname',
|
||||
'list of people',
|
||||
handles=handle)
|
||||
return True
|
||||
return False # did not handle event
|
||||
|
||||
class MyScrolledWindow(gtk.ScrolledWindow):
|
||||
def show_all(self):
|
||||
# first show them all:
|
||||
|
@ -76,7 +76,7 @@ from ReportBase import (CATEGORY_QR_PERSON, CATEGORY_QR_FAMILY,
|
||||
class CalendarGramplet(Gramplet):
|
||||
def init(self):
|
||||
import gtk
|
||||
self.tooltip = _("Double-click a day for details")
|
||||
self.set_tooltip(_("Double-click a day for details"))
|
||||
self.gui.calendar = gtk.Calendar()
|
||||
self.gui.calendar.connect('day-selected-double-click', self.double_click)
|
||||
self.gui.calendar.connect('month-changed', self.refresh)
|
||||
@ -149,7 +149,7 @@ class CalendarGramplet(Gramplet):
|
||||
|
||||
class LogGramplet(Gramplet):
|
||||
def init(self):
|
||||
self.tooltip = _("Click name to change active\nDouble-click name to edit")
|
||||
self.set_tooltip(_("Click name to change active\nDouble-click name to edit"))
|
||||
self.set_text(_("Log for this Session"))
|
||||
self.gui.force_update = True # will always update, even if minimized
|
||||
self.last_log = None
|
||||
@ -202,7 +202,7 @@ class LogGramplet(Gramplet):
|
||||
|
||||
class TopSurnamesGramplet(Gramplet):
|
||||
def init(self):
|
||||
self.tooltip = _("Double-click surname for details")
|
||||
self.set_tooltip(_("Double-click surname for details"))
|
||||
self.top_size = 10 # will be overwritten in load
|
||||
self.set_text(_("No Family Tree loaded."))
|
||||
|
||||
@ -281,7 +281,7 @@ def make_tag_size(n, counts, mins=8, maxs=20):
|
||||
|
||||
class SurnameCloudGramplet(Gramplet):
|
||||
def init(self):
|
||||
self.tooltip = _("Double-click surname for details")
|
||||
self.set_tooltip(_("Double-click surname for details"))
|
||||
self.top_size = 100 # will be overwritten in load
|
||||
self.set_text(_("No Family Tree loaded."))
|
||||
|
||||
@ -369,8 +369,8 @@ class RelativesGramplet(Gramplet):
|
||||
"""
|
||||
def init(self):
|
||||
self.set_text(_("No Family Tree loaded."))
|
||||
self.tooltip = _("Click name to make person active\n") + \
|
||||
_("Right-click name to edit person")
|
||||
self.set_tooltip(_("Click name to make person active\n") +
|
||||
_("Right-click name to edit person"))
|
||||
|
||||
def db_changed(self):
|
||||
"""
|
||||
@ -466,7 +466,7 @@ class RelativesGramplet(Gramplet):
|
||||
class PedigreeGramplet(Gramplet):
|
||||
def init(self):
|
||||
self.set_text(_("No Family Tree loaded."))
|
||||
self.tooltip = _("Move mouse over links for options")
|
||||
self.set_tooltip(_("Move mouse over links for options"))
|
||||
self.set_use_markup(True)
|
||||
self.max_generations = 100
|
||||
self.show_dates = 1
|
||||
@ -688,7 +688,7 @@ class PedigreeGramplet(Gramplet):
|
||||
class StatsGramplet(Gramplet):
|
||||
def init(self):
|
||||
self.set_text(_("No Family Tree loaded."))
|
||||
self.tooltip = _("Double-click item to see matches")
|
||||
self.set_tooltip(_("Double-click item to see matches"))
|
||||
|
||||
def db_changed(self):
|
||||
self.dbstate.db.connect('person-add', self.update)
|
||||
@ -829,7 +829,7 @@ class StatsGramplet(Gramplet):
|
||||
class PythonGramplet(Gramplet):
|
||||
def init(self):
|
||||
self.prompt = ">"
|
||||
self.tooltip = _("Enter Python expressions")
|
||||
self.set_tooltip(_("Enter Python expressions"))
|
||||
self.env = {"dbstate": self.gui.dbstate,
|
||||
"uistate": self.gui.uistate,
|
||||
"self": self,
|
||||
@ -928,7 +928,7 @@ class PythonGramplet(Gramplet):
|
||||
class QueryGramplet(PythonGramplet):
|
||||
def init(self):
|
||||
self.prompt = "$"
|
||||
self.tooltip = _("Enter SQL query")
|
||||
self.set_tooltip(_("Enter SQL query"))
|
||||
# GUI setup:
|
||||
self.gui.textview.set_editable(True)
|
||||
self.set_text("Structured Query Language\n%s " % self.prompt)
|
||||
@ -944,7 +944,7 @@ class QueryGramplet(PythonGramplet):
|
||||
class TODOGramplet(Gramplet):
|
||||
def init(self):
|
||||
# GUI setup:
|
||||
self.tooltip = _("Enter text")
|
||||
self.set_tooltip(_("Enter text"))
|
||||
self.gui.textview.set_editable(True)
|
||||
self.append_text(_("Enter your TODO list here."))
|
||||
|
||||
@ -994,7 +994,7 @@ class NewsGramplet(Gramplet):
|
||||
URL = "http://www.gramps-project.org/wiki/index.php?title=%s&action=raw"
|
||||
|
||||
def init(self):
|
||||
self.tooltip = _("Read news from the GRAMPS wiki")
|
||||
self.set_tooltip(_("Read news from the GRAMPS wiki"))
|
||||
|
||||
def main(self):
|
||||
continuation = self.process('News')
|
||||
@ -1088,7 +1088,7 @@ class AgeOnDateGramplet(Gramplet):
|
||||
def init(self):
|
||||
import gtk
|
||||
# GUI setup:
|
||||
self.tooltip = _("Enter a date, click Run")
|
||||
self.set_tooltip(_("Enter a date, click Run"))
|
||||
vbox = gtk.VBox()
|
||||
hbox = gtk.HBox()
|
||||
# label, entry
|
||||
|
@ -44,7 +44,7 @@ import DateHandler
|
||||
class DescendantGramplet(Gramplet):
|
||||
def init(self):
|
||||
self.set_text(_("No Family Tree loaded."))
|
||||
self.tooltip = _("Move mouse over links for options")
|
||||
self.set_tooltip(_("Move mouse over links for options"))
|
||||
self.set_use_markup(True)
|
||||
self.no_wrap()
|
||||
self.max_generations = 100
|
||||
|
@ -34,7 +34,7 @@ def make_tag_size(n, counts, mins=8, maxs=20):
|
||||
|
||||
class GivenNameCloudGramplet(Gramplet):
|
||||
def init(self):
|
||||
self.tooltip = _("Double-click given name for details")
|
||||
self.set_tooltip(_("Double-click given name for details"))
|
||||
self.top_size = 100 # will be overwritten in load
|
||||
self.set_text(_("No Family Tree loaded."))
|
||||
|
||||
|
@ -323,7 +323,7 @@ class RecordsGramplet(Gramplet):
|
||||
|
||||
def init(self):
|
||||
self.set_use_markup(True)
|
||||
self.tooltip = _("Double-click name for details")
|
||||
self.set_tooltip(_("Double-click name for details"))
|
||||
self.set_text(_("No Family Tree loaded."))
|
||||
|
||||
|
||||
|
@ -57,7 +57,7 @@ class WhatNextGramplet(Gramplet):
|
||||
|
||||
def init(self):
|
||||
|
||||
self.tooltip = _("Double-click name for details")
|
||||
self.set_tooltip(_("Double-click name for details"))
|
||||
self.set_text(_("No Family Tree loaded."))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user