diff --git a/ChangeLog b/ChangeLog index a6530e07e..569dd45ad 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2007-09-09 Don Allingham + * src/Reorder.py: cleanup + * src/TransUtils.py: cleanup + * src/TipOfDay.py: cleanup + * src/SubstKeywords.py: cleanup + * src/Utils.py: cleanup + * src/soundex.py: cleanup + * src/Sort.py: cleanup + 2007-09-09 Don Allingham * src/ViewManager.py: cleanup * src/DisplayState.py: cleanup diff --git a/src/Reorder.py b/src/Reorder.py index 1e45b9bf1..4d8d8fe4c 100644 --- a/src/Reorder.py +++ b/src/Reorder.py @@ -7,7 +7,7 @@ # 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, +# 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. @@ -17,8 +17,6 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # -# $Id: _SourceView.py 7138 2006-08-06 06:26:10Z rshura $ - from gettext import gettext as _ @@ -29,157 +27,157 @@ from BasicUtils import name_displayer import ListModel import ManagedWindow -_parent_titles = [(_('Father'),-1,200),(_('Mother'),-1,200),('',-1,0)] -_family_titles = [(_('Spouse'),-1,200),(_('Relationship'),-1,200),('',-1,0)] +PARENT_TITLES = [(_('Father'), -1, 200), (_('Mother'), -1, 200), ('', -1, 0)] +FAMILY_TITLES = [(_('Spouse'), -1, 200), (_('Relationship'), -1, 200), ('', -1, 0)] class Reorder(ManagedWindow.ManagedWindow): def __init__(self, state, uistate, track, handle): xml = gtk.glade.XML(const.GLADE_FILE, "reorder", "gramps") - top = xml.get_widget('reorder') + top = xml.get_widget('reorder') - self.dbstate = state + self.dbstate = state ManagedWindow.ManagedWindow.__init__(self, uistate, track, self) - self.person = self.dbstate.db.get_person_from_handle(handle) - self.parent_list = self.person.get_parent_family_handle_list() - self.family_list = self.person.get_family_handle_list() + self.person = self.dbstate.db.get_person_from_handle(handle) + self.parent_list = self.person.get_parent_family_handle_list() + self.family_list = self.person.get_family_handle_list() - penable = len(self.parent_list) > 1 - fenable = len(self.family_list) > 1 + penable = len(self.parent_list) > 1 + fenable = len(self.family_list) > 1 - self.set_window(top, None, _("Reorder Relationships")) + self.set_window(top, None, _("Reorder Relationships")) - self.ptree = xml.get_widget('ptree') - self.pmodel = ListModel.ListModel(self.ptree,_parent_titles) + self.ptree = xml.get_widget('ptree') + self.pmodel = ListModel.ListModel(self.ptree, PARENT_TITLES) - self.ftree = xml.get_widget('ftree') - self.fmodel = ListModel.ListModel(self.ftree,_family_titles) + self.ftree = xml.get_widget('ftree') + self.fmodel = ListModel.ListModel(self.ftree, FAMILY_TITLES) - xml.get_widget('ok').connect('clicked', self.ok_clicked) - xml.get_widget('cancel').connect('clicked', self.cancel_clicked) + xml.get_widget('ok').connect('clicked', self.ok_clicked) + xml.get_widget('cancel').connect('clicked', self.cancel_clicked) - fup = xml.get_widget('fup') - fup.connect('clicked', self.fup_clicked) - fup.set_sensitive(fenable) + fup = xml.get_widget('fup') + fup.connect('clicked', self.fup_clicked) + fup.set_sensitive(fenable) - fdown = xml.get_widget('fdown') - fdown.connect('clicked', self.fdown_clicked) - fdown.set_sensitive(fenable) + fdown = xml.get_widget('fdown') + fdown.connect('clicked', self.fdown_clicked) + fdown.set_sensitive(fenable) - pup = xml.get_widget('pup') - pup.connect('clicked', self.pup_clicked) - pup.set_sensitive(penable) + pup = xml.get_widget('pup') + pup.connect('clicked', self.pup_clicked) + pup.set_sensitive(penable) - pdown = xml.get_widget('pdown') - pdown.connect('clicked', self.pdown_clicked) - pdown.set_sensitive(penable) + pdown = xml.get_widget('pdown') + pdown.connect('clicked', self.pdown_clicked) + pdown.set_sensitive(penable) - self.fill_data() + self.fill_data() - self.show() + self.show() def fill_data(self): - self.fill_parents() - self.fill_family() + self.fill_parents() + self.fill_family() def fill_parents(self): - for handle in self.parent_list: - family = self.dbstate.db.get_family_from_handle(handle) - fhandle = family.get_father_handle() - mhandle = family.get_mother_handle() + for handle in self.parent_list: + family = self.dbstate.db.get_family_from_handle(handle) + fhandle = family.get_father_handle() + mhandle = family.get_mother_handle() - fname = "" - if fhandle: - father = self.dbstate.db.get_person_from_handle(fhandle) - if father: - fname = name_displayer.display(father) + fname = "" + if fhandle: + father = self.dbstate.db.get_person_from_handle(fhandle) + if father: + fname = name_displayer.display(father) - mname = "" - if mhandle: - mother = self.dbstate.db.get_person_from_handle(mhandle) - if mother: - mname = name_displayer.display(mother) + mname = "" + if mhandle: + mother = self.dbstate.db.get_person_from_handle(mhandle) + if mother: + mname = name_displayer.display(mother) - self.pmodel.add([fname, mname, handle]) + self.pmodel.add([fname, mname, handle]) def fill_family(self): - for handle in self.family_list: + for handle in self.family_list: - family = self.dbstate.db.get_family_from_handle(handle) - fhandle = family.get_father_handle() - mhandle = family.get_mother_handle() + family = self.dbstate.db.get_family_from_handle(handle) + fhandle = family.get_father_handle() + mhandle = family.get_mother_handle() - name = "" + name = "" - if fhandle and fhandle != self.person.handle: - spouse = self.dbstate.db.get_person_from_handle(fhandle) - if spouse: - name = name_displayer.display(spouse) - elif mhandle: - spouse = self.dbstate.db.get_person_from_handle(mhandle) - if spouse: - name = name_displayer.display(spouse) + if fhandle and fhandle != self.person.handle: + spouse = self.dbstate.db.get_person_from_handle(fhandle) + if spouse: + name = name_displayer.display(spouse) + elif mhandle: + spouse = self.dbstate.db.get_person_from_handle(mhandle) + if spouse: + name = name_displayer.display(spouse) - reltype = str(family.get_relationship()) + reltype = str(family.get_relationship()) - self.fmodel.add([name, reltype, handle]) + self.fmodel.add([name, reltype, handle]) def cancel_clicked(self, obj): - self.close() + self.close() def ok_clicked(self, obj): trans = self.dbstate.db.transaction_begin() - self.dbstate.db.commit_person(self.person, trans) - name = name_displayer.display(self.person) - msg = _("Reorder Relationships: %s") % name + self.dbstate.db.commit_person(self.person, trans) + name = name_displayer.display(self.person) + msg = _("Reorder Relationships: %s") % name self.dbstate.db.transaction_commit(trans, msg) - self.close() + self.close() - def pup_clicked(self,obj): + def pup_clicked(self, obj): """Moves the current selection up one row""" row = self.pmodel.get_selected_row() if not row or row == -1: return - store,the_iter = self.pmodel.get_selected() - data = self.pmodel.get_data(the_iter,xrange(3)) + store, the_iter = self.pmodel.get_selected() + data = self.pmodel.get_data(the_iter, xrange(3)) self.pmodel.remove(the_iter) - self.pmodel.insert(row-1,data,None,1) + self.pmodel.insert(row-1, data, None, 1) handle = self.parent_list.pop(row) - self.parent_list.insert(row-1,handle) + self.parent_list.insert(row-1, handle) def pdown_clicked(self, obj): row = self.pmodel.get_selected_row() if row + 1 >= self.pmodel.count or row == -1: return - store,the_iter = self.pmodel.get_selected() - data = self.pmodel.get_data(the_iter,xrange(3)) + store, the_iter = self.pmodel.get_selected() + data = self.pmodel.get_data(the_iter, xrange(3)) self.pmodel.remove(the_iter) - self.pmodel.insert(row+1,data,None,1) + self.pmodel.insert(row+1, data, None, 1) handle = self.parent_list.pop(row) - self.parent_list.insert(row+1,handle) + self.parent_list.insert(row+1, handle) def fup_clicked(self, obj): row = self.fmodel.get_selected_row() if not row or row == -1: return - store,the_iter = self.fmodel.get_selected() - data = self.fmodel.get_data(the_iter,xrange(3)) + store, the_iter = self.fmodel.get_selected() + data = self.fmodel.get_data(the_iter, xrange(3)) self.fmodel.remove(the_iter) - self.fmodel.insert(row-1,data,None,1) + self.fmodel.insert(row-1, data, None, 1) handle = self.family_list.pop(row) - self.family_list.insert(row-1,handle) + self.family_list.insert(row-1, handle) def fdown_clicked(self, obj): row = self.fmodel.get_selected_row() if row + 1 >= self.fmodel.count or row == -1: return - store,the_iter = self.fmodel.get_selected() - data = self.fmodel.get_data(the_iter,xrange(3)) + store, the_iter = self.fmodel.get_selected() + data = self.fmodel.get_data(the_iter, xrange(3)) self.fmodel.remove(the_iter) - self.fmodel.insert(row+1,data,None,1) + self.fmodel.insert(row+1, data, None, 1) handle = self.family_list.pop(row) - self.family_list.insert(row+1,handle) + self.family_list.insert(row+1, handle) diff --git a/src/Sort.py b/src/Sort.py index 22e64a50a..a03a2e4a6 100644 --- a/src/Sort.py +++ b/src/Sort.py @@ -8,7 +8,7 @@ # 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, +# 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. @@ -22,7 +22,7 @@ """ Provides sorting routines for use in GRAMPS. Since these functions are -intended to provide fast sorting, they tend to bypass access methods, +intended to provide fast sorting, they tend to bypass access methods, and directly use class members. For this reason, care needs to be taken to make sure these remain in sync with the rest of the design. """ @@ -48,18 +48,13 @@ from BasicUtils import name_displayer as _nd # #------------------------------------------------------------------------- -_plist = [ 'de', 'van', 'von', 'la', 'di', 'le', 'du' ] - -_prefix = {} -for i in _plist: - _prefix[i] = 1 - class Sort: - def __init__(self,database): + + def __init__(self, database): self.database = database - def by_last_name(self,first_id,second_id): - """Sort routine for comparing two last names. If last names are equal, + def by_last_name(self, first_id, second_id): + """Sort routine for comparing two last names. If last names are equal, uses the given name and suffix""" first = self.database.get_person_from_handle(first_id) second = self.database.get_person_from_handle(second_id) @@ -80,7 +75,7 @@ class Sort: else: return locale.strcoll(fsn, ssn) - def by_sorted_name(self,first_id,second_id): + def by_sorted_name(self, first_id, second_id): """ Sort routine for comparing two displayed names. """ @@ -91,9 +86,9 @@ class Sort: name1 = _nd.sorted(first) name2 = _nd.sorted(second) - return locale.strcoll(name1,name2) + return locale.strcoll(name1, name2) - def by_birthdate(self,first_id,second_id): + def by_birthdate(self, first_id, second_id): """Sort routine for comparing two people by birth dates. If the birth dates are equal, sorts by name""" first = self.database.get_person_from_handle(first_id) @@ -114,23 +109,23 @@ class Sort: dsv1 = date1.get_sort_value() dsv2 = date2.get_sort_value() - val = cmp(dsv1,dsv2) + val = cmp(dsv1, dsv2) if val == 0: - return self.by_last_name(first_id,second_id) + return self.by_last_name(first_id, second_id) return val - def by_date(self,a_id,b_id): + def by_date(self, a_id, b_id): """Sort routine for comparing two events by their dates. """ if not (a_id and b_id): return 0 - a = self.database.get_event_from_handle(a_id) - b = self.database.get_event_from_handle(b_id) - return cmp(a.get_date_object(),b.get_date_object()) + a_obj = self.database.get_event_from_handle(a_id) + b_obj = self.database.get_event_from_handle(b_id) + return cmp(a_obj.get_date_object(), b_obj.get_date_object()) - def by_place_title(self,a_id,b_id): + def by_place_title(self, a_id, b_id): """Sort routine for comparing two events by their dates. """ if not (a_id and b_id): return 0 - a = self.database.get_place_from_handle(a_id) - b = self.database.get_place_from_handle(b_id) - return cmp(a.title,b.title) + a_obj = self.database.get_place_from_handle(a_id) + b_obj = self.database.get_place_from_handle(b_id) + return cmp(a_obj.title, b_obj.title) diff --git a/src/SubstKeywords.py b/src/SubstKeywords.py index a5edd6988..02f7530eb 100644 --- a/src/SubstKeywords.py +++ b/src/SubstKeywords.py @@ -8,7 +8,7 @@ # 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, +# 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. @@ -68,7 +68,7 @@ class SubstKeywords: $M -> Place of preferred marriage """ - def __init__(self,database,person_handle): + def __init__(self, database, person_handle): """Creates a new object and associates a person with it.""" person = database.get_person_from_handle(person_handle) @@ -124,35 +124,26 @@ class SubstKeywords: if mplace_handle: self.M = database.get_place_from_handle(mplace_handle).get_title() - def replace(self,line): + self.array = [ ("%n", self.n), ("%N", self.N), ("%b", self.b), + ("%B", self.B), ("%d", self.d), ("%D", self.D), + ("%i", self.i), ("%S", self.S), ("%s", self.s), + ("%m", self.m), ("%M", self.M), ("$$", "$") ] + + def replace(self, line): """Returns a new line of text with the substitutions performed.""" - - line = line.replace("$n",self.n) - line = line.replace("$N",self.N) - line = line.replace("$b",self.b) - line = line.replace("$B",self.B) - line = line.replace("$d",self.d) - line = line.replace("$D",self.D) - line = line.replace("$i",self.i) - line = line.replace("$S",self.S) - line = line.replace("$s",self.s) - line = line.replace("$m",self.m) - line = line.replace("$M",self.M) - return line.replace("$$",'$') + for (key, value) in self.array: + line = line.replace(key, value) + return line def replace_and_clean(self, lines): - array = [ ("%n",self.n), ("%N",self.N), ("%b",self.b), - ("%B",self.B), ("%d",self.d), ("%D",self.D), - ("%i",self.i), ("%S",self.S), ("%s",self.s), - ("%m",self.m), ("%M",self.M)] new = [] for line in lines: remove = False - for (key,value) in array: + for (key, value) in self.array: if line.find(key) != -1: if value: - line = line.replace(key,value) + line = line.replace(key, value) else: remove = True if not remove: diff --git a/src/TipOfDay.py b/src/TipOfDay.py index 0a438a2f0..7224a2f22 100644 --- a/src/TipOfDay.py +++ b/src/TipOfDay.py @@ -8,7 +8,7 @@ # 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, +# 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. @@ -20,12 +20,17 @@ # $Id$ +""" +Handles the Tip of the Day dialog +""" + #------------------------------------------------------------------------- # # standard python modules # #------------------------------------------------------------------------- from xml.parsers.expat import ParserCreate +from xml.sax.saxutils import escape from random import Random from gettext import gettext as _ import os @@ -52,30 +57,30 @@ import ManagedWindow # #------------------------------------------------------------------------- class TipOfDay(ManagedWindow.ManagedWindow): - def __init__(self,uistate): + def __init__(self, uistate): ManagedWindow.ManagedWindow.__init__(self, uistate, [], self) xml = gtk.glade.XML(const.GLADE_FILE, "tod_window", "gramps") window = xml.get_widget("tod_window") - self.set_window(window, - xml.get_widget("title"), - _("Tip of the Day"), + self.set_window(window, + xml.get_widget("title"), + _("Tip of the Day"), _("Tip of the Day")) self.tip = xml.get_widget("tip") self.use = xml.get_widget('usetips') self.use.set_active(Config.get(Config.USE_TIPS)) image = xml.get_widget('image') - image.set_from_file(os.path.join(const.IMAGE_DIR,'splash.jpg')) + image.set_from_file(os.path.join(const.IMAGE_DIR, 'splash.jpg')) next = xml.get_widget('next') - next.connect("clicked",self.next_tip_cb) + next.connect("clicked", self.next_tip_cb) close = xml.get_widget('close') - close.connect("clicked",self.close_cb) + close.connect("clicked", self.close_cb) - tp = TipParser() - self.tip_list = tp.get() + tparser = TipParser() + self.tip_list = tparser.get() self.new_index = range(len(self.tip_list)) Random().shuffle(self.new_index) @@ -85,8 +90,9 @@ class TipOfDay(ManagedWindow.ManagedWindow): window.show_all() - def next_tip_cb(self,dummy=None): - tip_text = self.escape(self.tip_list[self.new_index[self.index]]) + def next_tip_cb(self, dummy=None): + tip_text = escape(self.tip_list[self.new_index[self.index]], + { '"' : '"' }) self.tip.set_text(_(tip_text)) self.tip.set_use_markup(True) if self.index >= len(self.tip_list)-1: @@ -94,17 +100,11 @@ class TipOfDay(ManagedWindow.ManagedWindow): else: self.index += 1 - def escape(self,text): - text = text.replace('&','&'); # Must be first - text = text.replace(' > ',' > ') # Replace standalone > char - text = text.replace('"','"') # quotes - return text - - def close_cb(self,dummy=None): - Config.set(Config.USE_TIPS,self.use.get_active()) + def close_cb(self, dummy=None): + Config.set(Config.USE_TIPS, self.use.get_active()) self.close() - def build_menu_names(self,obj): + def build_menu_names(self, obj): return (_("Tip of the Day"), None) #------------------------------------------------------------------------- @@ -126,23 +126,27 @@ class TipParser: """ self.mylist = [] + self.skip = False xml_file = open(const.TIP_DATA) self.tlist = [] - p = ParserCreate() - p.StartElementHandler = self.startElement - p.EndElementHandler = self.endElement - p.CharacterDataHandler = self.characters - p.ParseFile(xml_file) + parser = ParserCreate() + parser.StartElementHandler = self.startElement + parser.EndElementHandler = self.endElement + parser.CharacterDataHandler = self.characters + parser.ParseFile(xml_file) xml_file.close() def get(self): + """ + Returns the list of tips + """ return self.mylist - def setDocumentLocator(self,locator): + def setDocumentLocator(self, locator): """Sets the XML document locator""" self.locator = locator - def startElement(self,tag,attrs): + def startElement(self, tag, attrs): """ Loads the dictionary when an XML tag of 'template' is found. The format XML tag is