2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-06-18 10:30:51 +05:30
|
|
|
# Copyright (C) 2000-2007 Donald N. Allingham
|
2002-10-20 19:55:16 +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.
|
|
|
|
#
|
2007-07-12 09:54:44 +05:30
|
|
|
# This program is distributed in the hope that it will be useful,
|
2002-10-20 19:55:16 +05:30
|
|
|
# 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
|
|
|
|
#
|
|
|
|
|
2003-12-02 09:57:23 +05:30
|
|
|
# $Id$
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-12-20 09:25:43 +05:30
|
|
|
import random
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2007-06-22 11:27:48 +05:30
|
|
|
from xml.sax.saxutils import escape
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/Gnome modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-11-14 11:01:42 +05:30
|
|
|
import gtk
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# gramps modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-03-03 05:40:52 +05:30
|
|
|
import Config
|
2004-09-17 09:00:04 +05:30
|
|
|
import DateHandler
|
2007-06-28 11:11:40 +05:30
|
|
|
from BasicUtils import name_displayer as _nd
|
2007-12-01 05:20:05 +05:30
|
|
|
import Utils
|
2007-10-08 22:11:39 +05:30
|
|
|
from gen.lib import Name
|
2006-04-26 07:14:03 +05:30
|
|
|
import ManagedWindow
|
|
|
|
from GrampsWidgets import *
|
2006-07-30 02:26:11 +05:30
|
|
|
import QuestionDialog
|
2007-06-22 11:27:48 +05:30
|
|
|
from Errors import NameDisplayError
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-07-15 08:24:04 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Constants
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
_surname_styles = [
|
2007-07-12 09:54:44 +05:30
|
|
|
_("Father's surname"),
|
|
|
|
_("None"),
|
|
|
|
_("Combination of mother's and father's surname"),
|
|
|
|
_("Icelandic style"),
|
2002-10-20 19:55:16 +05:30
|
|
|
]
|
2006-05-13 00:19:12 +05:30
|
|
|
|
2006-07-16 20:14:13 +05:30
|
|
|
# column numbers for the 'name format' model
|
|
|
|
COL_NUM = 0
|
|
|
|
COL_NAME = 1
|
|
|
|
COL_FMT = 2
|
|
|
|
COL_EXPL = 3
|
|
|
|
|
2004-07-20 07:57:55 +05:30
|
|
|
def set_calendar_date_format():
|
2004-09-25 10:42:15 +05:30
|
|
|
format_list = DateHandler.get_date_formats()
|
2006-03-03 05:40:52 +05:30
|
|
|
DateHandler.set_format(Config.get_date_format(format_list))
|
2004-07-20 07:57:55 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
def get_researcher():
|
2007-10-08 22:11:39 +05:30
|
|
|
import gen.lib
|
2006-04-26 07:14:03 +05:30
|
|
|
|
2006-04-25 02:34:01 +05:30
|
|
|
n = Config.get(Config.RESEARCHER_NAME)
|
|
|
|
a = Config.get(Config.RESEARCHER_ADDR)
|
|
|
|
c = Config.get(Config.RESEARCHER_CITY)
|
|
|
|
s = Config.get(Config.RESEARCHER_STATE)
|
|
|
|
ct = Config.get(Config.RESEARCHER_COUNTRY)
|
|
|
|
p = Config.get(Config.RESEARCHER_POSTAL)
|
|
|
|
ph = Config.get(Config.RESEARCHER_PHONE)
|
|
|
|
e = Config.get(Config.RESEARCHER_EMAIL)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-10-08 22:11:39 +05:30
|
|
|
owner = gen.lib.Researcher()
|
2007-10-09 00:30:28 +05:30
|
|
|
owner.set_name(n)
|
|
|
|
owner.set_address(a)
|
|
|
|
owner.set_city(c)
|
2007-10-09 02:56:20 +05:30
|
|
|
owner.set_state(s)
|
2007-10-09 00:30:28 +05:30
|
|
|
owner.set_country(ct)
|
2007-10-09 01:47:52 +05:30
|
|
|
owner.set_postal_code(p)
|
2007-10-09 00:30:28 +05:30
|
|
|
owner.set_phone(ph)
|
|
|
|
owner.set_email(e)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
return owner
|
2006-04-26 07:14:03 +05:30
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2007-12-10 07:21:39 +05:30
|
|
|
class DisplayNameEditor(ManagedWindow.ManagedWindow):
|
|
|
|
def __init__(self, uistate, dbstate, track, dialog):
|
2007-12-13 07:52:06 +05:30
|
|
|
# Assumes that there are two methods: dialog.name_changed_check(),
|
|
|
|
# and dialog._build_custom_name_ui()
|
2007-12-10 07:21:39 +05:30
|
|
|
ManagedWindow.ManagedWindow.__init__(self, uistate, [], DisplayNameEditor)
|
|
|
|
self.dialog = dialog
|
|
|
|
self.dbstate = dbstate
|
|
|
|
self.set_window(
|
|
|
|
gtk.Dialog(_('Display Name Editor'),
|
|
|
|
flags=gtk.DIALOG_NO_SEPARATOR,
|
|
|
|
buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)),
|
|
|
|
None, _('Display Name Editor'), None)
|
|
|
|
table = self.dialog._build_custom_name_ui()
|
|
|
|
self.window.vbox.add(table)
|
|
|
|
self.window.set_default_size(600, 300)
|
|
|
|
self.window.connect('response', self.close)
|
|
|
|
self.show()
|
2007-12-13 07:52:06 +05:30
|
|
|
def close(self, *obj):
|
|
|
|
self.dialog.name_changed_check()
|
|
|
|
ManagedWindow.ManagedWindow.close(self, *obj)
|
|
|
|
|
2007-12-10 07:21:39 +05:30
|
|
|
def build_menu_names(self, obj):
|
|
|
|
return (_(" Name Editor"), _("Preferences"))
|
|
|
|
|
2006-08-26 05:16:19 +05:30
|
|
|
class GrampsPreferences(ManagedWindow.ManagedWindow):
|
2006-08-25 22:47:37 +05:30
|
|
|
def __init__(self, uistate, dbstate):
|
2006-07-16 20:14:13 +05:30
|
|
|
self.dbstate = dbstate
|
2007-12-10 07:21:39 +05:30
|
|
|
ManagedWindow.ManagedWindow.__init__(self, uistate, [], GrampsPreferences)
|
2006-06-15 01:50:39 +05:30
|
|
|
self.set_window(
|
2007-07-12 09:54:44 +05:30
|
|
|
gtk.Dialog(_('Preferences'),
|
|
|
|
flags=gtk.DIALOG_NO_SEPARATOR,
|
|
|
|
buttons=(gtk.STOCK_CLOSE, gtk.RESPONSE_CLOSE)),
|
2006-10-30 08:57:55 +05:30
|
|
|
None, _('Preferences'), None)
|
2006-04-26 07:14:03 +05:30
|
|
|
panel = gtk.Notebook()
|
2006-09-26 07:37:03 +05:30
|
|
|
self.original = Config.get(Config.TRANSACTIONS)
|
2006-04-26 07:14:03 +05:30
|
|
|
self.window.vbox.add(panel)
|
2007-07-12 09:54:44 +05:30
|
|
|
self.window.connect('response', self.done)
|
|
|
|
panel.append_page(self.add_behavior_panel(),
|
2006-10-30 08:57:55 +05:30
|
|
|
MarkupLabel(_('General')))
|
2007-07-12 09:54:44 +05:30
|
|
|
panel.append_page(self.add_database_panel(),
|
2007-06-17 04:47:29 +05:30
|
|
|
MarkupLabel(_('Database')))
|
2007-07-12 09:54:44 +05:30
|
|
|
panel.append_page(self.add_formats_panel(),
|
2006-10-30 08:57:55 +05:30
|
|
|
MarkupLabel(_('Display')))
|
2007-12-10 07:21:39 +05:30
|
|
|
#panel.append_page(self.add_name_panel(),
|
|
|
|
# MarkupLabel(_('Name Display')))
|
2007-07-12 09:54:44 +05:30
|
|
|
panel.append_page(self.add_prefix_panel(),
|
2006-10-30 08:57:55 +05:30
|
|
|
MarkupLabel(_('ID Formats')))
|
2007-07-12 09:54:44 +05:30
|
|
|
panel.append_page(self.add_advanced_panel(),
|
2006-10-30 08:57:55 +05:30
|
|
|
MarkupLabel(_('Warnings')))
|
2007-07-12 09:54:44 +05:30
|
|
|
panel.append_page(self.add_researcher_panel(),
|
2006-10-30 08:57:55 +05:30
|
|
|
MarkupLabel(_('Researcher')))
|
2007-07-12 09:54:44 +05:30
|
|
|
panel.append_page(self.add_color_panel(),
|
2006-10-30 08:57:55 +05:30
|
|
|
MarkupLabel(_('Marker Colors')))
|
2006-04-26 07:14:03 +05:30
|
|
|
self.window.show_all()
|
|
|
|
self.show()
|
|
|
|
|
|
|
|
def done(self, obj, value):
|
2006-09-26 07:37:03 +05:30
|
|
|
if not self.original and Config.get(Config.TRANSACTIONS):
|
|
|
|
Config.set(Config.PORT_WARN, True)
|
2006-04-26 07:14:03 +05:30
|
|
|
self.close()
|
|
|
|
|
|
|
|
def add_researcher_panel(self):
|
2007-07-12 09:54:44 +05:30
|
|
|
table = gtk.Table(3, 8)
|
2006-04-26 07:14:03 +05:30
|
|
|
table.set_border_width(12)
|
|
|
|
table.set_col_spacings(6)
|
|
|
|
table.set_row_spacings(6)
|
|
|
|
self.add_entry(table, _('Name'), 0, Config.RESEARCHER_NAME)
|
|
|
|
self.add_entry(table, _('Address'), 1, Config.RESEARCHER_ADDR)
|
|
|
|
self.add_entry(table, _('City'), 2, Config.RESEARCHER_CITY)
|
|
|
|
self.add_entry(table, _('State/Province'), 3, Config.RESEARCHER_STATE)
|
|
|
|
self.add_entry(table, _('Country'), 4, Config.RESEARCHER_COUNTRY)
|
|
|
|
self.add_entry(table, _('ZIP/Postal Code'), 5, Config.RESEARCHER_POSTAL)
|
|
|
|
self.add_entry(table, _('Phone'), 6, Config.RESEARCHER_PHONE)
|
|
|
|
self.add_entry(table, _('Email'), 7, Config.RESEARCHER_EMAIL)
|
|
|
|
return table
|
|
|
|
|
|
|
|
def add_prefix_panel(self):
|
2007-07-12 09:54:44 +05:30
|
|
|
table = gtk.Table(3, 8)
|
2006-04-26 07:14:03 +05:30
|
|
|
table.set_border_width(12)
|
|
|
|
table.set_col_spacings(6)
|
|
|
|
table.set_row_spacings(6)
|
|
|
|
self.add_entry(table, _('Person'), 0, Config.IPREFIX)
|
|
|
|
self.add_entry(table, _('Family'), 1, Config.FPREFIX)
|
|
|
|
self.add_entry(table, _('Place'), 2, Config.PPREFIX)
|
|
|
|
self.add_entry(table, _('Source'), 3, Config.SPREFIX)
|
|
|
|
self.add_entry(table, _('Media Object'), 4, Config.OPREFIX)
|
|
|
|
self.add_entry(table, _('Event'), 5, Config.EPREFIX)
|
|
|
|
self.add_entry(table, _('Repository'), 6, Config.RPREFIX)
|
2008-01-11 01:47:05 +05:30
|
|
|
#added notes prefix
|
|
|
|
self.add_entry(table, _('Note'), 7, Config.NPREFIX)
|
2006-04-26 07:14:03 +05:30
|
|
|
return table
|
|
|
|
|
|
|
|
def add_advanced_panel(self):
|
2007-07-12 09:54:44 +05:30
|
|
|
table = gtk.Table(4, 8)
|
2006-04-26 07:14:03 +05:30
|
|
|
table.set_border_width(12)
|
|
|
|
table.set_col_spacings(6)
|
|
|
|
table.set_row_spacings(6)
|
2006-05-13 09:23:06 +05:30
|
|
|
self.add_checkbox(
|
2007-07-12 09:54:44 +05:30
|
|
|
table, _('Suppress warning when adding parents to a child'),
|
2006-05-13 09:23:06 +05:30
|
|
|
0, Config.FAMILY_WARN)
|
2006-03-06 05:09:20 +05:30
|
|
|
|
2006-05-13 09:23:06 +05:30
|
|
|
self.add_checkbox(
|
2007-07-12 09:54:44 +05:30
|
|
|
table, _('Suppress warning when cancelling with changed data'),
|
2006-05-13 09:23:06 +05:30
|
|
|
1, Config.DONT_ASK)
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2007-02-04 23:07:36 +05:30
|
|
|
self.add_checkbox(
|
|
|
|
table, _('Suppress warning about missing researcher when'
|
2007-07-12 09:54:44 +05:30
|
|
|
' exporting to GEDCOM'),
|
2007-02-04 23:07:36 +05:30
|
|
|
2, Config.OWNER_WARN)
|
|
|
|
|
2006-05-13 09:23:06 +05:30
|
|
|
self.add_checkbox(
|
2007-07-12 09:54:44 +05:30
|
|
|
table, _('Show plugin status dialog on plugin load error'),
|
2007-02-04 23:07:36 +05:30
|
|
|
3, Config.POP_PLUGIN_STATUS)
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2006-04-26 07:14:03 +05:30
|
|
|
return table
|
|
|
|
|
2006-05-12 23:50:18 +05:30
|
|
|
def add_color_panel(self):
|
2007-07-12 09:54:44 +05:30
|
|
|
table = gtk.Table(3, 8)
|
2006-05-12 23:50:18 +05:30
|
|
|
table.set_border_width(12)
|
2006-05-13 09:23:06 +05:30
|
|
|
table.set_col_spacings(12)
|
2006-05-12 23:50:18 +05:30
|
|
|
table.set_row_spacings(6)
|
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
self.comp_color = self.add_color(table, _("Complete"), 0,
|
2006-05-13 10:42:19 +05:30
|
|
|
Config.COMPLETE_COLOR)
|
2007-07-12 09:54:44 +05:30
|
|
|
self.todo_color = self.add_color(table, _("ToDo"), 1,
|
2006-05-13 10:42:19 +05:30
|
|
|
Config.TODO_COLOR)
|
2007-07-12 09:54:44 +05:30
|
|
|
self.custom_color = self.add_color(table, _("Custom"), 2,
|
2006-05-13 10:42:19 +05:30
|
|
|
Config.CUSTOM_MARKER_COLOR)
|
|
|
|
|
|
|
|
button = gtk.Button(stock=gtk.STOCK_REVERT_TO_SAVED)
|
|
|
|
button.connect('clicked', self.reset_colors)
|
|
|
|
table.attach(button, 1, 2, 3, 4, yoptions=0, xoptions=0)
|
2006-05-12 23:50:18 +05:30
|
|
|
return table
|
|
|
|
|
2006-05-13 10:42:19 +05:30
|
|
|
def reset_colors(self, obj):
|
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def_comp = Config.get_default(Config.COMPLETE_COLOR, '')
|
|
|
|
def_todo = Config.get_default(Config.TODO_COLOR, '')
|
|
|
|
def_cust = Config.get_default(Config.CUSTOM_MARKER_COLOR, '')
|
2006-05-13 10:42:19 +05:30
|
|
|
|
|
|
|
Config.set(Config.COMPLETE_COLOR, def_comp)
|
|
|
|
Config.set(Config.TODO_COLOR, def_todo)
|
|
|
|
Config.set(Config.CUSTOM_MARKER_COLOR, def_cust)
|
|
|
|
|
|
|
|
self.comp_color.set_color(gtk.gdk.color_parse(def_comp))
|
|
|
|
self.todo_color.set_color(gtk.gdk.color_parse(def_todo))
|
|
|
|
self.custom_color.set_color(gtk.gdk.color_parse(def_cust))
|
2007-07-12 09:54:44 +05:30
|
|
|
for widget in [self.comp_color, self.todo_color, self.custom_color]:
|
2006-05-13 11:23:47 +05:30
|
|
|
widget.emit('color-set')
|
2006-05-13 10:42:19 +05:30
|
|
|
|
2006-06-15 01:50:39 +05:30
|
|
|
def add_name_panel(self):
|
2006-07-16 20:14:13 +05:30
|
|
|
"""
|
|
|
|
Name format settings panel
|
|
|
|
"""
|
|
|
|
|
|
|
|
# a dummy name to be used in the examples
|
|
|
|
self.examplename = Name()
|
|
|
|
self.examplename.set_title('Dr.')
|
2007-12-10 19:50:22 +05:30
|
|
|
self.examplename.set_first_name('Edwin Jose')
|
2006-07-16 20:14:13 +05:30
|
|
|
self.examplename.set_surname_prefix('Rev.')
|
|
|
|
self.examplename.set_surname('Smith')
|
|
|
|
self.examplename.set_suffix('Sr')
|
2007-12-10 10:22:26 +05:30
|
|
|
self.examplename.set_patronymic('Wilson')
|
2006-07-21 00:42:22 +05:30
|
|
|
self.examplename.set_call_name('Ed')
|
2006-07-16 20:14:13 +05:30
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
table = gtk.Table(2, 2)
|
2006-06-15 01:50:39 +05:30
|
|
|
table.set_border_width(12)
|
|
|
|
table.set_col_spacings(6)
|
|
|
|
table.set_row_spacings(6)
|
|
|
|
|
2006-07-16 20:14:13 +05:30
|
|
|
# get the model for the combo and the treeview
|
2006-07-31 16:38:44 +05:30
|
|
|
active = _nd.get_default_format()
|
2007-07-12 09:54:44 +05:30
|
|
|
self.fmt_model, active = self._build_name_format_model(active)
|
2006-06-15 01:50:39 +05:30
|
|
|
|
2006-07-16 20:14:13 +05:30
|
|
|
# set up the combo to choose the preset format
|
|
|
|
self.fmt_obox = gtk.ComboBox()
|
2006-07-07 01:41:32 +05:30
|
|
|
cell = gtk.CellRendererText()
|
2006-07-16 20:14:13 +05:30
|
|
|
self.fmt_obox.pack_start(cell, True)
|
|
|
|
self.fmt_obox.add_attribute(cell, 'text', 1)
|
|
|
|
self.fmt_obox.set_model(self.fmt_model)
|
|
|
|
|
|
|
|
# set the default value as active in the combo
|
2006-07-31 16:38:44 +05:30
|
|
|
self.fmt_obox.set_active(active)
|
2006-07-16 20:14:13 +05:30
|
|
|
self.fmt_obox.connect('changed', self.cb_name_changed)
|
|
|
|
# label for the combo
|
2006-07-21 00:42:22 +05:30
|
|
|
lwidget = BasicLabel("%s: " % _('_Display format'))
|
|
|
|
lwidget.set_use_underline(True)
|
|
|
|
lwidget.set_mnemonic_widget(self.fmt_obox)
|
2006-07-16 20:14:13 +05:30
|
|
|
|
|
|
|
# build the format manager ui
|
|
|
|
custom_ui = self._build_custom_name_ui()
|
|
|
|
name_exp = gtk.expander_new_with_mnemonic(_('C_ustom format details'))
|
|
|
|
name_exp.add(custom_ui)
|
|
|
|
name_exp.set_sensitive(self.dbstate.open)
|
|
|
|
|
|
|
|
# put all these together
|
|
|
|
table.attach(lwidget, 0, 1, 0, 1, yoptions=0)
|
2006-07-20 01:26:15 +05:30
|
|
|
table.attach(self.fmt_obox, 1, 2, 0, 1, yoptions=0)
|
2006-07-21 00:42:22 +05:30
|
|
|
table.attach(name_exp, 0, 2, 1, 2, yoptions=gtk.FILL|gtk.EXPAND)
|
2006-07-16 20:14:13 +05:30
|
|
|
|
|
|
|
return table
|
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def _build_name_format_model(self, active):
|
2006-07-16 20:14:13 +05:30
|
|
|
"""
|
|
|
|
Create a common model for ComboBox and TreeView
|
|
|
|
"""
|
2007-07-12 09:54:44 +05:30
|
|
|
name_format_model = gtk.ListStore(int, str, str, str)
|
2006-07-31 16:38:44 +05:30
|
|
|
index = 0
|
|
|
|
the_index = 0
|
2007-07-12 09:54:44 +05:30
|
|
|
for num, name, fmt_str, act in _nd.get_name_format():
|
2007-12-12 09:29:18 +05:30
|
|
|
translation = fmt_str
|
|
|
|
for key in Utils.get_keywords():
|
|
|
|
if key in translation:
|
|
|
|
translation = translation.replace(key, Utils.get_translation_from_keyword(key))
|
2006-07-16 20:14:13 +05:30
|
|
|
self.examplename.set_display_as(num)
|
|
|
|
name_format_model.append(
|
2007-12-12 09:29:18 +05:30
|
|
|
row=[num, translation, fmt_str, _nd.display_name(self.examplename)])
|
2006-07-31 16:38:44 +05:30
|
|
|
if num == active: the_index = index
|
2006-07-06 23:16:46 +05:30
|
|
|
index += 1
|
2007-07-12 09:54:44 +05:30
|
|
|
return name_format_model, the_index
|
2006-07-06 23:16:46 +05:30
|
|
|
|
2007-12-10 07:21:39 +05:30
|
|
|
def __new_name(self, obj):
|
2007-12-20 09:25:43 +05:30
|
|
|
lyst = ["%s, %s %s (%s)" % (_("Surname"), _("Given"), _("Suffix"),
|
|
|
|
_("Common")),
|
|
|
|
"%s, %s %s (%s)" % (_("Surname"), _("Given"), _("Suffix"),
|
|
|
|
_("Call")),
|
|
|
|
"%s, %s %s (%s)" % (_("SURNAME"), _("Given"), _("Suffix"),
|
|
|
|
_("Call")),
|
|
|
|
"%s, %s (%s)" % (_("Surname"), _("Given"), _("Common")),
|
|
|
|
"%s, %s (%s)" % (_("Surname"), _("Given"), _("Call")),
|
|
|
|
"%s %s" % (_("Given"), _("Surname")),
|
|
|
|
"%s %s, %s" % (_("Given"), _("Surname"), _("Suffix")),
|
|
|
|
"%s %s %s" % (_("Given"), _("Surname"), _("Patronymic")),
|
|
|
|
"%s, %s %s (%s)" % (_("SURNAME"), _("Given"), _("Suffix"),
|
|
|
|
_("Common")),
|
|
|
|
"%s, %s (%s)" % (_("SURNAME"), _("Given"), _("Common")),
|
|
|
|
"%s, %s (%s)" % (_("SURNAME"), _("Given"), _("Call")),
|
|
|
|
"%s %s" % (_("Given"), _("SURNAME")),
|
|
|
|
"%s %s, %s" % (_("Given"), _("SURNAME"), _("Suffix")),
|
|
|
|
"%s /%s/" % (_("Given"), _("SURNAME")),
|
|
|
|
]
|
|
|
|
f = lyst[int(random.random() * len(lyst))]
|
2007-12-12 09:29:18 +05:30
|
|
|
i = _nd.add_name_format(f, f.lower())
|
|
|
|
node = self.fmt_model.append(row=[i, f, f.lower(),
|
2007-12-10 07:21:39 +05:30
|
|
|
_nd.format_str(self.examplename, f)])
|
|
|
|
path = self.fmt_model.get_path(node)
|
|
|
|
self.format_list.set_cursor(path,
|
|
|
|
focus_column=self.name_column,
|
|
|
|
start_editing=True)
|
|
|
|
|
|
|
|
def __edit_name(self, obj):
|
|
|
|
store, node = self.format_list.get_selection().get_selected()
|
|
|
|
path = self.fmt_model.get_path(node)
|
|
|
|
self.format_list.set_cursor(path,
|
|
|
|
focus_column=self.name_column,
|
|
|
|
start_editing=True)
|
|
|
|
|
2007-12-20 09:25:43 +05:30
|
|
|
def __check_for_name(self, name, oldnode):
|
|
|
|
"""
|
|
|
|
Check to see if there is another name the same as name
|
|
|
|
in the format list. Don't compare with self (oldnode).
|
|
|
|
"""
|
|
|
|
model = self.fmt_obox.get_model()
|
|
|
|
iter = model.get_iter_first()
|
|
|
|
while iter != None:
|
|
|
|
othernum = model.get_value(iter, COL_NUM)
|
|
|
|
oldnum = model.get_value(oldnode, COL_NUM)
|
|
|
|
if othernum == oldnum:
|
|
|
|
pass# skip comparison with self
|
|
|
|
else:
|
|
|
|
othername = model.get_value(iter, COL_NAME)
|
|
|
|
if othername == name:
|
|
|
|
return True
|
|
|
|
iter = model.iter_next(iter)
|
|
|
|
return False
|
|
|
|
|
2007-12-10 07:21:39 +05:30
|
|
|
def __change_name(self, text, path, new_text):
|
|
|
|
"""
|
|
|
|
If the new string is empty, do nothing. Otherwise, renaming the
|
|
|
|
database is simply changing the contents of the name file.
|
|
|
|
"""
|
|
|
|
if len(new_text) > 0 and text != new_text:
|
2007-12-12 21:54:40 +05:30
|
|
|
# build a pattern from translated pattern:
|
2007-12-12 09:29:18 +05:30
|
|
|
pattern = new_text
|
|
|
|
for key in Utils.get_translations():
|
|
|
|
if key in pattern:
|
|
|
|
pattern = pattern.replace(key, Utils.get_keyword_from_translation(key))
|
2007-12-12 21:54:40 +05:30
|
|
|
# now build up a proper translation:
|
|
|
|
translation = pattern
|
|
|
|
for key in Utils.get_keywords():
|
|
|
|
if key in translation:
|
|
|
|
translation = translation.replace(key, Utils.get_translation_from_keyword(key))
|
2007-12-10 07:21:39 +05:30
|
|
|
num, name, fmt = self.selected_fmt[COL_NUM:COL_EXPL]
|
|
|
|
node = self.fmt_model.get_iter(path)
|
|
|
|
oldname = self.fmt_model.get_value(node, COL_NAME)
|
2007-12-20 09:25:43 +05:30
|
|
|
# check to see if this pattern already exists
|
|
|
|
if self.__check_for_name(translation, node):
|
|
|
|
QuestionDialog.ErrorDialog(_("This format exists already"),
|
|
|
|
translation)
|
|
|
|
self.edit_button.emit('clicked')
|
|
|
|
return
|
|
|
|
# else, change the name
|
2007-12-12 09:29:18 +05:30
|
|
|
exmpl = _nd.format_str(self.examplename, pattern)
|
2007-12-12 21:54:40 +05:30
|
|
|
self.fmt_model.set(self.iter, COL_NAME, translation,
|
2007-12-12 09:29:18 +05:30
|
|
|
COL_FMT, pattern,
|
2007-12-10 07:21:39 +05:30
|
|
|
COL_EXPL, exmpl)
|
2007-12-12 21:54:40 +05:30
|
|
|
self.selected_fmt = (num, translation, pattern, exmpl)
|
|
|
|
_nd.edit_name_format(num, translation, pattern)
|
2007-12-10 07:21:39 +05:30
|
|
|
self.dbstate.db.name_formats = _nd.get_name_format(only_custom=True,
|
|
|
|
only_active=False)
|
|
|
|
|
|
|
|
def __format_change(self, obj):
|
|
|
|
try:
|
|
|
|
t = (_nd.format_str(self.name, escape(obj.get_text())))
|
|
|
|
self.valid = True
|
|
|
|
except NameDisplayError:
|
|
|
|
t = _("Invalid or incomplete format definition")
|
|
|
|
self.valid = False
|
|
|
|
self.fmt_model.set(self.iter, COL_EXPL, t)
|
|
|
|
|
2006-07-16 20:14:13 +05:30
|
|
|
def _build_custom_name_ui(self):
|
|
|
|
"""
|
|
|
|
UI to manage the custom name formats
|
|
|
|
"""
|
2006-06-15 01:50:39 +05:30
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
table = gtk.Table(2, 3)
|
2006-07-16 20:14:13 +05:30
|
|
|
table.set_border_width(6)
|
|
|
|
table.set_col_spacings(6)
|
|
|
|
table.set_row_spacings(6)
|
|
|
|
|
|
|
|
# make a treeview for listing all the name formats
|
|
|
|
format_tree = gtk.TreeView(self.fmt_model)
|
|
|
|
name_renderer = gtk.CellRendererText()
|
2007-12-10 10:22:26 +05:30
|
|
|
name_column = gtk.TreeViewColumn(_('Format'),
|
2007-07-12 09:54:44 +05:30
|
|
|
name_renderer,
|
2006-07-16 20:14:13 +05:30
|
|
|
text=COL_NAME)
|
2007-12-11 04:39:48 +05:30
|
|
|
name_renderer.set_property('editable', False)
|
2007-12-10 07:21:39 +05:30
|
|
|
name_renderer.connect('edited', self.__change_name)
|
2007-12-11 04:39:48 +05:30
|
|
|
self.name_renderer = name_renderer
|
2006-07-16 20:14:13 +05:30
|
|
|
format_tree.append_column(name_column)
|
|
|
|
example_renderer = gtk.CellRendererText()
|
2007-07-12 09:54:44 +05:30
|
|
|
example_column = gtk.TreeViewColumn(_('Example'),
|
|
|
|
example_renderer,
|
2006-07-16 20:14:13 +05:30
|
|
|
text=COL_EXPL)
|
|
|
|
format_tree.append_column(example_column)
|
2007-07-12 09:54:44 +05:30
|
|
|
format_tree.get_selection().connect('changed',
|
2006-07-16 20:14:13 +05:30
|
|
|
self.cb_format_tree_select)
|
|
|
|
format_tree.set_rules_hint(True)
|
2006-07-21 00:42:22 +05:30
|
|
|
|
2006-07-16 20:14:13 +05:30
|
|
|
# ... and put it into a scrolled win
|
|
|
|
format_sw = gtk.ScrolledWindow()
|
2007-07-12 09:54:44 +05:30
|
|
|
format_sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
|
2006-07-16 20:14:13 +05:30
|
|
|
format_sw.add(format_tree)
|
|
|
|
format_sw.set_shadow_type(gtk.SHADOW_IN)
|
2006-07-21 00:42:22 +05:30
|
|
|
table.attach(format_sw, 0, 3, 0, 1, yoptions=gtk.FILL|gtk.EXPAND)
|
2006-07-16 20:14:13 +05:30
|
|
|
|
|
|
|
# to hold the values of the selected row of the tree and the iter
|
|
|
|
self.selected_fmt = ()
|
|
|
|
self.iter = None
|
|
|
|
|
|
|
|
insert_button = gtk.Button(stock=gtk.STOCK_ADD)
|
2007-12-10 07:21:39 +05:30
|
|
|
insert_button.connect('clicked', self.__new_name)
|
|
|
|
#self.cb_insert_fmt_str)
|
2006-07-16 20:14:13 +05:30
|
|
|
|
|
|
|
self.edit_button = gtk.Button(stock=gtk.STOCK_EDIT)
|
2007-12-10 07:21:39 +05:30
|
|
|
self.edit_button.connect('clicked', self.__edit_name)
|
|
|
|
#self.cb_edit_fmt_str)
|
2006-07-16 20:14:13 +05:30
|
|
|
self.edit_button.set_sensitive(False)
|
|
|
|
|
|
|
|
self.remove_button = gtk.Button(stock=gtk.STOCK_REMOVE)
|
2007-07-12 09:54:44 +05:30
|
|
|
self.remove_button.connect('clicked', self.cb_del_fmt_str)
|
2006-07-16 20:14:13 +05:30
|
|
|
self.remove_button.set_sensitive(False)
|
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
table.attach(insert_button, 0, 1, 1, 2, yoptions=0)
|
|
|
|
table.attach(self.remove_button, 1, 2, 1, 2, yoptions=0)
|
|
|
|
table.attach(self.edit_button, 2, 3, 1, 2, yoptions=0)
|
2007-12-10 07:21:39 +05:30
|
|
|
self.format_list = format_tree
|
|
|
|
self.name_column = name_column
|
2006-06-15 01:50:39 +05:30
|
|
|
return table
|
|
|
|
|
2007-12-13 07:52:06 +05:30
|
|
|
def name_changed_check(self):
|
|
|
|
"""
|
|
|
|
Method to check for a name change. Called by Name Edit Dialog.
|
|
|
|
"""
|
|
|
|
obj = self.fmt_obox
|
|
|
|
the_list = obj.get_model()
|
|
|
|
the_iter = obj.get_active_iter()
|
|
|
|
format = the_list.get_value(the_iter, COL_FMT)
|
|
|
|
if format != self.old_format:
|
|
|
|
# Yes a change; call the callback
|
|
|
|
self.cb_name_changed(obj)
|
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def cb_name_changed(self, obj):
|
2006-07-16 20:14:13 +05:30
|
|
|
"""
|
|
|
|
Preset name format ComboBox callback
|
|
|
|
"""
|
2006-07-21 00:42:22 +05:30
|
|
|
the_list = obj.get_model()
|
2006-07-31 16:38:44 +05:30
|
|
|
the_iter = obj.get_active_iter()
|
2007-07-12 09:54:44 +05:30
|
|
|
new_idx = the_list.get_value(the_iter, COL_NUM)
|
|
|
|
Config.set(Config.NAME_FORMAT, new_idx)
|
2006-07-31 16:38:44 +05:30
|
|
|
_nd.set_default_format(new_idx)
|
2006-08-26 05:16:19 +05:30
|
|
|
self.uistate.emit('nameformat-changed')
|
2006-06-16 02:37:41 +05:30
|
|
|
|
2006-07-16 20:14:13 +05:30
|
|
|
def cb_format_tree_select(self, tree_selection):
|
|
|
|
"""
|
|
|
|
Name format editor TreeView callback
|
|
|
|
|
2006-07-27 16:18:16 +05:30
|
|
|
Remember the values of the selected row (self.selected_fmt, self.iter)
|
|
|
|
and set the Remove and Edit button sensitivity
|
2006-07-31 16:38:44 +05:30
|
|
|
|
2006-07-16 20:14:13 +05:30
|
|
|
"""
|
2007-07-12 09:54:44 +05:30
|
|
|
model, self.iter = tree_selection.get_selected()
|
2006-07-16 20:14:13 +05:30
|
|
|
if self.iter == None:
|
|
|
|
tree_selection.select_path(0)
|
2007-07-12 09:54:44 +05:30
|
|
|
model, self.iter = tree_selection.get_selected()
|
2006-07-16 20:14:13 +05:30
|
|
|
self.selected_fmt = model.get(self.iter, 0, 1, 2)
|
|
|
|
idx = self.selected_fmt[COL_NUM] < 0
|
|
|
|
self.remove_button.set_sensitive(idx)
|
|
|
|
self.edit_button.set_sensitive(idx)
|
2007-12-11 04:39:48 +05:30
|
|
|
self.name_renderer.set_property('editable', idx)
|
|
|
|
|
2006-07-16 20:14:13 +05:30
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def cb_edit_fmt_str(self, obj):
|
2006-07-16 20:14:13 +05:30
|
|
|
"""
|
2006-07-31 16:38:44 +05:30
|
|
|
Name format editor Edit button callback
|
|
|
|
"""
|
2007-07-12 09:54:44 +05:30
|
|
|
num, name, fmt = self.selected_fmt[COL_NUM:COL_EXPL]
|
2007-06-22 11:27:48 +05:30
|
|
|
dlg = NameFormatEditDlg(name, fmt, self.examplename)
|
2006-07-31 16:38:44 +05:30
|
|
|
dlg.dlg.set_transient_for(self.window)
|
2007-07-12 09:54:44 +05:30
|
|
|
(res, name, fmt) = dlg.run()
|
2006-07-31 16:38:44 +05:30
|
|
|
|
2007-06-22 11:27:48 +05:30
|
|
|
if res == gtk.RESPONSE_OK and (name != self.selected_fmt[COL_NAME] or
|
|
|
|
fmt != self.selected_fmt[COL_FMT]):
|
2007-07-12 09:54:44 +05:30
|
|
|
exmpl = _nd.format_str(self.examplename, fmt)
|
|
|
|
self.fmt_model.set(self.iter, COL_NAME, name,
|
|
|
|
COL_FMT, fmt,
|
|
|
|
COL_EXPL, exmpl)
|
|
|
|
self.selected_fmt = (num, name, fmt, exmpl)
|
|
|
|
_nd.edit_name_format(num, name, fmt)
|
|
|
|
|
|
|
|
self.dbstate.db.name_formats = _nd.get_name_format(only_custom=True,
|
2006-07-31 16:38:44 +05:30
|
|
|
only_active=False)
|
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def cb_insert_fmt_str(self, obj):
|
2006-07-31 16:38:44 +05:30
|
|
|
"""
|
|
|
|
Name format editor Insert button callback
|
2006-07-16 20:14:13 +05:30
|
|
|
"""
|
2007-07-12 09:54:44 +05:30
|
|
|
dlg = NameFormatEditDlg('', '', self.examplename)
|
2006-07-21 00:42:22 +05:30
|
|
|
dlg.dlg.set_transient_for(self.window)
|
2007-07-12 09:54:44 +05:30
|
|
|
(res, n, f) = dlg.run()
|
2006-07-16 20:14:13 +05:30
|
|
|
|
|
|
|
if res == gtk.RESPONSE_OK:
|
2007-07-12 09:54:44 +05:30
|
|
|
i = _nd.add_name_format(n, f)
|
|
|
|
self.fmt_model.append(row=[i, n, f,
|
|
|
|
_nd.format_str(self.examplename, f)])
|
2006-07-31 16:38:44 +05:30
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
self.dbstate.db.name_formats = _nd.get_name_format(only_custom=True,
|
2006-07-31 16:38:44 +05:30
|
|
|
only_active=False)
|
2006-07-16 20:14:13 +05:30
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def cb_del_fmt_str(self, obj):
|
2006-07-16 20:14:13 +05:30
|
|
|
"""
|
|
|
|
Name format editor Remove button callback
|
|
|
|
"""
|
2006-07-27 16:18:16 +05:30
|
|
|
num = self.selected_fmt[COL_NUM]
|
2006-07-31 16:38:44 +05:30
|
|
|
|
|
|
|
if _nd.get_default_format() == num:
|
|
|
|
self.fmt_obox.set_active(0)
|
|
|
|
|
2006-07-16 20:14:13 +05:30
|
|
|
self.fmt_model.remove(self.iter)
|
2006-07-31 16:38:44 +05:30
|
|
|
_nd.set_format_inactive(num)
|
2007-07-12 09:54:44 +05:30
|
|
|
self.dbstate.db.name_formats = _nd.get_name_format(only_custom=True,
|
2006-07-31 16:38:44 +05:30
|
|
|
only_active=False)
|
|
|
|
|
2006-04-26 07:14:03 +05:30
|
|
|
def add_formats_panel(self):
|
2007-12-10 07:21:39 +05:30
|
|
|
row = 0
|
|
|
|
table = gtk.Table(4, 8)
|
2006-04-26 07:14:03 +05:30
|
|
|
table.set_border_width(12)
|
|
|
|
table.set_col_spacings(6)
|
|
|
|
table.set_row_spacings(6)
|
|
|
|
|
2007-12-10 07:21:39 +05:30
|
|
|
# Display name:
|
|
|
|
self.examplename = Name()
|
|
|
|
self.examplename.set_title('Dr.')
|
2007-12-10 19:50:22 +05:30
|
|
|
self.examplename.set_first_name('Edwin Jose')
|
2007-12-10 07:21:39 +05:30
|
|
|
self.examplename.set_surname_prefix('Rev.')
|
|
|
|
self.examplename.set_surname('Smith')
|
|
|
|
self.examplename.set_suffix('Sr')
|
2007-12-10 19:50:22 +05:30
|
|
|
self.examplename.set_patronymic('Wilson')
|
2007-12-10 07:21:39 +05:30
|
|
|
self.examplename.set_call_name('Ed')
|
|
|
|
# get the model for the combo and the treeview
|
|
|
|
active = _nd.get_default_format()
|
|
|
|
self.fmt_model, active = self._build_name_format_model(active)
|
|
|
|
# set up the combo to choose the preset format
|
|
|
|
self.fmt_obox = gtk.ComboBox()
|
|
|
|
cell = gtk.CellRendererText()
|
|
|
|
self.fmt_obox.pack_start(cell, True)
|
|
|
|
self.fmt_obox.add_attribute(cell, 'text', 1)
|
|
|
|
self.fmt_obox.set_model(self.fmt_model)
|
|
|
|
# set the default value as active in the combo
|
|
|
|
self.fmt_obox.set_active(active)
|
|
|
|
self.fmt_obox.connect('changed', self.cb_name_changed)
|
|
|
|
# label for the combo
|
|
|
|
lwidget = BasicLabel("%s: " % _('Name format'))
|
|
|
|
lwidget.set_use_underline(True)
|
|
|
|
lwidget.set_mnemonic_widget(self.fmt_obox)
|
|
|
|
hbox = gtk.HBox()
|
|
|
|
btn = gtk.Button("%s..." % _('Edit') )
|
|
|
|
btn.connect('clicked', self.cb_name_dialog)
|
|
|
|
hbox.pack_start(self.fmt_obox, expand=True, fill=True)
|
|
|
|
hbox.pack_start(btn, expand=False, fill=False)
|
|
|
|
table.attach(lwidget, 0, 1, row, row+1, yoptions=0)
|
|
|
|
table.attach(hbox, 1, 3, row, row+1, yoptions=0)
|
|
|
|
row += 1
|
|
|
|
|
|
|
|
# Date format:
|
2006-04-26 07:14:03 +05:30
|
|
|
obox = gtk.combo_box_new_text()
|
|
|
|
formats = DateHandler.get_date_formats()
|
|
|
|
for item in formats:
|
|
|
|
obox.append_text(item)
|
|
|
|
active = Config.get(Config.DATE_FORMAT)
|
|
|
|
if active >= len(formats):
|
|
|
|
active = 0
|
|
|
|
obox.set_active(active)
|
2006-11-05 10:50:35 +05:30
|
|
|
obox.connect('changed', self.date_format_changed)
|
2006-04-26 07:14:03 +05:30
|
|
|
lwidget = BasicLabel("%s: " % _('Date format'))
|
2007-12-10 07:21:39 +05:30
|
|
|
table.attach(lwidget, 0, 1, row, row+1, yoptions=0)
|
|
|
|
table.attach(obox, 1, 3, row, row+1, yoptions=0)
|
|
|
|
row += 1
|
2006-04-26 07:14:03 +05:30
|
|
|
|
2007-12-10 07:21:39 +05:30
|
|
|
# Surname guessing:
|
2006-04-26 07:14:03 +05:30
|
|
|
obox = gtk.combo_box_new_text()
|
|
|
|
formats = _surname_styles
|
|
|
|
for item in formats:
|
|
|
|
obox.append_text(item)
|
|
|
|
obox.set_active(Config.get(Config.SURNAME_GUESSING))
|
2007-07-12 09:54:44 +05:30
|
|
|
obox.connect('changed',
|
2006-11-05 10:50:35 +05:30
|
|
|
lambda obj: Config.set(Config.SURNAME_GUESSING,
|
|
|
|
obj.get_active()))
|
2006-04-26 07:14:03 +05:30
|
|
|
lwidget = BasicLabel("%s: " % _('Surname Guessing'))
|
2007-12-10 07:21:39 +05:30
|
|
|
table.attach(lwidget, 0, 1, row, row+1, yoptions=0)
|
|
|
|
table.attach(obox, 1, 3, row, row+1, yoptions=0)
|
|
|
|
row += 1
|
2006-04-26 07:14:03 +05:30
|
|
|
|
2007-12-10 07:21:39 +05:30
|
|
|
# Status bar:
|
2006-04-26 07:14:03 +05:30
|
|
|
obox = gtk.combo_box_new_text()
|
2007-07-12 09:54:44 +05:30
|
|
|
formats = [_("Active person's name and ID"),
|
2006-04-26 07:14:03 +05:30
|
|
|
_("Relationship to home person")]
|
|
|
|
for item in formats:
|
|
|
|
obox.append_text(item)
|
|
|
|
active = Config.get(Config.STATUSBAR)
|
|
|
|
if active < 2:
|
|
|
|
obox.set_active(0)
|
|
|
|
else:
|
|
|
|
obox.set_active(1)
|
2007-07-12 09:54:44 +05:30
|
|
|
obox.connect('changed',
|
2006-04-26 07:14:03 +05:30
|
|
|
lambda obj: Config.set(Config.STATUSBAR, 2*obj.get_active()))
|
|
|
|
lwidget = BasicLabel("%s: " % _('Status bar'))
|
2007-12-10 07:21:39 +05:30
|
|
|
table.attach(lwidget, 0, 1, row, row+1, yoptions=0)
|
|
|
|
table.attach(obox, 1, 3, row, row+1, yoptions=0)
|
|
|
|
row += 1
|
2006-05-04 03:51:59 +05:30
|
|
|
|
2007-12-10 07:21:39 +05:30
|
|
|
# Text in sidebar:
|
2007-07-12 09:54:44 +05:30
|
|
|
self.add_checkbox(table, _("Show text in sidebar buttons (takes effect on restart)"),
|
2007-12-10 07:21:39 +05:30
|
|
|
row, Config.SIDEBAR_TEXT)
|
|
|
|
row += 1
|
2006-04-26 07:14:03 +05:30
|
|
|
|
|
|
|
return table
|
|
|
|
|
2007-12-10 07:21:39 +05:30
|
|
|
def cb_name_dialog(self, obj):
|
2007-12-13 07:52:06 +05:30
|
|
|
the_list = self.fmt_obox.get_model()
|
|
|
|
the_iter = self.fmt_obox.get_active_iter()
|
|
|
|
self.old_format = the_list.get_value(the_iter, COL_FMT)
|
2007-12-10 07:21:39 +05:30
|
|
|
win = DisplayNameEditor(self.uistate, self.dbstate, self.track, self)
|
|
|
|
|
2006-11-05 10:50:35 +05:30
|
|
|
def date_format_changed(self, obj):
|
|
|
|
from QuestionDialog import OkDialog
|
|
|
|
|
|
|
|
Config.set(Config.DATE_FORMAT, obj.get_active())
|
2007-07-12 09:54:44 +05:30
|
|
|
OkDialog(_('Change is not immediate'),
|
2006-11-05 10:50:35 +05:30
|
|
|
_('Changing the data format will not take '
|
|
|
|
'effect until the next time GRAMPS is started.'))
|
|
|
|
|
2006-04-26 07:14:03 +05:30
|
|
|
def add_behavior_panel(self):
|
2007-07-12 09:54:44 +05:30
|
|
|
table = gtk.Table(3, 8)
|
2006-04-26 07:14:03 +05:30
|
|
|
table.set_border_width(12)
|
|
|
|
table.set_col_spacings(6)
|
|
|
|
table.set_row_spacings(6)
|
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
self.add_checkbox(table, _('Add default source on import'),
|
2007-06-17 04:47:29 +05:30
|
|
|
0, Config.DEFAULT_SOURCE)
|
2007-07-12 09:54:44 +05:30
|
|
|
self.add_checkbox(table, _('Enable spelling checker'),
|
2007-06-17 04:47:29 +05:30
|
|
|
1, Config.SPELLCHECK)
|
2007-07-12 09:54:44 +05:30
|
|
|
self.add_checkbox(table, _('Display Tip of the Day'),
|
2007-06-17 04:47:29 +05:30
|
|
|
2, Config.USE_TIPS)
|
2007-07-12 09:54:44 +05:30
|
|
|
self.add_checkbox(table, _('Use shading in Relationship View'),
|
2007-06-17 04:47:29 +05:30
|
|
|
3, Config.RELATION_SHADE)
|
2007-07-12 09:54:44 +05:30
|
|
|
self.add_checkbox(table, _('Display edit buttons on Relationship View'),
|
2007-06-17 04:47:29 +05:30
|
|
|
4, Config.RELEDITBTN)
|
2007-07-12 09:54:44 +05:30
|
|
|
self.add_checkbox(table, _('Remember last view displayed'),
|
2007-06-17 04:47:29 +05:30
|
|
|
5, Config.USE_LAST_VIEW)
|
2007-11-22 21:43:10 +05:30
|
|
|
self.add_pos_int_entry(table,
|
|
|
|
_('Number of generations for relationship determination'),
|
|
|
|
6, Config.GENERATION_DEPTH, self.update_gen_depth)
|
2007-12-01 05:20:05 +05:30
|
|
|
self.path_entry = gtk.Entry()
|
|
|
|
self.add_path_box(table, _('Base path for relative media paths'),
|
|
|
|
7, self.path_entry, self.dbstate.db.get_mediapath(),
|
|
|
|
self.set_mediapath, self.select_mediapath)
|
2006-04-26 07:14:03 +05:30
|
|
|
|
|
|
|
return table
|
|
|
|
|
2007-06-17 04:47:29 +05:30
|
|
|
def add_database_panel(self):
|
2007-07-12 09:54:44 +05:30
|
|
|
table = gtk.Table(3, 8)
|
2007-06-17 04:47:29 +05:30
|
|
|
table.set_border_width(12)
|
|
|
|
table.set_col_spacings(6)
|
|
|
|
table.set_row_spacings(6)
|
|
|
|
|
|
|
|
self.add_entry(table, _('Database path'), 0, Config.DATABASE_PATH)
|
2007-07-12 09:54:44 +05:30
|
|
|
self.add_checkbox(table, _('Automatically backup database on exit'),
|
2007-06-17 04:47:29 +05:30
|
|
|
1, Config.ENABLE_AUTOBACKUP)
|
2007-07-12 09:54:44 +05:30
|
|
|
self.add_checkbox(table, _('Automatically load last database'),
|
2007-06-17 04:47:29 +05:30
|
|
|
2, Config.AUTOLOAD)
|
2007-07-12 09:54:44 +05:30
|
|
|
self.add_checkbox(table, _('Enable database transactions'),
|
2007-06-17 04:47:29 +05:30
|
|
|
3, Config.TRANSACTIONS)
|
|
|
|
return table
|
|
|
|
|
2006-04-26 07:14:03 +05:30
|
|
|
def add_checkbox(self, table, label, index, constant):
|
|
|
|
checkbox = gtk.CheckButton(label)
|
|
|
|
checkbox.set_active(Config.get(constant))
|
2007-07-12 09:54:44 +05:30
|
|
|
checkbox.connect('toggled', self.update_checkbox, constant)
|
2006-04-26 07:14:03 +05:30
|
|
|
table.attach(checkbox, 1, 3, index, index+1, yoptions=0)
|
2007-12-01 05:20:05 +05:30
|
|
|
|
|
|
|
def add_path_box(self, table, label, index, entry, path, callback_label,
|
|
|
|
callback_sel):
|
|
|
|
''' Add an entry to give in path and a select button to open a
|
|
|
|
dialog.
|
|
|
|
Changing entry calls callback_label
|
|
|
|
Clicking open button call callback_sel
|
|
|
|
'''
|
|
|
|
lwidget = BasicLabel("%s: " %label)
|
|
|
|
hbox = gtk.HBox()
|
|
|
|
if path:
|
|
|
|
entry.set_text(path)
|
|
|
|
entry.connect('changed', callback_label)
|
|
|
|
btn = gtk.Button()
|
|
|
|
btn.connect('clicked', callback_sel)
|
|
|
|
image = gtk.Image()
|
|
|
|
image.set_from_stock(gtk.STOCK_OPEN, gtk.ICON_SIZE_BUTTON)
|
|
|
|
image.show()
|
|
|
|
btn.add(image)
|
|
|
|
hbox.pack_start(entry, expand=True, fill=True)
|
|
|
|
hbox.pack_start(btn, expand=False, fill=False)
|
|
|
|
table.attach(lwidget, 1, 2, index, index+1, yoptions=0,
|
|
|
|
xoptions=gtk.FILL)
|
|
|
|
table.attach(hbox, 2, 3, index, index+1, yoptions=0)
|
|
|
|
|
2006-04-26 07:14:03 +05:30
|
|
|
def add_entry(self, table, label, index, constant):
|
|
|
|
lwidget = BasicLabel("%s: " % label)
|
|
|
|
entry = gtk.Entry()
|
|
|
|
entry.set_text(Config.get(constant))
|
|
|
|
entry.connect('changed', self.update_entry, constant)
|
2007-07-12 09:54:44 +05:30
|
|
|
table.attach(lwidget, 0, 1, index, index+1, yoptions=0,
|
2006-05-13 09:23:06 +05:30
|
|
|
xoptions=gtk.FILL)
|
|
|
|
table.attach(entry, 1, 2, index, index+1, yoptions=0)
|
2006-04-26 07:14:03 +05:30
|
|
|
|
2007-11-22 21:43:10 +05:30
|
|
|
def add_pos_int_entry(self, table, label, index, constant, callback=None):
|
|
|
|
''' entry field for positive integers
|
|
|
|
'''
|
|
|
|
lwidget = BasicLabel("%s: " % label)
|
|
|
|
entry = gtk.Entry()
|
|
|
|
entry.set_text(str(Config.get(constant)))
|
|
|
|
if callback:
|
|
|
|
entry.connect('changed', callback, constant)
|
|
|
|
table.attach(lwidget, 1, 2, index, index+1, yoptions=0,
|
|
|
|
xoptions=gtk.FILL)
|
|
|
|
table.attach(entry, 2, 3, index, index+1, yoptions=0)
|
|
|
|
|
2006-05-12 23:50:18 +05:30
|
|
|
def add_color(self, table, label, index, constant):
|
|
|
|
lwidget = BasicLabel("%s: " % label)
|
|
|
|
hexval = Config.get(constant)
|
|
|
|
color = gtk.gdk.color_parse(hexval)
|
|
|
|
entry = gtk.ColorButton(color=color)
|
2006-05-13 10:00:47 +05:30
|
|
|
color_hex_label = BasicLabel(hexval)
|
2007-07-12 09:54:44 +05:30
|
|
|
entry.connect('color-set', self.update_color, constant, color_hex_label)
|
|
|
|
table.attach(lwidget, 0, 1, index, index+1, yoptions=0,
|
2006-05-13 09:23:06 +05:30
|
|
|
xoptions=gtk.FILL)
|
|
|
|
table.attach(entry, 1, 2, index, index+1, yoptions=0, xoptions=0)
|
2006-05-13 10:00:47 +05:30
|
|
|
table.attach(color_hex_label, 2, 3, index, index+1, yoptions=0)
|
2006-05-13 10:42:19 +05:30
|
|
|
return entry
|
2006-05-12 23:50:18 +05:30
|
|
|
|
2007-12-01 05:20:05 +05:30
|
|
|
def set_mediapath(self, *obj):
|
|
|
|
if self.path_entry.get_text().strip():
|
|
|
|
self.dbstate.db.set_mediapath(self.path_entry.get_text())
|
|
|
|
else:
|
|
|
|
self.dbstate.db.set_mediapath(None)
|
|
|
|
|
|
|
|
def select_mediapath(self, *obj):
|
|
|
|
f = gtk.FileChooserDialog(
|
|
|
|
_("Select media directory"),
|
|
|
|
action=gtk.FILE_CHOOSER_ACTION_CREATE_FOLDER,
|
|
|
|
buttons=(gtk.STOCK_CANCEL,
|
|
|
|
gtk.RESPONSE_CANCEL,
|
|
|
|
gtk.STOCK_APPLY,
|
|
|
|
gtk.RESPONSE_OK))
|
|
|
|
mpath = self.dbstate.db.get_mediapath()
|
|
|
|
if not mpath:
|
|
|
|
mpath = const.HOME_DIR
|
|
|
|
f.set_current_folder(os.path.dirname(mpath))
|
|
|
|
|
|
|
|
status = f.run()
|
|
|
|
if status == gtk.RESPONSE_OK:
|
|
|
|
val = Utils.get_unicode_path(f.get_filename())
|
|
|
|
if val:
|
|
|
|
self.path_entry.set_text(val)
|
|
|
|
f.destroy()
|
|
|
|
|
2006-04-26 07:14:03 +05:30
|
|
|
def update_entry(self, obj, constant):
|
|
|
|
Config.set(constant, unicode(obj.get_text()))
|
|
|
|
|
2007-11-22 21:43:10 +05:30
|
|
|
def update_gen_depth(self, obj, constant):
|
|
|
|
ok = True
|
|
|
|
if not obj.get_text():
|
|
|
|
return
|
|
|
|
try:
|
|
|
|
intval = int(obj.get_text())
|
|
|
|
except:
|
|
|
|
intval = Config.get(constant)
|
|
|
|
ok = False
|
|
|
|
if intval < 0 :
|
|
|
|
intval = Config.get(constant)
|
|
|
|
ok = False
|
|
|
|
if ok:
|
|
|
|
Config.set(constant, intval)
|
|
|
|
#immediately use this value in displaystate.
|
|
|
|
self.uistate.set_gendepth(intval)
|
|
|
|
else:
|
|
|
|
obj.set_text(str(intval))
|
|
|
|
|
2006-05-13 10:00:47 +05:30
|
|
|
def update_color(self, obj, constant, color_hex_label):
|
2006-05-12 23:50:18 +05:30
|
|
|
color = obj.get_color()
|
2007-07-12 09:54:44 +05:30
|
|
|
hexval = "#%02x%02x%02x" % (color.red/256,
|
|
|
|
color.green/256,
|
2006-05-12 23:50:18 +05:30
|
|
|
color.blue/256)
|
2006-05-13 10:00:47 +05:30
|
|
|
color_hex_label.set_text(hexval)
|
2006-05-12 23:50:18 +05:30
|
|
|
Config.set(constant, hexval)
|
|
|
|
|
2006-04-26 07:14:03 +05:30
|
|
|
def update_checkbox(self, obj, constant):
|
|
|
|
Config.set(constant, obj.get_active())
|
|
|
|
|
2007-07-12 09:54:44 +05:30
|
|
|
def build_menu_names(self, obj):
|
|
|
|
return (_('Preferences'), None)
|
2006-06-16 02:37:41 +05:30
|
|
|
|
2006-07-16 20:14:13 +05:30
|
|
|
# FIXME: is this needed?
|
|
|
|
def _set_button(stock):
|
|
|
|
button = gtk.Button()
|
|
|
|
image = gtk.Image()
|
|
|
|
image.set_from_stock(stock, gtk.ICON_SIZE_BUTTON)
|
|
|
|
image.show()
|
|
|
|
button.add(image)
|
|
|
|
button.show()
|
|
|
|
return button
|
|
|
|
|
|
|
|
class NameFormatEditDlg:
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
2007-06-22 11:27:48 +05:30
|
|
|
def __init__(self, fmt_name, fmt_str, name):
|
2006-07-16 20:14:13 +05:30
|
|
|
self.fmt_name = fmt_name
|
|
|
|
self.fmt_str = fmt_str
|
|
|
|
self.name = name
|
2007-06-22 11:27:48 +05:30
|
|
|
self.valid = True
|
2006-07-16 20:14:13 +05:30
|
|
|
|
2007-09-08 11:24:02 +05:30
|
|
|
self.top = gtk.glade.XML(const.GLADE_FILE, 'namefmt_edit', 'gramps')
|
2006-07-16 20:14:13 +05:30
|
|
|
self.dlg = self.top.get_widget('namefmt_edit')
|
2006-11-27 08:54:39 +05:30
|
|
|
ManagedWindow.set_titles(self.dlg, None, _('Name Format Editor'))
|
2006-07-16 20:14:13 +05:30
|
|
|
|
|
|
|
self.examplelabel = self.top.get_widget('example_label')
|
|
|
|
|
|
|
|
self.nameentry = self.top.get_widget('name_entry')
|
2007-12-10 07:21:39 +05:30
|
|
|
self.nameentry.set_text('<span weight="bold">%s</span>' % self.fmt_name)
|
|
|
|
self.nameentry.set_use_markup(True)
|
2006-07-16 20:14:13 +05:30
|
|
|
|
|
|
|
self.formatentry = self.top.get_widget('format_entry')
|
2007-06-22 11:27:48 +05:30
|
|
|
self.formatentry.connect('changed', self.cb_format_changed)
|
2006-07-16 20:14:13 +05:30
|
|
|
self.formatentry.set_text(self.fmt_str)
|
|
|
|
|
|
|
|
def run(self):
|
2006-07-30 02:26:11 +05:30
|
|
|
running = True
|
|
|
|
while running:
|
|
|
|
self.response = self.dlg.run()
|
|
|
|
|
|
|
|
running = False
|
|
|
|
self.fmt_name = self.nameentry.get_text()
|
|
|
|
self.fmt_str = self.formatentry.get_text()
|
|
|
|
|
|
|
|
if self.response == gtk.RESPONSE_OK:
|
2007-06-22 11:27:48 +05:30
|
|
|
if not self.valid:
|
|
|
|
q = QuestionDialog.QuestionDialog2(
|
2007-07-12 09:54:44 +05:30
|
|
|
_('The format definition is invalid'),
|
|
|
|
_('What would you like to do?'),
|
|
|
|
_('_Continue anyway'), _('_Modify format'),
|
2007-06-22 11:27:48 +05:30
|
|
|
parent=self.dlg)
|
|
|
|
running = not q.run()
|
|
|
|
self.response = gtk.RESPONSE_CANCEL
|
|
|
|
elif self.fmt_name == '' and self.fmt_str == '':
|
2006-07-30 02:26:11 +05:30
|
|
|
self.response = gtk.RESPONSE_CANCEL
|
|
|
|
elif (self.fmt_name == '') ^ (self.fmt_str == ''):
|
|
|
|
QuestionDialog.ErrorDialog(
|
2007-07-12 09:54:44 +05:30
|
|
|
_('Both Format name and definition have to be defined'),
|
2006-07-30 02:26:11 +05:30
|
|
|
parent=self.dlg)
|
|
|
|
running = True
|
2006-07-16 20:14:13 +05:30
|
|
|
|
|
|
|
self.dlg.destroy()
|
|
|
|
return (self.response, self.fmt_name, self.fmt_str)
|
|
|
|
|
2007-06-22 11:27:48 +05:30
|
|
|
def cb_format_changed(self, obj):
|
2007-06-18 10:30:51 +05:30
|
|
|
try:
|
2007-06-22 11:27:48 +05:30
|
|
|
t = (_nd.format_str(self.name, escape(obj.get_text())))
|
|
|
|
sample = '<span weight="bold" style="italic">%s</span>' % t
|
|
|
|
self.valid = True
|
|
|
|
except NameDisplayError:
|
|
|
|
t = _("Invalid or incomplete format definition")
|
|
|
|
sample = '<span foreground="#FF0000">%s</span>' % t
|
|
|
|
self.valid = False
|
|
|
|
|
|
|
|
self.examplelabel.set_text(sample)
|
2006-07-16 20:14:13 +05:30
|
|
|
self.examplelabel.set_use_markup(True)
|
2007-12-11 20:05:57 +05:30
|
|
|
self.nameentry.set_text('<span weight="bold">%s</span>' % obj.get_text())
|
2007-12-10 07:21:39 +05:30
|
|
|
self.nameentry.set_use_markup(True)
|