2006-01-14 04:04:14 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2006-05-19 04:32:47 +05:30
|
|
|
# Copyright (C) 2000-2006 Donald N. Allingham
|
2006-01-14 04:04:14 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
|
|
|
# $Id$
|
|
|
|
|
|
|
|
import cgi
|
2006-03-06 00:36:40 +05:30
|
|
|
import os
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2006-01-14 04:04:14 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import gobject
|
|
|
|
import gtk
|
2006-06-30 19:28:19 +05:30
|
|
|
import pango
|
2006-01-14 04:04:14 +05:30
|
|
|
|
2006-02-21 10:43:15 +05:30
|
|
|
import AutoComp
|
2006-02-22 05:42:52 +05:30
|
|
|
import DateHandler
|
|
|
|
import DateEdit
|
2006-03-06 00:36:40 +05:30
|
|
|
import const
|
2006-05-19 04:32:47 +05:30
|
|
|
import Errors
|
2006-03-06 00:36:40 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
_lock_path = os.path.join(const.image_dir, 'stock_lock.png')
|
|
|
|
_lock_open_path = os.path.join(const.image_dir, 'stock_lock-open.png')
|
2006-02-21 10:43:15 +05:30
|
|
|
|
2006-07-04 23:28:14 +05:30
|
|
|
hand_cursor = gtk.gdk.Cursor(gtk.gdk.HAND2)
|
2006-05-17 23:42:16 +05:30
|
|
|
def realize_cb(widget):
|
|
|
|
widget.window.set_cursor(hand_cursor)
|
|
|
|
|
2006-01-14 04:04:14 +05:30
|
|
|
class LinkLabel(gtk.EventBox):
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, label, func, handle):
|
2006-01-14 04:04:14 +05:30
|
|
|
gtk.EventBox.__init__(self)
|
|
|
|
self.orig_text = cgi.escape(label[0])
|
|
|
|
self.gender = label[1]
|
|
|
|
text = '<span underline="single">%s</span>' % self.orig_text
|
|
|
|
|
|
|
|
self.label = gtk.Label(text)
|
|
|
|
self.label.set_use_markup(True)
|
2006-04-06 03:00:27 +05:30
|
|
|
self.label.set_alignment(0, 0.5)
|
2006-01-14 04:04:14 +05:30
|
|
|
|
2006-06-30 19:28:19 +05:30
|
|
|
hbox = gtk.HBox()
|
2006-07-22 09:42:09 +05:30
|
|
|
hbox.pack_start(self.label, False, False, 0)
|
2006-06-30 19:28:19 +05:30
|
|
|
if label[1]:
|
2006-07-21 09:07:12 +05:30
|
|
|
hbox.pack_start(GenderLabel(label[1]), False, False, 4)
|
2006-06-30 19:28:19 +05:30
|
|
|
self.add(hbox)
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
self.connect('button-press-event', func, handle)
|
|
|
|
self.connect('enter-notify-event', self.enter_text, handle)
|
|
|
|
self.connect('leave-notify-event', self.leave_text, handle)
|
2006-05-17 23:42:16 +05:30
|
|
|
self.connect('realize', realize_cb)
|
2006-05-24 02:37:26 +05:30
|
|
|
|
|
|
|
def set_padding(self, x, y):
|
|
|
|
self.label.set_padding(x, y)
|
2006-01-14 04:04:14 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def enter_text(self, obj, event, handle):
|
2006-01-14 04:04:14 +05:30
|
|
|
text = '<span foreground="blue" underline="single">%s</span>' % self.orig_text
|
|
|
|
self.label.set_text(text)
|
|
|
|
self.label.set_use_markup(True)
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def leave_text(self, obj, event, handle):
|
2006-01-14 04:04:14 +05:30
|
|
|
text = '<span underline="single">%s</span>' % self.orig_text
|
|
|
|
self.label.set_text(text)
|
|
|
|
self.label.set_use_markup(True)
|
|
|
|
|
2006-05-03 08:03:29 +05:30
|
|
|
class IconButton(gtk.Button):
|
2006-01-14 04:04:14 +05:30
|
|
|
|
2006-04-29 04:12:07 +05:30
|
|
|
def __init__(self, func, handle, icon=gtk.STOCK_EDIT,
|
|
|
|
size=gtk.ICON_SIZE_MENU):
|
2006-05-03 08:03:29 +05:30
|
|
|
gtk.Button.__init__(self)
|
2006-01-14 04:04:14 +05:30
|
|
|
image = gtk.Image()
|
2006-04-06 03:00:27 +05:30
|
|
|
image.set_from_stock(icon, size)
|
2006-01-14 04:04:14 +05:30
|
|
|
image.show()
|
|
|
|
self.add(image)
|
2006-05-03 08:03:29 +05:30
|
|
|
self.set_relief(gtk.RELIEF_NONE)
|
2006-01-14 04:04:14 +05:30
|
|
|
self.show()
|
2006-01-24 03:18:34 +05:30
|
|
|
|
|
|
|
if func:
|
2006-04-06 03:00:27 +05:30
|
|
|
self.connect('button-press-event', func, handle)
|
2006-01-24 03:18:34 +05:30
|
|
|
|
2006-05-03 08:33:41 +05:30
|
|
|
class WarnButton(gtk.Button):
|
2006-01-24 03:18:34 +05:30
|
|
|
def __init__(self):
|
2006-05-03 08:33:41 +05:30
|
|
|
gtk.Button.__init__(self)
|
2006-01-24 03:18:34 +05:30
|
|
|
image = gtk.Image()
|
2006-03-11 02:35:00 +05:30
|
|
|
|
|
|
|
# Some versions of FreeBSD don't seem to have STOCK_INFO
|
|
|
|
try:
|
2006-04-06 03:00:27 +05:30
|
|
|
image.set_from_stock(gtk.STOCK_INFO, gtk.ICON_SIZE_MENU)
|
2006-03-11 02:35:00 +05:30
|
|
|
except:
|
2006-04-06 03:00:27 +05:30
|
|
|
image.set_from_stock(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_MENU)
|
2006-03-11 02:35:00 +05:30
|
|
|
|
2006-01-24 03:18:34 +05:30
|
|
|
image.show()
|
|
|
|
self.add(image)
|
2006-05-03 08:33:41 +05:30
|
|
|
self.set_relief(gtk.RELIEF_NONE)
|
2006-01-24 03:18:34 +05:30
|
|
|
self.show()
|
|
|
|
self.func = None
|
|
|
|
self.hide()
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def on_clicked(self, func):
|
|
|
|
self.connect('button-press-event', self._button_press)
|
2006-01-24 03:18:34 +05:30
|
|
|
self.func = func
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def _button_press(self, obj, event):
|
2006-01-24 03:18:34 +05:30
|
|
|
if event.type == gtk.gdk.BUTTON_PRESS and event.button == 1:
|
|
|
|
self.func(obj)
|
2006-01-15 06:56:47 +05:30
|
|
|
|
|
|
|
class SimpleButton(gtk.Button):
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, image, func):
|
2006-01-15 06:56:47 +05:30
|
|
|
gtk.Button.__init__(self)
|
|
|
|
self.set_relief(gtk.RELIEF_NONE)
|
2006-04-06 03:00:27 +05:30
|
|
|
self.add(gtk.image_new_from_stock(image, gtk.ICON_SIZE_BUTTON))
|
|
|
|
self.connect('clicked', func)
|
2006-01-15 06:56:47 +05:30
|
|
|
self.show()
|
2006-01-14 04:04:14 +05:30
|
|
|
|
|
|
|
class LinkBox(gtk.HBox):
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, link, button):
|
2006-01-14 04:04:14 +05:30
|
|
|
gtk.HBox.__init__(self)
|
|
|
|
self.set_spacing(6)
|
2006-04-06 03:00:27 +05:30
|
|
|
self.pack_start(link, False)
|
|
|
|
self.pack_start(button, False)
|
2006-01-14 04:04:14 +05:30
|
|
|
self.show()
|
|
|
|
|
2006-01-19 07:36:27 +05:30
|
|
|
class EditLabel(gtk.HBox):
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, text):
|
2006-01-19 07:36:27 +05:30
|
|
|
gtk.HBox.__init__(self)
|
2006-01-19 09:55:36 +05:30
|
|
|
label = BasicLabel(text)
|
2006-04-06 03:00:27 +05:30
|
|
|
self.pack_start(label, False)
|
|
|
|
self.pack_start(gtk.image_new_from_stock(gtk.STOCK_EDIT,
|
|
|
|
gtk.ICON_SIZE_MENU), False)
|
2006-01-19 07:36:27 +05:30
|
|
|
self.set_spacing(4)
|
|
|
|
self.show_all()
|
|
|
|
|
2006-01-14 04:04:14 +05:30
|
|
|
class BasicLabel(gtk.Label):
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, text):
|
|
|
|
gtk.Label.__init__(self, text)
|
|
|
|
self.set_alignment(0, 0.5)
|
2006-01-14 04:04:14 +05:30
|
|
|
self.show()
|
|
|
|
|
2006-06-30 19:28:19 +05:30
|
|
|
class GenderLabel(gtk.Label):
|
|
|
|
|
|
|
|
def __init__(self, text):
|
|
|
|
gtk.Label.__init__(self, text)
|
|
|
|
self.set_alignment(0, 0.5)
|
|
|
|
if os.sys.platform == "win32":
|
|
|
|
pangoFont = pango.FontDescription('Arial')
|
|
|
|
self.modify_font(pangoFont)
|
|
|
|
self.show()
|
|
|
|
|
2006-01-14 04:04:14 +05:30
|
|
|
class MarkupLabel(gtk.Label):
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, text):
|
|
|
|
gtk.Label.__init__(self, text)
|
|
|
|
self.set_alignment(0, 0.5)
|
2006-01-14 04:04:14 +05:30
|
|
|
self.set_use_markup(True)
|
2006-06-30 19:46:09 +05:30
|
|
|
self.show_all()
|
|
|
|
|
|
|
|
class DualMarkupLabel(gtk.HBox):
|
|
|
|
|
|
|
|
def __init__(self, text, alt):
|
|
|
|
gtk.HBox.__init__(self)
|
|
|
|
label = gtk.Label(text)
|
|
|
|
label.set_alignment(0, 0.5)
|
|
|
|
label.set_use_markup(True)
|
|
|
|
|
2006-07-21 09:07:12 +05:30
|
|
|
self.pack_start(label, False, False, 0)
|
2006-06-30 19:46:09 +05:30
|
|
|
b = GenderLabel(alt)
|
|
|
|
b.set_use_markup(True)
|
2006-07-21 09:07:12 +05:30
|
|
|
self.pack_start(b, False, False, 4)
|
2006-01-14 04:04:14 +05:30
|
|
|
self.show()
|
|
|
|
|
2006-01-17 20:37:01 +05:30
|
|
|
class IntEdit(gtk.Entry):
|
|
|
|
"""An gtk.Edit widget that only allows integers."""
|
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
gtk.Entry.__init__(self)
|
|
|
|
|
|
|
|
self._signal = self.connect("insert_text", self.insert_cb)
|
|
|
|
|
|
|
|
def insert_cb(self, widget, text, length, *args):
|
|
|
|
# if you don't do this, garbage comes in with text
|
|
|
|
text = text[:length]
|
|
|
|
pos = widget.get_position()
|
|
|
|
# stop default emission
|
|
|
|
widget.emit_stop_by_name("insert_text")
|
|
|
|
gobject.idle_add(self.insert, widget, text, pos)
|
|
|
|
|
|
|
|
def insert(self, widget, text, pos):
|
|
|
|
if len(text) > 0 and text.isdigit():
|
|
|
|
# the next three lines set up the text. this is done because we
|
|
|
|
# can't use insert_text(): it always inserts at position zero.
|
|
|
|
orig_text = widget.get_text()
|
|
|
|
new_text = orig_text[:pos] + text + orig_text[pos:]
|
|
|
|
# avoid recursive calls triggered by set_text
|
|
|
|
widget.handler_block(self._signal)
|
|
|
|
# replace the text with some new text
|
|
|
|
widget.set_text(new_text)
|
|
|
|
widget.handler_unblock(self._signal)
|
|
|
|
# set the correct position in the widget
|
|
|
|
widget.set_position(pos + len(text))
|
2006-01-19 07:36:27 +05:30
|
|
|
|
|
|
|
class TypeCellRenderer(gtk.CellRendererCombo):
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, values):
|
2006-01-19 07:36:27 +05:30
|
|
|
gtk.CellRendererCombo.__init__(self)
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
model = gtk.ListStore(str, int)
|
2006-01-19 07:36:27 +05:30
|
|
|
for key in values:
|
2006-04-06 03:00:27 +05:30
|
|
|
model.append(row=[values[key], key])
|
|
|
|
self.set_property('editable', True)
|
|
|
|
self.set_property('model', model)
|
|
|
|
self.set_property('text-column', 0)
|
2006-01-19 07:36:27 +05:30
|
|
|
|
2006-02-08 10:38:28 +05:30
|
|
|
class PrivacyButton:
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, button, obj, readonly=False):
|
2006-02-08 10:38:28 +05:30
|
|
|
self.button = button
|
2006-04-06 03:00:27 +05:30
|
|
|
self.button.connect('toggled', self._on_toggle)
|
2006-02-08 10:38:28 +05:30
|
|
|
self.tooltips = gtk.Tooltips()
|
|
|
|
self.obj = obj
|
|
|
|
self.set_active(obj.get_privacy())
|
2006-02-22 05:42:52 +05:30
|
|
|
self.button.set_sensitive(not readonly)
|
2006-02-08 10:38:28 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_sensitive(self, val):
|
2006-02-08 10:38:28 +05:30
|
|
|
self.button.set_sensitive(val)
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def set_active(self, val):
|
2006-02-08 10:38:28 +05:30
|
|
|
self.button.set_active(val)
|
|
|
|
self._on_toggle(self.button)
|
|
|
|
|
|
|
|
def get_active(self):
|
|
|
|
return self.button.get_active()
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def _on_toggle(self, obj):
|
2006-02-08 10:38:28 +05:30
|
|
|
child = obj.child
|
|
|
|
if child:
|
|
|
|
obj.remove(child)
|
|
|
|
image = gtk.Image()
|
|
|
|
if obj.get_active():
|
2006-04-06 03:00:27 +05:30
|
|
|
# image.set_from_icon_name('stock_lock', gtk.ICON_SIZE_MENU)
|
2006-03-06 00:36:40 +05:30
|
|
|
image.set_from_file(_lock_path)
|
2006-04-06 03:00:27 +05:30
|
|
|
self.tooltips.set_tip(obj, _('Record is private'))
|
2006-02-08 10:38:28 +05:30
|
|
|
self.obj.set_privacy(True)
|
|
|
|
else:
|
2006-04-06 03:00:27 +05:30
|
|
|
# image.set_from_icon_name('stock_lock-open', gtk.ICON_SIZE_MENU)
|
2006-03-06 00:36:40 +05:30
|
|
|
image.set_from_file(_lock_open_path)
|
2006-04-06 03:00:27 +05:30
|
|
|
self.tooltips.set_tip(obj, _('Record is public'))
|
2006-02-08 10:38:28 +05:30
|
|
|
self.obj.set_privacy(False)
|
|
|
|
image.show()
|
|
|
|
obj.add(image)
|
2006-02-22 05:42:52 +05:30
|
|
|
|
|
|
|
class MonitoredCheckbox:
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, obj, button, set_val, get_val, on_toggle=None):
|
2006-02-22 05:42:52 +05:30
|
|
|
self.button = button
|
2006-04-06 03:00:27 +05:30
|
|
|
self.button.connect('toggled', self._on_toggle)
|
2006-02-22 05:42:52 +05:30
|
|
|
self.on_toggle = on_toggle
|
|
|
|
self.obj = obj
|
|
|
|
self.set_val = set_val
|
|
|
|
self.get_val = get_val
|
2006-03-01 10:38:11 +05:30
|
|
|
self.obj.set_active(get_val())
|
2006-02-22 05:42:52 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def _on_toggle(self, obj):
|
2006-02-22 05:42:52 +05:30
|
|
|
self.set_val(obj.get_active())
|
|
|
|
if self.on_toggle:
|
2006-03-01 10:38:11 +05:30
|
|
|
self.on_toggle(self.get_val())
|
2006-02-08 10:38:28 +05:30
|
|
|
|
|
|
|
class MonitoredEntry:
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, obj, set_val, get_val, read_only=False,
|
2006-03-30 21:59:59 +05:30
|
|
|
autolist=None, changed=None):
|
2006-02-08 10:38:28 +05:30
|
|
|
self.obj = obj
|
|
|
|
self.set_val = set_val
|
|
|
|
self.get_val = get_val
|
2006-02-22 05:42:52 +05:30
|
|
|
self.changed = changed
|
2006-02-08 10:38:28 +05:30
|
|
|
|
2006-02-10 09:07:20 +05:30
|
|
|
if get_val():
|
|
|
|
self.obj.set_text(get_val())
|
2006-02-22 05:42:52 +05:30
|
|
|
self.obj.connect('changed', self._on_change)
|
2006-02-08 10:38:28 +05:30
|
|
|
self.obj.set_editable(not read_only)
|
2006-02-21 10:43:15 +05:30
|
|
|
|
2006-03-30 21:59:59 +05:30
|
|
|
if autolist:
|
|
|
|
AutoComp.fill_entry(obj,autolist)
|
|
|
|
|
2006-08-26 09:59:20 +05:30
|
|
|
def reinit(self, set_val, get_val):
|
|
|
|
self.set_val = set_val
|
|
|
|
self.get_val = get_val
|
|
|
|
self.update()
|
|
|
|
|
2006-05-22 08:21:20 +05:30
|
|
|
def set_text(self, text):
|
|
|
|
self.obj.set_text(text)
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def connect(self, signal, callback):
|
|
|
|
self.obj.connect(signal, callback)
|
2006-03-01 10:38:11 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def _on_change(self, obj):
|
2006-02-22 05:42:52 +05:30
|
|
|
self.set_val(unicode(obj.get_text()))
|
|
|
|
if self.changed:
|
|
|
|
self.changed(obj)
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def force_value(self, value):
|
2006-02-22 05:42:52 +05:30
|
|
|
self.obj.set_text(value)
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def get_value(self, value):
|
2006-03-01 10:38:11 +05:30
|
|
|
return unicode(self.obj.get_text())
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def enable(self, value):
|
2006-02-22 05:42:52 +05:30
|
|
|
self.obj.set_sensitive(value)
|
|
|
|
self.obj.set_editable(value)
|
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
def grab_focus(self):
|
|
|
|
self.obj.grab_focus()
|
|
|
|
|
|
|
|
def update(self):
|
|
|
|
if self.get_val():
|
|
|
|
self.obj.set_text(self.get_val())
|
|
|
|
|
2006-02-21 10:43:15 +05:30
|
|
|
class MonitoredText:
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, obj, set_val, get_val, read_only=False):
|
2006-02-21 10:43:15 +05:30
|
|
|
self.buf = obj.get_buffer()
|
|
|
|
self.set_val = set_val
|
|
|
|
self.get_val = get_val
|
|
|
|
|
|
|
|
if get_val():
|
|
|
|
self.buf.set_text(get_val())
|
|
|
|
self.buf.connect('changed', self.on_change)
|
|
|
|
obj.set_editable(not read_only)
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def on_change(self, obj):
|
|
|
|
s, e = self.buf.get_bounds()
|
|
|
|
self.set_val(unicode(self.buf.get_text(s, e, False)))
|
2006-02-21 10:43:15 +05:30
|
|
|
|
|
|
|
class MonitoredType:
|
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, obj, set_val, get_val, mapping, custom, readonly=False,
|
2006-04-01 05:16:34 +05:30
|
|
|
custom_values=None):
|
2006-02-21 10:43:15 +05:30
|
|
|
self.set_val = set_val
|
|
|
|
self.get_val = get_val
|
|
|
|
|
|
|
|
self.obj = obj
|
|
|
|
|
|
|
|
val = get_val()
|
|
|
|
if val:
|
|
|
|
default = val[0]
|
|
|
|
else:
|
|
|
|
default = None
|
2006-04-01 05:16:34 +05:30
|
|
|
|
2006-02-21 10:43:15 +05:30
|
|
|
self.sel = AutoComp.StandardCustomSelector(
|
2006-04-01 05:16:34 +05:30
|
|
|
mapping, obj, custom, default, additional=custom_values)
|
2006-02-21 10:43:15 +05:30
|
|
|
|
2006-04-01 01:47:23 +05:30
|
|
|
self.set_val(self.sel.get_values())
|
2006-02-26 09:59:39 +05:30
|
|
|
self.obj.set_sensitive(not readonly)
|
2006-02-21 10:43:15 +05:30
|
|
|
self.obj.connect('changed', self.on_change)
|
|
|
|
|
2006-08-26 09:59:20 +05:30
|
|
|
def reinit(self, set_val, get_val):
|
|
|
|
self.set_val = set_val
|
|
|
|
self.get_val = get_val
|
|
|
|
self.update()
|
|
|
|
|
2006-03-01 10:38:11 +05:30
|
|
|
def update(self):
|
|
|
|
if self.get_val():
|
|
|
|
self.sel.set_values(self.get_val())
|
|
|
|
|
2006-02-21 10:43:15 +05:30
|
|
|
def on_change(self, obj):
|
|
|
|
self.set_val(self.sel.get_values())
|
|
|
|
|
2006-04-14 10:06:25 +05:30
|
|
|
class MonitoredDataType:
|
|
|
|
|
2006-04-19 09:27:10 +05:30
|
|
|
def __init__(self, obj, set_val, get_val, readonly=False,
|
|
|
|
custom_values=None):
|
2006-04-14 10:06:25 +05:30
|
|
|
|
|
|
|
self.set_val = set_val
|
|
|
|
self.get_val = get_val
|
|
|
|
|
|
|
|
self.obj = obj
|
|
|
|
|
|
|
|
val = get_val()
|
2006-04-20 08:40:23 +05:30
|
|
|
|
2006-04-14 10:06:25 +05:30
|
|
|
if val:
|
|
|
|
default = int(val)
|
|
|
|
else:
|
|
|
|
default = None
|
|
|
|
|
|
|
|
self.sel = AutoComp.StandardCustomSelector(
|
|
|
|
get_val().get_map(),
|
|
|
|
obj,
|
|
|
|
get_val().get_custom(),
|
|
|
|
default,
|
|
|
|
additional=custom_values)
|
|
|
|
|
2006-05-12 22:00:38 +05:30
|
|
|
self.sel.set_values((int(get_val()),str(get_val())))
|
2006-04-14 10:06:25 +05:30
|
|
|
self.obj.set_sensitive(not readonly)
|
|
|
|
self.obj.connect('changed', self.on_change)
|
|
|
|
|
2006-08-26 09:59:20 +05:30
|
|
|
def reinit(self, set_val, get_val):
|
|
|
|
self.set_val = set_val
|
|
|
|
self.get_val = get_val
|
|
|
|
self.update()
|
|
|
|
|
2006-04-19 00:40:13 +05:30
|
|
|
def fix_value(self, value):
|
|
|
|
if value[0] == self.get_val().get_custom():
|
2006-04-19 09:27:10 +05:30
|
|
|
return value
|
2006-04-19 00:40:13 +05:30
|
|
|
else:
|
2006-04-19 09:27:10 +05:30
|
|
|
return (value[0],'')
|
2006-04-19 00:40:13 +05:30
|
|
|
|
2006-04-14 10:06:25 +05:30
|
|
|
def update(self):
|
2006-05-01 04:56:38 +05:30
|
|
|
val = self.get_val()
|
|
|
|
if type(val) == tuple :
|
|
|
|
self.sel.set_values(val)
|
|
|
|
else:
|
|
|
|
self.sel.set_values((int(val),str(val)))
|
2006-04-14 10:06:25 +05:30
|
|
|
|
|
|
|
def on_change(self, obj):
|
2006-04-20 04:29:33 +05:30
|
|
|
value = self.fix_value(self.sel.get_values())
|
|
|
|
self.set_val(value)
|
2006-04-14 10:06:25 +05:30
|
|
|
|
2006-02-21 10:43:15 +05:30
|
|
|
class MonitoredMenu:
|
|
|
|
|
2006-04-07 02:58:19 +05:30
|
|
|
def __init__(self, obj, set_val, get_val, mapping,
|
|
|
|
readonly=False, changed=None):
|
2006-02-21 10:43:15 +05:30
|
|
|
self.set_val = set_val
|
|
|
|
self.get_val = get_val
|
|
|
|
|
2006-04-05 09:46:16 +05:30
|
|
|
self.changed = changed
|
2006-02-21 10:43:15 +05:30
|
|
|
self.obj = obj
|
2006-04-05 09:46:16 +05:30
|
|
|
|
2006-04-07 02:58:19 +05:30
|
|
|
self.change_menu(mapping)
|
2006-04-06 03:00:27 +05:30
|
|
|
self.obj.connect('changed', self.on_change)
|
2006-02-22 05:42:52 +05:30
|
|
|
self.obj.set_sensitive(not readonly)
|
2006-02-21 10:43:15 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def force(self, value):
|
2006-03-01 10:38:11 +05:30
|
|
|
self.obj.set_active(value)
|
|
|
|
|
2006-04-05 09:46:16 +05:30
|
|
|
def change_menu(self, mapping):
|
2006-04-07 02:58:19 +05:30
|
|
|
self.data = {}
|
2006-04-06 03:00:27 +05:30
|
|
|
self.model = gtk.ListStore(str, int)
|
2006-04-07 02:58:19 +05:30
|
|
|
index = 0
|
2006-04-06 03:00:27 +05:30
|
|
|
for t, v in mapping:
|
|
|
|
self.model.append(row=[t, v])
|
2006-04-07 02:58:19 +05:30
|
|
|
self.data[v] = index
|
|
|
|
index += 1
|
2006-04-05 09:46:16 +05:30
|
|
|
self.obj.set_model(self.model)
|
2006-04-07 02:58:19 +05:30
|
|
|
self.obj.set_active(self.data.get(self.get_val(),0))
|
2006-04-05 09:46:16 +05:30
|
|
|
|
2006-02-21 10:43:15 +05:30
|
|
|
def on_change(self, obj):
|
2006-04-06 03:00:27 +05:30
|
|
|
self.set_val(self.model.get_value(obj.get_active_iter(), 1))
|
2006-04-05 09:46:16 +05:30
|
|
|
if self.changed:
|
|
|
|
self.changed()
|
2006-04-04 23:37:23 +05:30
|
|
|
|
2006-04-05 04:12:38 +05:30
|
|
|
class MonitoredStrMenu:
|
2006-04-04 23:37:23 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
def __init__(self, obj, set_val, get_val, mapping, readonly=False):
|
2006-04-05 04:12:38 +05:30
|
|
|
self.set_val = set_val
|
|
|
|
self.get_val = get_val
|
|
|
|
|
|
|
|
self.obj = obj
|
2006-04-05 04:50:47 +05:30
|
|
|
self.model = gtk.ListStore(str)
|
|
|
|
|
|
|
|
if len(mapping) > 20:
|
|
|
|
self.obj.set_wrap_width(3)
|
|
|
|
|
|
|
|
self.model.append(row=[''])
|
2006-04-05 04:12:38 +05:30
|
|
|
index = 0
|
|
|
|
self.data = ['']
|
|
|
|
|
|
|
|
default = get_val()
|
|
|
|
active = 0
|
2006-02-21 10:43:15 +05:30
|
|
|
|
2006-04-06 03:00:27 +05:30
|
|
|
for t, v in mapping:
|
2006-04-05 04:50:47 +05:30
|
|
|
self.model.append(row=[v])
|
|
|
|
self.data.append(t)
|
2006-04-05 04:12:38 +05:30
|
|
|
index += 1
|
2006-04-06 03:00:27 +05:30
|
|
|
if t == default:
|
|
|
|
active = index
|
2006-04-05 04:12:38 +05:30
|
|
|
|
|
|
|
self.obj.set_model(self.model)
|
2006-04-05 04:50:47 +05:30
|
|
|
self.obj.set_active(active)
|
2006-04-06 03:00:27 +05:30
|
|
|
self.obj.connect('changed', self.on_change)
|
2006-04-05 04:12:38 +05:30
|
|
|
self.obj.set_sensitive(not readonly)
|
|
|
|
|
|
|
|
def on_change(self, obj):
|
|
|
|
self.set_val(self.data[obj.get_active()])
|
|
|
|
|
2006-02-22 05:42:52 +05:30
|
|
|
class MonitoredDate:
|
|
|
|
|
2006-05-06 08:44:13 +05:30
|
|
|
def __init__(self, field, button, value, uistate, track, readonly=False):
|
2006-02-22 05:42:52 +05:30
|
|
|
self.date = value
|
|
|
|
self.date_check = DateEdit.DateEdit(
|
2006-05-06 08:44:13 +05:30
|
|
|
self.date, field, button, uistate, track)
|
2006-02-22 05:42:52 +05:30
|
|
|
field.set_editable(not readonly)
|
|
|
|
button.set_sensitive(not readonly)
|
|
|
|
|
|
|
|
field.set_text(DateHandler.displayer.display(self.date))
|
2006-02-23 08:43:15 +05:30
|
|
|
|
2006-02-24 10:35:46 +05:30
|
|
|
class PlaceEntry:
|
2006-05-18 01:02:19 +05:30
|
|
|
"""
|
|
|
|
handles the selection of a existing or new Place
|
|
|
|
"""
|
|
|
|
def __init__(self, dbstate, uistate, track, obj, set_val,
|
|
|
|
get_val, add_del, share):
|
2006-05-17 10:05:03 +05:30
|
|
|
|
2006-02-24 10:35:46 +05:30
|
|
|
self.obj = obj
|
2006-05-17 10:05:03 +05:30
|
|
|
self.add_del = add_del
|
|
|
|
self.share = share
|
2006-05-18 01:02:19 +05:30
|
|
|
self.dbstate = dbstate
|
|
|
|
self.db = dbstate.db
|
2006-05-17 10:05:03 +05:30
|
|
|
self.get_val = get_val
|
|
|
|
self.set_val = set_val
|
2006-05-18 01:02:19 +05:30
|
|
|
self.uistate = uistate
|
|
|
|
self.track = track
|
2006-02-24 10:35:46 +05:30
|
|
|
|
2006-05-17 10:05:03 +05:30
|
|
|
if get_val():
|
|
|
|
self.set_button(True)
|
|
|
|
p = self.db.get_place_from_handle(self.get_val())
|
|
|
|
name = "%s [%s]" % (p.get_title(),p.gramps_id)
|
2006-02-24 10:35:46 +05:30
|
|
|
else:
|
|
|
|
name = u""
|
2006-05-17 10:05:03 +05:30
|
|
|
self.set_button(False)
|
2006-02-24 10:35:46 +05:30
|
|
|
|
2006-05-18 01:02:19 +05:30
|
|
|
if self.db.readonly:
|
2006-05-17 10:05:03 +05:30
|
|
|
self.add_del.set_sensitive(False)
|
|
|
|
self.share.set_sensitive(False)
|
2006-02-24 10:35:46 +05:30
|
|
|
else:
|
2006-05-17 10:05:03 +05:30
|
|
|
self.add_del.set_sensitive(True)
|
|
|
|
self.share.set_sensitive(True)
|
2006-05-18 01:02:19 +05:30
|
|
|
|
|
|
|
self.add_del.connect('clicked', self.add_del_clicked)
|
|
|
|
self.share.connect('clicked', self.share_clicked)
|
2006-02-24 10:35:46 +05:30
|
|
|
|
|
|
|
obj.set_text(name)
|
|
|
|
|
2006-05-18 01:02:19 +05:30
|
|
|
def after_edit(self, place):
|
|
|
|
name = "%s [%s]" % (place.get_title(),place.gramps_id)
|
|
|
|
self.obj.set_text(name)
|
|
|
|
|
|
|
|
def add_del_clicked(self, obj):
|
|
|
|
if self.get_val():
|
|
|
|
self.set_val(None)
|
|
|
|
self.obj.set_text(u'')
|
|
|
|
self.set_button(False)
|
|
|
|
else:
|
|
|
|
from RelLib import Place
|
|
|
|
from Editors import EditPlace
|
|
|
|
|
|
|
|
place = Place()
|
2006-05-19 04:32:47 +05:30
|
|
|
try:
|
|
|
|
EditPlace(self.dbstate, self.uistate, self.track,
|
|
|
|
place, self.place_added)
|
|
|
|
except Errors.WindowActiveError:
|
|
|
|
pass
|
2006-05-18 01:02:19 +05:30
|
|
|
|
|
|
|
def place_added(self, data):
|
|
|
|
self.set_val(data.handle)
|
|
|
|
self.obj.set_text("%s [%s]" % (data.get_title(),data.gramps_id))
|
|
|
|
self.set_button(True)
|
|
|
|
|
|
|
|
def share_clicked(self, obj):
|
|
|
|
if self.get_val():
|
|
|
|
from Editors import EditPlace
|
|
|
|
|
|
|
|
place = self.db.get_place_from_handle(self.get_val())
|
2006-05-19 04:32:47 +05:30
|
|
|
try:
|
|
|
|
EditPlace(self.dbstate, self.uistate, self.track, place,
|
|
|
|
self.after_edit)
|
|
|
|
except Errors.WindowActiveError:
|
|
|
|
pass
|
2006-05-18 01:02:19 +05:30
|
|
|
else:
|
|
|
|
from Selectors import selector_factory
|
|
|
|
cls = selector_factory('Place')
|
|
|
|
select = cls(self.dbstate, self.uistate, self.track)
|
|
|
|
place = select.run()
|
|
|
|
if place:
|
|
|
|
self.place_added(place)
|
|
|
|
|
2006-05-17 10:05:03 +05:30
|
|
|
def set_button(self, use_add):
|
|
|
|
for i in self.add_del.get_children():
|
|
|
|
self.add_del.remove(i)
|
2006-05-18 01:02:19 +05:30
|
|
|
for i in self.share.get_children():
|
|
|
|
self.share.remove(i)
|
2006-05-17 10:05:03 +05:30
|
|
|
|
|
|
|
if use_add:
|
2006-05-18 01:02:19 +05:30
|
|
|
image = gtk.Image()
|
2006-05-17 10:05:03 +05:30
|
|
|
image.set_from_stock(gtk.STOCK_REMOVE,gtk.ICON_SIZE_BUTTON)
|
2006-05-18 01:02:19 +05:30
|
|
|
image.show()
|
|
|
|
self.add_del.add(image)
|
|
|
|
image = gtk.Image()
|
|
|
|
image.set_from_stock(gtk.STOCK_EDIT,gtk.ICON_SIZE_BUTTON)
|
|
|
|
image.show()
|
|
|
|
self.share.add(image)
|
2006-02-24 10:35:46 +05:30
|
|
|
else:
|
2006-05-18 01:02:19 +05:30
|
|
|
image = gtk.Image()
|
2006-05-17 10:05:03 +05:30
|
|
|
image.set_from_stock(gtk.STOCK_ADD,gtk.ICON_SIZE_BUTTON)
|
2006-05-18 01:02:19 +05:30
|
|
|
image.show()
|
|
|
|
self.add_del.add(image)
|
|
|
|
image = gtk.Image()
|
|
|
|
image.set_from_stock(gtk.STOCK_INDEX,gtk.ICON_SIZE_BUTTON)
|
|
|
|
image.show()
|
|
|
|
self.share.add(image)
|