From ac86b176a06e86c7a0fafe5be73ac543bb775659 Mon Sep 17 00:00:00 2001 From: Don Allingham Date: Fri, 24 Sep 2004 22:05:46 +0000 Subject: [PATCH] * src/DateDisplay.py: use LC_TIME and D_FMT to determine the locale date format * src/DateHandler.py: en.US to en_US * src/ReadGedcom.py: Allow user overriding of character set * src/StartupDialog.py: remove date entry setting * src/gedcomimport.glade: Allow user overriding of character set * src/gramps.py: set LC_TIME based of LANG * src/data/gramps.schemas: remove date entry setting * src/DateDisplay.py: use unicode encodings for french months svn: r3571 --- ChangeLog | 12 ++- src/DateDisplay.py | 18 ++-- src/DateHandler.py | 5 +- src/ReadGedcom.py | 47 +++++++++- src/StartupDialog.py | 76 ---------------- src/data/gramps.schemas | 14 --- src/gedcomimport.glade | 191 ++++++++++++++++++++++++++++++++++++++++ src/gramps.py | 1 + 8 files changed, 257 insertions(+), 107 deletions(-) diff --git a/ChangeLog b/ChangeLog index 765e2d5c4..114288e9c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,7 +1,17 @@ +2004-09-24 Don Allingham + * src/DateDisplay.py: use LC_TIME and D_FMT to determine + the locale date format + * src/DateHandler.py: en.US to en_US + * src/ReadGedcom.py: Allow user overriding of character set + * src/StartupDialog.py: remove date entry setting + * src/gedcomimport.glade: Allow user overriding of character set + * src/gramps.py: set LC_TIME based of LANG + * src/data/gramps.schemas: remove date entry setting + 2004-09-23 Don Allingham * src/Date.py: display calendar * src/DateParser.py: parse based on calendars - * src/DateDisplay.py: use unicode encodings for french monts + * src/DateDisplay.py: use unicode encodings for french months 2004-09-22 Don Allingham * src/EditPerson.py: change sort mechanism to new Date sort value diff --git a/src/DateDisplay.py b/src/DateDisplay.py index 38bb3b237..71495b878 100644 --- a/src/DateDisplay.py +++ b/src/DateDisplay.py @@ -30,6 +30,7 @@ __version__ = "$Revision$" import Date import locale +import time class DateDisplay: """ @@ -37,7 +38,7 @@ class DateDisplay: """ formats = ( - "YYYY-MM-DD", "MM/DD/YYYY", "Month Day, Year", + "YYYY-MM-DD (ISO)", "Numerical", "Month Day, Year", "MON DAY, YEAR", "Day Month Year", "DAY MON YEAR" ) @@ -88,6 +89,8 @@ class DateDisplay: unicode(locale.nl_langinfo(locale.ABMON_11),_codeset), unicode(locale.nl_langinfo(locale.ABMON_12),_codeset), ) + + _tformat = locale.nl_langinfo(locale.D_FMT) _hebrew = ( "", "Tishri", "Heshvan", "Kislev", "Tevet", "Shevat", @@ -127,7 +130,7 @@ class DateDisplay: self.format = 0 else: self.format = format - + self.display_cal = [ self._display_gregorian, self._display_julian, @@ -204,14 +207,11 @@ class DateDisplay: else: return "%s-%d-%d" % (year,date_val[1],date_val[0]) elif self.format == 1: - # MM/DD/YYYY (American numericalO) - if date_val[0] == 0: - if date_val[1] == 0: - return "%d" % date_val[2] - else: - return "%d/%d" % (date_val[1],date_val[2]) + if date_val[0] == 0 and date_val[1] == 0: + return str(date_val[2]) else: - return "%d/%d/%d" % (date_val[1],date_val[0],date_val[2]) + return time.strftime(self._tformat,(date_val[2],date_val[1], + date_val[0],0,0,0,0,0,0)) elif self.format == 2: # Month Day, Year if date_val[0] == 0: diff --git a/src/DateHandler.py b/src/DateHandler.py index de1451285..7ce65a410 100644 --- a/src/DateHandler.py +++ b/src/DateHandler.py @@ -16,12 +16,12 @@ _lang = os.environ.get('LANG','C') _lang_to_parser = { 'C' : DateParser.DateParser, - 'en.US' : DateParser.DateParser, + 'en_US' : DateParser.DateParser, } _lang_to_display = { 'C' : DateDisplay.DateDisplay, - 'en.US' : DateDisplay.DateDisplay, + 'en_US' : DateDisplay.DateDisplay, } def create_parser(): @@ -48,7 +48,6 @@ def set_format(val): try: _lang_to_display[_lang].display_format = val except: - print "not found" pass def get_format(): diff --git a/src/ReadGedcom.py b/src/ReadGedcom.py index b3a0bc54d..2ec48aee6 100644 --- a/src/ReadGedcom.py +++ b/src/ReadGedcom.py @@ -125,6 +125,33 @@ def importData(database, filename, cb=None): global callback + f = open(filename,"r") + + ansel = False + gramps = False + for index in range(0,50): + line = f.readline().split() + if line[1] == 'CHAR' and line[2] == "ANSEL": + ansel = True + if line[1] == 'SOUR' and line[2] == "GRAMPS": + gramps = True + f.close() + + if not gramps and ansel: + glade_file = "%s/gedcomimport.glade" % os.path.dirname(__file__) + top = gtk.glade.XML(glade_file,'encoding','gramps') + code = top.get_widget('codeset') + code.set_active(0) + dialog = top.get_widget('encoding') + dialog.run() + codeset = code.get_active() + dialog.destroy() + else: + codeset = None + import2(database, filename, cb, codeset) + + +def import2(database, filename, cb, codeset): # add some checking here glade_file = "%s/gedcomimport.glade" % os.path.dirname(__file__) @@ -143,7 +170,7 @@ def importData(database, filename, cb=None): }) try: - g = GedcomParser(database,filename,statusTop) + g = GedcomParser(database,filename,statusTop, codeset) except IOError,msg: Utils.destroy_passed_object(statusWindow) ErrorDialog(_("%s could not be opened\n") % filename,str(msg)) @@ -202,7 +229,7 @@ class GedcomParser: SyntaxError = "Syntax Error" BadFile = "Not a GEDCOM file" - def __init__(self, dbase, file, window): + def __init__(self, dbase, file, window, codeset): self.dp = DateParser.DateParser() self.db = dbase self.person = None @@ -230,7 +257,17 @@ class GedcomParser: self.filename = file self.index = 0 self.backoff = 0 - self.cnv = nocnv + self.override = codeset != None + + if self.override: + if self.override == 0: + self.cnv = ansel_to_utf8 + elif self.override == 1: + self.cnv = latin_utf8.latin_to_utf8 + else: + self.cnv = nocnv + else: + self.cnv = nocnv self.geddir = os.path.dirname(os.path.normpath(os.path.abspath(file))) @@ -1554,7 +1591,7 @@ class GedcomParser: if genby == "GRAMPS": self.gedsource = self.gedmap.get_from_source_tag(matches[2]) self.broken_conc = self.gedsource.get_conc() - elif matches[1] == "CHAR": + elif matches[1] == "CHAR" and not self.override: if matches[2] == "UNICODE" or matches[2] == "UTF-8" or matches[2] == "UTF8": self.cnv = nocnv elif matches[2] == "ANSEL": @@ -1564,6 +1601,8 @@ class GedcomParser: self.ignore_sub_junk(2) if self.window: self.update(self.encoding_obj,matches[2]) + else: + self.update(self.encoding_obj,_("Overridden")) elif matches[1] == "GEDC": self.ignore_sub_junk(2) elif matches[1] == "_SCHEMA": diff --git a/src/StartupDialog.py b/src/StartupDialog.py index f194ce476..3363c6f73 100644 --- a/src/StartupDialog.py +++ b/src/StartupDialog.py @@ -52,8 +52,6 @@ class StartupDialog: self.w.add(d) d.add(self.build_page1()) d.add(self.build_page2()) - d.add(self.build_page3()) - d.add(self.build_page4()) d.add(self.build_page5()) d.add(self.build_page_last()) @@ -106,14 +104,6 @@ class StartupDialog: GrampsCfg.save_researcher_phone(unicode(self.phone.get_text())) GrampsCfg.save_researcher_email(unicode(self.email.get_text())) - if self.date1.get_active(): - GrampsCfg.save_date_entry(0) - elif self.date2.get_active(): - GrampsCfg.save_date_entry(1) - elif self.date3.get_active(): - GrampsCfg.save_date_entry(2) - - GrampsCfg.save_calendar(self.calendar.get_active()) GrampsCfg.save_uselds(self.lds.get_active()) GrampsCfg.save_startup(const.startup) self.w.destroy() @@ -174,72 +164,6 @@ class StartupDialog: return p - def build_page3(self): - p = gnome.ui.DruidPageStandard() - p.set_title(_('Numerical date formats')) - p.set_title_foreground(self.fg_color) - p.set_background(self.bg_color) - p.set_logo(self.logo) - - box = gtk.VBox() - box.set_spacing(12) - p.append_item("",box,"") - - label = gtk.Label(_('There are three common formats for entering dates in a numerical\n' - 'format. Without some type of indication, GRAMPS cannot correctly\n' - 'tell what format you are using. Please indicate your preferred format\n' - 'for entering numerical dates.')) - box.add(label) - align = gtk.Alignment(0.5,0) - box.add(align) - vbox = gtk.VBox() - vbox.set_spacing(6) - align.add(vbox) - - self.date1 = gtk.RadioButton(label=_("MM/DD/YYYY (United States)")) - self.date2 = gtk.RadioButton(label=_("DD/MM/YYYY (European)"),group=self.date1) - self.date3 = gtk.RadioButton(label=_("YYYY-MM-DD (ISO)"),group=self.date1) - - val = GrampsCfg.get_date_entry() - - if val == 0: - self.date1.set_active(1) - elif val == 1: - self.date2.set_active(1) - elif val == 2: - self.date3.set_active(1) - - vbox.add(self.date1) - vbox.add(self.date2) - vbox.add(self.date3) - - box.show_all() - return p - - def build_page4(self): - p = gnome.ui.DruidPageStandard() - p.set_title(_('Alternate calendar support')) - p.set_title_foreground(self.fg_color) - p.set_background(self.bg_color) - p.set_logo(self.logo) - - box = gtk.VBox() - box.set_spacing(12) - p.append_item("",box,"") - - label = gtk.Label(_('By default, all dates stored by GRAMPS use the Gregorian calendar.\n' - 'This is normally sufficient for most users. Support may be enabled\n' - 'for the Julian, French Republican, and Hebrew calendar. If you believe\n' - 'that you will need one or more of these alternate calendars, enable\n' - 'alternate calendar support\n')) - box.add(label) - align = gtk.Alignment(0.5,0) - box.add(align) - vbox = gtk.VBox() - vbox.set_spacing(6) - box.show_all() - return p - def build_page5(self): p = gnome.ui.DruidPageStandard() p.set_title(_('LDS extensions')) diff --git a/src/data/gramps.schemas b/src/data/gramps.schemas index f433d2e89..ca6b07fb5 100644 --- a/src/data/gramps.schemas +++ b/src/data/gramps.schemas @@ -28,20 +28,6 @@ - - /schemas/apps/gramps/preferences/date-entry - /apps/gramps/preferences/date-entry - gramps - int - 0 - - Date entry format - This key determines the date entry format. O corresponds to - the MM/DD/YYYY (US format), 1 corrsponds to DD/MM/YYYY (European - format), and 2 corresponds to YYYY-MM-DD (ISO format). - - - /schemas/apps/gramps/preferences/date-format /apps/gramps/preferences/date-format diff --git a/src/gedcomimport.glade b/src/gedcomimport.glade index 90befce33..78f1d8756 100644 --- a/src/gedcomimport.glade +++ b/src/gedcomimport.glade @@ -13,6 +13,11 @@ 500 True False + True + False + False + GDK_WINDOW_TYPE_HINT_NORMAL + GDK_GRAVITY_NORTH_WEST @@ -181,6 +186,8 @@ True True False + False + True GTK_JUSTIFY_LEFT GTK_WRAP_WORD True @@ -265,6 +272,8 @@ True True False + False + True GTK_JUSTIFY_LEFT GTK_WRAP_NONE True @@ -486,6 +495,7 @@ gtk-close True GTK_RELIEF_NORMAL + True @@ -500,4 +510,185 @@ + + 400 + True + GRAMPS - GEDCOM Encoding + GTK_WINDOW_TOPLEVEL + GTK_WIN_POS_NONE + False + True + False + True + False + False + GDK_WINDOW_TYPE_HINT_DIALOG + GDK_GRAVITY_NORTH_WEST + False + + + + True + False + 0 + + + + True + GTK_BUTTONBOX_END + + + + True + True + True + gtk-ok + True + GTK_RELIEF_NORMAL + True + -5 + + + + + 0 + False + True + GTK_PACK_END + + + + + + True + False + 0 + + + + True + <span size="larger" weight="bold">GEDCOM Encoding</span> + False + True + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 6 + False + False + + + + + + True + This GEDCOM file has identified itself as using ANSEL enconding. Sometimes, this is in error. If the imported data contains unusual characters, undo the import, and override the character set by selecting a different encoding below. + False + False + GTK_JUSTIFY_LEFT + True + False + 0.5 + 0.5 + 6 + 6 + + + 0 + False + False + + + + + + 6 + True + False + 6 + + + + + + + + True + False + 0 + + + + True + Encoding: + False + False + GTK_JUSTIFY_LEFT + False + False + 0.5 + 0.5 + 0 + 0 + + + 0 + False + False + + + + + + True + ANSEL +ANSI (iso-8859-1) +ASCII +UNICODE + + + 0 + True + True + + + + + 0 + True + True + + + + + + + + + 0 + True + True + + + + + + + + + 0 + True + True + + + + + + diff --git a/src/gramps.py b/src/gramps.py index 2bf1ef79f..6c5dd68cd 100755 --- a/src/gramps.py +++ b/src/gramps.py @@ -56,6 +56,7 @@ else: try: locale.setlocale(locale.LC_ALL,'') + locale.setlocale(locale.LC_TIME,os.environ.get('LANG','C')) except locale.Error: pass except ValueError: