2007-12-24 20:26:15 +05:30
|
|
|
#
|
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2008-01-22 14:47:46 +05:30
|
|
|
# $Id$
|
2007-12-24 20:26:15 +05:30
|
|
|
|
|
|
|
"""
|
2008-01-25 02:08:10 +05:30
|
|
|
GrampletView interface.
|
2007-12-24 20:26:15 +05:30
|
|
|
"""
|
|
|
|
|
2008-02-19 01:37:09 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gtk modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-12-24 20:26:15 +05:30
|
|
|
import gtk
|
2008-02-19 01:37:09 +05:30
|
|
|
from gtk import glade
|
2007-12-24 20:26:15 +05:30
|
|
|
import gobject
|
2008-02-19 01:37:09 +05:30
|
|
|
import pango
|
|
|
|
|
2007-12-24 20:26:15 +05:30
|
|
|
import traceback
|
|
|
|
import time
|
2007-12-29 23:05:07 +05:30
|
|
|
import types
|
2007-12-26 13:56:33 +05:30
|
|
|
import os
|
2007-12-28 11:53:50 +05:30
|
|
|
from gettext import gettext as _
|
2007-12-25 10:04:42 +05:30
|
|
|
|
|
|
|
import Errors
|
|
|
|
import const
|
|
|
|
import PageView
|
2007-12-25 23:21:37 +05:30
|
|
|
import ManagedWindow
|
2007-12-26 13:56:33 +05:30
|
|
|
import ConfigParser
|
|
|
|
import Utils
|
2007-12-30 09:16:39 +05:30
|
|
|
from QuickReports import run_quick_report_by_name
|
2008-02-28 11:50:44 +05:30
|
|
|
import GrampsDisplay
|
2007-12-24 20:26:15 +05:30
|
|
|
|
2008-02-28 11:50:44 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
WIKI_HELP_PAGE = 'Gramps_3.0_Wiki_Manual_-_Gramplets'
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Globals
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-01-07 04:27:34 +05:30
|
|
|
AVAILABLE_GRAMPLETS = {}
|
|
|
|
GRAMPLET_FILENAME = os.path.join(const.HOME_DIR,"gramplets.ini")
|
2007-12-26 13:56:33 +05:30
|
|
|
NL = "\n"
|
2007-12-24 20:26:15 +05:30
|
|
|
|
2007-12-26 22:49:26 +05:30
|
|
|
debug = False
|
2007-12-24 20:26:15 +05:30
|
|
|
|
2008-01-07 04:27:34 +05:30
|
|
|
def register_gramplet(data_dict):
|
|
|
|
global AVAILABLE_GRAMPLETS
|
|
|
|
base_opts = {"name":"Unnamed Gramplet",
|
|
|
|
"tname": _("Unnamed Gramplet"),
|
2007-12-27 04:44:13 +05:30
|
|
|
"state":"maximized",
|
2007-12-27 20:36:28 +05:30
|
|
|
"column": -1, "row": -1,
|
|
|
|
"data": []}
|
2007-12-26 13:56:33 +05:30
|
|
|
base_opts.update(data_dict)
|
2008-01-07 04:27:34 +05:30
|
|
|
AVAILABLE_GRAMPLETS[base_opts["name"]] = base_opts
|
2007-12-24 20:26:15 +05:30
|
|
|
|
|
|
|
def register(**data):
|
|
|
|
if "type" in data:
|
2008-01-07 04:27:34 +05:30
|
|
|
if data["type"].lower() == "gramplet":
|
|
|
|
register_gramplet(data)
|
2007-12-27 04:44:13 +05:30
|
|
|
else:
|
|
|
|
print ("Unknown plugin type: '%s'" % data["type"])
|
|
|
|
else:
|
|
|
|
print ("Plugin did not define type.")
|
2007-12-24 20:26:15 +05:30
|
|
|
|
2008-03-10 10:07:45 +05:30
|
|
|
def parse_tag_attr(text):
|
|
|
|
text = text.strip()
|
|
|
|
parts = text.split(" ", 1)
|
|
|
|
attrs = {}
|
|
|
|
if len(parts) == 2:
|
|
|
|
attr_values = parts[1].split(" ") # "name=value name=value"
|
|
|
|
for av in attr_values:
|
|
|
|
attribute, value = av.split("=")
|
|
|
|
value = value.strip()
|
|
|
|
# trim off quotes:
|
|
|
|
if value[0] == value[-1] and value[0] in ['"', "'"]:
|
|
|
|
value = value[1:-1]
|
|
|
|
attrs[attribute.strip().lower()] = value
|
|
|
|
return [parts[0].upper(), attrs]
|
|
|
|
|
2008-01-07 04:27:34 +05:30
|
|
|
def get_gramplet_opts(name, opts):
|
|
|
|
if name in AVAILABLE_GRAMPLETS:
|
|
|
|
data = AVAILABLE_GRAMPLETS[name]
|
2007-12-27 04:44:13 +05:30
|
|
|
my_data = data.copy()
|
|
|
|
my_data.update(opts)
|
|
|
|
return my_data
|
|
|
|
else:
|
2008-01-07 04:27:34 +05:30
|
|
|
print ("Unknown gramplet name: '%s'" % name)
|
2007-12-27 04:44:13 +05:30
|
|
|
return {}
|
2007-12-24 20:26:15 +05:30
|
|
|
|
2008-01-07 04:27:34 +05:30
|
|
|
def get_gramplet_options_by_name(name):
|
2007-12-26 13:56:33 +05:30
|
|
|
if debug: print "name:", name
|
2008-01-07 04:27:34 +05:30
|
|
|
if name in AVAILABLE_GRAMPLETS:
|
|
|
|
return AVAILABLE_GRAMPLETS[name].copy()
|
2007-12-27 04:44:13 +05:30
|
|
|
else:
|
2008-01-07 04:27:34 +05:30
|
|
|
print ("Unknown gramplet name: '%s'" % name)
|
2007-12-27 04:44:13 +05:30
|
|
|
return None
|
2007-12-26 13:56:33 +05:30
|
|
|
|
2008-01-07 04:27:34 +05:30
|
|
|
def get_gramplet_options_by_tname(name):
|
2007-12-31 19:20:39 +05:30
|
|
|
if debug: print "name:", name
|
2008-01-07 04:27:34 +05:30
|
|
|
for key in AVAILABLE_GRAMPLETS:
|
|
|
|
if AVAILABLE_GRAMPLETS[key]["tname"] == name:
|
|
|
|
return AVAILABLE_GRAMPLETS[key].copy()
|
|
|
|
print ("Unknown gramplet name: '%s'" % name)
|
2007-12-31 19:20:39 +05:30
|
|
|
return None
|
|
|
|
|
2008-01-07 04:27:34 +05:30
|
|
|
def make_requested_gramplet(viewpage, name, opts, dbstate, uistate):
|
|
|
|
if name in AVAILABLE_GRAMPLETS:
|
|
|
|
gui = GuiGramplet(viewpage, dbstate, uistate, **opts)
|
2007-12-27 04:44:13 +05:30
|
|
|
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
|
|
|
|
if msg == None:
|
|
|
|
msg = _("Drag Properties Button to move and click it for setup")
|
|
|
|
if msg:
|
|
|
|
gui.tooltips = gtk.Tooltips()
|
2007-12-31 10:10:21 +05:30
|
|
|
gui.tooltips.set_tip(gui.scrolledwindow, msg)
|
2008-01-18 08:28:14 +05:30
|
|
|
gui.tooltips_text = msg
|
2008-03-06 05:28:55 +05:30
|
|
|
gui.gvoptions.hide()
|
2007-12-27 04:44:13 +05:30
|
|
|
return gui
|
2007-12-24 20:26:15 +05:30
|
|
|
return None
|
|
|
|
|
2007-12-25 10:04:42 +05:30
|
|
|
class LinkTag(gtk.TextTag):
|
|
|
|
lid = 0
|
|
|
|
def __init__(self, buffer):
|
|
|
|
LinkTag.lid += 1
|
|
|
|
gtk.TextTag.__init__(self, str(LinkTag.lid))
|
|
|
|
tag_table = buffer.get_tag_table()
|
2008-02-20 09:46:26 +05:30
|
|
|
self.set_property('foreground', "blue")
|
2007-12-28 11:53:50 +05:30
|
|
|
#self.set_property('underline', pango.UNDERLINE_SINGLE)
|
2007-12-25 10:04:42 +05:30
|
|
|
tag_table.add(self)
|
|
|
|
|
2008-01-07 04:27:34 +05:30
|
|
|
class GrampletWindow(ManagedWindow.ManagedWindow):
|
|
|
|
def __init__(self, gramplet):
|
2008-02-22 18:41:41 +05:30
|
|
|
self.title = gramplet.title + " " + _("Gramplet")
|
2008-01-07 04:27:34 +05:30
|
|
|
self.gramplet = gramplet
|
|
|
|
ManagedWindow.ManagedWindow.__init__(self, gramplet.uistate, [], gramplet)
|
|
|
|
self.set_window(gtk.Dialog("",gramplet.uistate.window,
|
2007-12-25 23:21:37 +05:30
|
|
|
gtk.DIALOG_DESTROY_WITH_PARENT,
|
|
|
|
(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)),
|
|
|
|
None, self.title)
|
2008-02-14 02:59:06 +05:30
|
|
|
self.window.set_size_request(gramplet.detached_width,
|
|
|
|
gramplet.detached_height)
|
2008-03-04 18:29:10 +05:30
|
|
|
self.window.add_button(gtk.STOCK_HELP, gtk.RESPONSE_HELP)
|
|
|
|
# add gramplet:
|
2008-01-07 04:27:34 +05:30
|
|
|
self.gramplet.mainframe.reparent(self.window.vbox)
|
2008-03-04 18:29:10 +05:30
|
|
|
self.window.connect('response', self.handle_response)
|
2007-12-26 13:56:33 +05:30
|
|
|
self.window.show()
|
2008-02-28 11:50:44 +05:30
|
|
|
|
|
|
|
def handle_response(self, object, response):
|
2008-03-10 20:06:24 +05:30
|
|
|
if response in [gtk.RESPONSE_CLOSE, gtk.STOCK_CLOSE]:
|
2008-02-28 11:50:44 +05:30
|
|
|
self.close()
|
2008-03-10 20:06:24 +05:30
|
|
|
elif response == gtk.RESPONSE_HELP:
|
2008-02-28 11:50:44 +05:30
|
|
|
# translated name:
|
2008-04-05 19:47:15 +05:30
|
|
|
GrampsDisplay.help(WIKI_HELP_PAGE,
|
2008-02-28 11:50:44 +05:30
|
|
|
self.gramplet.tname.replace(" ", "_"))
|
2007-12-25 23:21:37 +05:30
|
|
|
|
|
|
|
def build_menu_names(self, obj):
|
2008-01-07 04:27:34 +05:30
|
|
|
return (self.title, 'Gramplet')
|
2007-12-25 23:21:37 +05:30
|
|
|
|
|
|
|
def get_title(self):
|
|
|
|
return self.title
|
|
|
|
|
|
|
|
def close(self, *args):
|
2007-12-26 13:56:33 +05:30
|
|
|
"""
|
2008-01-07 04:27:34 +05:30
|
|
|
Closes the detached GrampletWindow.
|
2007-12-26 13:56:33 +05:30
|
|
|
"""
|
2008-03-04 18:29:10 +05:30
|
|
|
self.gramplet.gvoptions.hide()
|
2008-01-07 04:27:34 +05:30
|
|
|
self.gramplet.viewpage.detached_gramplets.remove(self.gramplet)
|
|
|
|
self.gramplet.state = "maximized"
|
2008-03-09 01:40:47 +05:30
|
|
|
parent = self.gramplet.viewpage.get_column_frame(self.gramplet.column)
|
|
|
|
self.gramplet.mainframe.reparent(parent)
|
|
|
|
expand,fill,padding,pack = parent.query_child_packing(self.gramplet.mainframe)
|
|
|
|
parent.set_child_packing(self.gramplet.mainframe,
|
|
|
|
self.gramplet.expand,
|
|
|
|
fill,
|
|
|
|
padding,
|
|
|
|
pack)
|
2008-03-08 21:25:06 +05:30
|
|
|
self.gramplet.gvclose.show()
|
|
|
|
self.gramplet.gvstate.show()
|
|
|
|
self.gramplet.gvproperties.show()
|
2007-12-25 23:21:37 +05:30
|
|
|
ManagedWindow.ManagedWindow.close(self, *args)
|
|
|
|
|
|
|
|
#------------------------------------------------------------------------
|
|
|
|
|
2008-01-07 04:27:34 +05:30
|
|
|
class Gramplet(object):
|
2007-12-24 20:26:15 +05:30
|
|
|
def __init__(self, gui):
|
|
|
|
self._idle_id = 0
|
|
|
|
self._generator = None
|
|
|
|
self._need_to_update = False
|
2007-12-25 10:04:42 +05:30
|
|
|
self._tags = []
|
2008-03-04 18:29:10 +05:30
|
|
|
self.option_dict = {}
|
2007-12-27 04:44:13 +05:30
|
|
|
self.tooltip = None
|
2007-12-25 10:04:42 +05:30
|
|
|
self.link_cursor = gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)
|
|
|
|
self.standard_cursor = gtk.gdk.Cursor(gtk.gdk.XTERM)
|
2007-12-26 22:18:51 +05:30
|
|
|
# links to each other:
|
2008-01-07 04:27:34 +05:30
|
|
|
self.gui = gui # plugin gramplet has link to gui
|
2007-12-26 22:18:51 +05:30
|
|
|
gui.pui = self # gui has link to plugin ui
|
2007-12-24 20:26:15 +05:30
|
|
|
self.dbstate = gui.dbstate
|
|
|
|
self.init()
|
2007-12-26 22:18:51 +05:30
|
|
|
self.on_load()
|
2007-12-24 20:26:15 +05:30
|
|
|
self.dbstate.connect('database-changed', self._db_changed)
|
|
|
|
self.dbstate.connect('active-changed', self.active_changed)
|
2007-12-25 10:04:42 +05:30
|
|
|
self.gui.textview.connect('button-press-event',
|
|
|
|
self.on_button_press)
|
|
|
|
self.gui.textview.connect('motion-notify-event',
|
|
|
|
self.on_motion)
|
2008-03-04 18:29:10 +05:30
|
|
|
# Add options to section on detached view
|
|
|
|
# FIXME: too many options will expand section: need scrollable area
|
|
|
|
for item in self.option_dict:
|
|
|
|
self.gui.option_vbox.add(gtk.Label(item))
|
2007-12-28 11:53:50 +05:30
|
|
|
if self.dbstate.active: # already changed
|
|
|
|
self._db_changed(self.dbstate.db)
|
|
|
|
self.active_changed(self.dbstate.active.handle)
|
2007-12-24 20:26:15 +05:30
|
|
|
|
2007-12-27 04:44:13 +05:30
|
|
|
def init(self): # once, constructor
|
|
|
|
pass
|
|
|
|
|
2007-12-29 17:19:15 +05:30
|
|
|
def main(self): # return false finishes
|
2007-12-27 04:44:13 +05:30
|
|
|
"""
|
|
|
|
Generator which will be run in the background.
|
|
|
|
"""
|
|
|
|
if debug: print "%s dummy" % self.gui.title
|
|
|
|
yield False
|
|
|
|
|
2007-12-26 22:18:51 +05:30
|
|
|
def on_load(self):
|
|
|
|
"""
|
2008-01-07 04:27:34 +05:30
|
|
|
Gramplets should override this to take care of loading previously
|
2007-12-26 22:18:51 +05:30
|
|
|
their special data.
|
|
|
|
"""
|
|
|
|
pass
|
|
|
|
|
|
|
|
def on_save(self):
|
|
|
|
"""
|
2008-01-07 04:27:34 +05:30
|
|
|
Gramplets should override this to take care of saving their
|
2007-12-26 22:18:51 +05:30
|
|
|
special data.
|
|
|
|
"""
|
2007-12-26 22:53:02 +05:30
|
|
|
if debug: print ("on_save: '%s'" % self.gui.title)
|
2007-12-26 22:48:43 +05:30
|
|
|
return
|
2007-12-26 22:18:51 +05:30
|
|
|
|
2007-12-24 20:26:15 +05:30
|
|
|
def active_changed(self, handle):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def db_changed(self):
|
|
|
|
if debug: print "%s is connecting" % self.gui.title
|
|
|
|
pass
|
|
|
|
|
2008-03-10 10:07:45 +05:30
|
|
|
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)
|
|
|
|
|
2008-01-18 08:28:14 +05:30
|
|
|
def link(self, text, link_type, data, size=None, tooltip=None):
|
2007-12-27 04:44:13 +05:30
|
|
|
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()
|
2008-01-18 08:28:14 +05:30
|
|
|
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)
|
2007-12-24 20:26:15 +05:30
|
|
|
|
2008-02-20 09:46:26 +05:30
|
|
|
# Shortcuts to the gui functionality:
|
|
|
|
|
2007-12-27 20:36:28 +05:30
|
|
|
def get_text(self):
|
2008-02-20 09:46:26 +05:30
|
|
|
return self.gui.get_text()
|
2007-12-27 20:36:28 +05:30
|
|
|
|
2007-12-27 04:44:13 +05:30
|
|
|
def insert_text(self, text):
|
2008-02-20 09:46:26 +05:30
|
|
|
self.gui.insert_text(text)
|
|
|
|
|
|
|
|
def render_text(self, text):
|
|
|
|
self.gui.render_text(text)
|
2007-12-27 04:44:13 +05:30
|
|
|
|
|
|
|
def clear_text(self):
|
2008-02-20 09:46:26 +05:30
|
|
|
self.gui.clear_text()
|
2007-12-27 04:44:13 +05:30
|
|
|
|
2007-12-27 20:36:28 +05:30
|
|
|
def set_text(self, text, scroll_to='start'):
|
2008-02-20 09:46:26 +05:30
|
|
|
self.gui.set_text(text, scroll_to)
|
2007-12-27 04:44:13 +05:30
|
|
|
|
|
|
|
def append_text(self, text, scroll_to="end"):
|
2008-02-20 09:46:26 +05:30
|
|
|
self.gui.append_text(text, scroll_to)
|
|
|
|
|
|
|
|
def set_use_markup(self, value):
|
|
|
|
self.gui.set_use_markup(value)
|
|
|
|
|
2008-02-28 16:00:12 +05:30
|
|
|
def no_wrap(self):
|
|
|
|
"""
|
|
|
|
The view in gramplet should not wrap.
|
|
|
|
"""
|
|
|
|
self.gui.scrolledwindow.set_policy(gtk.POLICY_AUTOMATIC,
|
|
|
|
gtk.POLICY_AUTOMATIC)
|
|
|
|
self.gui.textview.set_wrap_mode(gtk.WRAP_NONE)
|
|
|
|
|
2008-02-20 09:46:26 +05:30
|
|
|
# Other functions of the gramplet:
|
2007-12-24 20:26:15 +05:30
|
|
|
|
2007-12-27 20:36:28 +05:30
|
|
|
def load_data_to_text(self, pos=0):
|
|
|
|
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):
|
|
|
|
text = self.get_text()
|
|
|
|
text = text.replace(chr(10), "\\n")
|
|
|
|
self.gui.data.append(text)
|
|
|
|
|
2007-12-29 18:06:28 +05:30
|
|
|
def update(self, *args):
|
2007-12-24 20:26:15 +05:30
|
|
|
if self._idle_id != 0:
|
|
|
|
if debug: print "%s interrupt!" % self.gui.title
|
|
|
|
self.interrupt()
|
|
|
|
if debug: print "%s creating generator" % self.gui.title
|
2007-12-29 17:19:15 +05:30
|
|
|
self._generator = self.main()
|
2007-12-24 20:26:15 +05:30
|
|
|
if debug: print "%s adding to gobject" % self.gui.title
|
|
|
|
self._idle_id = gobject.idle_add(self._updater,
|
2007-12-29 22:23:14 +05:30
|
|
|
priority=gobject.PRIORITY_LOW - 10)
|
2007-12-24 20:26:15 +05:30
|
|
|
|
|
|
|
def interrupt(self):
|
|
|
|
"""
|
|
|
|
Force the generator to stop running.
|
|
|
|
"""
|
|
|
|
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
|
|
|
|
|
2007-12-27 04:44:13 +05:30
|
|
|
def _db_changed(self, db):
|
|
|
|
if debug: print "%s is _connecting" % self.gui.title
|
|
|
|
self.dbstate.db = db
|
|
|
|
self.gui.dbstate.db = db
|
|
|
|
self.db_changed()
|
|
|
|
self.update()
|
|
|
|
|
2007-12-24 20:26:15 +05:30
|
|
|
def _updater(self):
|
2007-12-26 13:56:33 +05:30
|
|
|
"""
|
|
|
|
Runs the generator.
|
|
|
|
"""
|
2007-12-24 20:26:15 +05:30
|
|
|
if debug: print "%s _updater" % self.gui.title
|
2007-12-29 23:05:07 +05:30
|
|
|
if type(self._generator) != types.GeneratorType:
|
|
|
|
self._idle_id = 0
|
|
|
|
return False
|
2007-12-24 20:26:15 +05:30
|
|
|
try:
|
|
|
|
retval = self._generator.next()
|
2008-02-05 06:01:57 +05:30
|
|
|
if not retval:
|
2007-12-24 20:26:15 +05:30
|
|
|
self._idle_id = 0
|
|
|
|
return retval
|
|
|
|
except StopIteration:
|
|
|
|
self._idle_id = 0
|
|
|
|
return False
|
|
|
|
except Exception, e:
|
2008-01-07 04:27:34 +05:30
|
|
|
print "Gramplet gave an error"
|
2007-12-24 20:26:15 +05:30
|
|
|
traceback.print_exc()
|
2008-01-07 04:27:34 +05:30
|
|
|
print "Continuing after gramplet error..."
|
2007-12-24 20:26:15 +05:30
|
|
|
self._idle_id = 0
|
|
|
|
return False
|
|
|
|
|
2007-12-25 10:04:42 +05:30
|
|
|
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)
|
2007-12-28 11:53:50 +05:30
|
|
|
cursor = self.standard_cursor
|
2008-01-18 08:28:14 +05:30
|
|
|
ttip = None
|
|
|
|
for (tag, link_type, handle, tooltip) in self._tags:
|
2007-12-25 10:04:42 +05:30
|
|
|
if iter.has_tag(tag):
|
2007-12-28 11:53:50 +05:30
|
|
|
tag.set_property('underline', pango.UNDERLINE_SINGLE)
|
|
|
|
cursor = self.link_cursor
|
2008-01-18 08:28:14 +05:30
|
|
|
ttip = tooltip
|
2007-12-28 11:53:50 +05:30
|
|
|
else:
|
|
|
|
tag.set_property('underline', pango.UNDERLINE_NONE)
|
|
|
|
view.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(cursor)
|
2008-01-18 08:28:14 +05:30
|
|
|
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)
|
2007-12-25 10:04:42 +05:30
|
|
|
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)
|
2008-01-18 08:28:14 +05:30
|
|
|
for (tag, link_type, handle, tooltip) in self._tags:
|
2007-12-25 10:04:42 +05:30
|
|
|
if iter.has_tag(tag):
|
2007-12-30 06:54:33 +05:30
|
|
|
if link_type == 'Person':
|
|
|
|
person = self.dbstate.db.get_person_from_handle(handle)
|
|
|
|
if person != None:
|
|
|
|
if event.button == 1: # left mouse
|
|
|
|
if event.type == gtk.gdk._2BUTTON_PRESS: # double
|
|
|
|
try:
|
2008-02-14 01:22:40 +05:30
|
|
|
from Editors import EditPerson
|
2007-12-30 06:54:33 +05:30
|
|
|
EditPerson(self.gui.dbstate,
|
|
|
|
self.gui.uistate,
|
|
|
|
[], person)
|
|
|
|
return True # handled event
|
|
|
|
except Errors.WindowActiveError:
|
|
|
|
pass
|
2008-02-14 01:22:40 +05:30
|
|
|
elif event.type == gtk.gdk.BUTTON_PRESS: # single click
|
2007-12-30 06:54:33 +05:30
|
|
|
self.gui.dbstate.change_active_person(person)
|
|
|
|
return True # handled event
|
2008-02-14 08:10:45 +05:30
|
|
|
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
|
2007-12-30 06:54:33 +05:30
|
|
|
elif link_type == 'Surname':
|
2007-12-30 09:16:39 +05:30
|
|
|
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)
|
2007-12-30 06:54:33 +05:30
|
|
|
return True
|
2008-03-05 09:31:27 +05:30
|
|
|
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)
|
2008-03-09 01:53:11 +05:30
|
|
|
return True
|
2008-03-10 10:07:45 +05:30
|
|
|
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
|
2008-04-05 19:47:15 +05:30
|
|
|
GrampsDisplay.help(handle.replace(" ", "_"))
|
2008-03-10 10:07:45 +05:30
|
|
|
return True
|
2008-03-07 19:49:30 +05:30
|
|
|
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)
|
2008-03-05 09:31:27 +05:30
|
|
|
return True
|
2007-12-25 10:04:42 +05:30
|
|
|
return False # did not handle event
|
2008-03-04 18:29:10 +05:30
|
|
|
|
|
|
|
def set_options(self, option_dict):
|
|
|
|
self.option_dict = option_dict
|
2007-12-24 20:26:15 +05:30
|
|
|
|
2007-12-26 13:56:33 +05:30
|
|
|
def logical_true(value):
|
|
|
|
return value in ["True", True, 1, "1"]
|
2007-12-24 20:26:15 +05:30
|
|
|
|
2008-01-07 04:27:34 +05:30
|
|
|
class GuiGramplet:
|
2007-12-24 20:26:15 +05:30
|
|
|
"""
|
2008-01-07 04:27:34 +05:30
|
|
|
Class that handles the plugin interfaces for the GrampletView.
|
2007-12-24 20:26:15 +05:30
|
|
|
"""
|
|
|
|
TARGET_TYPE_FRAME = 80
|
2008-01-07 04:27:34 +05:30
|
|
|
LOCAL_DRAG_TYPE = 'GRAMPLET'
|
2007-12-24 20:26:15 +05:30
|
|
|
LOCAL_DRAG_TARGET = (LOCAL_DRAG_TYPE, 0, TARGET_TYPE_FRAME)
|
2007-12-25 05:06:11 +05:30
|
|
|
def __init__(self, viewpage, dbstate, uistate, title, **kwargs):
|
2007-12-24 20:26:15 +05:30
|
|
|
self.viewpage = viewpage
|
|
|
|
self.dbstate = dbstate
|
2007-12-25 05:06:11 +05:30
|
|
|
self.uistate = uistate
|
2007-12-24 20:26:15 +05:30
|
|
|
self.title = title
|
|
|
|
########## Set defaults
|
2008-01-07 04:27:34 +05:30
|
|
|
self.name = kwargs.get("name", "Unnamed Gramplet")
|
2008-02-28 11:50:44 +05:30
|
|
|
self.tname = kwargs.get("tname", "Unnamed Gramplet")
|
2007-12-26 13:56:33 +05:30
|
|
|
self.expand = logical_true(kwargs.get("expand", False))
|
|
|
|
self.height = int(kwargs.get("height", 200))
|
|
|
|
self.column = int(kwargs.get("column", -1))
|
2008-02-14 02:59:06 +05:30
|
|
|
self.detached_height = int(kwargs.get("detached_height", 300))
|
|
|
|
self.detached_width = int(kwargs.get("detached_width", 400))
|
2007-12-26 13:56:33 +05:30
|
|
|
self.row = int(kwargs.get("row", -1))
|
2007-12-24 20:26:15 +05:30
|
|
|
self.state = kwargs.get("state", "maximized")
|
2007-12-27 20:36:28 +05:30
|
|
|
self.data = kwargs.get("data", [])
|
2007-12-24 20:26:15 +05:30
|
|
|
##########
|
2008-02-20 09:46:26 +05:30
|
|
|
self.use_markup = False
|
2007-12-26 22:48:43 +05:30
|
|
|
self.pui = None # user code
|
2008-01-18 08:28:14 +05:30
|
|
|
self.tooltips = None
|
|
|
|
self.tooltips_text = None
|
2008-02-19 01:37:09 +05:30
|
|
|
self.xml = glade.XML(const.GLADE_FILE, 'gvgramplet', "gramps")
|
2008-01-07 04:27:34 +05:30
|
|
|
self.mainframe = self.xml.get_widget('gvgramplet')
|
2008-03-04 18:29:10 +05:30
|
|
|
self.gvoptions = self.xml.get_widget('gvoptions')
|
|
|
|
self.option_vbox = self.xml.get_widget('option_vbox')
|
2007-12-24 20:26:15 +05:30
|
|
|
self.textview = self.xml.get_widget('gvtextview')
|
|
|
|
self.buffer = self.textview.get_buffer()
|
|
|
|
self.scrolledwindow = self.xml.get_widget('gvscrolledwindow')
|
|
|
|
self.titlelabel = self.xml.get_widget('gvtitle')
|
|
|
|
self.titlelabel.set_text("<b><i>%s</i></b>" % self.title)
|
|
|
|
self.titlelabel.set_use_markup(True)
|
2007-12-26 13:56:33 +05:30
|
|
|
self.gvclose = self.xml.get_widget('gvclose')
|
|
|
|
self.gvclose.connect('clicked', self.close)
|
|
|
|
self.gvstate = self.xml.get_widget('gvstate')
|
|
|
|
self.gvstate.connect('clicked', self.change_state)
|
|
|
|
self.gvproperties = self.xml.get_widget('gvproperties')
|
|
|
|
self.gvproperties.connect('clicked', self.set_properties)
|
2007-12-24 20:26:15 +05:30
|
|
|
self.xml.get_widget('gvcloseimage').set_from_stock(gtk.STOCK_CLOSE,
|
|
|
|
gtk.ICON_SIZE_MENU)
|
|
|
|
self.xml.get_widget('gvstateimage').set_from_stock(gtk.STOCK_REMOVE,
|
|
|
|
gtk.ICON_SIZE_MENU)
|
|
|
|
self.xml.get_widget('gvpropertiesimage').set_from_stock(gtk.STOCK_PROPERTIES,
|
|
|
|
gtk.ICON_SIZE_MENU)
|
|
|
|
|
|
|
|
# source:
|
2007-12-26 13:56:33 +05:30
|
|
|
drag = self.gvproperties
|
2007-12-24 20:26:15 +05:30
|
|
|
drag.drag_source_set(gtk.gdk.BUTTON1_MASK,
|
2008-01-07 04:27:34 +05:30
|
|
|
[GuiGramplet.LOCAL_DRAG_TARGET],
|
2007-12-24 20:26:15 +05:30
|
|
|
gtk.gdk.ACTION_COPY)
|
|
|
|
|
2007-12-28 11:53:50 +05:30
|
|
|
def close(self, *obj):
|
2007-12-26 13:56:33 +05:30
|
|
|
if self.state == "windowed":
|
|
|
|
return
|
2007-12-28 11:53:50 +05:30
|
|
|
self.state = "closed"
|
2008-01-07 04:27:34 +05:30
|
|
|
self.viewpage.closed_gramplets.append(self)
|
2007-12-28 11:53:50 +05:30
|
|
|
self.mainframe.get_parent().remove(self.mainframe)
|
2007-12-24 20:26:15 +05:30
|
|
|
|
2007-12-26 22:18:51 +05:30
|
|
|
def detach(self):
|
2007-12-26 13:56:33 +05:30
|
|
|
# hide buttons:
|
2007-12-27 04:44:13 +05:30
|
|
|
self.set_state("maximized")
|
2007-12-26 13:56:33 +05:30
|
|
|
self.gvclose.hide()
|
|
|
|
self.gvstate.hide()
|
|
|
|
self.gvproperties.hide()
|
2008-03-07 18:01:11 +05:30
|
|
|
if self.pui and len(self.pui.option_dict) > 0:
|
2008-03-04 18:29:10 +05:30
|
|
|
self.gvoptions.show()
|
2008-01-07 04:27:34 +05:30
|
|
|
self.viewpage.detached_gramplets.append(self)
|
2007-12-25 23:21:37 +05:30
|
|
|
# make a window, and attach it there
|
2008-01-07 04:27:34 +05:30
|
|
|
self.detached_window = GrampletWindow(self)
|
2007-12-26 13:56:33 +05:30
|
|
|
self.state = "windowed"
|
2007-12-25 23:21:37 +05:30
|
|
|
|
2007-12-25 10:04:42 +05:30
|
|
|
def set_state(self, state):
|
|
|
|
self.state = state
|
|
|
|
if state == "minimized":
|
2007-12-24 20:26:15 +05:30
|
|
|
self.scrolledwindow.hide()
|
|
|
|
self.xml.get_widget('gvstateimage').set_from_stock(gtk.STOCK_ADD,
|
|
|
|
gtk.ICON_SIZE_MENU)
|
2007-12-25 10:04:42 +05:30
|
|
|
column = self.mainframe.get_parent() # column
|
|
|
|
expand,fill,padding,pack = column.query_child_packing(self.mainframe)
|
|
|
|
column.set_child_packing(self.mainframe,False,fill,padding,pack)
|
|
|
|
|
2007-12-24 20:26:15 +05:30
|
|
|
else:
|
|
|
|
self.scrolledwindow.show()
|
|
|
|
self.xml.get_widget('gvstateimage').set_from_stock(gtk.STOCK_REMOVE,
|
|
|
|
gtk.ICON_SIZE_MENU)
|
|
|
|
column = self.mainframe.get_parent() # column
|
|
|
|
expand,fill,padding,pack = column.query_child_packing(self.mainframe)
|
2008-03-04 18:29:10 +05:30
|
|
|
column.set_child_packing(self.mainframe,
|
|
|
|
self.expand,
|
|
|
|
fill,
|
|
|
|
padding,
|
|
|
|
pack)
|
2007-12-25 10:04:42 +05:30
|
|
|
|
|
|
|
def change_state(self, obj):
|
2007-12-25 23:25:42 +05:30
|
|
|
if self.state == "windowed":
|
|
|
|
pass # don't change if windowed
|
2007-12-25 10:04:42 +05:30
|
|
|
else:
|
2007-12-25 23:25:42 +05:30
|
|
|
if self.state == "maximized":
|
|
|
|
self.set_state("minimized")
|
|
|
|
else:
|
|
|
|
self.set_state("maximized")
|
|
|
|
|
2007-12-24 20:26:15 +05:30
|
|
|
def set_properties(self, obj):
|
2007-12-25 23:21:37 +05:30
|
|
|
if self.state == "windowed":
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
self.detach()
|
|
|
|
return
|
2007-12-26 13:56:33 +05:30
|
|
|
# FIXME: add control for expand AND detach
|
2007-12-24 20:26:15 +05:30
|
|
|
self.expand = not self.expand
|
|
|
|
if self.state == "maximized":
|
|
|
|
column = self.mainframe.get_parent() # column
|
|
|
|
expand,fill,padding,pack = column.query_child_packing(self.mainframe)
|
|
|
|
column.set_child_packing(self.mainframe,self.expand,fill,padding,pack)
|
|
|
|
|
2008-02-20 09:46:26 +05:30
|
|
|
def append_text(self, text, scroll_to="end"):
|
|
|
|
enditer = self.buffer.get_end_iter()
|
|
|
|
start = self.buffer.create_mark(None, enditer, True)
|
|
|
|
self.buffer.insert(enditer, text)
|
|
|
|
if scroll_to == "end":
|
|
|
|
enditer = self.buffer.get_end_iter()
|
|
|
|
end = self.buffer.create_mark(None, enditer, True)
|
|
|
|
self.textview.scroll_to_mark(end, 0.0, True, 0, 0)
|
|
|
|
elif scroll_to == "start": # beginning of this append
|
|
|
|
self.textview.scroll_to_mark(start, 0.0, True, 0, 0)
|
2008-02-28 11:50:44 +05:30
|
|
|
elif scroll_to == "begin": # beginning of the buffer
|
2008-02-20 09:46:26 +05:30
|
|
|
begin_iter = self.buffer.get_start_iter()
|
|
|
|
begin = self.buffer.create_mark(None, begin_iter, True)
|
|
|
|
self.textview.scroll_to_mark(begin, 0.0, True, 0, 0)
|
|
|
|
else:
|
|
|
|
raise AttributeError, ("no such cursor position: '%s'" % scroll_to)
|
2007-12-24 20:26:15 +05:30
|
|
|
|
|
|
|
def clear_text(self):
|
|
|
|
self.buffer.set_text('')
|
2008-02-20 09:46:26 +05:30
|
|
|
|
|
|
|
def get_text(self):
|
|
|
|
start = self.buffer.get_start_iter()
|
|
|
|
end = self.buffer.get_end_iter()
|
|
|
|
return self.buffer.get_text(start, end)
|
|
|
|
|
|
|
|
def insert_text(self, text):
|
|
|
|
self.buffer.insert_at_cursor(text)
|
|
|
|
|
|
|
|
def render_text(self, text):
|
2008-03-10 10:07:45 +05:30
|
|
|
markup_pos = {"B": [], "I": [], "U": [], "A": []}
|
2008-02-20 09:46:26 +05:30
|
|
|
retval = ""
|
|
|
|
i = 0
|
|
|
|
r = 0
|
2008-03-10 10:07:45 +05:30
|
|
|
tag = ""
|
2008-02-20 09:46:26 +05:30
|
|
|
while i < len(text):
|
2008-03-10 10:07:45 +05:30
|
|
|
if text[i:i+2] == "</":
|
|
|
|
# start of ending tag
|
|
|
|
stop = text[i:].find(">")
|
|
|
|
if stop < 0:
|
|
|
|
retval += text[i]
|
|
|
|
r += 1
|
|
|
|
i += 1
|
2008-02-20 09:46:26 +05:30
|
|
|
else:
|
2008-03-10 10:07:45 +05:30
|
|
|
markup = text[i+2:i+stop].upper() # close tag
|
|
|
|
markup_pos[markup][-1].append(r)
|
|
|
|
i = i + stop + 1
|
|
|
|
elif text[i] == "<":
|
|
|
|
# start of start tag
|
|
|
|
stop = text[i:].find(">")
|
|
|
|
if stop < 0:
|
2008-02-20 09:46:26 +05:30
|
|
|
retval += text[i]
|
|
|
|
r += 1
|
|
|
|
i += 1
|
2008-03-10 10:07:45 +05:30
|
|
|
else:
|
|
|
|
markup, attr = parse_tag_attr(text[i+1:i+stop])
|
|
|
|
markup_pos[markup].append([r, attr])
|
|
|
|
i = i + stop + 1
|
2008-02-20 09:46:26 +05:30
|
|
|
elif text[i] == "\\":
|
|
|
|
retval += text[i+1]
|
|
|
|
r += 1
|
|
|
|
i += 2
|
|
|
|
elif ord(text[i]) > 126:
|
|
|
|
while ord(text[i]) > 126:
|
|
|
|
retval += text[i]
|
|
|
|
i += 1
|
|
|
|
r += 1
|
|
|
|
else:
|
|
|
|
retval += text[i]
|
|
|
|
r += 1
|
|
|
|
i += 1
|
2008-03-02 11:40:20 +05:30
|
|
|
offset = len(self.get_text())
|
|
|
|
self.append_text(retval)
|
2008-03-10 10:07:45 +05:30
|
|
|
for (a,attributes,b) in markup_pos["B"]:
|
2008-03-02 11:40:20 +05:30
|
|
|
start = self.buffer.get_iter_at_offset(a + offset)
|
|
|
|
stop = self.buffer.get_iter_at_offset(b + offset)
|
2008-02-20 09:46:26 +05:30
|
|
|
self.buffer.apply_tag_by_name("bold", start, stop)
|
2008-03-10 10:07:45 +05:30
|
|
|
for (a,attributes,b) in markup_pos["I"]:
|
2008-03-02 11:40:20 +05:30
|
|
|
start = self.buffer.get_iter_at_offset(a + offset)
|
|
|
|
stop = self.buffer.get_iter_at_offset(b + offset)
|
2008-02-20 09:46:26 +05:30
|
|
|
self.buffer.apply_tag_by_name("italic", start, stop)
|
2008-03-10 10:07:45 +05:30
|
|
|
for (a,attributes,b) in markup_pos["U"]:
|
2008-03-02 11:40:20 +05:30
|
|
|
start = self.buffer.get_iter_at_offset(a + offset)
|
|
|
|
stop = self.buffer.get_iter_at_offset(b + offset)
|
2008-02-20 09:46:26 +05:30
|
|
|
self.buffer.apply_tag_by_name("underline", start, stop)
|
2008-03-10 10:07:45 +05:30
|
|
|
for (a,attributes,b) in markup_pos["A"]:
|
|
|
|
start = self.buffer.get_iter_at_offset(a + offset)
|
|
|
|
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?
|
|
|
|
elif "wiki" in attributes:
|
|
|
|
url = attributes["wiki"]
|
|
|
|
self.pui.link_region(start, stop, "WIKI", url) # tooltip?
|
|
|
|
else:
|
|
|
|
print "warning: no url on link: '%s'" % text[start, stop]
|
2008-02-20 09:46:26 +05:30
|
|
|
|
|
|
|
def set_use_markup(self, value):
|
|
|
|
if self.use_markup == value: return
|
|
|
|
self.use_markup = value
|
|
|
|
if value:
|
|
|
|
self.buffer.create_tag("bold",weight=pango.WEIGHT_HEAVY)
|
|
|
|
self.buffer.create_tag("italic",style=pango.STYLE_ITALIC)
|
|
|
|
self.buffer.create_tag("underline",underline=pango.UNDERLINE_SINGLE)
|
|
|
|
else:
|
|
|
|
tag_table = self.buffer.get_tag_table()
|
|
|
|
tag_table.foreach(lambda tag, data: tag_table.remove(tag))
|
|
|
|
|
|
|
|
def set_text(self, text, scroll_to='start'):
|
|
|
|
self.buffer.set_text('')
|
|
|
|
self.append_text(text, scroll_to)
|
|
|
|
|
2007-12-26 13:56:33 +05:30
|
|
|
def get_source_widget(self):
|
|
|
|
"""
|
|
|
|
Hack to allow us to send this object to the drop_widget
|
|
|
|
method as a context.
|
|
|
|
"""
|
|
|
|
return self.gvproperties
|
|
|
|
|
|
|
|
class MyScrolledWindow(gtk.ScrolledWindow):
|
|
|
|
def show_all(self):
|
|
|
|
# first show them all:
|
|
|
|
gtk.ScrolledWindow.show_all(self)
|
|
|
|
# Hack to get around show_all that shows hidden items
|
|
|
|
# do once, the first time showing
|
|
|
|
if self.viewpage:
|
2008-01-07 04:27:34 +05:30
|
|
|
gramplets = [g for g in self.viewpage.gramplet_map.values() if g != None]
|
2007-12-26 13:56:33 +05:30
|
|
|
self.viewpage = None
|
2008-01-07 04:27:34 +05:30
|
|
|
for gramplet in gramplets:
|
2008-03-04 18:29:10 +05:30
|
|
|
gramplet.gvoptions.hide()
|
2008-01-07 04:27:34 +05:30
|
|
|
if gramplet.state == "minimized":
|
|
|
|
gramplet.set_state("minimized")
|
2007-12-24 20:26:15 +05:30
|
|
|
|
2008-03-07 17:35:34 +05:30
|
|
|
class GrampletView(PageView.PersonNavView):
|
2007-12-24 20:26:15 +05:30
|
|
|
"""
|
2008-01-07 04:27:34 +05:30
|
|
|
GrampletView interface
|
2007-12-24 20:26:15 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
def __init__(self, dbstate, uistate):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Create a GrampletView, with the current dbstate and uistate
|
2007-12-24 20:26:15 +05:30
|
|
|
"""
|
2008-03-07 17:35:34 +05:30
|
|
|
PageView.PersonNavView.__init__(self, _('Gramplets'), dbstate, uistate)
|
2007-12-26 13:56:33 +05:30
|
|
|
self._popup_xy = None
|
2007-12-24 20:26:15 +05:30
|
|
|
|
|
|
|
def build_widget(self):
|
|
|
|
"""
|
|
|
|
Builds the container widget for the interface. Must be overridden by the
|
|
|
|
the base class. Returns a gtk container widget.
|
|
|
|
"""
|
2008-01-07 04:27:34 +05:30
|
|
|
# load the user's gramplets and set columns, etc
|
|
|
|
user_gramplets = self.load_gramplets()
|
2007-12-26 13:56:33 +05:30
|
|
|
# build the GUI:
|
|
|
|
frame = MyScrolledWindow()
|
2008-01-07 04:27:34 +05:30
|
|
|
msg = _("Right click to add gramplets")
|
2007-12-27 04:44:13 +05:30
|
|
|
self.tooltips = gtk.Tooltips()
|
|
|
|
self.tooltips.set_tip(frame, msg)
|
2007-12-26 13:56:33 +05:30
|
|
|
frame.viewpage = self
|
2007-12-24 20:26:15 +05:30
|
|
|
frame.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
2007-12-26 13:56:33 +05:30
|
|
|
self.hbox = gtk.HBox(homogeneous=True)
|
2007-12-24 20:26:15 +05:30
|
|
|
# Set up drag and drop
|
|
|
|
frame.drag_dest_set(gtk.DEST_DEFAULT_MOTION |
|
|
|
|
gtk.DEST_DEFAULT_HIGHLIGHT |
|
|
|
|
gtk.DEST_DEFAULT_DROP,
|
2008-01-07 04:27:34 +05:30
|
|
|
[('GRAMPLET', 0, 80)],
|
2007-12-24 20:26:15 +05:30
|
|
|
gtk.gdk.ACTION_COPY)
|
|
|
|
frame.connect('drag_drop', self.drop_widget)
|
2007-12-26 13:56:33 +05:30
|
|
|
frame.connect('button-press-event', self._button_press)
|
2007-12-24 20:26:15 +05:30
|
|
|
|
2007-12-26 13:56:33 +05:30
|
|
|
frame.add_with_viewport(self.hbox)
|
2007-12-24 20:26:15 +05:30
|
|
|
# Create the columns:
|
|
|
|
self.columns = []
|
|
|
|
for i in range(self.column_count):
|
|
|
|
self.columns.append(gtk.VBox())
|
2007-12-26 13:56:33 +05:30
|
|
|
self.hbox.pack_start(self.columns[-1],expand=True)
|
2008-01-07 04:27:34 +05:30
|
|
|
# Load the gramplets
|
|
|
|
self.gramplet_map = {} # title->gramplet
|
|
|
|
self.frame_map = {} # frame->gramplet
|
|
|
|
self.detached_gramplets = [] # list of detached gramplets
|
|
|
|
self.closed_gramplets = [] # list of closed gramplets
|
2007-12-28 11:53:50 +05:30
|
|
|
self.closed_opts = [] # list of closed options from ini file
|
2008-01-07 04:27:34 +05:30
|
|
|
# get the user's gramplets from ~/.gramps/gramplets.ini
|
|
|
|
# Load the user's gramplets:
|
|
|
|
for (name, opts) in user_gramplets:
|
|
|
|
all_opts = get_gramplet_opts(name, opts)
|
2007-12-24 20:26:15 +05:30
|
|
|
if "title" not in all_opts:
|
2008-01-07 04:27:34 +05:30
|
|
|
all_opts["title"] = "Untitled Gramplet"
|
2007-12-28 13:16:26 +05:30
|
|
|
if "state" not in all_opts:
|
|
|
|
all_opts["state"] = "maximized"
|
2007-12-24 20:26:15 +05:30
|
|
|
# uniqify titles:
|
|
|
|
unique = all_opts["title"]
|
|
|
|
cnt = 1
|
2008-01-07 04:27:34 +05:30
|
|
|
while unique in self.gramplet_map:
|
2007-12-24 20:26:15 +05:30
|
|
|
unique = all_opts["title"] + ("-%d" % cnt)
|
|
|
|
cnt += 1
|
|
|
|
all_opts["title"] = unique
|
2007-12-28 11:53:50 +05:30
|
|
|
if all_opts["state"] == "closed":
|
2008-01-07 04:27:34 +05:30
|
|
|
self.gramplet_map[all_opts["title"]] = None # save closed name
|
2007-12-28 11:53:50 +05:30
|
|
|
self.closed_opts.append(all_opts)
|
|
|
|
continue
|
2008-01-07 04:27:34 +05:30
|
|
|
g = make_requested_gramplet(self, name, all_opts,
|
2007-12-28 11:53:50 +05:30
|
|
|
self.dbstate, self.uistate)
|
|
|
|
if g:
|
2008-01-07 04:27:34 +05:30
|
|
|
self.gramplet_map[all_opts["title"]] = g
|
2007-12-28 11:53:50 +05:30
|
|
|
self.frame_map[str(g.mainframe)] = g
|
2007-12-24 20:26:15 +05:30
|
|
|
else:
|
2008-01-07 04:27:34 +05:30
|
|
|
print "Can't make gramplet of type '%s'." % name
|
|
|
|
self.place_gramplets()
|
2007-12-26 13:56:33 +05:30
|
|
|
return frame
|
|
|
|
|
2008-03-09 01:40:47 +05:30
|
|
|
def get_column_frame(self, column_num):
|
|
|
|
if column_num < len(self.columns):
|
|
|
|
return self.columns[column_num]
|
|
|
|
else:
|
|
|
|
return self.columns[-1] # it was too big, so select largest
|
|
|
|
|
2008-01-07 04:27:34 +05:30
|
|
|
def clear_gramplets(self):
|
2007-12-26 13:56:33 +05:30
|
|
|
"""
|
2008-01-07 04:27:34 +05:30
|
|
|
Detach all of the mainframe gramplets from the columns.
|
2007-12-26 13:56:33 +05:30
|
|
|
"""
|
2008-01-07 04:27:34 +05:30
|
|
|
gramplets = [g for g in self.gramplet_map.values() if g != None]
|
|
|
|
for gramplet in gramplets:
|
2008-03-09 01:40:47 +05:30
|
|
|
if (gramplet.state == "windowed" or gramplet.state == "closed"):
|
|
|
|
continue
|
2008-01-07 04:27:34 +05:30
|
|
|
column = gramplet.mainframe.get_parent()
|
2008-01-06 18:33:28 +05:30
|
|
|
if column:
|
2008-01-07 04:27:34 +05:30
|
|
|
column.remove(gramplet.mainframe)
|
2007-12-26 13:56:33 +05:30
|
|
|
|
2008-03-09 01:40:47 +05:30
|
|
|
def place_gramplets(self, recolumn=False):
|
2007-12-26 13:56:33 +05:30
|
|
|
"""
|
2008-01-07 04:27:34 +05:30
|
|
|
Place the gramplet mainframes in the columns.
|
2007-12-26 13:56:33 +05:30
|
|
|
"""
|
2008-01-07 04:27:34 +05:30
|
|
|
gramplets = [g for g in self.gramplet_map.values() if g != None]
|
|
|
|
# put the gramplets where they go:
|
2007-12-26 13:56:33 +05:30
|
|
|
# sort by row
|
2008-01-07 04:27:34 +05:30
|
|
|
gramplets.sort(lambda a, b: cmp(a.row, b.row))
|
2007-12-24 20:26:15 +05:30
|
|
|
cnt = 0
|
2008-01-07 04:27:34 +05:30
|
|
|
for gramplet in gramplets:
|
2007-12-24 20:26:15 +05:30
|
|
|
# see if the user wants this in a particular location:
|
|
|
|
# and if there are that many columns
|
2008-01-07 04:27:34 +05:30
|
|
|
if gramplet.column >= 0 and gramplet.column < self.column_count:
|
|
|
|
pos = gramplet.column
|
2007-12-24 20:26:15 +05:30
|
|
|
else:
|
|
|
|
# else, spread them out:
|
2007-12-26 13:56:33 +05:30
|
|
|
pos = cnt % self.column_count
|
2008-01-07 04:27:34 +05:30
|
|
|
gramplet.column = pos
|
2008-03-09 01:40:47 +05:30
|
|
|
if recolumn and (gramplet.state == "windowed" or gramplet.state == "closed"):
|
|
|
|
continue
|
|
|
|
self.columns[pos].pack_start(gramplet.mainframe, expand=gramplet.expand)
|
2008-01-07 04:27:34 +05:30
|
|
|
# set height on gramplet.scrolledwindow here:
|
|
|
|
gramplet.scrolledwindow.set_size_request(-1, gramplet.height)
|
2007-12-26 13:56:33 +05:30
|
|
|
# Can't minimize here, because GRAMPS calls show_all later:
|
2008-01-07 04:27:34 +05:30
|
|
|
#if gramplet.state == "minimized": # starts max, change to min it
|
|
|
|
# gramplet.set_state("minimized") # minimize it
|
2007-12-29 23:26:23 +05:30
|
|
|
# set minimized is called in page subclass hack (above)
|
2008-01-07 04:27:34 +05:30
|
|
|
if gramplet.state == "windowed":
|
|
|
|
gramplet.detach()
|
|
|
|
elif gramplet.state == "closed":
|
|
|
|
gramplet.close()
|
2007-12-24 20:26:15 +05:30
|
|
|
cnt += 1
|
2007-12-26 13:56:33 +05:30
|
|
|
|
2008-01-07 04:27:34 +05:30
|
|
|
def load_gramplets(self):
|
2007-12-27 04:44:13 +05:30
|
|
|
self.column_count = 2 # default for new user
|
2007-12-26 13:56:33 +05:30
|
|
|
retval = []
|
2008-01-07 04:27:34 +05:30
|
|
|
filename = GRAMPLET_FILENAME
|
2007-12-26 13:56:33 +05:30
|
|
|
if filename and os.path.exists(filename):
|
|
|
|
cp = ConfigParser.ConfigParser()
|
|
|
|
cp.read(filename)
|
|
|
|
for sec in cp.sections():
|
2008-01-07 04:27:34 +05:30
|
|
|
if sec == "Gramplet View Options":
|
2007-12-26 13:56:33 +05:30
|
|
|
if "column_count" in cp.options(sec):
|
|
|
|
self.column_count = int(cp.get(sec, "column_count"))
|
|
|
|
else:
|
2007-12-29 23:26:23 +05:30
|
|
|
data = {"title": sec}
|
2007-12-26 13:56:33 +05:30
|
|
|
for opt in cp.options(sec):
|
2007-12-27 20:36:28 +05:30
|
|
|
if opt.startswith("data["):
|
|
|
|
temp = data.get("data", [])
|
|
|
|
temp.append(cp.get(sec, opt).strip())
|
|
|
|
data["data"] = temp
|
|
|
|
else:
|
|
|
|
data[opt] = cp.get(sec, opt).strip()
|
2007-12-26 13:56:33 +05:30
|
|
|
if "name" not in data:
|
2008-01-07 04:27:34 +05:30
|
|
|
data["name"] = "Unnamed Gramplet"
|
|
|
|
data["tname"]= _("Unnamed Gramplet")
|
2007-12-26 13:56:33 +05:30
|
|
|
retval.append((data["name"], data)) # name, opts
|
|
|
|
else:
|
|
|
|
# give defaults as currently known
|
2008-01-07 04:27:34 +05:30
|
|
|
for name in ["Top Surnames Gramplet", "Welcome Gramplet"]:
|
|
|
|
if name in AVAILABLE_GRAMPLETS:
|
|
|
|
retval.append((name, AVAILABLE_GRAMPLETS[name]))
|
2007-12-26 13:56:33 +05:30
|
|
|
return retval
|
|
|
|
|
|
|
|
def save(self, *args):
|
|
|
|
if debug: print "saving"
|
2007-12-29 22:23:14 +05:30
|
|
|
if len(self.frame_map.keys() +
|
2008-02-24 19:39:58 +05:30
|
|
|
self.detached_gramplets) == 0:
|
2007-12-29 22:23:14 +05:30
|
|
|
return # something is the matter
|
2008-01-07 04:27:34 +05:30
|
|
|
filename = GRAMPLET_FILENAME
|
2007-12-27 20:36:28 +05:30
|
|
|
try:
|
|
|
|
fp = open(filename, "w")
|
|
|
|
except:
|
2008-01-07 04:27:34 +05:30
|
|
|
print "Failed writing '%s'; gramplets not saved" % filename
|
2007-12-27 20:36:28 +05:30
|
|
|
return
|
2008-01-07 04:27:34 +05:30
|
|
|
fp.write(";; Gramps gramplets file" + NL)
|
2007-12-26 13:56:33 +05:30
|
|
|
fp.write((";; Automatically created at %s" % time.strftime("%Y/%m/%d %H:%M:%S")) + NL + NL)
|
2008-01-07 04:27:34 +05:30
|
|
|
fp.write("[Gramplet View Options]" + NL)
|
2007-12-26 13:56:33 +05:30
|
|
|
fp.write(("column_count=%d" + NL + NL) % self.column_count)
|
2008-01-07 04:27:34 +05:30
|
|
|
# showing gramplets:
|
2007-12-26 13:56:33 +05:30
|
|
|
for col in range(self.column_count):
|
|
|
|
row = 0
|
|
|
|
for gframe in self.columns[col]:
|
2008-01-07 04:27:34 +05:30
|
|
|
gramplet = self.frame_map[str(gframe)]
|
|
|
|
opts = get_gramplet_options_by_name(gramplet.name)
|
2007-12-26 13:56:33 +05:30
|
|
|
if opts != None:
|
|
|
|
base_opts = opts.copy()
|
|
|
|
for key in base_opts:
|
2008-01-07 04:27:34 +05:30
|
|
|
if key in gramplet.__dict__:
|
|
|
|
base_opts[key] = gramplet.__dict__[key]
|
|
|
|
fp.write(("[%s]" + NL) % gramplet.title)
|
2007-12-26 13:56:33 +05:30
|
|
|
for key in base_opts:
|
|
|
|
if key == "content": continue
|
2007-12-28 11:53:50 +05:30
|
|
|
elif key == "title": continue
|
|
|
|
elif key == "column": continue
|
|
|
|
elif key == "row": continue
|
|
|
|
elif key == "data":
|
2007-12-28 13:16:26 +05:30
|
|
|
if type(base_opts["data"]) not in [list, tuple]:
|
|
|
|
fp.write(("data[0]=%s" + NL) % base_opts["data"])
|
|
|
|
else:
|
|
|
|
cnt = 0
|
|
|
|
for item in base_opts["data"]:
|
|
|
|
fp.write(("data[%d]=%s" + NL) % (cnt, item))
|
|
|
|
cnt += 1
|
2007-12-27 20:36:28 +05:30
|
|
|
else:
|
|
|
|
fp.write(("%s=%s" + NL)% (key, base_opts[key]))
|
2007-12-26 13:56:33 +05:30
|
|
|
fp.write(("column=%d" + NL) % col)
|
|
|
|
fp.write(("row=%d" + NL) % row)
|
|
|
|
fp.write(NL)
|
|
|
|
row += 1
|
2008-02-24 19:39:58 +05:30
|
|
|
for gramplet in self.detached_gramplets:
|
2008-01-07 04:27:34 +05:30
|
|
|
opts = get_gramplet_options_by_name(gramplet.name)
|
2007-12-26 13:56:33 +05:30
|
|
|
if opts != None:
|
|
|
|
base_opts = opts.copy()
|
|
|
|
for key in base_opts:
|
2008-01-07 04:27:34 +05:30
|
|
|
if key in gramplet.__dict__:
|
|
|
|
base_opts[key] = gramplet.__dict__[key]
|
|
|
|
fp.write(("[%s]" + NL) % gramplet.title)
|
2007-12-26 13:56:33 +05:30
|
|
|
for key in base_opts:
|
|
|
|
if key == "content": continue
|
2007-12-28 11:53:50 +05:30
|
|
|
elif key == "title": continue
|
|
|
|
elif key == "data":
|
2007-12-28 13:16:26 +05:30
|
|
|
if type(base_opts["data"]) not in [list, tuple]:
|
|
|
|
fp.write(("data[0]=%s" + NL) % base_opts["data"])
|
|
|
|
else:
|
|
|
|
cnt = 0
|
|
|
|
for item in base_opts["data"]:
|
|
|
|
fp.write(("data[%d]=%s" + NL) % (cnt, item))
|
|
|
|
cnt += 1
|
2007-12-28 11:53:50 +05:30
|
|
|
else:
|
|
|
|
fp.write(("%s=%s" + NL)% (key, base_opts[key]))
|
2007-12-26 13:56:33 +05:30
|
|
|
fp.write(NL)
|
|
|
|
fp.close()
|
2007-12-24 20:26:15 +05:30
|
|
|
|
|
|
|
def drop_widget(self, source, context, x, y, timedata):
|
2007-12-26 13:56:33 +05:30
|
|
|
"""
|
|
|
|
This is the destination method for handling drag and drop
|
2008-01-07 04:27:34 +05:30
|
|
|
of a gramplet onto the main scrolled window.
|
2007-12-26 13:56:33 +05:30
|
|
|
"""
|
2007-12-24 20:26:15 +05:30
|
|
|
button = context.get_source_widget()
|
|
|
|
hbox = button.get_parent()
|
2008-03-05 09:31:27 +05:30
|
|
|
mframe = hbox.get_parent()
|
|
|
|
mainframe = mframe.get_parent() # actually a vbox
|
2007-12-24 20:26:15 +05:30
|
|
|
rect = source.get_allocation()
|
|
|
|
sx, sy = rect.width, rect.height
|
|
|
|
# first, find column:
|
|
|
|
col = 0
|
|
|
|
for i in range(len(self.columns)):
|
|
|
|
if x < (sx/len(self.columns) * (i + 1)):
|
|
|
|
col = i
|
|
|
|
break
|
|
|
|
fromcol = mainframe.get_parent()
|
2007-12-28 11:53:50 +05:30
|
|
|
if fromcol:
|
|
|
|
fromcol.remove(mainframe)
|
2007-12-24 20:26:15 +05:30
|
|
|
# now find where to insert in column:
|
|
|
|
stack = []
|
|
|
|
for gframe in self.columns[col]:
|
|
|
|
rect = gframe.get_allocation()
|
|
|
|
if y < (rect.y + 15): # starts at 0, this allows insert before
|
|
|
|
self.columns[col].remove(gframe)
|
|
|
|
stack.append(gframe)
|
2008-01-07 04:27:34 +05:30
|
|
|
maingramplet = self.frame_map.get(str(mainframe), None)
|
|
|
|
maingramplet.column = col
|
|
|
|
if maingramplet.state == "maximized":
|
|
|
|
expand = maingramplet.expand
|
2007-12-24 20:26:15 +05:30
|
|
|
else:
|
|
|
|
expand = False
|
|
|
|
self.columns[col].pack_start(mainframe, expand=expand)
|
|
|
|
for gframe in stack:
|
2008-01-07 04:27:34 +05:30
|
|
|
gramplet = self.frame_map[str(gframe)]
|
|
|
|
if gramplet.state == "maximized":
|
|
|
|
expand = gramplet.expand
|
2007-12-24 20:26:15 +05:30
|
|
|
else:
|
|
|
|
expand = False
|
|
|
|
self.columns[col].pack_start(gframe, expand=expand)
|
|
|
|
return True
|
|
|
|
|
|
|
|
def define_actions(self):
|
|
|
|
"""
|
|
|
|
Defines the UIManager actions. Called by the ViewManager to set up the
|
|
|
|
View. The user typically defines self.action_list and
|
|
|
|
self.action_toggle_list in this function.
|
|
|
|
"""
|
2008-01-07 04:27:34 +05:30
|
|
|
self.action = gtk.ActionGroup(self.title + "/Gramplets")
|
|
|
|
self.action.add_actions([('AddGramplet',gtk.STOCK_ADD,_("_Add a gramplet")),
|
2008-02-24 19:39:58 +05:30
|
|
|
('RestoreGramplet',None,_("_Undelete gramplet")),
|
2008-01-29 02:52:06 +05:30
|
|
|
('Columns1',None,_("Set Columns to _1"),
|
2007-12-26 13:56:33 +05:30
|
|
|
None,None,
|
|
|
|
lambda obj:self.set_columns(1)),
|
2008-01-29 02:52:06 +05:30
|
|
|
('Columns2',None,_("Set Columns to _2"),
|
2007-12-26 13:56:33 +05:30
|
|
|
None,None,
|
|
|
|
lambda obj:self.set_columns(2)),
|
2008-01-29 02:52:06 +05:30
|
|
|
('Columns3',None,_("Set Columns to _3"),
|
2007-12-26 13:56:33 +05:30
|
|
|
None,None,
|
|
|
|
lambda obj:self.set_columns(3)),
|
|
|
|
])
|
|
|
|
self._add_action_group(self.action)
|
2008-03-07 17:35:34 +05:30
|
|
|
# Back, Forward, Home
|
|
|
|
self.fwd_action = gtk.ActionGroup(self.title + '/Forward')
|
|
|
|
self.fwd_action.add_actions([
|
|
|
|
('Forward', gtk.STOCK_GO_FORWARD, _("_Forward"),
|
|
|
|
"<ALT>Right", _("Go to the next person in the history"),
|
|
|
|
self.fwd_clicked)
|
|
|
|
])
|
|
|
|
|
|
|
|
# add the Backward action group to handle the Forward button
|
|
|
|
self.back_action = gtk.ActionGroup(self.title + '/Backward')
|
|
|
|
self.back_action.add_actions([
|
|
|
|
('Back', gtk.STOCK_GO_BACK, _("_Back"),
|
|
|
|
"<ALT>Left", _("Go to the previous person in the history"),
|
|
|
|
self.back_clicked)
|
|
|
|
])
|
|
|
|
self._add_action('HomePerson', gtk.STOCK_HOME, _("_Home"),
|
|
|
|
accel="<Alt>Home",
|
|
|
|
tip=_("Go to the default person"), callback=self.home)
|
|
|
|
self.other_action = gtk.ActionGroup(self.title + '/PersonOther')
|
|
|
|
self.other_action.add_actions([
|
|
|
|
('SetActive', gtk.STOCK_HOME, _("Set _Home Person"), None,
|
|
|
|
None, self.set_default_person),
|
|
|
|
])
|
|
|
|
self._add_action_group(self.back_action)
|
|
|
|
self._add_action_group(self.fwd_action)
|
|
|
|
self._add_action_group(self.other_action)
|
|
|
|
|
|
|
|
def set_active(self):
|
|
|
|
PageView.PersonNavView.set_active(self)
|
|
|
|
self.key_active_changed = self.dbstate.connect('active-changed',
|
|
|
|
self.goto_active_person)
|
|
|
|
|
|
|
|
def set_inactive(self):
|
|
|
|
PageView.PersonNavView.set_inactive(self)
|
|
|
|
self.dbstate.disconnect(self.key_active_changed)
|
|
|
|
|
|
|
|
def goto_active_person(self, handle=None):
|
|
|
|
self.dirty = True
|
|
|
|
if handle:
|
|
|
|
self.handle_history(handle)
|
|
|
|
self.uistate.modify_statusbar(self.dbstate)
|
2007-12-26 13:56:33 +05:30
|
|
|
|
|
|
|
def set_columns(self, num):
|
2008-01-07 04:27:34 +05:30
|
|
|
# clear the gramplets:
|
|
|
|
self.clear_gramplets()
|
2007-12-26 13:56:33 +05:30
|
|
|
# clear the columns:
|
|
|
|
for column in self.columns:
|
|
|
|
frame = column.get_parent()
|
|
|
|
frame.remove(column)
|
|
|
|
del column
|
|
|
|
# create the new ones:
|
|
|
|
self.column_count = num
|
|
|
|
self.columns = []
|
|
|
|
for i in range(self.column_count):
|
|
|
|
self.columns.append(gtk.VBox())
|
|
|
|
self.columns[-1].show()
|
|
|
|
self.hbox.pack_start(self.columns[-1],expand=True)
|
2008-01-07 04:27:34 +05:30
|
|
|
# place the gramplets back in the new columns
|
2008-03-09 01:40:47 +05:30
|
|
|
self.place_gramplets(recolumn=True)
|
2007-12-26 13:56:33 +05:30
|
|
|
self.widget.show()
|
|
|
|
|
2008-01-07 04:27:34 +05:30
|
|
|
def restore_gramplet(self, obj):
|
2007-12-28 11:53:50 +05:30
|
|
|
name = obj.get_child().get_label()
|
|
|
|
############### First kind: from current session
|
2008-01-07 04:27:34 +05:30
|
|
|
for gramplet in self.closed_gramplets:
|
|
|
|
if gramplet.title == name:
|
2008-02-24 20:28:35 +05:30
|
|
|
#gramplet.state = "maximized"
|
2008-01-07 04:27:34 +05:30
|
|
|
self.closed_gramplets.remove(gramplet)
|
2007-12-28 11:53:50 +05:30
|
|
|
if self._popup_xy != None:
|
2008-01-07 04:27:34 +05:30
|
|
|
self.drop_widget(self.widget, gramplet,
|
2007-12-28 11:53:50 +05:30
|
|
|
self._popup_xy[0], self._popup_xy[1], 0)
|
|
|
|
else:
|
2008-01-07 04:27:34 +05:30
|
|
|
self.drop_widget(self.widget, gramplet, 0, 0, 0)
|
2008-02-24 20:28:35 +05:30
|
|
|
gramplet.set_state("maximized")
|
2007-12-28 11:53:50 +05:30
|
|
|
return
|
|
|
|
################ Second kind: from options
|
|
|
|
for opts in self.closed_opts:
|
|
|
|
if opts["title"] == name:
|
|
|
|
self.closed_opts.remove(opts)
|
2008-01-07 04:27:34 +05:30
|
|
|
g = make_requested_gramplet(self, opts["name"], opts,
|
2007-12-28 11:53:50 +05:30
|
|
|
self.dbstate, self.uistate)
|
|
|
|
if g:
|
2008-01-07 04:27:34 +05:30
|
|
|
self.gramplet_map[opts["title"]] = g
|
2007-12-28 11:53:50 +05:30
|
|
|
self.frame_map[str(g.mainframe)] = g
|
|
|
|
else:
|
2008-01-07 04:27:34 +05:30
|
|
|
print "Can't make gramplet of type '%s'." % name
|
2007-12-28 11:53:50 +05:30
|
|
|
if g:
|
2008-01-07 04:27:34 +05:30
|
|
|
gramplet = g
|
|
|
|
gramplet.state = "maximized"
|
|
|
|
if gramplet.column >= 0 and gramplet.column < len(self.columns):
|
|
|
|
pos = gramplet.column
|
2007-12-28 11:53:50 +05:30
|
|
|
else:
|
|
|
|
pos = 0
|
2008-01-07 04:27:34 +05:30
|
|
|
self.columns[pos].pack_start(gramplet.mainframe, expand=gramplet.expand)
|
|
|
|
# set height on gramplet.scrolledwindow here:
|
|
|
|
gramplet.scrolledwindow.set_size_request(-1, gramplet.height)
|
2007-12-28 11:53:50 +05:30
|
|
|
## now drop it in right place
|
|
|
|
if self._popup_xy != None:
|
2008-01-07 04:27:34 +05:30
|
|
|
self.drop_widget(self.widget, gramplet,
|
2007-12-28 11:53:50 +05:30
|
|
|
self._popup_xy[0], self._popup_xy[1], 0)
|
|
|
|
else:
|
2008-01-07 04:27:34 +05:30
|
|
|
self.drop_widget(self.widget, gramplet, 0, 0, 0)
|
2007-12-28 11:53:50 +05:30
|
|
|
|
2008-01-07 04:27:34 +05:30
|
|
|
def add_gramplet(self, obj):
|
2007-12-31 19:20:39 +05:30
|
|
|
tname = obj.get_child().get_label()
|
2008-01-07 04:27:34 +05:30
|
|
|
all_opts = get_gramplet_options_by_tname(tname)
|
2007-12-31 19:20:39 +05:30
|
|
|
name = all_opts["name"]
|
2007-12-30 23:13:19 +05:30
|
|
|
if all_opts == None:
|
2008-01-07 04:27:34 +05:30
|
|
|
print "Unknown gramplet type: '%s'; bad gramplets.ini file?" % name
|
2007-12-30 23:13:19 +05:30
|
|
|
return
|
2007-12-26 13:56:33 +05:30
|
|
|
if "title" not in all_opts:
|
2008-01-07 04:27:34 +05:30
|
|
|
all_opts["title"] = "Untitled Gramplet"
|
2007-12-26 13:56:33 +05:30
|
|
|
# uniqify titles:
|
|
|
|
unique = all_opts["title"]
|
|
|
|
cnt = 1
|
2008-01-07 04:27:34 +05:30
|
|
|
while unique in self.gramplet_map:
|
2007-12-26 13:56:33 +05:30
|
|
|
unique = all_opts["title"] + ("-%d" % cnt)
|
|
|
|
cnt += 1
|
|
|
|
all_opts["title"] = unique
|
2008-01-07 04:27:34 +05:30
|
|
|
if all_opts["title"] not in self.gramplet_map:
|
|
|
|
g = make_requested_gramplet(self, name, all_opts,
|
2007-12-28 11:55:46 +05:30
|
|
|
self.dbstate, self.uistate)
|
2007-12-26 13:56:33 +05:30
|
|
|
if g:
|
2008-01-07 04:27:34 +05:30
|
|
|
self.gramplet_map[all_opts["title"]] = g
|
2007-12-28 11:53:50 +05:30
|
|
|
self.frame_map[str(g.mainframe)] = g
|
2008-01-07 04:27:34 +05:30
|
|
|
gramplet = g
|
|
|
|
if gramplet.column >= 0 and gramplet.column < len(self.columns):
|
|
|
|
pos = gramplet.column
|
2007-12-26 13:56:33 +05:30
|
|
|
else:
|
|
|
|
pos = 0
|
2008-01-07 04:27:34 +05:30
|
|
|
self.columns[pos].pack_start(gramplet.mainframe, expand=gramplet.expand)
|
|
|
|
# set height on gramplet.scrolledwindow here:
|
|
|
|
gramplet.scrolledwindow.set_size_request(-1, gramplet.height)
|
2007-12-28 11:53:50 +05:30
|
|
|
## now drop it in right place
|
|
|
|
if self._popup_xy != None:
|
2008-01-07 04:27:34 +05:30
|
|
|
self.drop_widget(self.widget, gramplet,
|
2007-12-28 11:53:50 +05:30
|
|
|
self._popup_xy[0], self._popup_xy[1], 0)
|
|
|
|
else:
|
2008-01-07 04:27:34 +05:30
|
|
|
self.drop_widget(self.widget, gramplet, 0, 0, 0)
|
2007-12-28 11:53:50 +05:30
|
|
|
else:
|
2008-01-07 04:27:34 +05:30
|
|
|
print "Can't make gramplet of type '%s'." % name
|
2007-12-24 20:26:15 +05:30
|
|
|
|
|
|
|
def get_stock(self):
|
|
|
|
"""
|
2008-02-24 19:25:55 +05:30
|
|
|
Return image associated with the view, which is used for the
|
2007-12-24 20:26:15 +05:30
|
|
|
icon for the button.
|
|
|
|
"""
|
2008-01-08 03:14:41 +05:30
|
|
|
return 'gramps-gramplet'
|
2007-12-24 20:26:15 +05:30
|
|
|
|
|
|
|
def build_tree(self):
|
|
|
|
return
|
|
|
|
|
2007-12-26 13:56:33 +05:30
|
|
|
def ui_definition(self):
|
|
|
|
return """
|
|
|
|
<ui>
|
2007-12-27 04:44:13 +05:30
|
|
|
<menubar name="MenuBar">
|
2008-03-07 17:35:34 +05:30
|
|
|
<menu action="GoMenu">
|
|
|
|
<placeholder name="CommonGo">
|
|
|
|
<menuitem action="Back"/>
|
|
|
|
<menuitem action="Forward"/>
|
|
|
|
<separator/>
|
|
|
|
<menuitem action="HomePerson"/>
|
|
|
|
<separator/>
|
|
|
|
</placeholder>
|
|
|
|
</menu>
|
2007-12-27 04:44:13 +05:30
|
|
|
<menu action="ViewMenu">
|
|
|
|
<menuitem action="Columns1"/>
|
|
|
|
<menuitem action="Columns2"/>
|
|
|
|
<menuitem action="Columns3"/>
|
|
|
|
</menu>
|
|
|
|
</menubar>
|
2008-03-07 17:35:34 +05:30
|
|
|
<toolbar name="ToolBar">
|
|
|
|
<placeholder name="CommonNavigation">
|
|
|
|
<toolitem action="Back"/>
|
|
|
|
<toolitem action="Forward"/>
|
|
|
|
<toolitem action="HomePerson"/>
|
|
|
|
</placeholder>
|
|
|
|
</toolbar>
|
2007-12-26 13:56:33 +05:30
|
|
|
<popup name="Popup">
|
2008-01-07 04:27:34 +05:30
|
|
|
<menuitem action="AddGramplet"/>
|
|
|
|
<menuitem action="RestoreGramplet"/>
|
2007-12-26 13:56:33 +05:30
|
|
|
<separator/>
|
|
|
|
<menuitem action="Columns1"/>
|
|
|
|
<menuitem action="Columns2"/>
|
|
|
|
<menuitem action="Columns3"/>
|
|
|
|
</popup>
|
|
|
|
</ui>
|
|
|
|
"""
|
|
|
|
|
|
|
|
def _button_press(self, obj, event):
|
2007-12-28 11:53:50 +05:30
|
|
|
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 3:
|
2007-12-26 13:56:33 +05:30
|
|
|
self._popup_xy = (event.x, event.y)
|
|
|
|
menu = self.uistate.uimanager.get_widget('/Popup')
|
2008-01-07 04:27:34 +05:30
|
|
|
ag_menu = self.uistate.uimanager.get_widget('/Popup/AddGramplet')
|
2007-12-27 04:44:13 +05:30
|
|
|
if ag_menu:
|
|
|
|
qr_menu = ag_menu.get_submenu()
|
|
|
|
if qr_menu == None:
|
|
|
|
qr_menu = gtk.Menu()
|
2008-01-07 04:27:34 +05:30
|
|
|
names = [AVAILABLE_GRAMPLETS[key]["tname"] for key
|
|
|
|
in AVAILABLE_GRAMPLETS.keys()]
|
2007-12-27 04:44:13 +05:30
|
|
|
names.sort()
|
|
|
|
for name in names:
|
|
|
|
Utils.add_menuitem(qr_menu, name,
|
2008-01-07 04:27:34 +05:30
|
|
|
None, self.add_gramplet)
|
|
|
|
self.uistate.uimanager.get_widget('/Popup/AddGramplet').set_submenu(qr_menu)
|
|
|
|
rg_menu = self.uistate.uimanager.get_widget('/Popup/RestoreGramplet')
|
2007-12-28 11:53:50 +05:30
|
|
|
if rg_menu:
|
|
|
|
qr_menu = rg_menu.get_submenu()
|
|
|
|
if qr_menu != None:
|
|
|
|
rg_menu.remove_submenu()
|
|
|
|
names = []
|
2008-01-07 04:27:34 +05:30
|
|
|
for gramplet in self.closed_gramplets:
|
|
|
|
names.append(gramplet.title)
|
2007-12-28 11:53:50 +05:30
|
|
|
for opts in self.closed_opts:
|
|
|
|
names.append(opts["title"])
|
|
|
|
names.sort()
|
|
|
|
if len(names) > 0:
|
|
|
|
qr_menu = gtk.Menu()
|
|
|
|
for name in names:
|
|
|
|
Utils.add_menuitem(qr_menu, name,
|
2008-01-07 04:27:34 +05:30
|
|
|
None, self.restore_gramplet)
|
|
|
|
self.uistate.uimanager.get_widget('/Popup/RestoreGramplet').set_submenu(qr_menu)
|
2007-12-26 13:56:33 +05:30
|
|
|
if menu:
|
|
|
|
menu.popup(None, None, None, event.button, event.time)
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2007-12-26 22:18:51 +05:30
|
|
|
def on_delete(self):
|
2008-01-07 04:27:34 +05:30
|
|
|
gramplets = [g for g in self.gramplet_map.values() if g != None]
|
|
|
|
for gramplet in gramplets:
|
2007-12-26 22:18:51 +05:30
|
|
|
# this is the only place where the gui runs user code directly
|
2008-01-07 04:27:34 +05:30
|
|
|
if gramplet.pui:
|
|
|
|
gramplet.pui.on_save()
|
2007-12-26 22:18:51 +05:30
|
|
|
self.save()
|