2007-12-27 Douglas S. Blank <dblank@cs.brynmawr.edu>
* src/DataViews/_MyGrampsView.py: added API for data save/load * src/plugins/DefaultGadgets.py: top surnames takes count; TODO saves svn: r9597
This commit is contained in:
parent
76cff3a349
commit
becd01ef12
@ -1,3 +1,7 @@
|
|||||||
|
2007-12-27 Douglas S. Blank <dblank@cs.brynmawr.edu>
|
||||||
|
* src/DataViews/_MyGrampsView.py: added API for data save/load
|
||||||
|
* src/plugins/DefaultGadgets.py: top surnames takes count; TODO saves
|
||||||
|
|
||||||
2007-12-26 Douglas S. Blank <dblank@cs.brynmawr.edu>
|
2007-12-26 Douglas S. Blank <dblank@cs.brynmawr.edu>
|
||||||
* src/DataViews/_MyGrampsView.py: added tooltips, cleanup, menu work
|
* src/DataViews/_MyGrampsView.py: added tooltips, cleanup, menu work
|
||||||
* src/plugins/DefaultGadgets.py: fine tuning
|
* src/plugins/DefaultGadgets.py: fine tuning
|
||||||
|
@ -51,7 +51,8 @@ def register_gadget(data_dict):
|
|||||||
global AVAILABLE_GADGETS
|
global AVAILABLE_GADGETS
|
||||||
base_opts = {"name":"Unnamed Gadget",
|
base_opts = {"name":"Unnamed Gadget",
|
||||||
"state":"maximized",
|
"state":"maximized",
|
||||||
"column": -1, "row": -1}
|
"column": -1, "row": -1,
|
||||||
|
"data": []}
|
||||||
base_opts.update(data_dict)
|
base_opts.update(data_dict)
|
||||||
AVAILABLE_GADGETS[base_opts["name"]] = base_opts
|
AVAILABLE_GADGETS[base_opts["name"]] = base_opts
|
||||||
|
|
||||||
@ -150,7 +151,6 @@ class Gadget(object):
|
|||||||
self._generator = None
|
self._generator = None
|
||||||
self._need_to_update = False
|
self._need_to_update = False
|
||||||
self._tags = []
|
self._tags = []
|
||||||
self.data = {}
|
|
||||||
self.tooltip = None
|
self.tooltip = None
|
||||||
self.link_cursor = gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)
|
self.link_cursor = gtk.gdk.Cursor(gtk.gdk.LEFT_PTR)
|
||||||
self.standard_cursor = gtk.gdk.Cursor(gtk.gdk.XTERM)
|
self.standard_cursor = gtk.gdk.Cursor(gtk.gdk.XTERM)
|
||||||
@ -212,14 +212,20 @@ class Gadget(object):
|
|||||||
self._tags.append((LinkTag(buffer),data))
|
self._tags.append((LinkTag(buffer),data))
|
||||||
buffer.apply_tag(self._tags[-1][0], start, end)
|
buffer.apply_tag(self._tags[-1][0], start, end)
|
||||||
|
|
||||||
|
def get_text(self):
|
||||||
|
start = self.gui.buffer.get_start_iter()
|
||||||
|
end = self.gui.buffer.get_end_iter()
|
||||||
|
return self.gui.buffer.get_text(start, end)
|
||||||
|
|
||||||
def insert_text(self, text):
|
def insert_text(self, text):
|
||||||
self.gui.buffer.insert_at_cursor(text)
|
self.gui.buffer.insert_at_cursor(text)
|
||||||
|
|
||||||
def clear_text(self):
|
def clear_text(self):
|
||||||
self.gui.buffer.set_text('')
|
self.gui.buffer.set_text('')
|
||||||
|
|
||||||
def set_text(self, text):
|
def set_text(self, text, scroll_to='start'):
|
||||||
self.gui.buffer.set_text(text)
|
self.gui.buffer.set_text('')
|
||||||
|
self.append_text(text, scroll_to)
|
||||||
|
|
||||||
def append_text(self, text, scroll_to="end"):
|
def append_text(self, text, scroll_to="end"):
|
||||||
enditer = self.gui.buffer.get_end_iter()
|
enditer = self.gui.buffer.get_end_iter()
|
||||||
@ -232,6 +238,17 @@ class Gadget(object):
|
|||||||
else:
|
else:
|
||||||
self.gui.textview.scroll_to_mark(start, 0.0, True, 0, 0)
|
self.gui.textview.scroll_to_mark(start, 0.0, True, 0, 0)
|
||||||
|
|
||||||
|
def load_data_to_text(self, pos=0):
|
||||||
|
if len(self.gui.data) >= pos + 1:
|
||||||
|
text = self.gui.data[pos]
|
||||||
|
text = text.replace("\\n", chr(10))
|
||||||
|
self.set_text(text, 'end')
|
||||||
|
|
||||||
|
def save_text_to_data(self):
|
||||||
|
text = self.get_text()
|
||||||
|
text = text.replace(chr(10), "\\n")
|
||||||
|
self.gui.data.append(text)
|
||||||
|
|
||||||
def update(self, *handles):
|
def update(self, *handles):
|
||||||
self.main()
|
self.main()
|
||||||
if self._idle_id != 0:
|
if self._idle_id != 0:
|
||||||
@ -349,6 +366,7 @@ class GuiGadget:
|
|||||||
self.column = int(kwargs.get("column", -1))
|
self.column = int(kwargs.get("column", -1))
|
||||||
self.row = int(kwargs.get("row", -1))
|
self.row = int(kwargs.get("row", -1))
|
||||||
self.state = kwargs.get("state", "maximized")
|
self.state = kwargs.get("state", "maximized")
|
||||||
|
self.data = kwargs.get("data", [])
|
||||||
##########
|
##########
|
||||||
self.pui = None # user code
|
self.pui = None # user code
|
||||||
self.xml = gtk.glade.XML(const.GLADE_FILE, 'gvgadget', "gramps")
|
self.xml = gtk.glade.XML(const.GLADE_FILE, 'gvgadget', "gramps")
|
||||||
@ -597,7 +615,12 @@ class MyGrampsView(PageView.PageView):
|
|||||||
else:
|
else:
|
||||||
data = {}
|
data = {}
|
||||||
for opt in cp.options(sec):
|
for opt in cp.options(sec):
|
||||||
data[opt] = cp.get(sec, opt).strip()
|
if opt.startswith("data["):
|
||||||
|
temp = data.get("data", [])
|
||||||
|
temp.append(cp.get(sec, opt).strip())
|
||||||
|
data["data"] = temp
|
||||||
|
else:
|
||||||
|
data[opt] = cp.get(sec, opt).strip()
|
||||||
if "name" not in data:
|
if "name" not in data:
|
||||||
data["name"] = "Unnamed Gadget"
|
data["name"] = "Unnamed Gadget"
|
||||||
retval.append((data["name"], data)) # name, opts
|
retval.append((data["name"], data)) # name, opts
|
||||||
@ -611,7 +634,11 @@ class MyGrampsView(PageView.PageView):
|
|||||||
def save(self, *args):
|
def save(self, *args):
|
||||||
if debug: print "saving"
|
if debug: print "saving"
|
||||||
filename = GADGET_FILENAME
|
filename = GADGET_FILENAME
|
||||||
fp = open(filename, "w")
|
try:
|
||||||
|
fp = open(filename, "w")
|
||||||
|
except:
|
||||||
|
print "Failed writing '%s'; gadgets not saved" % filename
|
||||||
|
return
|
||||||
fp.write(";; Gramps gadgets file" + NL)
|
fp.write(";; Gramps gadgets file" + NL)
|
||||||
fp.write((";; Automatically created at %s" % time.strftime("%Y/%m/%d %H:%M:%S")) + NL + NL)
|
fp.write((";; Automatically created at %s" % time.strftime("%Y/%m/%d %H:%M:%S")) + NL + NL)
|
||||||
fp.write("[My Gramps View Options]" + NL)
|
fp.write("[My Gramps View Options]" + NL)
|
||||||
@ -632,7 +659,13 @@ class MyGrampsView(PageView.PageView):
|
|||||||
if key == "title": continue
|
if key == "title": continue
|
||||||
if key == "column": continue
|
if key == "column": continue
|
||||||
if key == "row": continue
|
if key == "row": continue
|
||||||
fp.write(("%s=%s" + NL)% (key, base_opts[key]))
|
if key == "data":
|
||||||
|
cnt = 0
|
||||||
|
for item in base_opts["data"]:
|
||||||
|
fp.write(("data[%d]=%s" + NL) % (cnt, item))
|
||||||
|
cnt += 1
|
||||||
|
else:
|
||||||
|
fp.write(("%s=%s" + NL)% (key, base_opts[key]))
|
||||||
fp.write(("column=%d" + NL) % col)
|
fp.write(("column=%d" + NL) % col)
|
||||||
fp.write(("row=%d" + NL) % row)
|
fp.write(("row=%d" + NL) % row)
|
||||||
fp.write(NL)
|
fp.write(NL)
|
||||||
|
@ -94,8 +94,16 @@ class LogGadget(Gadget):
|
|||||||
|
|
||||||
class TopSurnamesGadget(Gadget):
|
class TopSurnamesGadget(Gadget):
|
||||||
def init(self):
|
def init(self):
|
||||||
|
self.top_size = 10 # will be overwritten in load
|
||||||
self.set_text("No Family Tree loaded.")
|
self.set_text("No Family Tree loaded.")
|
||||||
|
|
||||||
|
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):
|
def main(self):
|
||||||
self.set_text("Processing...\n")
|
self.set_text("Processing...\n")
|
||||||
|
|
||||||
@ -131,7 +139,7 @@ class TopSurnamesGadget(Gadget):
|
|||||||
(line + 1, surname,
|
(line + 1, surname,
|
||||||
int((float(count)/total) * 100), count))
|
int((float(count)/total) * 100), count))
|
||||||
line += 1
|
line += 1
|
||||||
if line >= 10:
|
if line >= self.top_size:
|
||||||
break
|
break
|
||||||
self.append_text("\nTotal unique surnames: %d\n" % total_surnames)
|
self.append_text("\nTotal unique surnames: %d\n" % total_surnames)
|
||||||
self.append_text("Total people: %d" % total_people)
|
self.append_text("Total people: %d" % total_people)
|
||||||
@ -359,6 +367,13 @@ class TODOGadget(Gadget):
|
|||||||
self.gui.textview.set_editable(True)
|
self.gui.textview.set_editable(True)
|
||||||
self.append_text("Enter your TODO list here.")
|
self.append_text("Enter your TODO list here.")
|
||||||
|
|
||||||
|
def on_load(self):
|
||||||
|
self.load_data_to_text()
|
||||||
|
|
||||||
|
def on_save(self):
|
||||||
|
self.gui.data = [] # clear out old data
|
||||||
|
self.save_text_to_data()
|
||||||
|
|
||||||
def make_welcome_content(gui):
|
def make_welcome_content(gui):
|
||||||
text = """
|
text = """
|
||||||
Welcome to GRAMPS!
|
Welcome to GRAMPS!
|
||||||
|
Loading…
Reference in New Issue
Block a user