* 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 <don@gramps-project.org> svn: r8955
This commit is contained in:
@ -1,3 +1,12 @@
|
|||||||
|
2007-09-09 Don Allingham <don@gramps-project.org>
|
||||||
|
* 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 <don@gramps-project.org>
|
2007-09-09 Don Allingham <don@gramps-project.org>
|
||||||
* src/ViewManager.py: cleanup
|
* src/ViewManager.py: cleanup
|
||||||
* src/DisplayState.py: cleanup
|
* src/DisplayState.py: cleanup
|
||||||
|
172
src/Reorder.py
172
src/Reorder.py
@ -7,7 +7,7 @@
|
|||||||
# the Free Software Foundation; either version 2 of the License, or
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
# (at your option) any later version.
|
# (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
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
@ -17,8 +17,6 @@
|
|||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# 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 _
|
from gettext import gettext as _
|
||||||
|
|
||||||
@ -29,157 +27,157 @@ from BasicUtils import name_displayer
|
|||||||
import ListModel
|
import ListModel
|
||||||
import ManagedWindow
|
import ManagedWindow
|
||||||
|
|
||||||
_parent_titles = [(_('Father'),-1,200),(_('Mother'),-1,200),('',-1,0)]
|
PARENT_TITLES = [(_('Father'), -1, 200), (_('Mother'), -1, 200), ('', -1, 0)]
|
||||||
_family_titles = [(_('Spouse'),-1,200),(_('Relationship'),-1,200),('',-1,0)]
|
FAMILY_TITLES = [(_('Spouse'), -1, 200), (_('Relationship'), -1, 200), ('', -1, 0)]
|
||||||
|
|
||||||
|
|
||||||
class Reorder(ManagedWindow.ManagedWindow):
|
class Reorder(ManagedWindow.ManagedWindow):
|
||||||
|
|
||||||
def __init__(self, state, uistate, track, handle):
|
def __init__(self, state, uistate, track, handle):
|
||||||
xml = gtk.glade.XML(const.GLADE_FILE, "reorder", "gramps")
|
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)
|
ManagedWindow.ManagedWindow.__init__(self, uistate, track, self)
|
||||||
|
|
||||||
self.person = self.dbstate.db.get_person_from_handle(handle)
|
self.person = self.dbstate.db.get_person_from_handle(handle)
|
||||||
self.parent_list = self.person.get_parent_family_handle_list()
|
self.parent_list = self.person.get_parent_family_handle_list()
|
||||||
self.family_list = self.person.get_family_handle_list()
|
self.family_list = self.person.get_family_handle_list()
|
||||||
|
|
||||||
penable = len(self.parent_list) > 1
|
penable = len(self.parent_list) > 1
|
||||||
fenable = len(self.family_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.ptree = xml.get_widget('ptree')
|
||||||
self.pmodel = ListModel.ListModel(self.ptree,_parent_titles)
|
self.pmodel = ListModel.ListModel(self.ptree, PARENT_TITLES)
|
||||||
|
|
||||||
self.ftree = xml.get_widget('ftree')
|
self.ftree = xml.get_widget('ftree')
|
||||||
self.fmodel = ListModel.ListModel(self.ftree,_family_titles)
|
self.fmodel = ListModel.ListModel(self.ftree, FAMILY_TITLES)
|
||||||
|
|
||||||
xml.get_widget('ok').connect('clicked', self.ok_clicked)
|
xml.get_widget('ok').connect('clicked', self.ok_clicked)
|
||||||
xml.get_widget('cancel').connect('clicked', self.cancel_clicked)
|
xml.get_widget('cancel').connect('clicked', self.cancel_clicked)
|
||||||
|
|
||||||
fup = xml.get_widget('fup')
|
fup = xml.get_widget('fup')
|
||||||
fup.connect('clicked', self.fup_clicked)
|
fup.connect('clicked', self.fup_clicked)
|
||||||
fup.set_sensitive(fenable)
|
fup.set_sensitive(fenable)
|
||||||
|
|
||||||
fdown = xml.get_widget('fdown')
|
fdown = xml.get_widget('fdown')
|
||||||
fdown.connect('clicked', self.fdown_clicked)
|
fdown.connect('clicked', self.fdown_clicked)
|
||||||
fdown.set_sensitive(fenable)
|
fdown.set_sensitive(fenable)
|
||||||
|
|
||||||
pup = xml.get_widget('pup')
|
pup = xml.get_widget('pup')
|
||||||
pup.connect('clicked', self.pup_clicked)
|
pup.connect('clicked', self.pup_clicked)
|
||||||
pup.set_sensitive(penable)
|
pup.set_sensitive(penable)
|
||||||
|
|
||||||
pdown = xml.get_widget('pdown')
|
pdown = xml.get_widget('pdown')
|
||||||
pdown.connect('clicked', self.pdown_clicked)
|
pdown.connect('clicked', self.pdown_clicked)
|
||||||
pdown.set_sensitive(penable)
|
pdown.set_sensitive(penable)
|
||||||
|
|
||||||
self.fill_data()
|
self.fill_data()
|
||||||
|
|
||||||
self.show()
|
self.show()
|
||||||
|
|
||||||
def fill_data(self):
|
def fill_data(self):
|
||||||
self.fill_parents()
|
self.fill_parents()
|
||||||
self.fill_family()
|
self.fill_family()
|
||||||
|
|
||||||
def fill_parents(self):
|
def fill_parents(self):
|
||||||
for handle in self.parent_list:
|
for handle in self.parent_list:
|
||||||
family = self.dbstate.db.get_family_from_handle(handle)
|
family = self.dbstate.db.get_family_from_handle(handle)
|
||||||
fhandle = family.get_father_handle()
|
fhandle = family.get_father_handle()
|
||||||
mhandle = family.get_mother_handle()
|
mhandle = family.get_mother_handle()
|
||||||
|
|
||||||
fname = ""
|
fname = ""
|
||||||
if fhandle:
|
if fhandle:
|
||||||
father = self.dbstate.db.get_person_from_handle(fhandle)
|
father = self.dbstate.db.get_person_from_handle(fhandle)
|
||||||
if father:
|
if father:
|
||||||
fname = name_displayer.display(father)
|
fname = name_displayer.display(father)
|
||||||
|
|
||||||
mname = ""
|
mname = ""
|
||||||
if mhandle:
|
if mhandle:
|
||||||
mother = self.dbstate.db.get_person_from_handle(mhandle)
|
mother = self.dbstate.db.get_person_from_handle(mhandle)
|
||||||
if mother:
|
if mother:
|
||||||
mname = name_displayer.display(mother)
|
mname = name_displayer.display(mother)
|
||||||
|
|
||||||
self.pmodel.add([fname, mname, handle])
|
self.pmodel.add([fname, mname, handle])
|
||||||
|
|
||||||
def fill_family(self):
|
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)
|
family = self.dbstate.db.get_family_from_handle(handle)
|
||||||
fhandle = family.get_father_handle()
|
fhandle = family.get_father_handle()
|
||||||
mhandle = family.get_mother_handle()
|
mhandle = family.get_mother_handle()
|
||||||
|
|
||||||
name = ""
|
name = ""
|
||||||
|
|
||||||
if fhandle and fhandle != self.person.handle:
|
if fhandle and fhandle != self.person.handle:
|
||||||
spouse = self.dbstate.db.get_person_from_handle(fhandle)
|
spouse = self.dbstate.db.get_person_from_handle(fhandle)
|
||||||
if spouse:
|
if spouse:
|
||||||
name = name_displayer.display(spouse)
|
name = name_displayer.display(spouse)
|
||||||
elif mhandle:
|
elif mhandle:
|
||||||
spouse = self.dbstate.db.get_person_from_handle(mhandle)
|
spouse = self.dbstate.db.get_person_from_handle(mhandle)
|
||||||
if spouse:
|
if spouse:
|
||||||
name = name_displayer.display(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):
|
def cancel_clicked(self, obj):
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def ok_clicked(self, obj):
|
def ok_clicked(self, obj):
|
||||||
trans = self.dbstate.db.transaction_begin()
|
trans = self.dbstate.db.transaction_begin()
|
||||||
self.dbstate.db.commit_person(self.person, trans)
|
self.dbstate.db.commit_person(self.person, trans)
|
||||||
name = name_displayer.display(self.person)
|
name = name_displayer.display(self.person)
|
||||||
msg = _("Reorder Relationships: %s") % name
|
msg = _("Reorder Relationships: %s") % name
|
||||||
self.dbstate.db.transaction_commit(trans, msg)
|
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"""
|
"""Moves the current selection up one row"""
|
||||||
row = self.pmodel.get_selected_row()
|
row = self.pmodel.get_selected_row()
|
||||||
if not row or row == -1:
|
if not row or row == -1:
|
||||||
return
|
return
|
||||||
store,the_iter = self.pmodel.get_selected()
|
store, the_iter = self.pmodel.get_selected()
|
||||||
data = self.pmodel.get_data(the_iter,xrange(3))
|
data = self.pmodel.get_data(the_iter, xrange(3))
|
||||||
self.pmodel.remove(the_iter)
|
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)
|
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):
|
def pdown_clicked(self, obj):
|
||||||
row = self.pmodel.get_selected_row()
|
row = self.pmodel.get_selected_row()
|
||||||
if row + 1 >= self.pmodel.count or row == -1:
|
if row + 1 >= self.pmodel.count or row == -1:
|
||||||
return
|
return
|
||||||
store,the_iter = self.pmodel.get_selected()
|
store, the_iter = self.pmodel.get_selected()
|
||||||
data = self.pmodel.get_data(the_iter,xrange(3))
|
data = self.pmodel.get_data(the_iter, xrange(3))
|
||||||
self.pmodel.remove(the_iter)
|
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)
|
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):
|
def fup_clicked(self, obj):
|
||||||
row = self.fmodel.get_selected_row()
|
row = self.fmodel.get_selected_row()
|
||||||
if not row or row == -1:
|
if not row or row == -1:
|
||||||
return
|
return
|
||||||
store,the_iter = self.fmodel.get_selected()
|
store, the_iter = self.fmodel.get_selected()
|
||||||
data = self.fmodel.get_data(the_iter,xrange(3))
|
data = self.fmodel.get_data(the_iter, xrange(3))
|
||||||
self.fmodel.remove(the_iter)
|
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)
|
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):
|
def fdown_clicked(self, obj):
|
||||||
row = self.fmodel.get_selected_row()
|
row = self.fmodel.get_selected_row()
|
||||||
if row + 1 >= self.fmodel.count or row == -1:
|
if row + 1 >= self.fmodel.count or row == -1:
|
||||||
return
|
return
|
||||||
store,the_iter = self.fmodel.get_selected()
|
store, the_iter = self.fmodel.get_selected()
|
||||||
data = self.fmodel.get_data(the_iter,xrange(3))
|
data = self.fmodel.get_data(the_iter, xrange(3))
|
||||||
self.fmodel.remove(the_iter)
|
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)
|
handle = self.family_list.pop(row)
|
||||||
self.family_list.insert(row+1,handle)
|
self.family_list.insert(row+1, handle)
|
||||||
|
43
src/Sort.py
43
src/Sort.py
@ -8,7 +8,7 @@
|
|||||||
# the Free Software Foundation; either version 2 of the License, or
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
# (at your option) any later version.
|
# (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
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
@ -22,7 +22,7 @@
|
|||||||
|
|
||||||
"""
|
"""
|
||||||
Provides sorting routines for use in GRAMPS. Since these functions are
|
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
|
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.
|
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:
|
class Sort:
|
||||||
def __init__(self,database):
|
|
||||||
|
def __init__(self, database):
|
||||||
self.database = database
|
self.database = database
|
||||||
|
|
||||||
def by_last_name(self,first_id,second_id):
|
def by_last_name(self, first_id, second_id):
|
||||||
"""Sort routine for comparing two last names. If last names are equal,
|
"""Sort routine for comparing two last names. If last names are equal,
|
||||||
uses the given name and suffix"""
|
uses the given name and suffix"""
|
||||||
first = self.database.get_person_from_handle(first_id)
|
first = self.database.get_person_from_handle(first_id)
|
||||||
second = self.database.get_person_from_handle(second_id)
|
second = self.database.get_person_from_handle(second_id)
|
||||||
@ -80,7 +75,7 @@ class Sort:
|
|||||||
else:
|
else:
|
||||||
return locale.strcoll(fsn, ssn)
|
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.
|
Sort routine for comparing two displayed names.
|
||||||
"""
|
"""
|
||||||
@ -91,9 +86,9 @@ class Sort:
|
|||||||
name1 = _nd.sorted(first)
|
name1 = _nd.sorted(first)
|
||||||
name2 = _nd.sorted(second)
|
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
|
"""Sort routine for comparing two people by birth dates. If the birth dates
|
||||||
are equal, sorts by name"""
|
are equal, sorts by name"""
|
||||||
first = self.database.get_person_from_handle(first_id)
|
first = self.database.get_person_from_handle(first_id)
|
||||||
@ -114,23 +109,23 @@ class Sort:
|
|||||||
dsv1 = date1.get_sort_value()
|
dsv1 = date1.get_sort_value()
|
||||||
dsv2 = date2.get_sort_value()
|
dsv2 = date2.get_sort_value()
|
||||||
|
|
||||||
val = cmp(dsv1,dsv2)
|
val = cmp(dsv1, dsv2)
|
||||||
if val == 0:
|
if val == 0:
|
||||||
return self.by_last_name(first_id,second_id)
|
return self.by_last_name(first_id, second_id)
|
||||||
return val
|
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. """
|
"""Sort routine for comparing two events by their dates. """
|
||||||
if not (a_id and b_id):
|
if not (a_id and b_id):
|
||||||
return 0
|
return 0
|
||||||
a = self.database.get_event_from_handle(a_id)
|
a_obj = self.database.get_event_from_handle(a_id)
|
||||||
b = self.database.get_event_from_handle(b_id)
|
b_obj = self.database.get_event_from_handle(b_id)
|
||||||
return cmp(a.get_date_object(),b.get_date_object())
|
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. """
|
"""Sort routine for comparing two events by their dates. """
|
||||||
if not (a_id and b_id):
|
if not (a_id and b_id):
|
||||||
return 0
|
return 0
|
||||||
a = self.database.get_place_from_handle(a_id)
|
a_obj = self.database.get_place_from_handle(a_id)
|
||||||
b = self.database.get_place_from_handle(b_id)
|
b_obj = self.database.get_place_from_handle(b_id)
|
||||||
return cmp(a.title,b.title)
|
return cmp(a_obj.title, b_obj.title)
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
# the Free Software Foundation; either version 2 of the License, or
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
# (at your option) any later version.
|
# (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
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
@ -68,7 +68,7 @@ class SubstKeywords:
|
|||||||
$M -> Place of preferred marriage
|
$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."""
|
"""Creates a new object and associates a person with it."""
|
||||||
|
|
||||||
person = database.get_person_from_handle(person_handle)
|
person = database.get_person_from_handle(person_handle)
|
||||||
@ -124,35 +124,26 @@ class SubstKeywords:
|
|||||||
if mplace_handle:
|
if mplace_handle:
|
||||||
self.M = database.get_place_from_handle(mplace_handle).get_title()
|
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."""
|
"""Returns a new line of text with the substitutions performed."""
|
||||||
|
for (key, value) in self.array:
|
||||||
line = line.replace("$n",self.n)
|
line = line.replace(key, value)
|
||||||
line = line.replace("$N",self.N)
|
return line
|
||||||
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("$$",'$')
|
|
||||||
|
|
||||||
def replace_and_clean(self, lines):
|
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 = []
|
new = []
|
||||||
for line in lines:
|
for line in lines:
|
||||||
remove = False
|
remove = False
|
||||||
for (key,value) in array:
|
for (key, value) in self.array:
|
||||||
if line.find(key) != -1:
|
if line.find(key) != -1:
|
||||||
if value:
|
if value:
|
||||||
line = line.replace(key,value)
|
line = line.replace(key, value)
|
||||||
else:
|
else:
|
||||||
remove = True
|
remove = True
|
||||||
if not remove:
|
if not remove:
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
# the Free Software Foundation; either version 2 of the License, or
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
# (at your option) any later version.
|
# (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
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
@ -20,12 +20,17 @@
|
|||||||
|
|
||||||
# $Id$
|
# $Id$
|
||||||
|
|
||||||
|
"""
|
||||||
|
Handles the Tip of the Day dialog
|
||||||
|
"""
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# standard python modules
|
# standard python modules
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
from xml.parsers.expat import ParserCreate
|
from xml.parsers.expat import ParserCreate
|
||||||
|
from xml.sax.saxutils import escape
|
||||||
from random import Random
|
from random import Random
|
||||||
from gettext import gettext as _
|
from gettext import gettext as _
|
||||||
import os
|
import os
|
||||||
@ -52,30 +57,30 @@ import ManagedWindow
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
class TipOfDay(ManagedWindow.ManagedWindow):
|
class TipOfDay(ManagedWindow.ManagedWindow):
|
||||||
def __init__(self,uistate):
|
def __init__(self, uistate):
|
||||||
|
|
||||||
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self)
|
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self)
|
||||||
|
|
||||||
xml = gtk.glade.XML(const.GLADE_FILE, "tod_window", "gramps")
|
xml = gtk.glade.XML(const.GLADE_FILE, "tod_window", "gramps")
|
||||||
window = xml.get_widget("tod_window")
|
window = xml.get_widget("tod_window")
|
||||||
self.set_window(window,
|
self.set_window(window,
|
||||||
xml.get_widget("title"),
|
xml.get_widget("title"),
|
||||||
_("Tip of the Day"),
|
_("Tip of the Day"),
|
||||||
_("Tip of the Day"))
|
_("Tip of the Day"))
|
||||||
|
|
||||||
self.tip = xml.get_widget("tip")
|
self.tip = xml.get_widget("tip")
|
||||||
self.use = xml.get_widget('usetips')
|
self.use = xml.get_widget('usetips')
|
||||||
self.use.set_active(Config.get(Config.USE_TIPS))
|
self.use.set_active(Config.get(Config.USE_TIPS))
|
||||||
image = xml.get_widget('image')
|
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 = xml.get_widget('next')
|
||||||
next.connect("clicked",self.next_tip_cb)
|
next.connect("clicked", self.next_tip_cb)
|
||||||
close = xml.get_widget('close')
|
close = xml.get_widget('close')
|
||||||
close.connect("clicked",self.close_cb)
|
close.connect("clicked", self.close_cb)
|
||||||
|
|
||||||
tp = TipParser()
|
tparser = TipParser()
|
||||||
self.tip_list = tp.get()
|
self.tip_list = tparser.get()
|
||||||
|
|
||||||
self.new_index = range(len(self.tip_list))
|
self.new_index = range(len(self.tip_list))
|
||||||
Random().shuffle(self.new_index)
|
Random().shuffle(self.new_index)
|
||||||
@ -85,8 +90,9 @@ class TipOfDay(ManagedWindow.ManagedWindow):
|
|||||||
|
|
||||||
window.show_all()
|
window.show_all()
|
||||||
|
|
||||||
def next_tip_cb(self,dummy=None):
|
def next_tip_cb(self, dummy=None):
|
||||||
tip_text = self.escape(self.tip_list[self.new_index[self.index]])
|
tip_text = escape(self.tip_list[self.new_index[self.index]],
|
||||||
|
{ '"' : '"' })
|
||||||
self.tip.set_text(_(tip_text))
|
self.tip.set_text(_(tip_text))
|
||||||
self.tip.set_use_markup(True)
|
self.tip.set_use_markup(True)
|
||||||
if self.index >= len(self.tip_list)-1:
|
if self.index >= len(self.tip_list)-1:
|
||||||
@ -94,17 +100,11 @@ class TipOfDay(ManagedWindow.ManagedWindow):
|
|||||||
else:
|
else:
|
||||||
self.index += 1
|
self.index += 1
|
||||||
|
|
||||||
def escape(self,text):
|
def close_cb(self, dummy=None):
|
||||||
text = text.replace('&','&'); # Must be first
|
Config.set(Config.USE_TIPS, self.use.get_active())
|
||||||
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())
|
|
||||||
self.close()
|
self.close()
|
||||||
|
|
||||||
def build_menu_names(self,obj):
|
def build_menu_names(self, obj):
|
||||||
return (_("Tip of the Day"), None)
|
return (_("Tip of the Day"), None)
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -126,23 +126,27 @@ class TipParser:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
self.mylist = []
|
self.mylist = []
|
||||||
|
self.skip = False
|
||||||
xml_file = open(const.TIP_DATA)
|
xml_file = open(const.TIP_DATA)
|
||||||
self.tlist = []
|
self.tlist = []
|
||||||
p = ParserCreate()
|
parser = ParserCreate()
|
||||||
p.StartElementHandler = self.startElement
|
parser.StartElementHandler = self.startElement
|
||||||
p.EndElementHandler = self.endElement
|
parser.EndElementHandler = self.endElement
|
||||||
p.CharacterDataHandler = self.characters
|
parser.CharacterDataHandler = self.characters
|
||||||
p.ParseFile(xml_file)
|
parser.ParseFile(xml_file)
|
||||||
xml_file.close()
|
xml_file.close()
|
||||||
|
|
||||||
def get(self):
|
def get(self):
|
||||||
|
"""
|
||||||
|
Returns the list of tips
|
||||||
|
"""
|
||||||
return self.mylist
|
return self.mylist
|
||||||
|
|
||||||
def setDocumentLocator(self,locator):
|
def setDocumentLocator(self, locator):
|
||||||
"""Sets the XML document locator"""
|
"""Sets the XML document locator"""
|
||||||
self.locator = 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
|
Loads the dictionary when an XML tag of 'template' is found. The format
|
||||||
XML tag is <template title=\"name\" file=\"path\">
|
XML tag is <template title=\"name\" file=\"path\">
|
||||||
@ -156,7 +160,7 @@ class TipParser:
|
|||||||
# let all the other tags through, except for the "tips" tag
|
# let all the other tags through, except for the "tips" tag
|
||||||
self.tlist.append("<%s>" % tag)
|
self.tlist.append("<%s>" % tag)
|
||||||
|
|
||||||
def endElement(self,tag):
|
def endElement(self, tag):
|
||||||
if tag == "tip" and not self.skip:
|
if tag == "tip" and not self.skip:
|
||||||
text = ''.join(self.tlist)
|
text = ''.join(self.tlist)
|
||||||
self.mylist.append(' '.join(text.split()))
|
self.mylist.append(' '.join(text.split()))
|
||||||
|
@ -20,9 +20,13 @@
|
|||||||
|
|
||||||
# $Id$
|
# $Id$
|
||||||
|
|
||||||
|
"""
|
||||||
|
Provides translation assistance
|
||||||
|
"""
|
||||||
|
|
||||||
from gettext import gettext
|
from gettext import gettext
|
||||||
|
|
||||||
def sgettext(msgid,sep='|'):
|
def sgettext(msgid, sep='|'):
|
||||||
"""
|
"""
|
||||||
Strip the context used for resolving translation ambiguities.
|
Strip the context used for resolving translation ambiguities.
|
||||||
|
|
||||||
|
241
src/Utils.py
241
src/Utils.py
@ -8,7 +8,7 @@
|
|||||||
# the Free Software Foundation; either version 2 of the License, or
|
# the Free Software Foundation; either version 2 of the License, or
|
||||||
# (at your option) any later version.
|
# (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
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
# GNU General Public License for more details.
|
# GNU General Public License for more details.
|
||||||
@ -57,32 +57,32 @@ from QuestionDialog import WarningDialog
|
|||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
gender = {
|
gender = {
|
||||||
RelLib.Person.MALE : _("male"),
|
RelLib.Person.MALE : _("male"),
|
||||||
RelLib.Person.FEMALE : _("female"),
|
RelLib.Person.FEMALE : _("female"),
|
||||||
RelLib.Person.UNKNOWN : _("unknown"),
|
RelLib.Person.UNKNOWN : _("unknown"),
|
||||||
}
|
}
|
||||||
def format_gender( type):
|
def format_gender( type):
|
||||||
return gender.get(type[0],_("Invalid"))
|
return gender.get(type[0], _("Invalid"))
|
||||||
|
|
||||||
confidence = {
|
confidence = {
|
||||||
RelLib.SourceRef.CONF_VERY_HIGH : _("Very High"),
|
RelLib.SourceRef.CONF_VERY_HIGH : _("Very High"),
|
||||||
RelLib.SourceRef.CONF_HIGH : _("High"),
|
RelLib.SourceRef.CONF_HIGH : _("High"),
|
||||||
RelLib.SourceRef.CONF_NORMAL : _("Normal"),
|
RelLib.SourceRef.CONF_NORMAL : _("Normal"),
|
||||||
RelLib.SourceRef.CONF_LOW : _("Low"),
|
RelLib.SourceRef.CONF_LOW : _("Low"),
|
||||||
RelLib.SourceRef.CONF_VERY_LOW : _("Very Low"),
|
RelLib.SourceRef.CONF_VERY_LOW : _("Very Low"),
|
||||||
}
|
}
|
||||||
|
|
||||||
family_rel_descriptions = {
|
family_rel_descriptions = {
|
||||||
RelLib.FamilyRelType.MARRIED : _("A legal or common-law relationship "
|
RelLib.FamilyRelType.MARRIED : _("A legal or common-law relationship "
|
||||||
"between a husband and wife"),
|
"between a husband and wife"),
|
||||||
RelLib.FamilyRelType.UNMARRIED : _("No legal or common-law relationship "
|
RelLib.FamilyRelType.UNMARRIED : _("No legal or common-law relationship "
|
||||||
"between man and woman"),
|
"between man and woman"),
|
||||||
RelLib.FamilyRelType.CIVIL_UNION : _("An established relationship between "
|
RelLib.FamilyRelType.CIVIL_UNION : _("An established relationship between "
|
||||||
"members of the same sex"),
|
"members of the same sex"),
|
||||||
RelLib.FamilyRelType.UNKNOWN : _("Unknown relationship between a man "
|
RelLib.FamilyRelType.UNKNOWN : _("Unknown relationship between a man "
|
||||||
"and woman"),
|
"and woman"),
|
||||||
RelLib.FamilyRelType.CUSTOM : _("An unspecified relationship "
|
RelLib.FamilyRelType.CUSTOM : _("An unspecified relationship "
|
||||||
"a man and woman"),
|
"a man and woman"),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -109,16 +109,16 @@ def fix_encoding(value):
|
|||||||
codeset = locale.getpreferredencoding()
|
codeset = locale.getpreferredencoding()
|
||||||
except:
|
except:
|
||||||
codeset = "UTF-8"
|
codeset = "UTF-8"
|
||||||
return unicode(value,codeset)
|
return unicode(value, codeset)
|
||||||
else:
|
else:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def xml_lang():
|
def xml_lang():
|
||||||
(loc,enc) = locale.getlocale()
|
loc = locale.getlocale()
|
||||||
if loc == None:
|
if loc[0] == None:
|
||||||
return ""
|
return ""
|
||||||
else:
|
else:
|
||||||
return loc.replace('_','-')
|
return loc[0].replace('_', '-')
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -128,9 +128,9 @@ def xml_lang():
|
|||||||
|
|
||||||
def force_unicode(n):
|
def force_unicode(n):
|
||||||
if type(n) != unicode:
|
if type(n) != unicode:
|
||||||
return (unicode(n).lower(),unicode(n))
|
return (unicode(n).lower(), unicode(n))
|
||||||
else:
|
else:
|
||||||
return (n.lower(),n)
|
return (n.lower(), n)
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
@ -162,7 +162,7 @@ def family_name(family, db, noname=_("unknown")):
|
|||||||
fname = name_displayer.display(father)
|
fname = name_displayer.display(father)
|
||||||
mname = name_displayer.display(mother)
|
mname = name_displayer.display(mother)
|
||||||
name = _("%(father)s and %(mother)s") % {
|
name = _("%(father)s and %(mother)s") % {
|
||||||
"father" : fname,
|
"father" : fname,
|
||||||
"mother" : mname}
|
"mother" : mname}
|
||||||
elif father:
|
elif father:
|
||||||
name = name_displayer.display(father)
|
name = name_displayer.display(father)
|
||||||
@ -182,7 +182,7 @@ def family_upper_name(family, db):
|
|||||||
fname = father.get_primary_name().get_upper_name()
|
fname = father.get_primary_name().get_upper_name()
|
||||||
mname = mother.get_primary_name().get_upper_name()
|
mname = mother.get_primary_name().get_upper_name()
|
||||||
name = _("%{father}s and %{mother}s") % {
|
name = _("%{father}s and %{mother}s") % {
|
||||||
'father' : fname,
|
'father' : fname,
|
||||||
'mother' : mname
|
'mother' : mname
|
||||||
}
|
}
|
||||||
elif father:
|
elif father:
|
||||||
@ -196,7 +196,7 @@ def family_upper_name(family, db):
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
def redraw_list(dlist,clist,func):
|
def redraw_list(dlist, clist, func):
|
||||||
clist.clear()
|
clist.clear()
|
||||||
|
|
||||||
index = 0
|
index = 0
|
||||||
@ -204,7 +204,7 @@ def redraw_list(dlist,clist,func):
|
|||||||
col = 0
|
col = 0
|
||||||
node = clist.append()
|
node = clist.append()
|
||||||
for data in func(obj):
|
for data in func(obj):
|
||||||
clist.set_value(node,col,data)
|
clist.set_value(node, col, data)
|
||||||
col = col + 1
|
col = col + 1
|
||||||
index = index + 1
|
index = index + 1
|
||||||
return index
|
return index
|
||||||
@ -214,12 +214,12 @@ def redraw_list(dlist,clist,func):
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
def delete_selected(obj,list):
|
def delete_selected(obj, dlist):
|
||||||
sel = obj.get_selection()
|
sel = obj.get_selection()
|
||||||
model,node = sel.get_selected()
|
model, node = sel.get_selected()
|
||||||
if node:
|
if node:
|
||||||
index = model.get_path(node)[0]
|
index = model.get_path(node)[0]
|
||||||
del list[index]
|
del dlist[index]
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
@ -227,10 +227,10 @@ def delete_selected(obj,list):
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
def add_menuitem(menu,msg,obj,func):
|
def add_menuitem(menu, msg, obj, func):
|
||||||
item = gtk.MenuItem(msg)
|
item = gtk.MenuItem(msg)
|
||||||
item.set_data('o',obj)
|
item.set_data('o', obj)
|
||||||
item.connect("activate",func)
|
item.connect("activate", func)
|
||||||
item.show()
|
item.show()
|
||||||
menu.append(item)
|
menu.append(item)
|
||||||
|
|
||||||
@ -246,7 +246,7 @@ def view_photo(photo):
|
|||||||
prog = data[0]
|
prog = data[0]
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
launch(prog,photo.get_path())
|
launch(prog, photo.get_path())
|
||||||
|
|
||||||
def find_file( filename):
|
def find_file( filename):
|
||||||
# try the filename we got
|
# try the filename we got
|
||||||
@ -290,7 +290,8 @@ def find_folder( filename):
|
|||||||
|
|
||||||
# Build list of elternate encodings
|
# Build list of elternate encodings
|
||||||
try:
|
try:
|
||||||
encodings = [sys.getfilesystemencoding(), locale.getpreferredencoding(),
|
encodings = [sys.getfilesystemencoding(),
|
||||||
|
locale.getpreferredencoding(),
|
||||||
'UTF-8', 'ISO-8859-1']
|
'UTF-8', 'ISO-8859-1']
|
||||||
except:
|
except:
|
||||||
encodings = [sys.getfilesystemencoding(), 'UTF-8', 'ISO-8859-1']
|
encodings = [sys.getfilesystemencoding(), 'UTF-8', 'ISO-8859-1']
|
||||||
@ -341,12 +342,12 @@ def build_string_optmenu(mapping, start_val):
|
|||||||
#
|
#
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
def build_columns(tree,list):
|
def build_columns(tree, list):
|
||||||
cnum = 0
|
cnum = 0
|
||||||
for name in list:
|
for name in list:
|
||||||
renderer = gtk.CellRendererText()
|
renderer = gtk.CellRendererText()
|
||||||
renderer.set_fixed_height_from_font(1)
|
renderer.set_fixed_height_from_font(1)
|
||||||
column = gtk.TreeViewColumn(name[0],renderer,text=cnum)
|
column = gtk.TreeViewColumn(name[0], renderer, text=cnum)
|
||||||
column.set_min_width(name[1])
|
column.set_min_width(name[1])
|
||||||
if name[2] >= 0:
|
if name[2] >= 0:
|
||||||
column.set_sort_column_id(name[2])
|
column.set_sort_column_id(name[2])
|
||||||
@ -365,22 +366,22 @@ def for_each_ancestor(db, start, func, data):
|
|||||||
"""
|
"""
|
||||||
Recursively iterate (breadth-first) over ancestors of
|
Recursively iterate (breadth-first) over ancestors of
|
||||||
people listed in start.
|
people listed in start.
|
||||||
Call func(data,pid) for the Id of each person encountered.
|
Call func(data, pid) for the Id of each person encountered.
|
||||||
Exit and return 1, as soon as func returns true.
|
Exit and return 1, as soon as func returns true.
|
||||||
Return 0 otherwise.
|
Return 0 otherwise.
|
||||||
"""
|
"""
|
||||||
todo = start
|
todo = start
|
||||||
doneIds = {}
|
done_ids = set()
|
||||||
while len(todo):
|
while len(todo):
|
||||||
p_handle = todo.pop()
|
p_handle = todo.pop()
|
||||||
p = db.get_person_from_handle(p_handle)
|
p = db.get_person_from_handle(p_handle)
|
||||||
# Don't process the same handle twice. This can happen
|
# Don't process the same handle twice. This can happen
|
||||||
# if there is a cycle in the database, or if the
|
# if there is a cycle in the database, or if the
|
||||||
# initial list contains X and some of X's ancestors.
|
# initial list contains X and some of X's ancestors.
|
||||||
if doneIds.has_key(p_handle):
|
if p_handle in done_ids:
|
||||||
continue
|
continue
|
||||||
doneIds[p_handle] = 1
|
done_ids.add(p_handle)
|
||||||
if func(data,p_handle):
|
if func(data, p_handle):
|
||||||
return 1
|
return 1
|
||||||
for fam_handle in p.get_parent_family_handle_list():
|
for fam_handle in p.get_parent_family_handle_list():
|
||||||
fam = db.get_family_from_handle(fam_handle)
|
fam = db.get_family_from_handle(fam_handle)
|
||||||
@ -394,13 +395,13 @@ def for_each_ancestor(db, start, func, data):
|
|||||||
def title(n):
|
def title(n):
|
||||||
return '<span weight="bold" size="larger">%s</span>' % n
|
return '<span weight="bold" size="larger">%s</span>' % n
|
||||||
|
|
||||||
def set_title_label(xmlobj,t):
|
def set_title_label(xmlobj, t):
|
||||||
title_label = xmlobj.get_widget('title')
|
title_label = xmlobj.get_widget('title')
|
||||||
title_label.set_text('<span weight="bold" size="larger">%s</span>' % t)
|
title_label.set_text('<span weight="bold" size="larger">%s</span>' % t)
|
||||||
title_label.set_use_markup(True)
|
title_label.set_use_markup(True)
|
||||||
|
|
||||||
from warnings import warn
|
from warnings import warn
|
||||||
def set_titles(window,title,t,msg=None):
|
def set_titles(window, title, t, msg=None):
|
||||||
warn('The Utils.set_titles is deprecated. Use ManagedWindow methods')
|
warn('The Utils.set_titles is deprecated. Use ManagedWindow methods')
|
||||||
|
|
||||||
def gfloat(val):
|
def gfloat(val):
|
||||||
@ -414,9 +415,9 @@ def gfloat(val):
|
|||||||
return float(val)
|
return float(val)
|
||||||
except:
|
except:
|
||||||
try:
|
try:
|
||||||
return float(val.replace('.',','))
|
return float(val.replace('.', ', '))
|
||||||
except:
|
except:
|
||||||
return float(val.replace(',','.'))
|
return float(val.replace(', ', '.'))
|
||||||
return 0.0
|
return 0.0
|
||||||
|
|
||||||
def gformat(val):
|
def gformat(val):
|
||||||
@ -428,7 +429,7 @@ def gformat(val):
|
|||||||
|
|
||||||
decimal_point = locale.localeconv()['decimal_point']
|
decimal_point = locale.localeconv()['decimal_point']
|
||||||
return_val = "%.3f" % val
|
return_val = "%.3f" % val
|
||||||
return return_val.replace(decimal_point,'.')
|
return return_val.replace(decimal_point, '.')
|
||||||
|
|
||||||
def search_for(name):
|
def search_for(name):
|
||||||
if name.startswith( '"' ):
|
if name.startswith( '"' ):
|
||||||
@ -437,13 +438,13 @@ def search_for(name):
|
|||||||
name = name.split()[0]
|
name = name.split()[0]
|
||||||
if os.sys.platform == "win32":
|
if os.sys.platform == "win32":
|
||||||
for i in os.environ['PATH'].split(';'):
|
for i in os.environ['PATH'].split(';'):
|
||||||
fname = os.path.join(i,name)
|
fname = os.path.join(i, name)
|
||||||
if os.access(fname,os.X_OK) and not os.path.isdir(fname):
|
if os.access(fname, os.X_OK) and not os.path.isdir(fname):
|
||||||
return 1
|
return 1
|
||||||
else:
|
else:
|
||||||
for i in os.environ['PATH'].split(':'):
|
for i in os.environ['PATH'].split(':'):
|
||||||
fname = os.path.join(i,name)
|
fname = os.path.join(i, name)
|
||||||
if os.access(fname,os.X_OK) and not os.path.isdir(fname):
|
if os.access(fname, os.X_OK) and not os.path.isdir(fname):
|
||||||
return 1
|
return 1
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
@ -452,58 +453,58 @@ def search_for(name):
|
|||||||
# Change label appearance
|
# Change label appearance
|
||||||
#
|
#
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
def bold_label(label,widget=None):
|
def bold_label(label, widget=None):
|
||||||
if label.__class__ == gtk.Label:
|
if label.__class__ == gtk.Label:
|
||||||
text = unicode(label.get_text())
|
text = unicode(label.get_text())
|
||||||
text = text.replace('<i>','')
|
text = text.replace('<i>', '')
|
||||||
text = text.replace('</i>','')
|
text = text.replace('</i>', '')
|
||||||
label.set_text("<b>%s</b>" % text )
|
label.set_text("<b>%s</b>" % text )
|
||||||
label.set_use_markup(True)
|
label.set_use_markup(True)
|
||||||
else:
|
else:
|
||||||
clist = label.get_children()
|
clist = label.get_children()
|
||||||
text = unicode(clist[1].get_text())
|
text = unicode(clist[1].get_text())
|
||||||
text = text.replace('<i>','')
|
text = text.replace('<i>', '')
|
||||||
text = text.replace('</i>','')
|
text = text.replace('</i>', '')
|
||||||
clist[0].show()
|
clist[0].show()
|
||||||
clist[1].set_text("<b>%s</b>" % text )
|
clist[1].set_text("<b>%s</b>" % text )
|
||||||
clist[1].set_use_markup(True)
|
clist[1].set_use_markup(True)
|
||||||
if widget:
|
if widget:
|
||||||
widget.window.set_cursor(None)
|
widget.window.set_cursor(None)
|
||||||
|
|
||||||
def unbold_label(label,widget=None):
|
def unbold_label(label, widget=None):
|
||||||
if label.__class__ == gtk.Label:
|
if label.__class__ == gtk.Label:
|
||||||
text = unicode(label.get_text())
|
text = unicode(label.get_text())
|
||||||
text = text.replace('<b>','')
|
text = text.replace('<b>', '')
|
||||||
text = text.replace('</b>','')
|
text = text.replace('</b>', '')
|
||||||
text = text.replace('<i>','')
|
text = text.replace('<i>', '')
|
||||||
text = text.replace('</i>','')
|
text = text.replace('</i>', '')
|
||||||
label.set_text(text)
|
label.set_text(text)
|
||||||
label.set_use_markup(False)
|
label.set_use_markup(False)
|
||||||
else:
|
else:
|
||||||
clist = label.get_children()
|
clist = label.get_children()
|
||||||
text = unicode(clist[1].get_text())
|
text = unicode(clist[1].get_text())
|
||||||
text = text.replace('<b>','')
|
text = text.replace('<b>', '')
|
||||||
text = text.replace('</b>','')
|
text = text.replace('</b>', '')
|
||||||
text = text.replace('<i>','')
|
text = text.replace('<i>', '')
|
||||||
text = text.replace('</i>','')
|
text = text.replace('</i>', '')
|
||||||
clist[0].hide()
|
clist[0].hide()
|
||||||
clist[1].set_text(text)
|
clist[1].set_text(text)
|
||||||
clist[1].set_use_markup(False)
|
clist[1].set_use_markup(False)
|
||||||
if widget:
|
if widget:
|
||||||
widget.window.set_cursor(None)
|
widget.window.set_cursor(None)
|
||||||
|
|
||||||
def temp_label(label,widget=None):
|
def temp_label(label, widget=None):
|
||||||
if label.__class__ == gtk.Label:
|
if label.__class__ == gtk.Label:
|
||||||
text = unicode(label.get_text())
|
text = unicode(label.get_text())
|
||||||
text = text.replace('<b>','')
|
text = text.replace('<b>', '')
|
||||||
text = text.replace('</b>','')
|
text = text.replace('</b>', '')
|
||||||
label.set_text("<i>%s</i>" % text )
|
label.set_text("<i>%s</i>" % text )
|
||||||
label.set_use_markup(True)
|
label.set_use_markup(True)
|
||||||
else:
|
else:
|
||||||
clist = label.get_children()
|
clist = label.get_children()
|
||||||
text = unicode(clist[1].get_text())
|
text = unicode(clist[1].get_text())
|
||||||
text = text.replace('<b>','')
|
text = text.replace('<b>', '')
|
||||||
text = text.replace('</b>','')
|
text = text.replace('</b>', '')
|
||||||
clist[0].hide()
|
clist[0].hide()
|
||||||
clist[1].set_text("<i>%s</i>" % text )
|
clist[1].set_text("<i>%s</i>" % text )
|
||||||
clist[1].set_use_markup(True)
|
clist[1].set_use_markup(True)
|
||||||
@ -518,10 +519,10 @@ def temp_label(label,widget=None):
|
|||||||
rand = random.Random(time.time())
|
rand = random.Random(time.time())
|
||||||
|
|
||||||
def create_id():
|
def create_id():
|
||||||
return "%08x%08x" % ( int(time.time()*10000),
|
return "%08x%08x" % ( int(time.time()*10000),
|
||||||
rand.randint(0,sys.maxint))
|
rand.randint(0, sys.maxint))
|
||||||
|
|
||||||
def probably_alive(person,db,current_year=None,limit=0):
|
def probably_alive(person, db, current_year=None, limit=0):
|
||||||
"""Returns true if the person may be alive.
|
"""Returns true if the person may be alive.
|
||||||
|
|
||||||
This works by a process of emlimination. If we can't find a good
|
This works by a process of emlimination. If we can't find a good
|
||||||
@ -549,8 +550,8 @@ def probably_alive(person,db,current_year=None,limit=0):
|
|||||||
# These are fairly good indications that someone's not alive.
|
# These are fairly good indications that someone's not alive.
|
||||||
for ev_ref in person.get_primary_event_ref_list():
|
for ev_ref in person.get_primary_event_ref_list():
|
||||||
ev = db.get_event_from_handle(ev_ref.ref)
|
ev = db.get_event_from_handle(ev_ref.ref)
|
||||||
if ev and int(ev.get_type()) in [RelLib.EventType.CAUSE_DEATH,
|
if ev and int(ev.get_type()) in [RelLib.EventType.CAUSE_DEATH,
|
||||||
RelLib.EventType.BURIAL,
|
RelLib.EventType.BURIAL,
|
||||||
RelLib.EventType.CREMATION]:
|
RelLib.EventType.CREMATION]:
|
||||||
if not death_year:
|
if not death_year:
|
||||||
death_year = ev.get_date_object().get_year()
|
death_year = ev.get_date_object().get_year()
|
||||||
@ -559,7 +560,7 @@ def probably_alive(person,db,current_year=None,limit=0):
|
|||||||
return False
|
return False
|
||||||
# For any other event of this person, check whether it happened
|
# For any other event of this person, check whether it happened
|
||||||
# too long ago. If so then the person is likely dead now.
|
# too long ago. If so then the person is likely dead now.
|
||||||
elif ev and too_old(ev.get_date_object(),current_year):
|
elif ev and too_old(ev.get_date_object(), current_year):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
birth_year = None
|
birth_year = None
|
||||||
@ -573,9 +574,9 @@ def probably_alive(person,db,current_year=None,limit=0):
|
|||||||
birth_year = birth.get_date_object().get_year()
|
birth_year = birth.get_date_object().get_year()
|
||||||
# Check whether the birth event is too old because the
|
# Check whether the birth event is too old because the
|
||||||
# code above did not look at birth, only at other events
|
# code above did not look at birth, only at other events
|
||||||
if too_old(birth.get_date_object(),current_year):
|
if too_old(birth.get_date_object(), current_year):
|
||||||
return False
|
return False
|
||||||
if not_too_old(birth.get_date_object(),current_year):
|
if not_too_old(birth.get_date_object(), current_year):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if not birth_year and death_year:
|
if not birth_year and death_year:
|
||||||
@ -584,7 +585,7 @@ def probably_alive(person,db,current_year=None,limit=0):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
# Neither birth nor death events are available. Try looking
|
# Neither birth nor death events are available. Try looking
|
||||||
# at siblings. If a sibling was born more than 120 years past,
|
# at siblings. If a sibling was born more than 120 years past,
|
||||||
# or more than 20 future, then problem then this person is
|
# or more than 20 future, then problem then this person is
|
||||||
# probably not alive. If the sibling died more than 120 years
|
# probably not alive. If the sibling died more than 120 years
|
||||||
# past, or more than 120 years future, then probably not alive.
|
# past, or more than 120 years future, then probably not alive.
|
||||||
@ -637,7 +638,7 @@ def probably_alive(person,db,current_year=None,limit=0):
|
|||||||
val = d.get_start_date()
|
val = d.get_start_date()
|
||||||
val = d.get_year() - years
|
val = d.get_year() - years
|
||||||
d.set_year(val)
|
d.set_year(val)
|
||||||
if not not_too_old (d,current_year):
|
if not not_too_old (d, current_year):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
child_death_ref = child.get_death_ref()
|
child_death_ref = child.get_death_ref()
|
||||||
@ -645,7 +646,7 @@ def probably_alive(person,db,current_year=None,limit=0):
|
|||||||
child_death = db.get_event_from_handle(child_death_ref.ref)
|
child_death = db.get_event_from_handle(child_death_ref.ref)
|
||||||
dobj = child_death.get_date_object()
|
dobj = child_death.get_date_object()
|
||||||
if dobj.get_start_date() != RelLib.Date.EMPTY:
|
if dobj.get_start_date() != RelLib.Date.EMPTY:
|
||||||
if not not_too_old (dobj,current_year):
|
if not not_too_old (dobj, current_year):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if descendants_too_old (child, years + min_generation):
|
if descendants_too_old (child, years + min_generation):
|
||||||
@ -680,11 +681,8 @@ def probably_alive(person,db,current_year=None,limit=0):
|
|||||||
father_birth_ref.ref)
|
father_birth_ref.ref)
|
||||||
dobj = father_birth.get_date_object()
|
dobj = father_birth.get_date_object()
|
||||||
if dobj.get_start_date() != RelLib.Date.EMPTY:
|
if dobj.get_start_date() != RelLib.Date.EMPTY:
|
||||||
if not not_too_old (dobj,year - average_generation_gap):
|
if not not_too_old (dobj, year - average_generation_gap):
|
||||||
#print father.get_primary_name().get_name(), " father of ", person.get_primary_name().get_name(), " is too old by birth. birth year ", dobj.get_year(), " test year ", year - average_generation_gap
|
|
||||||
return True
|
return True
|
||||||
#else:
|
|
||||||
#print father.get_primary_name().get_name(), " father of ", person.get_primary_name().get_name(), " is NOT too old by birth. birth year ", dobj.get_year(), " test year ", year - average_generation_gap
|
|
||||||
|
|
||||||
father_death_ref = father.get_death_ref()
|
father_death_ref = father.get_death_ref()
|
||||||
if father_death_ref and father_death_ref.get_role() == RelLib.EventRoleType.PRIMARY:
|
if father_death_ref and father_death_ref.get_role() == RelLib.EventRoleType.PRIMARY:
|
||||||
@ -693,7 +691,6 @@ def probably_alive(person,db,current_year=None,limit=0):
|
|||||||
dobj = father_death.get_date_object()
|
dobj = father_death.get_date_object()
|
||||||
if dobj.get_start_date() != RelLib.Date.EMPTY:
|
if dobj.get_start_date() != RelLib.Date.EMPTY:
|
||||||
if dobj.get_year() < year - average_generation_gap:
|
if dobj.get_year() < year - average_generation_gap:
|
||||||
#print father.get_primary_name().get_name(), " father of ", person.get_primary_name().get_name(), " is too old by death."
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if ancestors_too_old (father, year - average_generation_gap):
|
if ancestors_too_old (father, year - average_generation_gap):
|
||||||
@ -707,11 +704,8 @@ def probably_alive(person,db,current_year=None,limit=0):
|
|||||||
mother_birth = db.get_event_from_handle(mother_birth_ref.ref)
|
mother_birth = db.get_event_from_handle(mother_birth_ref.ref)
|
||||||
dobj = mother_birth.get_date_object()
|
dobj = mother_birth.get_date_object()
|
||||||
if dobj.get_start_date() != RelLib.Date.EMPTY:
|
if dobj.get_start_date() != RelLib.Date.EMPTY:
|
||||||
if not not_too_old (dobj,year - average_generation_gap):
|
if not not_too_old (dobj, year - average_generation_gap):
|
||||||
#print mother.get_primary_name().get_name(), " mother of ", person.get_primary_name().get_name(), " is too old by birth. birth year ", dobj.get_year(), " test year ", year - average_generation_gap
|
|
||||||
return True
|
return True
|
||||||
#else:
|
|
||||||
#print mother.get_primary_name().get_name(), " mother of ", person.get_primary_name().get_name(), " is NOT too old by birth. birth year ", dobj.get_year(), " test year ", year - average_generation_gap
|
|
||||||
|
|
||||||
mother_death_ref = mother.get_death_ref()
|
mother_death_ref = mother.get_death_ref()
|
||||||
if mother_death_ref and mother_death_ref.get_role() == RelLib.EventRoleType.PRIMARY:
|
if mother_death_ref and mother_death_ref.get_role() == RelLib.EventRoleType.PRIMARY:
|
||||||
@ -720,7 +714,6 @@ def probably_alive(person,db,current_year=None,limit=0):
|
|||||||
dobj = mother_death.get_date_object()
|
dobj = mother_death.get_date_object()
|
||||||
if dobj.get_start_date() != RelLib.Date.EMPTY:
|
if dobj.get_start_date() != RelLib.Date.EMPTY:
|
||||||
if dobj.get_year() < year - average_generation_gap:
|
if dobj.get_year() < year - average_generation_gap:
|
||||||
#print mother.get_primary_name().get_name(), " mother of ", person.get_primary_name().get_name(), " is too old by death."
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
if ancestors_too_old (mother, year - average_generation_gap):
|
if ancestors_too_old (mother, year - average_generation_gap):
|
||||||
@ -739,7 +732,7 @@ def probably_alive(person,db,current_year=None,limit=0):
|
|||||||
#print person.get_primary_name().get_name(), " is probably alive."
|
#print person.get_primary_name().get_name(), " is probably alive."
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def not_too_old(date,current_year=None):
|
def not_too_old(date, current_year=None):
|
||||||
if not current_year:
|
if not current_year:
|
||||||
time_struct = time.localtime(time.time())
|
time_struct = time.localtime(time.time())
|
||||||
current_year = time_struct[0]
|
current_year = time_struct[0]
|
||||||
@ -748,7 +741,7 @@ def not_too_old(date,current_year=None):
|
|||||||
return False
|
return False
|
||||||
return (year != 0 and current_year - year < 110)
|
return (year != 0 and current_year - year < 110)
|
||||||
|
|
||||||
def too_old(date,current_year=None):
|
def too_old(date, current_year=None):
|
||||||
if current_year:
|
if current_year:
|
||||||
the_current_year = current_year
|
the_current_year = current_year
|
||||||
else:
|
else:
|
||||||
@ -778,7 +771,7 @@ def get_referents(handle, db, primary_objects):
|
|||||||
|
|
||||||
for primary in primary_objects:
|
for primary in primary_objects:
|
||||||
primary_list = [item[1] for item in object_list if item[0] == primary]
|
primary_list = [item[1] for item in object_list if item[0] == primary]
|
||||||
the_lists = the_lists + (primary_list,)
|
the_lists = the_lists + (primary_list, )
|
||||||
|
|
||||||
return the_lists
|
return the_lists
|
||||||
|
|
||||||
@ -789,12 +782,12 @@ def get_source_referents(source_handle, db):
|
|||||||
secondary child-objects) to a given source handle in a given database.
|
secondary child-objects) to a given source handle in a given database.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
_primaries = ('Person', 'Family', 'Event', 'Place',
|
_primaries = ('Person', 'Family', 'Event', 'Place',
|
||||||
'Source', 'MediaObject', 'Repository')
|
'Source', 'MediaObject', 'Repository')
|
||||||
|
|
||||||
return (get_referents(source_handle, db, _primaries))
|
return (get_referents(source_handle, db, _primaries))
|
||||||
|
|
||||||
def get_media_referents(media_handle,db):
|
def get_media_referents(media_handle, db):
|
||||||
""" Find objects that refer the media object.
|
""" Find objects that refer the media object.
|
||||||
|
|
||||||
This function finds all primary objects that refer
|
This function finds all primary objects that refer
|
||||||
@ -812,7 +805,7 @@ def get_note_referents(note_handle, db):
|
|||||||
to a given note handle in a given database.
|
to a given note handle in a given database.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
_primaries = ('Person', 'Family', 'Event', 'Place',
|
_primaries = ('Person', 'Family', 'Event', 'Place',
|
||||||
'Source', 'MediaObject', 'Repository')
|
'Source', 'MediaObject', 'Repository')
|
||||||
|
|
||||||
return (get_referents(note_handle, db, _primaries))
|
return (get_referents(note_handle, db, _primaries))
|
||||||
@ -824,12 +817,12 @@ def get_note_referents(note_handle, db):
|
|||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
_NEW_NAME_PATTERN = '%s%sUntitled_%d.%s'
|
_NEW_NAME_PATTERN = '%s%sUntitled_%d.%s'
|
||||||
|
|
||||||
def get_new_filename(ext,folder='~/'):
|
def get_new_filename(ext, folder='~/'):
|
||||||
ix = 1
|
ix = 1
|
||||||
while os.path.isfile(os.path.expanduser(_NEW_NAME_PATTERN %
|
while os.path.isfile(os.path.expanduser(_NEW_NAME_PATTERN %
|
||||||
(folder,os.path.sep,ix,ext))):
|
(folder, os.path.sep, ix, ext))):
|
||||||
ix = ix + 1
|
ix = ix + 1
|
||||||
return os.path.expanduser(_NEW_NAME_PATTERN % (folder,os.path.sep,ix,ext))
|
return os.path.expanduser(_NEW_NAME_PATTERN % (folder, os.path.sep, ix, ext))
|
||||||
|
|
||||||
def cast_to_bool(val):
|
def cast_to_bool(val):
|
||||||
if val == str(True):
|
if val == str(True):
|
||||||
@ -841,7 +834,7 @@ def get_type_converter(val):
|
|||||||
Returns function that converts strings into the type of val.
|
Returns function that converts strings into the type of val.
|
||||||
"""
|
"""
|
||||||
val_type = type(val)
|
val_type = type(val)
|
||||||
if val_type in (str,unicode):
|
if val_type in (str, unicode):
|
||||||
return unicode
|
return unicode
|
||||||
elif val_type == int:
|
elif val_type == int:
|
||||||
return int
|
return int
|
||||||
@ -849,7 +842,7 @@ def get_type_converter(val):
|
|||||||
return float
|
return float
|
||||||
elif val_type == bool:
|
elif val_type == bool:
|
||||||
return cast_to_bool
|
return cast_to_bool
|
||||||
elif val_type in (list,tuple):
|
elif val_type in (list, tuple):
|
||||||
return list
|
return list
|
||||||
|
|
||||||
def type_name(val):
|
def type_name(val):
|
||||||
@ -864,7 +857,7 @@ def type_name(val):
|
|||||||
return 'int'
|
return 'int'
|
||||||
elif val_type == float:
|
elif val_type == float:
|
||||||
return 'float'
|
return 'float'
|
||||||
elif val_type in (str,unicode):
|
elif val_type in (str, unicode):
|
||||||
return 'unicode'
|
return 'unicode'
|
||||||
return 'unicode'
|
return 'unicode'
|
||||||
|
|
||||||
@ -879,7 +872,7 @@ def get_type_converter_by_name(val_str):
|
|||||||
return int
|
return int
|
||||||
elif val_str == 'float':
|
elif val_str == 'float':
|
||||||
return float
|
return float
|
||||||
elif val_str in ('str','unicode'):
|
elif val_str in ('str', 'unicode'):
|
||||||
return unicode
|
return unicode
|
||||||
return unicode
|
return unicode
|
||||||
|
|
||||||
@ -896,7 +889,7 @@ def relative_path(original, base):
|
|||||||
for i in range(min(len(base_list), len(target_list))):
|
for i in range(min(len(base_list), len(target_list))):
|
||||||
if base_list[i] <> target_list[i]: break
|
if base_list[i] <> target_list[i]: break
|
||||||
else:
|
else:
|
||||||
i+=1
|
i += 1
|
||||||
rel_list = [os.pardir] * (len(base_list)-i) + target_list[i:]
|
rel_list = [os.pardir] * (len(base_list)-i) + target_list[i:]
|
||||||
return os.path.join(*rel_list)
|
return os.path.join(*rel_list)
|
||||||
|
|
||||||
@ -904,13 +897,13 @@ class ProgressMeter:
|
|||||||
"""
|
"""
|
||||||
Progress meter class for GRAMPS.
|
Progress meter class for GRAMPS.
|
||||||
"""
|
"""
|
||||||
def __init__(self,title,header=''):
|
def __init__(self, title, header=''):
|
||||||
"""
|
"""
|
||||||
Specify the title and the current pass header.
|
Specify the title and the current pass header.
|
||||||
"""
|
"""
|
||||||
self.old_val = -1
|
self.old_val = -1
|
||||||
self.ptop = gtk.Dialog()
|
self.ptop = gtk.Dialog()
|
||||||
self.ptop.connect('delete_event',self.warn)
|
self.ptop.connect('delete_event', self.warn)
|
||||||
self.ptop.set_has_separator(False)
|
self.ptop.set_has_separator(False)
|
||||||
self.ptop.set_title(title)
|
self.ptop.set_title(title)
|
||||||
self.ptop.set_border_width(12)
|
self.ptop.set_border_width(12)
|
||||||
@ -924,13 +917,13 @@ class ProgressMeter:
|
|||||||
self.ptop.vbox.set_border_width(24)
|
self.ptop.vbox.set_border_width(24)
|
||||||
self.pbar = gtk.ProgressBar()
|
self.pbar = gtk.ProgressBar()
|
||||||
|
|
||||||
self.ptop.set_size_request(350,125)
|
self.ptop.set_size_request(350, 125)
|
||||||
self.ptop.vbox.add(self.pbar)
|
self.ptop.vbox.add(self.pbar)
|
||||||
self.ptop.show_all()
|
self.ptop.show_all()
|
||||||
if header == '':
|
if header == '':
|
||||||
self.lbl.hide()
|
self.lbl.hide()
|
||||||
|
|
||||||
def set_pass(self,header,total):
|
def set_pass(self, header, total):
|
||||||
"""
|
"""
|
||||||
Reset for another pass. Provide a new header and define number
|
Reset for another pass. Provide a new header and define number
|
||||||
of steps to be used.
|
of steps to be used.
|
||||||
@ -966,10 +959,10 @@ class ProgressMeter:
|
|||||||
while gtk.events_pending():
|
while gtk.events_pending():
|
||||||
gtk.main_iteration()
|
gtk.main_iteration()
|
||||||
|
|
||||||
def warn(self,*obj):
|
def warn(self, *obj):
|
||||||
WarningDialog(
|
WarningDialog(
|
||||||
_("Attempt to force closing the dialog"),
|
_("Attempt to force closing the dialog"),
|
||||||
_("Please do not force closing this important dialog."),
|
_("Please do not force closing this important dialog."),
|
||||||
self.ptop)
|
self.ptop)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -979,25 +972,25 @@ class ProgressMeter:
|
|||||||
"""
|
"""
|
||||||
self.ptop.destroy()
|
self.ptop.destroy()
|
||||||
|
|
||||||
def launch(prog_str,path):
|
def launch(prog_str, path):
|
||||||
|
|
||||||
if sys.platform == "win32":
|
if sys.platform == "win32":
|
||||||
|
|
||||||
import subprocess
|
import subprocess
|
||||||
if prog_str.find("%1") != -1:
|
if prog_str.find("%1") != -1:
|
||||||
prog_str = prog_str.replace("%1",path)
|
prog_str = prog_str.replace("%1", path)
|
||||||
else:
|
else:
|
||||||
prog_str = '%s "%s"' %(prog_str,path)
|
prog_str = '%s "%s"' % (prog_str, path)
|
||||||
subprocess.Popen(prog_str)
|
subprocess.Popen(prog_str)
|
||||||
|
|
||||||
else:
|
else:
|
||||||
subval = {
|
subval = {
|
||||||
'%F' : path,
|
'%F' : path,
|
||||||
'%f' : path,
|
'%f' : path,
|
||||||
'%u' : path,
|
'%u' : path,
|
||||||
'%U' : path,
|
'%U' : path,
|
||||||
'%n' : path,
|
'%n' : path,
|
||||||
'%N' : path,
|
'%N' : path,
|
||||||
}
|
}
|
||||||
|
|
||||||
prog_data = prog_str.split()
|
prog_data = prog_str.split()
|
||||||
@ -1021,19 +1014,19 @@ def launch(prog_str,path):
|
|||||||
|
|
||||||
os.spawnvpe(os.P_NOWAIT, prog, prog_list, os.environ)
|
os.spawnvpe(os.P_NOWAIT, prog, prog_list, os.environ)
|
||||||
|
|
||||||
def profile(func,*args):
|
def profile(func, *args):
|
||||||
import hotshot, hotshot.stats
|
import hotshot, hotshot.stats
|
||||||
|
|
||||||
pr = hotshot.Profile('mystats.profile')
|
prf = hotshot.Profile('mystats.profile')
|
||||||
print "Start"
|
print "Start"
|
||||||
pr.runcall(func,*args)
|
prf.runcall(func, *args)
|
||||||
print "Finished"
|
print "Finished"
|
||||||
pr.close()
|
prf.close()
|
||||||
print "Loading profile"
|
print "Loading profile"
|
||||||
stats = hotshot.stats.load('mystats.profile')
|
stats = hotshot.stats.load('mystats.profile')
|
||||||
print "done"
|
print "done"
|
||||||
stats.strip_dirs()
|
stats.strip_dirs()
|
||||||
stats.sort_stats('time','calls')
|
stats.sort_stats('time', 'calls')
|
||||||
stats.print_stats(100)
|
stats.print_stats(100)
|
||||||
stats.print_callers(100)
|
stats.print_callers(100)
|
||||||
|
|
||||||
|
@ -18,6 +18,10 @@
|
|||||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||||
#
|
#
|
||||||
|
|
||||||
|
"""
|
||||||
|
Provides soundex calculation
|
||||||
|
"""
|
||||||
|
|
||||||
#-------------------------------------------------------------------------
|
#-------------------------------------------------------------------------
|
||||||
#
|
#
|
||||||
# Standard python modules
|
# Standard python modules
|
||||||
@ -44,17 +48,17 @@ def soundex(strval):
|
|||||||
|
|
||||||
strval = strval.upper().strip()
|
strval = strval.upper().strip()
|
||||||
if not strval:
|
if not strval:
|
||||||
return "Z000"
|
return "Z000"
|
||||||
strval = strval.encode('iso-8859-1')
|
strval = strval.encode('iso-8859-1')
|
||||||
str2 = strval[0]
|
str2 = strval[0]
|
||||||
strval = strval.translate(TABLE, IGNORE)
|
strval = strval.translate(TABLE, IGNORE)
|
||||||
if not strval:
|
if not strval:
|
||||||
return "Z000"
|
return "Z000"
|
||||||
prev = strval[0]
|
prev = strval[0]
|
||||||
for x in strval[1:]:
|
for character in strval[1:]:
|
||||||
if x != prev and x != "0":
|
if character != prev and character != "0":
|
||||||
str2 = str2 + x
|
str2 = str2 + character
|
||||||
prev = x
|
prev = character
|
||||||
# pad with zeros
|
# pad with zeros
|
||||||
str2 = str2+"0000"
|
str2 = str2+"0000"
|
||||||
return str2[:4]
|
return str2[:4]
|
||||||
|
Reference in New Issue
Block a user