2004-05-18 12:30:34 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2005-01-26 02:55:15 +05:30
|
|
|
# Copyright (C) 2000-2005 Donald N. Allingham
|
2004-05-18 12:30:34 +05:30
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation; either version 2 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|
|
|
#
|
|
|
|
|
2004-09-30 01:04:16 +05:30
|
|
|
# $Id$
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# standard python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2005-02-19 06:19:49 +05:30
|
|
|
from xml.parsers.expat import ParserCreate
|
2004-09-30 01:04:16 +05:30
|
|
|
from random import Random
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GTK/GNOME modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-05-18 12:30:34 +05:30
|
|
|
import gtk
|
|
|
|
import gtk.glade
|
2004-09-30 01:04:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-05-18 12:30:34 +05:30
|
|
|
import const
|
2005-01-06 22:58:31 +05:30
|
|
|
import GrampsKeys
|
2004-05-18 12:30:34 +05:30
|
|
|
|
2004-09-30 01:04:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Tip Display class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-05-18 12:30:34 +05:30
|
|
|
class TipOfDay:
|
2005-01-26 02:55:15 +05:30
|
|
|
def __init__(self,parent):
|
2004-05-18 12:30:34 +05:30
|
|
|
xml = gtk.glade.XML(const.gladeFile, "tod", "gramps")
|
|
|
|
top = xml.get_widget("tod")
|
|
|
|
tip = xml.get_widget("tip")
|
|
|
|
use = xml.get_widget('usetips')
|
|
|
|
|
|
|
|
tp = TipParser()
|
|
|
|
tip_list = tp.get()
|
2005-01-06 22:58:31 +05:30
|
|
|
use.set_active(GrampsKeys.get_usetips())
|
2004-05-18 12:30:34 +05:30
|
|
|
|
2004-09-30 01:04:16 +05:30
|
|
|
new_index = range(len(tip_list))
|
|
|
|
Random().shuffle(new_index)
|
|
|
|
|
2005-01-26 02:55:15 +05:30
|
|
|
top.set_transient_for(parent.topWindow)
|
|
|
|
|
2004-05-18 12:30:34 +05:30
|
|
|
index = 0
|
|
|
|
rval = 0
|
|
|
|
while rval == 0:
|
2004-09-30 01:04:16 +05:30
|
|
|
tip.set_text(tip_list[new_index[index]])
|
|
|
|
tip.set_use_markup(1)
|
2004-05-18 12:30:34 +05:30
|
|
|
rval = top.run()
|
|
|
|
if index >= len(tip_list)-1:
|
|
|
|
index = 0
|
|
|
|
else:
|
|
|
|
index += 1
|
|
|
|
|
2005-01-06 22:58:31 +05:30
|
|
|
GrampsKeys.save_usetips(use.get_active())
|
2004-05-18 12:30:34 +05:30
|
|
|
top.destroy()
|
|
|
|
|
2004-09-30 01:04:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Tip parser class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2004-05-18 12:30:34 +05:30
|
|
|
class TipParser:
|
|
|
|
"""
|
|
|
|
Interface to the document template file
|
|
|
|
"""
|
|
|
|
def __init__(self):
|
|
|
|
"""
|
|
|
|
Creates a template parser. The parser loads map of tempate names
|
|
|
|
to the file containing the tempate.
|
|
|
|
|
|
|
|
data - dictionary that holds the name to path mappings
|
|
|
|
fpath - filename of the XML file
|
|
|
|
"""
|
|
|
|
|
|
|
|
self.mylist = []
|
2004-08-23 04:46:57 +05:30
|
|
|
xml_file = open(const.tipdata)
|
2004-05-18 12:30:34 +05:30
|
|
|
self.tlist = []
|
2005-02-19 06:19:49 +05:30
|
|
|
p = ParserCreate()
|
2004-05-18 12:30:34 +05:30
|
|
|
p.StartElementHandler = self.startElement
|
|
|
|
p.EndElementHandler = self.endElement
|
|
|
|
p.CharacterDataHandler = self.characters
|
2004-08-23 04:46:57 +05:30
|
|
|
p.ParseFile(xml_file)
|
|
|
|
xml_file.close()
|
2004-05-18 12:30:34 +05:30
|
|
|
|
|
|
|
def get(self):
|
|
|
|
return self.mylist
|
|
|
|
|
|
|
|
def setDocumentLocator(self,locator):
|
|
|
|
"""Sets the XML document locator"""
|
|
|
|
self.locator = locator
|
|
|
|
|
|
|
|
def startElement(self,tag,attrs):
|
|
|
|
"""
|
|
|
|
Loads the dictionary when an XML tag of 'template' is found. The format
|
|
|
|
XML tag is <template title=\"name\" file=\"path\">
|
|
|
|
"""
|
2004-09-30 01:04:16 +05:30
|
|
|
if tag == "tip":
|
|
|
|
self.tlist = []
|
|
|
|
elif tag != "tips":
|
|
|
|
# let all the other tags through, except for the "tips" tag
|
|
|
|
self.tlist.append("<%s>" % tag)
|
2004-05-18 12:30:34 +05:30
|
|
|
|
|
|
|
def endElement(self,tag):
|
|
|
|
if tag == "tip":
|
2004-10-08 23:29:34 +05:30
|
|
|
text = self.escape(''.join(self.tlist))
|
2004-09-30 01:04:16 +05:30
|
|
|
self.mylist.append(' '.join(text.split()))
|
|
|
|
elif tag != "tips":
|
|
|
|
# let all the other tags through, except for the "tips" tag
|
|
|
|
self.tlist.append("</%s>" % tag)
|
2004-05-18 12:30:34 +05:30
|
|
|
|
|
|
|
def characters(self, data):
|
|
|
|
self.tlist.append(data)
|
2004-10-08 23:29:34 +05:30
|
|
|
|
|
|
|
def escape(self,text):
|
|
|
|
"""
|
|
|
|
The tip's text will be interpreted as a markup, so we need to escape
|
|
|
|
some special chars.
|
|
|
|
"""
|
|
|
|
text = text.replace('&','&'); # Must be first
|
|
|
|
return text
|