2007-05-14 Espen Berg <espen.berg@ntnu.no>

* src/DateHandler/_Date_nb.py: 



svn: r8470
This commit is contained in:
Don Allingham 2007-05-15 03:35:59 +00:00
parent c7de89499c
commit f00b8f381c
3 changed files with 270 additions and 86 deletions

View File

@ -1,3 +1,6 @@
2007-05-14 Espen Berg <espen.berg@ntnu.no>
* src/DateHandler/_Date_nb.py:
2007-05-13 Brian Matherly <brian@gramps-project.org>
* src/plugins/NarrativeWeb.py: Fix reference paths on Windows.

View File

@ -0,0 +1,171 @@
# -*- coding: utf-8 -*-
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2004-2006 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# $Id: _Date_nb.py 2007-05-10 13:37:16Z espenbe $
"""
Nowegian-specific classes for parsing and displaying dates.
"""
#-------------------------------------------------------------------------
#
# Python modules
#
#-------------------------------------------------------------------------
import re
#-------------------------------------------------------------------------
#
# GRAMPS modules
#
#-------------------------------------------------------------------------
from RelLib import Date
from _DateParser import DateParser
from _DateDisplay import DateDisplay
from _DateHandler import register_datehandler
#-------------------------------------------------------------------------
#
# Swedish parser class
#
#-------------------------------------------------------------------------
class DateParserNb(DateParser):
"""
Converts a text string into a Date object, expecting a date
notation in the swedish language. If the date cannot be converted,
the text string is assigned.
"""
# modifiers before the date
modifier_to_int = {
u'før' : Date.MOD_BEFORE,
u'innen' : Date.MOD_BEFORE,
u'etter' : Date.MOD_AFTER,
u'omkring' : Date.MOD_ABOUT,
u'ca' : Date.MOD_ABOUT,
u'ca' : Date.MOD_ABOUT
}
bce = ["f Kr"]
calendar_to_int = {
u'gregoriansk ' : Date.CAL_GREGORIAN,
u'g' : Date.CAL_GREGORIAN,
u'juliansk' : Date.CAL_JULIAN,
u'j' : Date.CAL_JULIAN,
u'hebraisk' : Date.CAL_HEBREW,
u'h' : Date.CAL_HEBREW,
u'islamisk' : Date.CAL_ISLAMIC,
u'muslimsk' : Date.CAL_ISLAMIC,
u'i' : Date.CAL_ISLAMIC,
u'fransk' : Date.CAL_FRENCH,
u'fransk republikansk' : Date.CAL_FRENCH,
u'f' : Date.CAL_FRENCH,
u'persisk' : Date.CAL_PERSIAN,
u'p' : Date.CAL_PERSIAN,
}
quality_to_int = {
u'estimert' : Date.QUAL_ESTIMATED,
u'estimert' : Date.QUAL_ESTIMATED,
u'antatt' : Date.QUAL_ESTIMATED,
u'antatt' : Date.QUAL_ESTIMATED,
u'beregnet' : Date.QUAL_CALCULATED,
u'beregnet' : Date.QUAL_CALCULATED,
}
def init_strings(self):
DateParser.init_strings(self)
self._span = re.compile(u"(fra)?\s*(?P<start>.+)\s*(til|--|)\s*(?P<stop>.+)",
re.IGNORECASE)
self._range = re.compile(u"(mellom)\s+(?P<start>.+)\s+og\s+(?P<stop>.+)",
re.IGNORECASE)
#-------------------------------------------------------------------------
#
# Swedish display class
#
#-------------------------------------------------------------------------
class DateDisplayNb(DateDisplay):
"""
Norwegian language date display class.
"""
formats = (
u"YYYY-MM-DD (ISO)",
u"Numerisk",
u"Måned dag, år",
u"MND DAG ÅR",
u"Dag måned år",
u"DAG MND ÅR",
)
calendar = (
"",
" (juliansk)",
" (hebraisk)",
" (fransk republikansk)",
" (persisk)",
" (islamisk)"
)
_mod_str = ("",u"før ",u"etter ",u"ca ","","","")
_qual_str = ("",u"estimert ",u"beregnet ")
_bce_str = "%s f Kr"
def display(self,date):
"""
Returns a text string representing the date.
"""
mod = date.get_modifier()
cal = date.get_calendar()
qual = date.get_quality()
start = date.get_start_date()
qual_str = self._qual_str[qual]
if mod == Date.MOD_TEXTONLY:
return date.get_text()
elif start == Date.EMPTY:
return u""
elif mod == Date.MOD_SPAN:
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
return u"%sfra %s til %s%s" % (qual_str,d1,d2,self.calendar[cal])
elif mod == Date.MOD_RANGE:
d1 = self.display_cal[cal](start)
d2 = self.display_cal[cal](date.get_stop_date())
return u"%smellom %s og %s%s" % (qual_str,d1,d2,
self.calendar[cal])
else:
text = self.display_cal[date.get_calendar()](start)
return u"%s%s%s%s" % (qual_str,self._mod_str[mod],
text,self.calendar[cal])
#-------------------------------------------------------------------------
#
# Register classes
#
#-------------------------------------------------------------------------
register_datehandler(('nb_NO','nb','norsk'),DateParserNb, DateDisplayNb)

View File

@ -20,6 +20,10 @@
# $Id$
"""
Family Editor dialog
"""
#-------------------------------------------------------------------------
#
# python modules
@ -108,6 +112,9 @@ class ChildEmbedList(EmbeddedList):
_('Children'), ChildModel, True)
def get_popup_menu_items(self):
"""
Creates the data for the popup menu
"""
return [
(True, True, gtk.STOCK_ADD, self.add_button_clicked),
(True, False, _('Share'), self.edit_button_clicked),
@ -123,8 +130,11 @@ class ChildEmbedList(EmbeddedList):
reflist = [ref.ref for ref in self.family.get_child_ref_list()]
return reflist.index(obj)
def _find_row(self,x,y):
row = self.tree.get_path_at_pos(x,y)
def _find_row(self, x_loc, y_loc):
"""
Find the row from x/y coordinates
"""
row = self.tree.get_path_at_pos(x_loc, y_loc)
if row == None:
return len(self.family.get_child_ref_list())
else:
@ -187,7 +197,8 @@ class ChildEmbedList(EmbeddedList):
return self.family
def column_order(self):
return [(1,0),(1,1),(1,2),(1,3),(1,4),(1,5),(1,6),(0,8),(0,9)]
return [(1, 0), (1, 1), (1, 2), (1, 3), (1, 4), (1, 5),
(1, 6), (0, 8), (0, 9)]
def add_button_clicked(self, obj):
from Editors import EditPerson
@ -269,11 +280,11 @@ class ChildEmbedList(EmbeddedList):
for ref in self.family.get_child_ref_list():
if ref.ref == handle:
try:
p = self.dbstate.db.get_person_from_handle(handle)
person = self.dbstate.db.get_person_from_handle(handle)
EditPerson(self.dbstate, self.uistate, self.track,
p, self.child_ref_edited)
person, self.child_ref_edited)
except Errors.WindowActiveError:
pass
continue
break
def drag_data_received(self, widget, context, x, y, sel_data, info, time):
@ -416,9 +427,10 @@ class EditFamily(EditPrimary):
def check_for_family_change(self, handles):
# check to see if the handle matches the current object
if self.obj.get_handle() in handles:
hndl = self.obj.get_handle()
if hndl in handles:
self.obj = self.dbstate.db.get_family_from_handle(self.obj.get_handle())
self.obj = self.dbstate.db.get_family_from_handle(hndl)
self.reload_people()
self.event_embed.rebuild()
self.source_embed.rebuild()
@ -543,13 +555,16 @@ class EditFamily(EditPrimary):
notebook,
ChildEmbedList(self.dbstate, self.uistate, self.track, self.obj))
self.event_embed = EventEmbedList(self.dbstate,self.uistate, self.track,self.obj)
self.event_embed = EventEmbedList(self.dbstate, self.uistate,
self.track, self.obj)
self.event_list = self._add_tab(notebook, self.event_embed)
self.source_embed = SourceEmbedList(self.dbstate,self.uistate,self.track,self.obj)
self.source_embed = SourceEmbedList(self.dbstate, self.uistate,
self.track, self.obj)
self.src_list = self._add_tab(notebook, self.source_embed)
self.attr_embed = FamilyAttrEmbedList(self.dbstate, self.uistate, self.track,
self.attr_embed = FamilyAttrEmbedList(
self.dbstate, self.uistate, self.track,
self.obj.get_attribute_list())
self.attr_list = self._add_tab(notebook, self.attr_embed)
@ -630,8 +645,7 @@ class EditFamily(EditPrimary):
if person:
self.check_for_existing_family(self.obj.get_father_handle(),
person.handle,
self.obj.handle)
person.handle)
self.obj.set_mother_handle(person.handle)
self.update_mother(person.handle)
@ -673,16 +687,13 @@ class EditFamily(EditPrimary):
person = sel.run()
if person:
self.check_for_existing_family(person.handle,
self.obj.get_mother_handle(),
self.obj.handle)
self.obj.get_mother_handle())
self.obj.set_father_handle(person.handle)
self.update_father(person.handle)
def check_for_existing_family(self, father_handle, mother_handle,
family_handle):
def check_for_existing_family(self, father_handle, mother_handle):
if father_handle:
father = self.dbstate.db.get_person_from_handle(father_handle)
@ -814,7 +825,6 @@ class EditFamily(EditPrimary):
self.ok_button.set_sensitive(True)
return
if not original and not self.object_is_empty():
trans = self.db.transaction_begin()