Bug 3018: remove calls to keys() and values() dictionary method where possible
svn: r12579
This commit is contained in:
parent
1edada53d0
commit
81a0848490
@ -202,7 +202,7 @@ class StandardCustomSelector(object):
|
|||||||
else:
|
else:
|
||||||
int_val = self.custom_key
|
int_val = self.custom_key
|
||||||
str_val = self.selector.child.get_text().strip()
|
str_val = self.selector.child.get_text().strip()
|
||||||
if str_val in self.mapping.values():
|
if str_val in self.mapping.itervalues():
|
||||||
for key in self.mapping:
|
for key in self.mapping:
|
||||||
if str_val == self.mapping[key]:
|
if str_val == self.mapping[key]:
|
||||||
int_val = key
|
int_val = key
|
||||||
|
@ -1685,7 +1685,7 @@ class TextDoc(object):
|
|||||||
else:
|
else:
|
||||||
tagspos[start] = [(tag, FIRST)]
|
tagspos[start] = [(tag, FIRST)]
|
||||||
if end in tagspos:
|
if end in tagspos:
|
||||||
tagspos[end] = [(tag, LAST)] + tagspos[end]
|
tagspos[end] += [(tag, LAST)]
|
||||||
else:
|
else:
|
||||||
tagspos[end] = [(tag, LAST)]
|
tagspos[end] = [(tag, LAST)]
|
||||||
start = 0
|
start = 0
|
||||||
@ -1705,10 +1705,8 @@ class TextDoc(object):
|
|||||||
while splitpos <> -1:
|
while splitpos <> -1:
|
||||||
otext += self.ESCAPE_FUNC()(text[start:start+splitpos])
|
otext += self.ESCAPE_FUNC()(text[start:start+splitpos])
|
||||||
#close open tags
|
#close open tags
|
||||||
opentags.reverse()
|
for opentag in reversed(opentags):
|
||||||
for opentag in opentags:
|
|
||||||
otext += opentag[1]
|
otext += opentag[1]
|
||||||
opentags.reverse()
|
|
||||||
#add split text
|
#add split text
|
||||||
otext += self.ESCAPE_FUNC()(split)
|
otext += self.ESCAPE_FUNC()(split)
|
||||||
#open the tags again
|
#open the tags again
|
||||||
@ -1722,10 +1720,8 @@ class TextDoc(object):
|
|||||||
#write out tags
|
#write out tags
|
||||||
for tag in tagspos[pos]:
|
for tag in tagspos[pos]:
|
||||||
#close open tags starting from last open
|
#close open tags starting from last open
|
||||||
opentags.reverse()
|
for opentag in reversed(opentags):
|
||||||
for opentag in opentags:
|
|
||||||
otext += opentag[1]
|
otext += opentag[1]
|
||||||
opentags.reverse()
|
|
||||||
#if start, add to opentag in beginning as first to open
|
#if start, add to opentag in beginning as first to open
|
||||||
if tag[1] == FIRST:
|
if tag[1] == FIRST:
|
||||||
opentags = [tag[0]] + opentags
|
opentags = [tag[0]] + opentags
|
||||||
@ -1744,8 +1740,7 @@ class TextDoc(object):
|
|||||||
if opentags:
|
if opentags:
|
||||||
print 'WARNING: TextDoc : More style tags in text than length '\
|
print 'WARNING: TextDoc : More style tags in text than length '\
|
||||||
'of text allows.\n', opentags
|
'of text allows.\n', opentags
|
||||||
opentags.reverse()
|
for opentag in reversed(opentags):
|
||||||
for opentag in opentags:
|
|
||||||
otext += opentag[1]
|
otext += opentag[1]
|
||||||
|
|
||||||
return otext
|
return otext
|
||||||
|
@ -1077,7 +1077,8 @@ class MyScrolledWindow(gtk.ScrolledWindow):
|
|||||||
# Hack to get around show_all that shows hidden items
|
# Hack to get around show_all that shows hidden items
|
||||||
# do once, the first time showing
|
# do once, the first time showing
|
||||||
if self.viewpage:
|
if self.viewpage:
|
||||||
gramplets = [g for g in self.viewpage.gramplet_map.values() if g is not None]
|
gramplets = (g for g in self.viewpage.gramplet_map.itervalues()
|
||||||
|
if g is not None)
|
||||||
self.viewpage = None
|
self.viewpage = None
|
||||||
for gramplet in gramplets:
|
for gramplet in gramplets:
|
||||||
gramplet.gvoptions.hide()
|
gramplet.gvoptions.hide()
|
||||||
@ -1171,7 +1172,8 @@ class GrampletView(PageView.PersonNavView):
|
|||||||
"""
|
"""
|
||||||
Detach all of the mainframe gramplets from the columns.
|
Detach all of the mainframe gramplets from the columns.
|
||||||
"""
|
"""
|
||||||
gramplets = [g for g in self.gramplet_map.values() if g is not None]
|
gramplets = (g for g in self.gramplet_map.itervalues()
|
||||||
|
if g is not None)
|
||||||
for gramplet in gramplets:
|
for gramplet in gramplets:
|
||||||
if (gramplet.state == "detached" or gramplet.state == "closed"):
|
if (gramplet.state == "detached" or gramplet.state == "closed"):
|
||||||
continue
|
continue
|
||||||
@ -1183,12 +1185,13 @@ class GrampletView(PageView.PersonNavView):
|
|||||||
"""
|
"""
|
||||||
Place the gramplet mainframes in the columns.
|
Place the gramplet mainframes in the columns.
|
||||||
"""
|
"""
|
||||||
gramplets = [g for g in self.gramplet_map.values() if g is not None]
|
gramplets = [g for g in self.gramplet_map.itervalues()
|
||||||
|
if g is not None]
|
||||||
# put the gramplets where they go:
|
# put the gramplets where they go:
|
||||||
# sort by row
|
# sort by row
|
||||||
gramplets.sort(lambda a, b: cmp(a.row, b.row))
|
gramplets.sort(key=lambda x: x.row)
|
||||||
cnt = 0
|
|
||||||
for gramplet in gramplets:
|
for cnt, gramplet in enumerate(gramplets):
|
||||||
# see if the user wants this in a particular location:
|
# see if the user wants this in a particular location:
|
||||||
# and if there are that many columns
|
# and if there are that many columns
|
||||||
if gramplet.column >= 0 and gramplet.column < self.column_count:
|
if gramplet.column >= 0 and gramplet.column < self.column_count:
|
||||||
@ -1213,7 +1216,6 @@ class GrampletView(PageView.PersonNavView):
|
|||||||
gramplet.detach()
|
gramplet.detach()
|
||||||
elif gramplet.state == "closed":
|
elif gramplet.state == "closed":
|
||||||
gramplet.close()
|
gramplet.close()
|
||||||
cnt += 1
|
|
||||||
|
|
||||||
def load_gramplets(self):
|
def load_gramplets(self):
|
||||||
self.column_count = 2 # default for new user
|
self.column_count = 2 # default for new user
|
||||||
@ -1609,7 +1611,8 @@ class GrampletView(PageView.PersonNavView):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def on_delete(self):
|
def on_delete(self):
|
||||||
gramplets = [g for g in self.gramplet_map.values() if g is not None]
|
gramplets = (g for g in self.gramplet_map.itervalues()
|
||||||
|
if g is not None)
|
||||||
for gramplet in gramplets:
|
for gramplet in gramplets:
|
||||||
# this is the only place where the gui runs user code directly
|
# this is the only place where the gui runs user code directly
|
||||||
if gramplet.pui:
|
if gramplet.pui:
|
||||||
|
@ -132,7 +132,8 @@ class GenChart(object):
|
|||||||
new_y = 0
|
new_y = 0
|
||||||
for key, i in self.array.iteritems():
|
for key, i in self.array.iteritems():
|
||||||
old_y = key
|
old_y = key
|
||||||
if self.not_blank(i.values()):
|
print __name__, i
|
||||||
|
if self.not_blank(i.itervalues()):
|
||||||
self.compress_map[old_y] = new_y
|
self.compress_map[old_y] = new_y
|
||||||
new_array[new_y] = i
|
new_array[new_y] = i
|
||||||
x = 0
|
x = 0
|
||||||
|
@ -534,19 +534,15 @@ class StatisticsChart(Report):
|
|||||||
"""creates & stores a sorted index for the items"""
|
"""creates & stores a sorted index for the items"""
|
||||||
|
|
||||||
# sort by item keys
|
# sort by item keys
|
||||||
index = data.keys()
|
index = sorted(data, reverse=True if reverse else False)
|
||||||
index.sort()
|
|
||||||
if reverse:
|
|
||||||
index.reverse()
|
|
||||||
|
|
||||||
if sort == _options.SORT_VALUE:
|
if sort == _options.SORT_VALUE:
|
||||||
# set for the sorting function
|
# set for the sorting function
|
||||||
self.lookup_items = data
|
self.lookup_items = data
|
||||||
|
|
||||||
# then sort by value
|
# then sort by value
|
||||||
index.sort(self.lookup_compare)
|
index.sort(self.lookup_compare,
|
||||||
if reverse:
|
reverse=True if reverse else False)
|
||||||
index.reverse()
|
|
||||||
|
|
||||||
return index
|
return index
|
||||||
|
|
||||||
|
@ -200,8 +200,9 @@ class AgeStatsGramplet(Gramplet):
|
|||||||
|
|
||||||
def compute_stats(self, hash):
|
def compute_stats(self, hash):
|
||||||
""" Returns the statistics of a dictionary of data """
|
""" Returns the statistics of a dictionary of data """
|
||||||
|
print "compute_stats", hash
|
||||||
hashkeys = sorted(hash)
|
hashkeys = sorted(hash)
|
||||||
count = sum(hash.values())
|
count = sum(hash.itervalues())
|
||||||
sumval = sum([k * hash[k] for k in hash])
|
sumval = sum([k * hash[k] for k in hash])
|
||||||
minval = min(hashkeys)
|
minval = min(hashkeys)
|
||||||
maxval = max(hashkeys)
|
maxval = max(hashkeys)
|
||||||
@ -239,6 +240,7 @@ class AgeStatsGramplet(Gramplet):
|
|||||||
where the key is the age, and the value stored is the count.
|
where the key is the age, and the value stored is the count.
|
||||||
"""
|
"""
|
||||||
# first, binify:
|
# first, binify:
|
||||||
|
print "create_bargraph", hash
|
||||||
bin = [0] * (max_val/bin_size)
|
bin = [0] * (max_val/bin_size)
|
||||||
for value, hash_value in hash.iteritems():
|
for value, hash_value in hash.iteritems():
|
||||||
bin[value/bin_size] += hash_value
|
bin[value/bin_size] += hash_value
|
||||||
@ -246,22 +248,36 @@ class AgeStatsGramplet(Gramplet):
|
|||||||
max_bin = float(max(bin))
|
max_bin = float(max(bin))
|
||||||
if max_bin != 0:
|
if max_bin != 0:
|
||||||
i = 0
|
i = 0
|
||||||
self.append_text("--------" + self.format("", graph_width-4, fill = "-", borders="++") + "-----\n")
|
self.append_text("--------" +
|
||||||
self.append_text(column.center(8) + self.format(title, graph_width-4, align="center") + " % " + "\n")
|
self.format("", graph_width-4, fill = "-", borders="++") +
|
||||||
self.append_text("--------" + self.format("", graph_width-4, fill = "-", borders="++") + "-----\n")
|
"-----\n")
|
||||||
|
self.append_text(column.center(8) +
|
||||||
|
self.format(title, graph_width-4, align="center") +
|
||||||
|
" % " + "\n")
|
||||||
|
self.append_text("--------" +
|
||||||
|
self.format("", graph_width-4, fill = "-", borders="++") +
|
||||||
|
"-----\n")
|
||||||
for bin in bin:
|
for bin in bin:
|
||||||
self.append_text((" %3d-%3d" % (i * 5, (i+1)* 5,)))
|
self.append_text((" %3d-%3d" % (i * 5, (i+1)* 5,)))
|
||||||
selected = self.make_handles_set(i * 5, (i+1) *5, handles)
|
selected = self.make_handles_set(i * 5, (i+1) *5, handles)
|
||||||
self.link(self.format("X" * int(bin/max_bin * (graph_width-4)), graph_width-4),
|
self.link(self.format("X" * int(bin/max_bin * (graph_width-4)),
|
||||||
|
graph_width-4),
|
||||||
'PersonList',
|
'PersonList',
|
||||||
selected,
|
selected,
|
||||||
tooltip=_("Double-click to see %d people") % len(selected))
|
tooltip=_("Double-click to see %d people") %
|
||||||
procent = float(len(selected))/(float(sum(hash.values())))*100
|
len(selected))
|
||||||
|
procent = (float(len(selected)) /
|
||||||
|
(float(sum(hash.itervalues())))*100)
|
||||||
self.append_text(locale.format("%#5.2f", procent))
|
self.append_text(locale.format("%#5.2f", procent))
|
||||||
self.append_text("\n")
|
self.append_text("\n")
|
||||||
i += 1
|
i += 1
|
||||||
self.append_text("--------" + self.format("", graph_width-4, fill = "-", borders="++") + "-----\n")
|
self.append_text("--------" +
|
||||||
self.append_text(" % " + self.ticks(graph_width-4, start = 0, stop = int(max_bin/(float(sum(hash.values())))*100)) + "\n\n")
|
self.format("", graph_width-4, fill = "-", borders="++") +
|
||||||
|
"-----\n")
|
||||||
|
self.append_text(" % " +
|
||||||
|
self.ticks(graph_width-4, start = 0,
|
||||||
|
stop = int(max_bin/(float(sum(hash.itervalues())))*100)) +
|
||||||
|
"\n\n")
|
||||||
self.append_text(self.compute_stats(hash))
|
self.append_text(self.compute_stats(hash))
|
||||||
self.append_text("\n")
|
self.append_text("\n")
|
||||||
|
|
||||||
|
@ -101,8 +101,7 @@ class GivenNameCloudGramplet(Gramplet):
|
|||||||
totals = {}
|
totals = {}
|
||||||
for (count, givensubname) in cloud_names: # givensubname_sort:
|
for (count, givensubname) in cloud_names: # givensubname_sort:
|
||||||
totals[count] = totals.get(count, 0) + 1
|
totals[count] = totals.get(count, 0) + 1
|
||||||
sums = sorted(totals)
|
sums = sorted(totals, reverse=True)
|
||||||
sums.reverse()
|
|
||||||
total = 0
|
total = 0
|
||||||
include_greater_than = 0
|
include_greater_than = 0
|
||||||
for s in sums:
|
for s in sums:
|
||||||
|
@ -114,8 +114,7 @@ class SurnameCloudGramplet(Gramplet):
|
|||||||
totals = {}
|
totals = {}
|
||||||
for (count, givensubname) in cloud_names: # givensubname_sort:
|
for (count, givensubname) in cloud_names: # givensubname_sort:
|
||||||
totals[count] = totals.get(count, 0) + 1
|
totals[count] = totals.get(count, 0) + 1
|
||||||
sums = sorted(totals)
|
sums = sorted(totals, reverse=True)
|
||||||
sums.reverse()
|
|
||||||
total = 0
|
total = 0
|
||||||
include_greater_than = 0
|
include_greater_than = 0
|
||||||
for s in sums:
|
for s in sums:
|
||||||
|
@ -107,19 +107,19 @@ def set_font_families():
|
|||||||
families = pangocairo.cairo_font_map_get_default().list_families()
|
families = pangocairo.cairo_font_map_get_default().list_families()
|
||||||
family_names = [family.get_name() for family in families]
|
family_names = [family.get_name() for family in families]
|
||||||
|
|
||||||
fam = [f for f in _TTF_FREEFONT.values() if f in family_names]
|
fam = [f for f in _TTF_FREEFONT.itervalues() if f in family_names]
|
||||||
if len(fam) == len(_TTF_FREEFONT):
|
if len(fam) == len(_TTF_FREEFONT):
|
||||||
font_families = _TTF_FREEFONT
|
font_families = _TTF_FREEFONT
|
||||||
log.debug('Using FreeFonts: %s' % font_families)
|
log.debug('Using FreeFonts: %s' % font_families)
|
||||||
return
|
return
|
||||||
|
|
||||||
fam = [f for f in _MS_TTFONT.values() if f in family_names]
|
fam = [f for f in _MS_TTFONT.itervalues() if f in family_names]
|
||||||
if len(fam) == len(_MS_TTFONT):
|
if len(fam) == len(_MS_TTFONT):
|
||||||
font_families = _MS_TTFONT
|
font_families = _MS_TTFONT
|
||||||
log.debug('Using MS TrueType fonts: %s' % font_families)
|
log.debug('Using MS TrueType fonts: %s' % font_families)
|
||||||
return
|
return
|
||||||
|
|
||||||
fam = [f for f in _GNOME_FONT.values() if f in family_names]
|
fam = [f for f in _GNOME_FONT.itervalues() if f in family_names]
|
||||||
if len(fam) == len(_GNOME_FONT):
|
if len(fam) == len(_GNOME_FONT):
|
||||||
font_families = _GNOME_FONT
|
font_families = _GNOME_FONT
|
||||||
log.debug('Using Gnome fonts: %s' % font_families)
|
log.debug('Using Gnome fonts: %s' % font_families)
|
||||||
|
@ -180,9 +180,9 @@ class DetAncestorReport(Report):
|
|||||||
for family_handle in person.get_family_handle_list():
|
for family_handle in person.get_family_handle_list():
|
||||||
family = self.database.get_family_from_handle(family_handle)
|
family = self.database.get_family_from_handle(family_handle)
|
||||||
mother_handle = family.get_mother_handle()
|
mother_handle = family.get_mother_handle()
|
||||||
if mother_handle is None or \
|
if (mother_handle is None or
|
||||||
mother_handle not in self.map.values() or \
|
mother_handle not in self.map.itervalues() or
|
||||||
person.get_gender() == gen.lib.Person.FEMALE:
|
person.get_gender() == gen.lib.Person.FEMALE):
|
||||||
# The second test above also covers the 1. person's
|
# The second test above also covers the 1. person's
|
||||||
# mate, which is not an ancestor and as such is not
|
# mate, which is not an ancestor and as such is not
|
||||||
# included in the self.map dictionary
|
# included in the self.map dictionary
|
||||||
|
@ -92,11 +92,12 @@ class NumberOfAncestorsReport(Report):
|
|||||||
while thisgensize > 0:
|
while thisgensize > 0:
|
||||||
thisgensize = 0
|
thisgensize = 0
|
||||||
if thisgen != {}:
|
if thisgen != {}:
|
||||||
thisgensize = len(thisgen.values())
|
thisgensize = len(thisgen)
|
||||||
gen += 1
|
gen += 1
|
||||||
theoretical = math.pow(2, ( gen - 1 ) )
|
theoretical = math.pow(2, ( gen - 1 ) )
|
||||||
total_theoretical += theoretical
|
total_theoretical += theoretical
|
||||||
percent = '(%s%%)' % locale.format('%3.2f', ((sum(thisgen.values()) / theoretical ) * 100))
|
percent = '(%s%%)' % locale.format('%3.2f',
|
||||||
|
((sum(thisgen.itervalues()) / theoretical ) * 100))
|
||||||
|
|
||||||
# TC # English return something like:
|
# TC # English return something like:
|
||||||
# Generation 3 has 2 individuals. (50.00%)
|
# Generation 3 has 2 individuals. (50.00%)
|
||||||
@ -132,7 +133,8 @@ class NumberOfAncestorsReport(Report):
|
|||||||
person_data
|
person_data
|
||||||
|
|
||||||
if( total_theoretical != 1 ):
|
if( total_theoretical != 1 ):
|
||||||
percent = '(%3.2f%%)' % (( sum(all_people.values()) / (total_theoretical-1) ) * 100)
|
percent = '(%3.2f%%)' % (( sum(all_people.itervalues())
|
||||||
|
/ (total_theoretical-1) ) * 100)
|
||||||
else:
|
else:
|
||||||
percent = 0
|
percent = 0
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user