From 74c4e3e30be04e52dd2fdc7e01eb735490e666db Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Sat, 29 Dec 2007 16:53:14 +0000 Subject: [PATCH] No save if no gadgets; added news gadget svn: r9627 --- src/DataViews/MyGrampsView.py | 6 ++- src/plugins/DefaultGadgets.py | 81 ++++++++++++++++++++++++++++++++++- 2 files changed, 85 insertions(+), 2 deletions(-) diff --git a/src/DataViews/MyGrampsView.py b/src/DataViews/MyGrampsView.py index 4d0ec4954..3eba2e457 100644 --- a/src/DataViews/MyGrampsView.py +++ b/src/DataViews/MyGrampsView.py @@ -258,7 +258,7 @@ class Gadget(object): self._generator = self.main() if debug: print "%s adding to gobject" % self.gui.title self._idle_id = gobject.idle_add(self._updater, - priority=gobject.PRIORITY_LOW) + priority=gobject.PRIORITY_LOW - 10) def interrupt(self): """ @@ -631,6 +631,10 @@ class MyGrampsView(PageView.PageView): def save(self, *args): if debug: print "saving" + if len(self.frame_map.keys() + + self.detached_gadgets + + self.closed_gadgets) == 0: + return # something is the matter filename = GADGET_FILENAME try: fp = open(filename, "w") diff --git a/src/plugins/DefaultGadgets.py b/src/plugins/DefaultGadgets.py index fd780995d..1df1b66a6 100644 --- a/src/plugins/DefaultGadgets.py +++ b/src/plugins/DefaultGadgets.py @@ -4,8 +4,10 @@ import DateHandler import gen.lib import sys import os +import re import time import string +import urllib # # Hello World, in Gramps Gadgets @@ -64,7 +66,7 @@ class CalendarGadget(Gadget): self.update() def run_update(self, signal, *args): - print "signal:", signal + #print "signal:", signal self.update() def refresh(self, *obj): @@ -399,6 +401,75 @@ You can right-click on the background of this page to add additional gadgets and gui.set_text(text) +class NewsGadget(Gadget): + URL = "http://www.gramps-project.org/wiki/index.php?title=%s&action=raw" + def main(self): + continuation = self.process('News') + retval = True + while retval: + retval, text = continuation.next() + self.cleanup(text) + yield True + self.cleanup(text) + yield False + + def cleanup(self, text): + # final text + text = text.replace("
", "\n") + while "\n\n\n" in text: + text = text.replace("\n\n\n", "\n\n") + text = text.strip() + self.set_text(text) + + def process(self, title): + #print "processing '%s'..." % title + title = title.replace(" ", "_") + yield True, "Reading '%s'..." % title + fp = urllib.urlopen(self.URL % title) + text = fp.read() + #text = text.replace("\n", " ") + html = re.findall('<.*?>', text) + for exp in html: + text = text.replace(exp, "") + text = text.replace("\n", "
") + fp.close() + pattern = '{{.*?}}' + matches = re.findall(pattern, text) + #print " before:", text + for match in matches: + page = match[2:-2] + oldtext = match + if "|" in page: + template, heading, body = page.split("|", 2) + if template.lower() == "release": + newtext = "GRAMPS " + heading + " released.

" + else: + newtext = heading + "

" + newtext += body + "
" + text = text.replace(oldtext, newtext) + else: # a macro/redirect + continuation = self.process("Template:" + page) + retval = True + while retval: + retval, newtext = continuation.next() + yield True, newtext + text = text.replace(oldtext, newtext) + #print " after:", text + pattern = '#REDIRECT \[\[.*?\]\]' + matches = re.findall(pattern, text) + #print " before:", text + for match in matches: + page = match[12:-2] + oldtext = match + continuation = self.process(page) + retval = True + while retval: + retval, newtext = continuation.next() + yield True, newtext + text = text.replace(oldtext, newtext) + #print " after:", text + yield False, text + register(type="gadget", name="Top Surnames Gadget", height=230, @@ -452,3 +523,11 @@ register(type="gadget", title="Calendar", ) +register(type="gadget", + name="News Gadget", + height=300, + expand=True, + content = NewsGadget, + title="News", + ) +