Removed stub gadgets

svn: r9610
This commit is contained in:
Doug Blank 2007-12-28 07:46:26 +00:00
parent c0d16ee50b
commit 6b0deef1eb
2 changed files with 49 additions and 114 deletions

View File

@ -553,6 +553,8 @@ class MyGrampsView(PageView.PageView):
all_opts = get_gadget_opts(name, opts) all_opts = get_gadget_opts(name, opts)
if "title" not in all_opts: if "title" not in all_opts:
all_opts["title"] = "Untitled Gadget" all_opts["title"] = "Untitled Gadget"
if "state" not in all_opts:
all_opts["state"] = "maximized"
# uniqify titles: # uniqify titles:
unique = all_opts["title"] unique = all_opts["title"]
cnt = 1 cnt = 1
@ -673,10 +675,13 @@ class MyGrampsView(PageView.PageView):
elif key == "column": continue elif key == "column": continue
elif key == "row": continue elif key == "row": continue
elif key == "data": elif key == "data":
cnt = 0 if type(base_opts["data"]) not in [list, tuple]:
for item in base_opts["data"]: fp.write(("data[0]=%s" + NL) % base_opts["data"])
fp.write(("data[%d]=%s" + NL) % (cnt, item)) else:
cnt += 1 cnt = 0
for item in base_opts["data"]:
fp.write(("data[%d]=%s" + NL) % (cnt, item))
cnt += 1
else: else:
fp.write(("%s=%s" + NL)% (key, base_opts[key])) fp.write(("%s=%s" + NL)% (key, base_opts[key]))
fp.write(("column=%d" + NL) % col) fp.write(("column=%d" + NL) % col)
@ -695,10 +700,13 @@ class MyGrampsView(PageView.PageView):
if key == "content": continue if key == "content": continue
elif key == "title": continue elif key == "title": continue
elif key == "data": elif key == "data":
cnt = 0 if type(base_opts["data"]) not in [list, tuple]:
for item in base_opts["data"]: fp.write(("data[0]=%s" + NL) % base_opts["data"])
fp.write(("data[%d]=%s" + NL) % (cnt, item)) else:
cnt += 1 cnt = 0
for item in base_opts["data"]:
fp.write(("data[%d]=%s" + NL) % (cnt, item))
cnt += 1
else: else:
fp.write(("%s=%s" + NL)% (key, base_opts[key])) fp.write(("%s=%s" + NL)% (key, base_opts[key]))
fp.write(NL) fp.write(NL)
@ -708,10 +716,13 @@ class MyGrampsView(PageView.PageView):
if key == "content": continue if key == "content": continue
elif key == "title": continue elif key == "title": continue
elif key == "data": elif key == "data":
cnt = 0 if type(opts["data"]) not in [list, tuple]:
for item in opts["data"]: fp.write(("data[0]=%s" + NL) % opts["data"])
fp.write(("data[%d]=%s" + NL) % (cnt, item)) else:
cnt += 1 cnt = 0
for item in opts["data"]:
fp.write(("data[%d]=%s" + NL) % (cnt, item))
cnt += 1
else: else:
fp.write(("%s=%s" + NL)% (key, opts[key])) fp.write(("%s=%s" + NL)% (key, opts[key]))
fp.write(NL) fp.write(NL)

View File

@ -13,33 +13,25 @@ import string
# First, you need a function or class that takes a single argument # First, you need a function or class that takes a single argument
# a GuiGadget: # a GuiGadget:
def init(gui): #from DataViews import register
gui.set_text("Hello world!") #def init(gui):
# gui.set_text("Hello world!")
# In this function, you can do some things to update the gadget, # In this function, you can do some things to update the gadget,
# like set text of the main scroll window. # like set text of the main scroll window.
# Then, you need to register the gadget: # Then, you need to register the gadget:
register(type="gadget", # case in-senstitive keyword "gadget" #register(type="gadget", # case in-senstitive keyword "gadget"
name="Hello World Gadget", # gadget name, unique among gadgets # name="Hello World Gadget", # gadget name, unique among gadgets
height = 20, # height = 20,
content = init, # function/class; takes guigadget # content = init, # function/class; takes guigadget
title="Sample Gadget", # default title, user changeable # title="Sample Gadget", # default title, user changeable
) # )
# There are a number of arguments that you can provide, including: # There are a number of arguments that you can provide, including:
# name, height, content, title, expand, state # name, height, content, title, expand, state
# Here are a couple of other examples, with their register lines at the
# bottom:
def make_family_content(gui):
gui.set_text("Families:")
def make_event_content(gui):
gui.set_text("Events:")
# Here is a Gadget object. It has a number of method possibilities: # Here is a Gadget object. It has a number of method possibilities:
# init- run once, on construction # init- run once, on construction
# active_changed- run when active-changed is triggered # active_changed- run when active-changed is triggered
@ -58,6 +50,13 @@ class LogGadget(Gadget):
self.dbstate.db.connect('family-delete', self.log_family_delete) self.dbstate.db.connect('family-delete', self.log_family_delete)
self.dbstate.db.connect('family-update', self.log_family_update) self.dbstate.db.connect('family-update', self.log_family_update)
def on_load(self):
if len(self.gui.data) > 0:
self.show_duplicates = self.gui.data[0]
def on_save(self):
self.gui.data = [self.show_duplicates]
def active_changed(self, handle): def active_changed(self, handle):
self.log_active_changed(handle) self.log_active_changed(handle)
@ -82,7 +81,9 @@ class LogGadget(Gadget):
def get_person(self, handles, ltype): def get_person(self, handles, ltype):
for person_handle in handles: for person_handle in handles:
if ltype + ": " + person_handle not in self.history: if ((self.show_duplicates == "no" and
ltype + ": " + person_handle not in self.history) or
self.show_duplicates == "yes"):
self.append_text("%s: " % ltype) self.append_text("%s: " % ltype)
self.history[ltype + ": " + person_handle] = 1 self.history[ltype + ": " + person_handle] = 1
person = self.dbstate.db.get_person_from_handle(person_handle) person = self.dbstate.db.get_person_from_handle(person_handle)
@ -97,6 +98,11 @@ class TopSurnamesGadget(Gadget):
self.top_size = 10 # will be overwritten in load self.top_size = 10 # will be overwritten in load
self.set_text("No Family Tree loaded.") 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): def on_load(self):
if len(self.gui.data) > 0: if len(self.gui.data) > 0:
self.top_size = int(self.gui.data[0]) self.top_size = int(self.gui.data[0])
@ -244,68 +250,6 @@ class StatsGadget(Gadget):
text = text + "%s\n" % p text = text + "%s\n" % p
self.set_text(text) self.set_text(text)
class ShellGadget(Gadget):
def init(self):
from os import O_NONBLOCK
from subprocess import Popen, PIPE
try:
from fcntl import fcntl, F_SETFL, F_GETFL
unix = True
except:
unix = False
if unix:
command = ["/bin/bash"]
else:
command = ["cmd.exe"]
self.pipe = Popen(command, shell=False, bufsize=0,
stdin=PIPE, stdout=PIPE, stderr=PIPE,
close_fds=True)
if unix:
for fd in (self.pipe.stdout.fileno(),
self.pipe.stderr.fileno()):
fcntl(fd, F_SETFL, fcntl(fd, F_GETFL) | O_NONBLOCK)
# GUI setup:
self.gui.textview.set_editable(True)
self.set_text("%s\n$ " % command[0])
self.gui.textview.connect('key-press-event', self.on_enter)
def write(self, text):
self.pipe.stdin.write("%s\n" % text)
def read(self, timeout=0.5,buffer_size=1024):
from errno import EAGAIN
end_time = time.time() + timeout
output = ""
while time.time() < end_time:
try:
output += self.pipe.stdout.read(buffer_size)
except IOError, e:
if e.errno != EAGAIN:
raise
return output
def on_enter(self, widget, event):
if event.keyval == 65293: # enter, where to get this?
# get line, "$ ls -al "
buffer = widget.get_buffer()
line_cnt = buffer.get_line_count()
start = buffer.get_iter_at_line(line_cnt - 1)
end = buffer.get_end_iter()
line = buffer.get_text(start, end)
if line.startswith("$ "):
self.append_text("\n")
line = line[2:]
self.write(line)
output = self.read()
self.append_text(output)
self.append_text("$ ")
else:
self.append_text("\n$ ")
return True
return False
class PythonGadget(Gadget): class PythonGadget(Gadget):
def init(self): def init(self):
self.env = {"dbstate": self.gui.dbstate, self.env = {"dbstate": self.gui.dbstate,
@ -394,20 +338,6 @@ You can right-click on the background of this page to add additional gadgets and
gui.set_text(text) gui.set_text(text)
register(type="gadget",
name="Families Gadget",
height=300,
content = make_family_content,
title="Favorite Families",
)
register(type="gadget",
name="Events Gadget",
height=100,
content = make_event_content,
title="Favorite Events",
)
register(type="gadget", register(type="gadget",
name="Top Surnames Gadget", name="Top Surnames Gadget",
height=230, height=230,
@ -426,22 +356,16 @@ register(type="gadget",
register(type="gadget", register(type="gadget",
name="Log Gadget", name="Log Gadget",
height=230, height=230,
data=['no'],
content = LogGadget, content = LogGadget,
title="Session Log", title="Session Log",
) )
register(type="gadget",
name="Shell Gadget",
height=300,
content = ShellGadget,
title="Shell",
)
register(type="gadget", register(type="gadget",
name="Python Gadget", name="Python Gadget",
height=250, height=250,
content = PythonGadget, content = PythonGadget,
title="Python", title="Python Shell",
) )
register(type="gadget", register(type="gadget",