Put space before comma (PEP8) in preparation for
some bugfixes. * src/plugins/PatchNames.py svn: r10517
This commit is contained in:
parent
7e910a6fc3
commit
c0a8ae9aff
@ -72,7 +72,7 @@ _fn_prefix_re = re.compile("(.*)\s+(%s)\s*$" % '|'.join(prefix_list),
|
||||
re.IGNORECASE)
|
||||
_sn_prefix_re = re.compile("^\s*(%s)\s+(.*)" % '|'.join(prefix_list),
|
||||
re.IGNORECASE)
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# Search each name in the database, and compare the firstname against the
|
||||
@ -81,18 +81,14 @@ _sn_prefix_re = re.compile("^\s*(%s)\s+(.*)" % '|'.join(prefix_list),
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
# PatchNames
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
|
||||
class PatchNames(Tool.BatchTool, ManagedWindow.ManagedWindow):
|
||||
|
||||
|
||||
def __init__(self, dbstate, uistate, options_class, name, callback=None):
|
||||
self.label = _('Name and title extraction tool')
|
||||
ManagedWindow.ManagedWindow.__init__(self,uistate,[],self.__class__)
|
||||
self.set_window(gtk.Window(),gtk.Label(),'')
|
||||
|
||||
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self.__class__)
|
||||
self.set_window(gtk.Window(), gtk.Label(), '')
|
||||
|
||||
Tool.BatchTool.__init__(self, dbstate, options_class, name)
|
||||
if self.fail:
|
||||
return
|
||||
@ -104,12 +100,12 @@ class PatchNames(Tool.BatchTool, ManagedWindow.ManagedWindow):
|
||||
self.prefix2_list = []
|
||||
|
||||
self.progress = Utils.ProgressMeter(
|
||||
_('Extracting Information from Names'),'')
|
||||
_('Extracting Information from Names'), '')
|
||||
self.progress.set_pass(_('Analyzing names'),
|
||||
self.db.get_number_of_people())
|
||||
|
||||
for key in self.db.get_person_handles(sort_handles=False):
|
||||
|
||||
|
||||
person = self.db.get_person_from_handle(key)
|
||||
name = person.get_primary_name()
|
||||
first = name.get_first_name()
|
||||
@ -129,14 +125,14 @@ class PatchNames(Tool.BatchTool, ManagedWindow.ManagedWindow):
|
||||
match = _title_re.match(first)
|
||||
|
||||
if new_title:
|
||||
self.title_list.append((key," ".join(old_title+new_title),
|
||||
self.title_list.append((key, " ".join(old_title+new_title),
|
||||
first))
|
||||
continue
|
||||
|
||||
|
||||
match = _nick_re.match(first)
|
||||
if match:
|
||||
groups = match.groups()
|
||||
self.nick_list.append((key,groups[0],groups[1]))
|
||||
self.nick_list.append((key, groups[0], groups[1]))
|
||||
continue
|
||||
|
||||
old_prefix = name.get_surname_prefix()
|
||||
@ -144,16 +140,16 @@ class PatchNames(Tool.BatchTool, ManagedWindow.ManagedWindow):
|
||||
match = _fn_prefix_re.match(first)
|
||||
if match:
|
||||
groups = match.groups()
|
||||
self.prefix1_list.append((key,groups[0],
|
||||
self.prefix1_list.append((key, groups[0],
|
||||
" ".join([groups[1], old_prefix]))
|
||||
)
|
||||
continue
|
||||
|
||||
|
||||
match = _sn_prefix_re.match(sname)
|
||||
if match:
|
||||
groups = match.groups()
|
||||
self.prefix2_list.append((key,groups[1],
|
||||
" ".join([old_prefix,groups[0]]))
|
||||
self.prefix2_list.append((key, groups[1],
|
||||
" ".join([old_prefix, groups[0]]))
|
||||
)
|
||||
|
||||
self.progress.step()
|
||||
@ -167,49 +163,49 @@ class PatchNames(Tool.BatchTool, ManagedWindow.ManagedWindow):
|
||||
_("No titles or nicknames were found"))
|
||||
|
||||
def build_menu_names(self, obj):
|
||||
return (self.label,None)
|
||||
return (self.label, None)
|
||||
|
||||
def toggled(self,cell,path_string):
|
||||
def toggled(self, cell, path_string):
|
||||
path = tuple([int (i) for i in path_string.split(':')])
|
||||
row = self.model[path]
|
||||
row[0] = not row[0]
|
||||
self.model.row_changed(path,row.iter)
|
||||
self.model.row_changed(path, row.iter)
|
||||
|
||||
def display(self):
|
||||
|
||||
base = os.path.dirname(__file__)
|
||||
glade_file = os.path.join(base,"patchnames.glade")
|
||||
|
||||
self.top = glade.XML(glade_file,"top","gramps")
|
||||
glade_file = os.path.join(base, "patchnames.glade")
|
||||
|
||||
self.top = glade.XML(glade_file, "top", "gramps")
|
||||
window = self.top.get_widget('top')
|
||||
self.top.signal_autoconnect({
|
||||
"destroy_passed_object" : self.close,
|
||||
"on_ok_clicked" : self.on_ok_clicked,
|
||||
"on_help_clicked" : self.on_help_clicked,
|
||||
})
|
||||
|
||||
self.list = self.top.get_widget("list")
|
||||
self.set_window(window,self.top.get_widget('title'),self.label)
|
||||
|
||||
self.model = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING,
|
||||
gobject.TYPE_STRING, gobject.TYPE_STRING,
|
||||
self.list = self.top.get_widget("list")
|
||||
self.set_window(window, self.top.get_widget('title'), self.label)
|
||||
|
||||
self.model = gtk.ListStore(gobject.TYPE_BOOLEAN, gobject.TYPE_STRING,
|
||||
gobject.TYPE_STRING, gobject.TYPE_STRING,
|
||||
gobject.TYPE_STRING)
|
||||
|
||||
r = gtk.CellRendererToggle()
|
||||
r.connect('toggled',self.toggled)
|
||||
c = gtk.TreeViewColumn(_('Select'),r,active=0)
|
||||
r.connect('toggled', self.toggled)
|
||||
c = gtk.TreeViewColumn(_('Select'), r, active=0)
|
||||
self.list.append_column(c)
|
||||
|
||||
c = gtk.TreeViewColumn(_('ID'),gtk.CellRendererText(),text=1)
|
||||
c = gtk.TreeViewColumn(_('ID'), gtk.CellRendererText(), text=1)
|
||||
self.list.append_column(c)
|
||||
|
||||
c = gtk.TreeViewColumn(_('Type'),gtk.CellRendererText(),text=2)
|
||||
c = gtk.TreeViewColumn(_('Type'), gtk.CellRendererText(), text=2)
|
||||
self.list.append_column(c)
|
||||
|
||||
c = gtk.TreeViewColumn(_('Value'),gtk.CellRendererText(),text=3)
|
||||
c = gtk.TreeViewColumn(_('Value'), gtk.CellRendererText(), text=3)
|
||||
self.list.append_column(c)
|
||||
|
||||
c = gtk.TreeViewColumn(_('Name'),gtk.CellRendererText(),text=4)
|
||||
c = gtk.TreeViewColumn(_('Name'), gtk.CellRendererText(), text=4)
|
||||
self.list.append_column(c)
|
||||
|
||||
self.list.set_model(self.model)
|
||||
@ -227,23 +223,23 @@ class PatchNames(Tool.BatchTool, ManagedWindow.ManagedWindow):
|
||||
p = self.db.get_person_from_handle(pid)
|
||||
gid = p.get_gramps_id()
|
||||
handle = self.model.append()
|
||||
self.model.set_value(handle,0,1)
|
||||
self.model.set_value(handle,1,gid)
|
||||
self.model.set_value(handle,2,_('Nickname'))
|
||||
self.model.set_value(handle,3, nick)
|
||||
self.model.set_value(handle,4,p.get_primary_name().get_name())
|
||||
self.model.set_value(handle, 0, 1)
|
||||
self.model.set_value(handle, 1, gid)
|
||||
self.model.set_value(handle, 2, _('Nickname'))
|
||||
self.model.set_value(handle, 3, nick)
|
||||
self.model.set_value(handle, 4, p.get_primary_name().get_name())
|
||||
self.nick_hash[pid] = handle
|
||||
self.progress.step()
|
||||
|
||||
|
||||
for (pid, title, name) in self.title_list:
|
||||
p = self.db.get_person_from_handle(pid)
|
||||
gid = p.get_gramps_id()
|
||||
handle = self.model.append()
|
||||
self.model.set_value(handle,0,1)
|
||||
self.model.set_value(handle,1,gid)
|
||||
self.model.set_value(handle,2,_('Title'))
|
||||
self.model.set_value(handle,3,title)
|
||||
self.model.set_value(handle,4,p.get_primary_name().get_name())
|
||||
self.model.set_value(handle, 0, 1)
|
||||
self.model.set_value(handle, 1, gid)
|
||||
self.model.set_value(handle, 2, _('Title'))
|
||||
self.model.set_value(handle, 3, title)
|
||||
self.model.set_value(handle, 4, p.get_primary_name().get_name())
|
||||
self.title_hash[pid] = handle
|
||||
self.progress.step()
|
||||
|
||||
@ -251,11 +247,11 @@ class PatchNames(Tool.BatchTool, ManagedWindow.ManagedWindow):
|
||||
p = self.db.get_person_from_handle(pid)
|
||||
gid = p.get_gramps_id()
|
||||
handle = self.model.append()
|
||||
self.model.set_value(handle,0,1)
|
||||
self.model.set_value(handle,1,gid)
|
||||
self.model.set_value(handle,2,_('Prefix'))
|
||||
self.model.set_value(handle,3,prefix)
|
||||
self.model.set_value(handle,4,p.get_primary_name().get_name())
|
||||
self.model.set_value(handle, 0, 1)
|
||||
self.model.set_value(handle, 1, gid)
|
||||
self.model.set_value(handle, 2, _('Prefix'))
|
||||
self.model.set_value(handle, 3, prefix)
|
||||
self.model.set_value(handle, 4, p.get_primary_name().get_name())
|
||||
self.prefix1_hash[pid] = handle
|
||||
self.progress.step()
|
||||
|
||||
@ -263,11 +259,11 @@ class PatchNames(Tool.BatchTool, ManagedWindow.ManagedWindow):
|
||||
p = self.db.get_person_from_handle(pid)
|
||||
gid = p.get_gramps_id()
|
||||
handle = self.model.append()
|
||||
self.model.set_value(handle,0,1)
|
||||
self.model.set_value(handle,1,gid)
|
||||
self.model.set_value(handle,2,_('Prefix'))
|
||||
self.model.set_value(handle,3,prefix)
|
||||
self.model.set_value(handle,4,p.get_primary_name().get_name())
|
||||
self.model.set_value(handle, 0, 1)
|
||||
self.model.set_value(handle, 1, gid)
|
||||
self.model.set_value(handle, 2, _('Prefix'))
|
||||
self.model.set_value(handle, 3, prefix)
|
||||
self.model.set_value(handle, 4, p.get_primary_name().get_name())
|
||||
self.prefix2_hash[pid] = handle
|
||||
self.progress.step()
|
||||
|
||||
@ -279,11 +275,11 @@ class PatchNames(Tool.BatchTool, ManagedWindow.ManagedWindow):
|
||||
GrampsDisplay.help()
|
||||
|
||||
def on_ok_clicked(self, obj):
|
||||
self.trans = self.db.transaction_begin("",batch=True)
|
||||
trans = self.db.transaction_begin("", batch=True)
|
||||
self.db.disable_signals()
|
||||
for grp in self.nick_list:
|
||||
handle = self.nick_hash[grp[0]]
|
||||
val = self.model.get_value(handle,0)
|
||||
val = self.model.get_value(handle, 0)
|
||||
if val:
|
||||
p = self.db.get_person_from_handle(grp[0])
|
||||
name = p.get_primary_name()
|
||||
@ -293,63 +289,55 @@ class PatchNames(Tool.BatchTool, ManagedWindow.ManagedWindow):
|
||||
attr.set_type(gen.lib.AttributeType.NICKNAME)
|
||||
attr.set_value(nick_name)
|
||||
p.add_attribute(attr)
|
||||
self.db.commit_person(p,self.trans)
|
||||
self.db.commit_person(p, trans)
|
||||
|
||||
for grp in self.title_list:
|
||||
handle = self.title_hash[grp[0]]
|
||||
val = self.model.get_value(handle,0)
|
||||
val = self.model.get_value(handle, 0)
|
||||
if val:
|
||||
p = self.db.get_person_from_handle(grp[0])
|
||||
name = p.get_primary_name()
|
||||
name.set_first_name(grp[2].strip())
|
||||
name.set_title(grp[1].strip())
|
||||
self.db.commit_person(p,self.trans)
|
||||
self.db.commit_person(p, trans)
|
||||
|
||||
for grp in self.prefix1_list:
|
||||
handle = self.prefix1_hash[grp[0]]
|
||||
val = self.model.get_value(handle,0)
|
||||
val = self.model.get_value(handle, 0)
|
||||
if val:
|
||||
p = self.db.get_person_from_handle(grp[0])
|
||||
name = p.get_primary_name()
|
||||
name.set_first_name(grp[1].strip())
|
||||
name.set_surname_prefix(grp[2].strip())
|
||||
self.db.commit_person(p,self.trans)
|
||||
self.db.commit_person(p, trans)
|
||||
|
||||
for grp in self.prefix2_list:
|
||||
handle = self.prefix2_hash[grp[0]]
|
||||
val = self.model.get_value(handle,0)
|
||||
val = self.model.get_value(handle, 0)
|
||||
if val:
|
||||
p = self.db.get_person_from_handle(grp[0])
|
||||
name = p.get_primary_name()
|
||||
name.set_surname(grp[1].strip())
|
||||
name.set_surname_prefix(grp[2].strip())
|
||||
self.db.commit_person(p,self.trans)
|
||||
self.db.commit_person(p, trans)
|
||||
|
||||
self.db.transaction_commit(self.trans,
|
||||
self.db.transaction_commit(trans,
|
||||
_("Extract information from names"))
|
||||
self.db.enable_signals()
|
||||
self.db.request_rebuild()
|
||||
self.close()
|
||||
self.cb()
|
||||
|
||||
#------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
|
||||
|
||||
class PatchNamesOptions(Tool.ToolOptions):
|
||||
"""
|
||||
Defines options and provides handling interface.
|
||||
"""
|
||||
|
||||
def __init__(self, name,person_id=None):
|
||||
Tool.ToolOptions.__init__(self, name,person_id)
|
||||
def __init__(self, name, person_id=None):
|
||||
Tool.ToolOptions.__init__(self, name, person_id)
|
||||
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
#
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
register_tool(
|
||||
name = 'patchnames',
|
||||
category = Tool.TOOL_DBPROC,
|
||||
|
Loading…
Reference in New Issue
Block a user