2
edits
Changes
From Gramps
→Patches
== Patches ==
===Non-english locale ===
PlaceCompletion 1.2 does not work correctly if your environment locale is not english (problem identified with locale set to fr_FR.UTF-8).
To solve this issue, you may apply the following patch:
<pre>
--- ../../Documents/genealogie/plugins/placecompletion_1_2/PlaceCompletion.py 2009-02-11 23:04:27.000000000 +0100
+++ ./PlaceCompletion.py 2009-11-22 13:50:35.000000000 +0100
@@ -56,10 +56,18 @@
from Filters.Rules.Place import *
import Utils
-from QuestionDialog import OkDialog, WarningDialog
+from QuestionDialog import OkDialog, WarningDialog, ErrorDialog
import PlaceUtils
import Errors
+if hasattr(Utils, "ProgressMeter"):
+ ProgressMeter = Utils.ProgressMeter
+else:
+ import gui.utils
+ if hasattr(gui.utils, "ProgressMeter"):
+ ProgressMeter = gui.utils.ProgressMeter
+ else:
+ raise ImportError("can't find ProgressMeter")
#------------------------------------------------------------------------
#
#
@@ -177,8 +185,8 @@
self.placechecklist = [self.find_latlon, self.match_regex_title,
self.construct_title, self.convert_latlon, self.set_data
]
- self.regextitlegroups = [_('street'), _('city'), _('parish'),
- _('county'), _('state'), _('country'), _('zip'),_('title')]
+ self.regextitlegroups = [('street'), ('city'), ('parish'),
+ ('county'), ('state'), ('country'), ('zip'), ('title')]
self.glade.signal_autoconnect({
"destroy_passed_object" : self.close,
@@ -198,29 +206,29 @@
''' Get the value corresponding to a group
The special groupname #latlon is allowed, returning lat/lon
'''
- if group == _('title') :
+ if group == ('title') :
return place.get_title()
- elif group == _('latitude') :
+ elif group == ('latitude') :
return place.get_latitude()
- elif group == _('longitude') :
+ elif group == ('longitude') :
return place.get_longitude()
elif group == '#latlon' :
return (place.get_latitude() , place.get_longitude())
else :
loc = place.get_main_location()
- if group == _('city') :
+ if group == ('city') :
return loc.get_city()
- elif group == _('country') :
+ elif group == ('country') :
return loc.get_country()
- elif group == _('county') :
+ elif group == ('county') :
return loc.get_county()
- elif group == _('state') :
+ elif group == ('state') :
return loc.get_state()
- elif group == _('street') :
+ elif group == ('street') :
return loc.get_street()
- elif group == _('parish') :
+ elif group == ('parish') :
return loc.get_parish()
- elif group == _('zip') :
+ elif group == ('zip') :
return loc.get_postal_code()
else :
ErrorDialog(_("Error in PlaceCompletion.py"),
@@ -234,11 +242,11 @@
'''
if not group :
return place
- if group == _('title') :
+ if group == ('title') :
place.set_title(val)
- elif group == _('latitude') :
+ elif group == ('latitude') :
place.set_latitude(val)
- elif group == _('longitude') :
+ elif group == ('longitude') :
place.set_longitude(val)
elif group == '#latlon' :
place.set_latitude(val[0])
@@ -247,20 +255,23 @@
loc = place.get_main_location()
if loc == None :
loc = Location()
- if group == _('city') :
+ if group == ('city') :
loc.set_city(val)
- elif group == _('country') :
+ elif group == ('country') :
loc.set_country(val)
- elif group == _('county') :
+ elif group == ('county') :
loc.set_county(val)
- elif group == _('state') :
+ elif group == ('state') :
loc.set_state(val)
- elif group == _('street') :
+ elif group == ('street') :
loc.set_street(val)
- elif group == _('parish') :
+ elif group == ('parish') :
loc.set_parish(val)
- elif group == _('zip') :
+ elif group == ('zip') :
loc.set_postal_code(val)
+ elif group == ('title') :
+ loc.set_title(val)
+
else :
ErrorDialog(_("Error in PlaceCompletion.py"),
_("Non existing group used in set"))
@@ -421,12 +432,12 @@
# Compile Regex file search partially
self.matchlatlon = None
self.extrafindgroup = [] #find always finds lat/lon, what extra groups?
- possibleextrafindgroups=[_('county'), _('state')]
+ possibleextrafindgroups=[('county'), ('state')]
if findregex :
try:
#compile regex aware of locale and unicode
self.matchlatlon = re.compile(findregex,re.U|re.L|re.M)
- latlongroup = [_('lat'),_('lon')]
+ latlongroup = [('lat'),('lon')]
for group in latlongroup :
if findregex.find(r'(?P<'+group+r'>') == -1 :
WarningDialog(_('Missing regex groups in match lat/lon'),
@@ -498,8 +509,8 @@
self.nrplaces_in_tree = len(ind_list)
# Populating might take a while, add a progress bar
- progress = Utils.ProgressMeter(
- _("Finding Places and appropriate changes"),'')
+ progress = ProgressMeter(
+ _("Finding Places and appropriate changes"),'')
#apply the filter
progress.set_pass(_('Filtering'),1)
progress.step()
@@ -559,7 +570,7 @@
# a line of text, do nothing
newval = 'no change'
if groupname == '#latlon' :
- self.model.set(id, 0, _('lat')+r'/'+_('lon') + ' :' \
+ self.model.set(id, 0, ('lat')+r'/'+('lon') + ' :' \
+ olddata
+ ' -> ' + newval[0]+r'/'+newval[1])
else :
@@ -704,7 +715,7 @@
self.trans = self.db.transaction_begin("",batch=True)
self.db.disable_signals()
- progress = Utils.ProgressMeter(_('Doing Place changes'),'')
+ progress = ProgressMeter(_('Doing Place changes'),'')
#we do not know how many places in the treeview, and counting would
# mean transversing the tree. Set the progress to the possible maximum
progress.set_pass('',self.db.get_number_of_places())
@@ -822,26 +833,26 @@
if len(filename) == 0:
return True
elif os.path.isdir(filename):
- QuestionDialog.ErrorDialog(
+ ErrorDialog(
_('Cannot open file'),
_('The selected file is a directory, not '
'a file.'))
return True
elif os.path.exists(filename):
if not os.access(filename, os.R_OK):
- QuestionDialog.ErrorDialog(
+ ErrorDialog(
_('Cannot open file'),
_('You do not have read access to the selected '
'file.'))
return True
elif not stat.S_ISREG(os.stat(filename)[stat.ST_MODE]):
- QuestionDialog.ErrorDialog(
+ ErrorDialog(
_('Cannot open file'),
_('The file you want to access is not a regular file.'))
return True
else :
# file does not exist
- QuestionDialog.ErrorDialog(
+ ErrorDialog(
_('Cannot open file'),
_('The file does not exist.'))
return True
@@ -892,36 +903,36 @@
# we need to lookup the latitude and longitude, construct regex:
pattern = self.matchlatlon.pattern
loc = place.get_main_location()
- if re.search(_('CITY'),pattern) :
+ if re.search(('CITY'),pattern) :
if loc.get_city().strip() == '' :
return valoud, valnew, valaction, place
- pattern = re.sub(_('CITY'), loc.get_city().strip(), pattern)
- if re.search(_('TITLEBEGIN'),pattern) :
+ pattern = re.sub(('CITY'), loc.get_city().strip(), pattern)
+ if re.search(('TITLEBEGIN'),pattern) :
tit = place.get_title().strip()
titb= tit.split(',')[0].strip()
if titb == '' :
return valoud, valnew, valaction, place
- pattern = re.sub(_('TITLEBEGIN'), titb, pattern)
- if re.search(_('TITLE'),pattern) :
+ pattern = re.sub(('TITLEBEGIN'), titb, pattern)
+ if re.search(('TITLE'),pattern) :
if place.get_title().strip() == '' :
return valoud, valnew, valaction, place
- pattern = re.sub(_('TITLE'), loc.get_title().strip(), pattern)
- if re.search(_('STATE'),pattern) :
+ pattern = re.sub(('TITLE'), loc.get_title().strip(), pattern)
+ if re.search(('STATE'),pattern) :
if place.get_state().strip() == '' :
return valoud, valnew, valaction, place
- pattern = re.sub(_('STATE'), loc.get_state().strip(), pattern)
- if re.search(_('PARISH'),pattern) :
+ pattern = re.sub(('STATE'), loc.get_state().strip(), pattern)
+ if re.search(('PARISH'),pattern) :
if loc.get_parish().strip() == '' :
return valoud, valnew, valaction, place
- pattern = re.sub(_('PARISH'), loc.get_parish().strip(), pattern)
+ pattern = re.sub(('PARISH'), loc.get_parish().strip(), pattern)
print 'DEBUG info: pattern for search is ' , pattern
regexll = re.compile(pattern,re.U|re.L|re.M)
- latlongroup = [_('lat'),_('lon')]
+ latlongroup = [('lat'),('lon')]
#find all occurences in the data file
iterator = regexll.finditer(self.latlonfile_datastr)
for result in iterator :
- lato =self.group_get(place, _('latitude'))
- lono =self.group_get(place, _('longitude'))
+ lato =self.group_get(place, ('latitude'))
+ lono =self.group_get(place, ('longitude'))
lat = result.group(latlongroup[0])
lon = result.group(latlongroup[1])
@@ -976,26 +987,26 @@
if latnew != None and latnew != lat :
valoud.append(lat)
valnew.append(latnew)
- valaction.append([_('latitude'),latnew])
+ valaction.append([('latitude'),latnew])
#do the action in memory
- place = self.group_set(place, _('latitude'),latnew)
+ place = self.group_set(place, ('latitude'),latnew)
elif lat != '' and latnew == None :
valoud.append(_('invalid lat or lon value, %(lat)s, %(lon)s')
% {'lat' : lat, 'lon' : lon})
valnew.append(None)
#do nothing
- valaction.append([_('latitude'), None])
+ valaction.append([('latitude'), None])
if lonnew != None and lonnew != lon :
valoud.append(lon)
valnew.append(lonnew)
- valaction.append([_('longitude'),lonnew])
+ valaction.append([('longitude'),lonnew])
#do the action in memory
- place = self.group_set(place, _('longitude'),lonnew)
+ place = self.group_set(place, ('longitude'),lonnew)
elif lon != '' and lonnew == None :
valoud.append(_('invalid lat or lon value, %(lat)s, %(lon)s')
% {'lat' : lat, 'lon' : lon})
valnew.append(None)
- valaction.append([_('longitude'), None])
+ valaction.append([('longitude'), None])
return valoud, valnew, valaction, place
def construct_title(self, place) :
@@ -1011,9 +1022,9 @@
if place.get_main_location().get_state() :
new += ', ' + place.get_main_location().get_state()
valnew.append(new)
- valaction.append([_('title'),new])
+ valaction.append([('title'),new])
#do the action in memory
- place = self.group_set(place, _('title'),new)
+ place = self.group_set(place, ('title'),new)
elif type == "T1CS" :
old = place.get_title()
valoud.append(old)
@@ -1024,9 +1035,9 @@
if place.get_main_location().get_state() :
new += ', ' + place.get_main_location().get_state()
valnew.append(new)
- valaction.append([_('title'),new])
+ valaction.append([('title'),new])
#do the action in memory
- place = self.group_set(place, _('title'),new)
+ place = self.group_set(place, ('title'),new)
return valoud, valnew, valaction, place
@@ -1035,12 +1046,12 @@
valnew = []
valaction = []
- for newval in [(self.options.handler.options_dict['countryset'],_('country')),
- (self.options.handler.options_dict['stateset'],_('state')),
- (self.options.handler.options_dict['countyset'],_('county')),
- (self.options.handler.options_dict['cityset'],_('city')),
- (self.options.handler.options_dict['parishset'],_('parish')),
- (self.options.handler.options_dict['zipset'],_('zip'))] :
+ for newval in [(self.options.handler.options_dict['countryset'],('country')),
+ (self.options.handler.options_dict['stateset'],('state')),
+ (self.options.handler.options_dict['countyset'],('county')),
+ (self.options.handler.options_dict['cityset'],('city')),
+ (self.options.handler.options_dict['parishset'],('parish')),
+ (self.options.handler.options_dict['zipset'],('zip'))] :
#we allow ' ' to mean store '':
if newval[0] :
nv = newval[0].strip()
@@ -1076,23 +1087,23 @@
# geonames : http://download.geonames.org/export/dump/
# geonet : ftp://ftp.nga.mil/pub/gns_data
- lat_translated = _('lat')
- lon_translated = _('lon')
- city_translated = _('city')
- county_translated = _('county')
- state_translated = _('state')
- country_translated = _('country')
- CITY_transl = _('CITY')
- TITLE_transl = _('TITLE')
- TITLEBEGIN_transl = _('TITLEBEGIN')
- STATE_transl = _('STATE')
- PARISH_transl = _('PARISH')
- latgr = r'(?P<'+lat_translated +r'>'
- longr = r'(?P<'+lon_translated +r'>'
- citygr = r'(?P<'+city_translated +r'>'
- countygr = r'(?P<'+county_translated +r'>'
- countrygr = r'(?P<'+country_translated +r'>'
- stategr = r'(?P<'+state_translated +r'>'
+# lat_translated = _('lat')
+# lon_translated = _('lon')
+# city_translated = _('city')
+# county_translated = _('county')
+# state_translated = _('state')
+# country_translated = _('country')
+ CITY_transl = ('CITY')
+ TITLE_transl = ('TITLE')
+ TITLEBEGIN_transl = ('TITLEBEGIN')
+ STATE_transl = ('STATE')
+ PARISH_transl = ('PARISH')
+ latgr = r'(?P<'+'lat' +r'>'
+ longr = r'(?P<'+'lon' +r'>'
+ citygr = r'(?P<'+'city' +r'>'
+ countygr = r'(?P<'+'county' +r'>'
+ countrygr = r'(?P<'+'country' +r'>'
+ stategr = r'(?P<'+'state' +r'>'
titleregex = (
("citystate", "City [,|.] State", _("City [,|.] State")
, r'\s*'+citygr +r'.+?)\s*[.,]\s*'+stategr+r'.+?)\s*$'),
</pre>
===Parsing place title===