2006-07-16 Zsolt Foldvari <zsolt.foldvari@nokia.com>

* src/ViewManager.py: Custom name format support.
	* src/GrampsCfg.py: Custom name format support.
	* src/RelLib/_Name.py: Custom name format support.
	* src/Editors/_EditName.py: Custom name format support.
	* src/glade/gramps.glade: Custom name format support.
	* src/NameDisplay.py: Custom name format support.



svn: r7032
This commit is contained in:
Alex Roitman 2006-07-16 14:44:13 +00:00
parent 4647713d27
commit 7bfdb53ca9
7 changed files with 756 additions and 241 deletions

View File

@ -1,3 +1,11 @@
2006-07-16 Zsolt Foldvari <zsolt.foldvari@nokia.com>
* src/ViewManager.py: Custom name format support.
* src/GrampsCfg.py: Custom name format support.
* src/RelLib/_Name.py: Custom name format support.
* src/Editors/_EditName.py: Custom name format support.
* src/glade/gramps.glade: Custom name format support.
* src/NameDisplay.py: Custom name format support.
2006-07-15 Don Allingham <don@gramps-project.org>
* src/Config/_GrampsConfigKeys.py: remove unused USE_LDS key
* data/gramps.schemas.in: remove unused USE_LDS key

View File

@ -102,7 +102,7 @@ class EditName(EditSecondary):
format_list += [(name,number) for (number,name,fmt_str)
in RelLib.Name.STANDARD_FORMATS]
format_list += [(name,number) for (number,name,fmt_str)
in NameDisplay.CUSTOM_FORMATS]
in NameDisplay.displayer.CUSTOM_FORMATS]
self.sort_as = MonitoredMenu(
self.top.get_widget('sort_as'),

View File

@ -41,7 +41,7 @@ import gtk
#-------------------------------------------------------------------------
import Config
import DateHandler
import NameDisplay
from NameDisplay import displayer as _nd
from RelLib import Name
import ManagedWindow
from GrampsWidgets import *
@ -59,6 +59,16 @@ _surname_styles = [
_("Icelandic style"),
]
# button names on the 'name format' editor dialog
INS_BTN_NAME = 'insert'
EDT_BTN_NAME = 'edit'
# column numbers for the 'name format' model
COL_NUM = 0
COL_NAME = 1
COL_FMT = 2
COL_EXPL = 3
def set_calendar_date_format():
format_list = DateHandler.get_date_formats()
DateHandler.set_format(Config.get_date_format(format_list))
@ -85,10 +95,12 @@ def get_researcher():
#
#-------------------------------------------------------------------------
class GrampsPreferences(ManagedWindow.ManagedWindow):
def __init__(self, uistate):
def __init__(self, uistate, dbstate):
ManagedWindow.ManagedWindow.__init__(self,uistate,[],GrampsPreferences)
self.dbstate = dbstate
tlabel = gtk.Label()
self.set_window(
gtk.Dialog(_('Preferences'),
@ -204,97 +216,237 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
widget.emit('color-set')
def add_name_panel(self):
table = gtk.Table(3,3)
"""
Name format settings panel
"""
# a dummy name to be used in the examples
self.examplename = Name()
self.examplename.set_title('Dr.')
self.examplename.set_first_name('Edwin')
self.examplename.set_surname_prefix('Rev.')
self.examplename.set_surname('Smith')
self.examplename.set_suffix('Sr')
self.examplename.set_patronymic('patr')
self.examplename.set_call_name('call')
table = gtk.Table(2,3)
table.set_border_width(12)
table.set_col_spacings(6)
table.set_row_spacings(6)
self.name_exp = gtk.expander_new_with_mnemonic(
_('C_ustom format details'))
self.name_exp.set_sensitive(False)
##format_list = []
##format_list += [(name,number) for (number,name,fmt_str)
##in Name.STANDARD_FORMATS]
##format_list += [(name,number) for (number,name,fmt_str)
##in NameDisplay.CUSTOM_FORMATS]
# get the model for the combo and the treeview
# index is used to set the active format in the combo quickly
# and to find an unused index number when a new format is created
(self.fmt_model, self.fmt_index) = self._build_name_format_model()
format_list = []
format_list += [(name,number) for (number,name,fmt_str)
in Name.STANDARD_FORMATS]
format_list += [(name,number) for (number,name,fmt_str)
in NameDisplay.CUSTOM_FORMATS]
obox = gtk.ComboBox()
obox_data = {}
obox_model = gtk.ListStore(str, int)
# set up the combo to choose the preset format
self.fmt_obox = gtk.ComboBox()
cell = gtk.CellRendererText()
obox.pack_start(cell, True)
obox.add_attribute(cell, 'text', 0)
index = 0
for t, v in format_list:
obox_model.append(row=[t, v])
obox_data[v] = index
index += 1
obox.set_model(obox_model)
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
active = int(Config.get(Config.NAME_FORMAT))
obox.set_active(active)
# obox.connect('changed', self.name_changed)
if active == 0 or not self.fmt_index.has_key(active):
active = Name.LNFN
self.fmt_obox.set_active(self.fmt_index[active])
self.fmt_obox.connect('changed', self.cb_name_changed)
# label for the combo
lwidget = BasicLabel("%s: " % _('Preset format'))
# custom_ui = self.build_custom_name_ui()
# self.name_exp.add(custom_ui)
# 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)
table.attach(obox, 1,3,0, 1, yoptions=0)
# table.attach(self.name_exp, 0,3,1, 2, yoptions=0)
table.attach(self.fmt_obox, 1, 3, 0, 1, yoptions=0)
table.attach(name_exp, 0, 3, 1, 2, yoptions=0)
return table
## def build_custom_name_ui(self):
## table = gtk.Table(2,3)
## table.set_border_width(6)
## table.set_col_spacings(6)
## table.set_row_spacings(6)
def _build_name_format_model(self):
"""
Create a common model for ComboBox and TreeView
"""
## avail_sw = gtk.ScrolledWindow()
## avail_sw.set_policy(gtk.POLICY_NEVER,gtk.POLICY_NEVER)
## avail_tree = gtk.TreeView()
## avail_sw.add(avail_tree)
name_format_model = gtk.ListStore(int,str,str,str)
## use_sw = gtk.ScrolledWindow()
## use_sw.set_policy(gtk.POLICY_NEVER,gtk.POLICY_NEVER)
## use_tree = gtk.TreeView()
## use_sw.add(use_tree)
## button_table = gtk.Table(3,3)
## up_button = _set_button(gtk.STOCK_GO_UP)
## down_button = _set_button(gtk.STOCK_GO_DOWN)
## add_button = _set_button(gtk.STOCK_ADD)
## remove_button = _set_button(gtk.STOCK_REMOVE)
## button_table.attach(up_button, 1, 2, 0, 1, xoptions = 0, yoptions=0)
## button_table.attach(remove_button, 2, 3, 1, 2, xoptions = 0,yoptions=0)
## button_table.attach(down_button, 1, 2, 2, 3, xoptions = 0, yoptions=0)
## button_table.attach(add_button, 0, 1, 1, 2, xoptions = 0,yoptions=0)
## example_label = gtk.Label('<b>%s</b>' % _('Example'))
## example_label.set_use_markup(True)
## table.attach(example_label,0,3,0,1,xoptions = 0,yoptions=0)
## table.attach(avail_sw, 0,1,1,2, yoptions=gtk.FILL)
## table.attach(button_table, 1, 2, 1, 2, xoptions = 0, yoptions=0)
## table.attach(use_sw, 2,3,1,2, yoptions=gtk.FILL)
index = 0
name_format_model_index = {}
## return table
# add all the standard formats to the list
for num,name,fmt_str in Name.STANDARD_FORMATS:
self.examplename.set_display_as(num)
name_format_model.append(
row=[num, name, fmt_str, _nd.display_name(self.examplename)])
name_format_model_index[num] = index
index += 1
## def name_changed(self,obj):
## custom_text = NameDisplay.formats[Name.CUSTOM]
## if obj.get_active_text() == custom_text:
## pass
## #self.name_exp.set_sensitive(True)
## #self.name_exp.set_expanded(True)
## else:
## Config.set(Config.NAME_FORMAT,obj.get_active())
## #self.name_exp.set_expanded(False)
## #self.name_exp.set_sensitive(False)
# add all the custom formats loaded from the db to the list
for num,name,fmt_str in _nd.CUSTOM_FORMATS:
self.examplename.set_display_as(num)
name_format_model.append(
row=[num, name, fmt_str, _nd.display_name(self.examplename)])
name_format_model_index[num] = index
index += 1
return (name_format_model, name_format_model_index)
def _build_custom_name_ui(self):
"""
UI to manage the custom name formats
"""
table = gtk.Table(2,3)
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()
name_column = gtk.TreeViewColumn(_('Title'),
name_renderer,
text=COL_NAME)
format_tree.append_column(name_column)
example_renderer = gtk.CellRendererText()
example_column = gtk.TreeViewColumn(_('Example name'),
example_renderer,
text=COL_EXPL)
format_tree.append_column(example_column)
format_tree.get_selection().connect('changed',
self.cb_format_tree_select)
format_tree.set_rules_hint(True)
# ... and put it into a scrolled win
format_sw = gtk.ScrolledWindow()
format_sw.set_policy(gtk.POLICY_AUTOMATIC,gtk.POLICY_NEVER)
format_sw.add(format_tree)
format_sw.set_shadow_type(gtk.SHADOW_IN)
table.attach(format_sw, 0, 3, 0, 1)
# 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)
insert_button.set_name(INS_BTN_NAME)
insert_button.connect('clicked',self.cb_edit_fmt_str)
self.edit_button = gtk.Button(stock=gtk.STOCK_EDIT)
self.edit_button.set_name(EDT_BTN_NAME)
self.edit_button.connect('clicked',self.cb_edit_fmt_str)
self.edit_button.set_sensitive(False)
self.remove_button = gtk.Button(stock=gtk.STOCK_REMOVE)
self.remove_button.connect('clicked',self.cb_del_fmt_str)
self.remove_button.set_sensitive(False)
table.attach(insert_button, 0, 1, 1, 2,)
table.attach(self.remove_button, 1, 2, 1, 2,)
table.attach(self.edit_button, 2, 3, 1, 2,)
return table
def cb_name_changed(self,obj):
"""
Preset name format ComboBox callback
Saves the new default to gconf and NameDisplay's fn_array
"""
list = obj.get_model()
iter = list.get_iter(obj.get_active())
new_idx = list.get_value(iter,COL_NUM)
Config.set(Config.NAME_FORMAT,new_idx)
_nd.set_format_default(new_idx)
def cb_format_tree_select(self, tree_selection):
"""
Name format editor TreeView callback
Remebers the selected row's values (self.selected_fmt, self.iter)
and sets the Remove and Edit button sensitivity
"""
model,self.iter = tree_selection.get_selected()
if self.iter == None:
tree_selection.select_path(0)
model,self.iter = tree_selection.get_selected()
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)
def cb_edit_fmt_str(self,obj):
"""
Name format editor Insert and Edit button callback
"""
n = ''
f = ''
if obj.get_name() == EDT_BTN_NAME:
n = self.selected_fmt[COL_NAME]
f = self.selected_fmt[COL_FMT]
dlg = NameFormatEditDlg(n,f,self.examplename)
(res,n,f) = dlg.run()
if res == gtk.RESPONSE_OK:
# if we created a new format...
if obj.get_name() == INS_BTN_NAME:
i = -1
while self.fmt_index.has_key(i):
i -= 1
self.fmt_model.append(row=[i,n,f,_nd.format_str(self.examplename,f)])
self.fmt_index[i] = len(self.fmt_model) - 1
# ...or if we edited an existing one
else:
if n != self.selected_fmt[COL_NAME] or \
f != self.selected_fmt[COL_FMT]:
e = _nd.format_str(self.examplename,f)
self.fmt_model.set(self.iter,COL_NAME,n,
COL_FMT,f,
COL_EXPL,e)
self.selected_fmt = (self.selected_fmt[COL_NUM],n,f,e)
self.register_fmt()
def cb_del_fmt_str(self,obj):
"""
Name format editor Remove button callback
"""
removed_idx = self.fmt_index[self.selected_fmt[COL_NUM]]
# if the item to be deleted is selected in the combo
if self.fmt_obox.get_active() == removed_idx:
self.fmt_obox.set_active(self.fmt_index[Name.LNFN])
# delete the row from the index...
del(self.fmt_index[self.selected_fmt[COL_NUM]])
for i in self.fmt_index.items():
if i[1] > removed_idx:
self.fmt_index[i[0]] -= 1
# ...and from the model
self.fmt_model.remove(self.iter)
# update the custom format registration in NameDisplay instance
self.register_fmt()
def register_fmt(self):
formats = []
iter = self.fmt_model.get_iter_first()
while iter:
(i,n,f) = self.fmt_model.get(iter,COL_NUM,COL_NAME,COL_FMT)
if i < 0:
formats.append((i,n,f))
iter = self.fmt_model.iter_next(iter)
self.dbstate.db.name_formats = formats
_nd.register_custom_formats(formats)
def add_formats_panel(self):
table = gtk.Table(3,8)
table.set_border_width(12)
@ -414,11 +566,52 @@ class GrampsPreferences(ManagedWindow.ManagedWindow):
def build_menu_names(self,obj):
return (_('Preferences'),None)
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
# 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:
"""
"""
def __init__(self,fmt_name,fmt_str,name):
self.fmt_name = fmt_name
self.fmt_str = fmt_str
self.name = name
self.top = gtk.glade.XML(const.gladeFile,'namefmt_edit','gramps')
self.dlg = self.top.get_widget('namefmt_edit')
ManagedWindow.set_titles(
self.dlg,
self.top.get_widget('title'),
_('Name Format Editor'))
self.examplelabel = self.top.get_widget('example_label')
self.nameentry = self.top.get_widget('name_entry')
self.nameentry.set_text(self.fmt_name)
self.formatentry = self.top.get_widget('format_entry')
self.formatentry.connect('changed',self.cb_format_changed)
self.formatentry.set_text(self.fmt_str)
def run(self):
self.response = self.dlg.run()
self.fmt_name = self.nameentry.get_text()
self.fmt_str = self.formatentry.get_text()
self.dlg.destroy()
return (self.response, self.fmt_name, self.fmt_str)
def cb_format_changed(self,obj):
t = (_nd.format_str(self.name,obj.get_text()))
self.examplelabel.set_text('<span weight="bold" style="italic">%s</span>' % t)
self.examplelabel.set_use_markup(True)

View File

@ -50,15 +50,15 @@ _SORT = 13
_DISPLAY = 14
_CALL = 15
#-------------------------------------------------------------------------
#
# formats registration
#
#-------------------------------------------------------------------------
CUSTOM_FORMATS = []
##-------------------------------------------------------------------------
##
## formats registration
##
##-------------------------------------------------------------------------
##CUSTOM_FORMATS = []
def register_custom_formats(formats):
CUSTOM_FORMATS = formats[:]
##def register_custom_formats(formats):
##CUSTOM_FORMATS = formats[:]
#-------------------------------------------------------------------------
#
@ -84,192 +84,215 @@ class NameDisplay:
@type use_upper: bool
"""
self.gramps_format = Config.get(Config.NAME_FORMAT)
if self.gramps_format == 0:
self.gramps_format = Name.LNFN
self.force_upper = use_upper
##self.force_upper = use_upper
self.CUSTOM_FORMATS = []
self.fn_array = {
Name.LNFN: self._lnfn,
Name.FNLN: self._fnln,
Name.PTFN: self._ptfn,
Name.FN: self._fn,
##Name.LNFN: self._lnfn,
##Name.FNLN: self._fnln,
##Name.PTFN: self._ptfn,
##Name.FN: self._fn,
}
self.raw_fn_array = {
Name.LNFN: self._lnfn_raw,
Name.FNLN: self._fnln_raw,
Name.PTFN: self._ptfn_raw,
Name.FN: self._fn_raw,
##Name.LNFN: self._lnfn_raw,
##Name.FNLN: self._fnln_raw,
##Name.PTFN: self._ptfn_raw,
##Name.FN: self._fn_raw,
}
self.extend_formats()
def extend_formats(self):
# Add custom formats to the mappings
for number,name,fmt_str in CUSTOM_FORMATS:
self.fn_array[number] = lambda x: self._format_str(x,fmt_str)
self.raw_fn_array[number] = lambda x: \
self._format_str_raw(x,fmt_str)
# Add mappings for the gramps-prefs format
self.fn_array[0] = self.fn_array[self.gramps_format]
self.raw_fn_array[0] = self.raw_fn_array[self.gramps_format]
def use_upper(self,upper):
"""
Changes the NameDisplay class to enable or display the displaying
of surnames in upper case.
self.set_format_fn()
@param upper: True indicates that the surname should be
displayed in upper case.
@type upper: bool
"""
self.force_upper = upper
default_idx = Config.get(Config.NAME_FORMAT)
if default_idx == 0:
default_idx = Name.LNFN
self.set_format_default(default_idx)
def _format_fn(self,fmt_str):
return lambda x: self.format_str(x,fmt_str)
def _format_raw_fn(self,fmt_str):
return lambda x: self.format_str_raw(x,fmt_str)
def set_format_fn(self):
# Add standard formats to mappings
for number,name,fmt_str in Name.STANDARD_FORMATS:
self.fn_array[number] = self._format_fn(fmt_str)
self.raw_fn_array[number] = self._format_raw_fn(fmt_str)
# Add custom formats to the mappings
for number,name,fmt_str in self.CUSTOM_FORMATS:
self.fn_array[number] = self._format_fn(fmt_str)
self.raw_fn_array[number] = self._format_raw_fn(fmt_str)
def set_format_default(self,idx):
# Add mappings for the gramps-prefs format
if not self.fn_array.has_key(idx):
idx = Name.LNFN
# this should not happen if the default is kept in the db
self.gramps_format = idx
self.fn_array[0] = self.fn_array[idx]
self.raw_fn_array[0] = self.raw_fn_array[idx]
def register_custom_formats(self,formats):
self.CUSTOM_FORMATS = formats[:]
self.set_format_fn()
##def use_upper(self,upper):
##"""
##Changes the NameDisplay class to enable or display the displaying
##of surnames in upper case.
##@param upper: True indicates that the surname should be
##displayed in upper case.
##@type upper: bool
##"""
##self.force_upper = upper
def sort_string(self,name):
return u"%-25s%-30s%s" % (name.surname,name.first_name,name.suffix)
def _fn(self,name):
return self._fn_base(name.first_name)
##def _fn(self,name):
##return self._fn_base(name.first_name)
def _fn_raw(self,raw_data):
first = raw_data[_FIRSTNAME]
return self._fn_base(first)
##def _fn_raw(self,raw_data):
##first = raw_data[_FIRSTNAME]
##return self._fn_base(first)
def _fn_base(self,first):
return first
##def _fn_base(self,first):
##return first
def _ptfn(self,name):
"""
Prints the Western style first name, last name style.
Typically this is::
##def _ptfn(self,name):
##"""
##Prints the Western style first name, last name style.
##Typically this is::
SurnamePrefix Patronymic SurnameSuffix, FirstName
"""
##SurnamePrefix Patronymic SurnameSuffix, FirstName
##"""
return self._ptfn_base(name.first_name,name.suffix,
name.prefix,name.patronymic)
##return self._ptfn_base(name.first_name,name.suffix,
##name.prefix,name.patronymic)
def _ptfn_raw(self,raw_data):
"""
Prints the Western style first name, last name style.
Typically this is::
##def _ptfn_raw(self,raw_data):
##"""
##Prints the Western style first name, last name style.
##Typically this is::
SurnamePrefix Patronymic SurnameSuffix, FirstName
"""
##SurnamePrefix Patronymic SurnameSuffix, FirstName
##"""
first = raw_data[_FIRSTNAME]
suffix = raw_data[_SUFFIX]
prefix = raw_data[_PREFIX]
patronymic = raw_data[_PATRONYM]
##first = raw_data[_FIRSTNAME]
##suffix = raw_data[_SUFFIX]
##prefix = raw_data[_PREFIX]
##patronymic = raw_data[_PATRONYM]
return self._ptfn_base(first,suffix,prefix,patronymic)
##return self._ptfn_base(first,suffix,prefix,patronymic)
def _ptfn_base(self,first,suffix,prefix,patronymic):
if self.force_upper:
last = patronymic.upper()
else:
last = patronymic
##def _ptfn_base(self,first,suffix,prefix,patronymic):
##if self.force_upper:
##last = patronymic.upper()
##else:
##last = patronymic
if suffix:
if prefix:
return "%s %s %s, %s" % (prefix, last, suffix, first)
else:
return "%s %s, %s" % (last, suffix, first)
else:
if prefix:
return "%s %s, %s" % (prefix, last, first)
else:
return "%s, %s" % (last, first)
##if suffix:
##if prefix:
##return "%s %s %s, %s" % (prefix, last, suffix, first)
##else:
##return "%s %s, %s" % (last, suffix, first)
##else:
##if prefix:
##return "%s %s, %s" % (prefix, last, first)
##else:
##return "%s, %s" % (last, first)
def _fnln(self,name):
"""
Prints the Western style first name, last name style.
Typically this is::
##def _fnln(self,name):
##"""
##Prints the Western style first name, last name style.
##Typically this is::
FirstName Patronymic SurnamePrefix Surname SurnameSuffix
"""
return self._fnln_base(name.first_name,name.surname,name.suffix,
name.prefix,name.patronymic)
##FirstName Patronymic SurnamePrefix Surname SurnameSuffix
##"""
##return self._fnln_base(name.first_name,name.surname,name.suffix,
##name.prefix,name.patronymic)
def _fnln_raw(self,raw_data):
"""
Prints the Western style first name, last name style.
Typically this is::
##def _fnln_raw(self,raw_data):
##"""
##Prints the Western style first name, last name style.
##Typically this is::
FirstName Patronymic SurnamePrefix Surname SurnameSuffix
"""
first = raw_data[_FIRSTNAME]
surname = raw_data[_SURNAME]
suffix = raw_data[_SUFFIX]
prefix = raw_data[_PREFIX]
patronymic = raw_data[_PATRONYM]
return self._fnln_base(first,surname,suffix,prefix,patronymic)
##FirstName Patronymic SurnamePrefix Surname SurnameSuffix
##"""
##first = raw_data[_FIRSTNAME]
##surname = raw_data[_SURNAME]
##suffix = raw_data[_SUFFIX]
##prefix = raw_data[_PREFIX]
##patronymic = raw_data[_PATRONYM]
##return self._fnln_base(first,surname,suffix,prefix,patronymic)
def _fnln_base(self,first,surname,suffix,prefix,patronymic):
if patronymic:
first = "%s %s" % (first, patronymic)
##def _fnln_base(self,first,surname,suffix,prefix,patronymic):
##if patronymic:
##first = "%s %s" % (first, patronymic)
if self.force_upper:
last = surname.upper()
else:
last = surname
##if self.force_upper:
##last = surname.upper()
##else:
##last = surname
if suffix:
if prefix:
return "%s %s %s, %s" % (first, prefix, last, suffix)
else:
return "%s %s, %s" % (first, last, suffix)
else:
if prefix:
return "%s %s %s" % (first, prefix, last)
else:
return "%s %s" % (first, last)
##if suffix:
##if prefix:
##return "%s %s %s, %s" % (first, prefix, last, suffix)
##else:
##return "%s %s, %s" % (first, last, suffix)
##else:
##if prefix:
##return "%s %s %s" % (first, prefix, last)
##else:
##return "%s %s" % (first, last)
def _lnfn(self,name):
"""
Prints the Western style last name, first name style.
Typically this is::
##def _lnfn(self,name):
##"""
##Prints the Western style last name, first name style.
##Typically this is::
SurnamePrefix Surname, FirstName Patronymic SurnameSuffix
"""
return self._lnfn_base(name.first_name,name.surname,name.prefix,
name.suffix,name.patronymic)
##SurnamePrefix Surname, FirstName Patronymic SurnameSuffix
##"""
##return self._lnfn_base(name.first_name,name.surname,name.prefix,
##name.suffix,name.patronymic)
def _lnfn_raw(self,raw_data):
"""
Prints the Western style last name, first name style.
Typically this is::
##def _lnfn_raw(self,raw_data):
##"""
##Prints the Western style last name, first name style.
##Typically this is::
SurnamePrefix Surname, FirstName Patronymic SurnameSuffix
"""
##SurnamePrefix Surname, FirstName Patronymic SurnameSuffix
##"""
surname = raw_data[_SURNAME]
prefix = raw_data[_PREFIX]
first = raw_data[_FIRSTNAME]
patronymic = raw_data[_PATRONYM]
suffix = raw_data[_SUFFIX]
##surname = raw_data[_SURNAME]
##prefix = raw_data[_PREFIX]
##first = raw_data[_FIRSTNAME]
##patronymic = raw_data[_PATRONYM]
##suffix = raw_data[_SUFFIX]
return self._lnfn_base(first,surname,prefix,suffix,patronymic)
##return self._lnfn_base(first,surname,prefix,suffix,patronymic)
def _lnfn_base(self,first,surname,prefix,suffix,patronymic):
if self.force_upper:
last = surname.upper()
else:
last = surname
##def _lnfn_base(self,first,surname,prefix,suffix,patronymic):
##if self.force_upper:
##last = surname.upper()
##else:
##last = surname
if last:
last += ","
##if last:
##last += ","
return " ".join([prefix, last, first, patronymic, suffix])
##return " ".join([prefix, last, first, patronymic, suffix])
def _format_str(self,name,format_str):
def format_str(self,name,format_str):
return self._format_str_base(name.first_name,name.surname,name.prefix,
name.suffix,name.patronymic,name.title,
name.call,format_str)
def _format_str_raw(self,raw_data,format_str):
def format_str_raw(self,raw_data,format_str):
surname = raw_data[_SURNAME]
prefix = raw_data[_PREFIX]
first = raw_data[_FIRSTNAME]
@ -318,7 +341,18 @@ class NameDisplay:
output = output.replace("%C",call.upper())
output = output.replace("%%",'%')
return output
# Suppress multiple spaces
prev_space = -1
namestr = ''
for i in range(len(output)):
if output[i] == ' ':
dist = i - prev_space
prev_space = i
if dist == 1:
continue
namestr += output[i]
return namestr.strip()
def sorted(self,person):
"""

View File

@ -65,10 +65,10 @@ class Name(SecondaryObject,PrivacyBase,SourceBase,NoteBase,DateBase):
(DEF,_("Default format (defined by GRAMPS preferences)"),'')
STANDARD_FORMATS = [
(LNFN, _("Family name, Given name Patronymic"),''),
(FNLN, _("Given name Family name"),''),
(PTFN, _("Patronymic, Given name"),''),
(FN, _("Given name"),'')
(LNFN, _("Family name, Given name Patronymic"),'%p %l, %f %y %s'),
(FNLN, _("Given name Family name"),'%f %y %p %l %s'),
(PTFN, _("Patronymic, Given name"),'%p %y, %s %f'),
(FN, _("Given name"),'%f')
]
def __init__(self,source=None,data=None):

View File

@ -507,7 +507,7 @@ class ViewManager:
def preferences_activate(self, obj):
try:
GrampsCfg.GrampsPreferences(self.uistate)
GrampsCfg.GrampsPreferences(self.uistate,self.state)
except Errors.WindowActiveError:
pass
@ -768,7 +768,10 @@ class ViewManager:
self.state.db.set_researcher(owner)
self.setup_bookmarks()
NameDisplay.register_custom_formats(self.state.db.name_formats)
NameDisplay.displayer.register_custom_formats(self.state.db.name_formats)
fmt_default = Config.get(Config.NAME_FORMAT)
if fmt_default < 0:
NameDisplay.displayer.set_format_default(fmt_default)
self.state.db.enable_signals()
self.state.signal_change()

View File

@ -14721,4 +14721,281 @@ You should select parents before adding any new information. If you select paren
</child>
</widget>
<widget class="GtkDialog" id="namefmt_edit">
<property name="visible">True</property>
<property name="title" translatable="yes"></property>
<property name="type">GTK_WINDOW_TOPLEVEL</property>
<property name="window_position">GTK_WIN_POS_NONE</property>
<property name="modal">True</property>
<property name="default_width">400</property>
<property name="resizable">True</property>
<property name="destroy_with_parent">False</property>
<property name="decorated">True</property>
<property name="skip_taskbar_hint">False</property>
<property name="skip_pager_hint">False</property>
<property name="type_hint">GDK_WINDOW_TYPE_HINT_DIALOG</property>
<property name="gravity">GDK_GRAVITY_NORTH_WEST</property>
<property name="focus_on_map">True</property>
<property name="urgency_hint">False</property>
<property name="has_separator">False</property>
<child internal-child="vbox">
<widget class="GtkVBox" id="dialog-vbox23">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child internal-child="action_area">
<widget class="GtkHButtonBox" id="dialog-action_area23">
<property name="visible">True</property>
<property name="layout_style">GTK_BUTTONBOX_END</property>
<child>
<widget class="GtkButton" id="cancelbutton2">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-cancel</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-6</property>
</widget>
</child>
<child>
<widget class="GtkButton" id="okbutton2">
<property name="visible">True</property>
<property name="can_default">True</property>
<property name="can_focus">True</property>
<property name="label">gtk-ok</property>
<property name="use_stock">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">True</property>
<property name="response_id">-5</property>
</widget>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="pack_type">GTK_PACK_END</property>
</packing>
</child>
<child>
<widget class="GtkVBox" id="vbox127">
<property name="visible">True</property>
<property name="homogeneous">False</property>
<property name="spacing">0</property>
<child>
<widget class="GtkLabel" id="title">
<property name="visible">True</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_CENTER</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">10</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">False</property>
<property name="fill">False</property>
</packing>
</child>
<child>
<widget class="GtkTable" id="table76">
<property name="border_width">12</property>
<property name="visible">True</property>
<property name="n_rows">3</property>
<property name="n_columns">2</property>
<property name="homogeneous">False</property>
<property name="row_spacing">6</property>
<property name="column_spacing">12</property>
<child>
<widget class="GtkLabel" id="name_label">
<property name="visible">True</property>
<property name="label" translatable="yes">_Name:</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_CENTER</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="mnemonic_widget">name_entry</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="format_label">
<property name="visible">True</property>
<property name="label" translatable="yes">_Format:</property>
<property name="use_underline">True</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_CENTER</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="mnemonic_widget">format_entry</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="example_label">
<property name="visible">True</property>
<property name="label" translatable="yes">Example:</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_CENTER</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="name_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">•</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkEntry" id="format_entry">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="editable">True</property>
<property name="visibility">True</property>
<property name="max_length">0</property>
<property name="text" translatable="yes"></property>
<property name="has_frame">True</property>
<property name="invisible_char">•</property>
<property name="activates_default">False</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="example_label">
<property name="visible">True</property>
<property name="label" translatable="yes"></property>
<property name="use_underline">False</property>
<property name="use_markup">True</property>
<property name="justify">GTK_JUSTIFY_CENTER</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">360</property>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
<packing>
<property name="padding">0</property>
<property name="expand">True</property>
<property name="fill">True</property>
</packing>
</child>
</widget>
</child>
</widget>
</glade-interface>