2008-01-17 Douglas S. Blank <dblank@cs.brynmawr.edu>

* src/DataViews/GrampletView.py (Gramplet.link): added size, tooltip
	to links
	* src/plugins/DefaultGramplets.py: added SurnameCloudGramplet



svn: r9874
This commit is contained in:
Doug Blank 2008-01-18 02:58:14 +00:00
parent 01460af4ef
commit ae1912f431
3 changed files with 125 additions and 5 deletions

View File

@ -1,3 +1,8 @@
2008-01-17 Douglas S. Blank <dblank@cs.brynmawr.edu>
* src/DataViews/GrampletView.py (Gramplet.link): added size, tooltip
to links
* src/plugins/DefaultGramplets.py: added SurnameCloudGramplet
2008-01-18 Benny Malengier <benny.malengier@gramps-project.org>
* src/Editors/_EditNote.py: focus on text field on start
* src/Editors/_EditChildRef.py: add usability: name of child, edit btn

View File

@ -109,6 +109,7 @@ def make_requested_gramplet(viewpage, name, opts, dbstate, uistate):
if msg:
gui.tooltips = gtk.Tooltips()
gui.tooltips.set_tip(gui.scrolledwindow, msg)
gui.tooltips_text = msg
return gui
return None
@ -215,15 +216,18 @@ class Gramplet(object):
if debug: print "%s is connecting" % self.gui.title
pass
def link(self, text, link_type, data):
def link(self, text, link_type, data, size=None, tooltip=None):
buffer = self.gui.buffer
iter = buffer.get_end_iter()
offset = buffer.get_char_count()
self.append_text(text)
start = buffer.get_iter_at_offset(offset)
end = buffer.get_end_iter()
self._tags.append((LinkTag(buffer), link_type, data))
buffer.apply_tag(self._tags[-1][0], start, end)
link_data = (LinkTag(buffer), link_type, data, tooltip)
if size:
link_data[0].set_property("size-points", size)
self._tags.append(link_data)
buffer.apply_tag(link_data[0], start, end)
def get_text(self):
start = self.gui.buffer.get_start_iter()
@ -317,13 +321,22 @@ class Gramplet(object):
int(event.y))
iter = view.get_iter_at_location(*buffer_location)
cursor = self.standard_cursor
for (tag, link_type, handle) in self._tags:
ttip = None
for (tag, link_type, handle, tooltip) in self._tags:
if iter.has_tag(tag):
tag.set_property('underline', pango.UNDERLINE_SINGLE)
cursor = self.link_cursor
ttip = tooltip
else:
tag.set_property('underline', pango.UNDERLINE_NONE)
view.get_window(gtk.TEXT_WINDOW_TEXT).set_cursor(cursor)
if self.gui.tooltips:
if ttip:
self.gui.tooltips.set_tip(self.gui.scrolledwindow,
ttip)
else:
self.gui.tooltips.set_tip(self.gui.scrolledwindow,
self.gui.tooltips_text)
return False # handle event further, if necessary
def on_button_press(self, view, event):
@ -332,7 +345,7 @@ class Gramplet(object):
int(event.x),
int(event.y))
iter = view.get_iter_at_location(*buffer_location)
for (tag, link_type, handle) in self._tags:
for (tag, link_type, handle, tooltip) in self._tags:
if iter.has_tag(tag):
if link_type == 'Person':
person = self.dbstate.db.get_person_from_handle(handle)
@ -384,6 +397,8 @@ class GuiGramplet:
self.data = kwargs.get("data", [])
##########
self.pui = None # user code
self.tooltips = None
self.tooltips_text = None
self.xml = gtk.glade.XML(const.GLADE_FILE, 'gvgramplet', "gramps")
self.mainframe = self.xml.get_widget('gvgramplet')
self.textview = self.xml.get_widget('gvtextview')

View File

@ -256,6 +256,97 @@ class TopSurnamesGramplet(Gramplet):
total_surnames)
self.append_text((_("Total people") + ": %d") % total_people)
def make_tag_size(n, counts, mins=8, maxs=20):
# return font sizes mins to maxs
diff = maxs - mins
# based on counts (biggest to smallest)
if len(counts) > 1:
position = diff - (diff * (float(counts.index(n)) / (len(counts) - 1)))
else:
position = 0
return int(position) + mins
class SurnameCloudGramplet(Gramplet):
def init(self):
self.tooltip = _("Double-click surname for details")
self.top_size = 100 # will be overwritten in load
self.set_text(_("No Family Tree loaded."))
def db_changed(self):
self.dbstate.db.connect('person-add', self.update)
self.dbstate.db.connect('person-delete', self.update)
self.dbstate.db.connect('person-update', self.update)
def on_load(self):
if len(self.gui.data) > 0:
self.top_size = int(self.gui.data[0])
def on_save(self):
self.gui.data = [self.top_size]
def main(self):
self.set_text(_("Processing...") + "\n")
people = self.dbstate.db.get_person_handles(sort_handles=False)
surnames = {}
representative_handle = {}
cnt = 0
for person_handle in people:
person = self.dbstate.db.get_person_from_handle(person_handle)
if person:
surname = person.get_primary_name().get_surname().strip()
surnames[surname] = surnames.get(surname, 0) + 1
representative_handle[surname] = person_handle
if cnt % 350 == 0:
yield True
cnt += 1
total_people = cnt
surname_sort = []
total = 0
cnt = 0
for surname in surnames:
surname_sort.append( (surnames[surname], surname) )
total += surnames[surname]
if cnt % 350 == 0:
yield True
cnt += 1
total_surnames = cnt
surname_sort.sort(lambda a,b: -cmp(a,b))
cloud_names = []
cloud_values = []
cnt = 0
for (count, surname) in surname_sort:
cloud_names.append( (count, surname) )
cloud_values.append( count )
if cnt > self.top_size:
break
cnt += 1
cloud_names.sort(lambda a,b: cmp(a[1], b[1]))
counts = list(set(cloud_values))
counts.sort()
counts.reverse()
line = 0
### All done!
self.set_text("")
for (count, surname) in cloud_names: # surname_sort:
if len(surname) == 0:
text = "(%s)" % _("blank")
# int((float(count)/total) * 100), count)
else:
text = surname
#
size = make_tag_size(count, counts)
self.link(text, 'Surname', representative_handle[surname], size,
"%s, %d%% (%d)" % (text,
int((float(count)/total) * 100),
count))
self.append_text(" ")
line += 1
if line >= self.top_size:
break
self.append_text(("\n" + _("Total unique surnames") + ": %d\n") %
total_surnames)
self.append_text((_("Total people") + ": %d") % total_people)
class StatsGramplet(Gramplet):
def init(self):
self.set_text(_("No Family Tree loaded."))
@ -610,6 +701,15 @@ register(type="gramplet",
title=_("Top Surnames"),
)
register(type="gramplet",
name= "Surname Cloud Gramplet",
tname=_("Surname Cloud Gramplet"),
height=300,
expand=True,
content = SurnameCloudGramplet,
title=_("Surname Cloud"),
)
register(type="gramplet",
name="Statistics Gramplet",
tname=_("Statistics Gramplet"),