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
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2006-03-06 10:52:45 +05:30
|
|
|
import os
|
2004-09-30 01:04:16 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# 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
|
2006-03-03 05:40:52 +05:30
|
|
|
import Config
|
2006-04-28 02:06:32 +05:30
|
|
|
import ManagedWindow
|
2004-05-18 12:30:34 +05:30
|
|
|
|
2004-09-30 01:04:16 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Tip Display class
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-04-28 02:06:32 +05:30
|
|
|
class TipOfDay(ManagedWindow.ManagedWindow):
|
2005-08-25 20:38:07 +05:30
|
|
|
def __init__(self,uistate):
|
2006-04-28 02:06:32 +05:30
|
|
|
|
|
|
|
ManagedWindow.ManagedWindow.__init__(self, uistate, [], self)
|
|
|
|
|
2006-05-17 19:20:49 +05:30
|
|
|
xml = gtk.glade.XML(const.gladeFile, "tod_window", "gramps")
|
|
|
|
window = xml.get_widget("tod_window")
|
|
|
|
self.set_window(window,
|
2006-04-28 02:06:32 +05:30
|
|
|
xml.get_widget("title"),
|
|
|
|
_("Tip of the Day"),
|
|
|
|
_("Tip of the Day"))
|
|
|
|
|
2006-05-17 19:20:49 +05:30
|
|
|
self.tip = xml.get_widget("tip")
|
|
|
|
self.use = xml.get_widget('usetips')
|
|
|
|
self.use.set_active(Config.get(Config.USE_TIPS))
|
2006-03-06 10:52:45 +05:30
|
|
|
image = xml.get_widget('image')
|
|
|
|
image.set_from_file(os.path.join(const.image_dir,'splash.jpg'))
|
2005-12-06 12:08:09 +05:30
|
|
|
|
2006-05-17 19:20:49 +05:30
|
|
|
next = xml.get_widget('next')
|
|
|
|
next.connect("clicked",self.next_tip_cb)
|
|
|
|
close = xml.get_widget('close')
|
|
|
|
close.connect("clicked",self.close_cb)
|
|
|
|
|
2004-05-18 12:30:34 +05:30
|
|
|
tp = TipParser()
|
2006-05-17 19:20:49 +05:30
|
|
|
self.tip_list = tp.get()
|
2004-05-18 12:30:34 +05:30
|
|
|
|
2006-05-17 19:20:49 +05:30
|
|
|
self.new_index = range(len(self.tip_list))
|
|
|
|
Random().shuffle(self.new_index)
|
2004-09-30 01:04:16 +05:30
|
|
|
|
2006-05-17 19:20:49 +05:30
|
|
|
self.index = 0
|
|
|
|
self.next_tip_cb()
|
2004-05-18 12:30:34 +05:30
|
|
|
|
2006-05-17 19:20:49 +05:30
|
|
|
window.show_all()
|
2006-04-28 02:06:32 +05:30
|
|
|
|
2006-05-17 19:20:49 +05:30
|
|
|
def next_tip_cb(self,dummy=None):
|
|
|
|
self.tip.set_text(_(self.tip_list[self.new_index[self.index]]))
|
|
|
|
self.tip.set_use_markup(True)
|
|
|
|
if self.index >= len(self.tip_list)-1:
|
|
|
|
self.index = 0
|
|
|
|
else:
|
|
|
|
self.index += 1
|
|
|
|
|
|
|
|
def close_cb(self,dummy=None):
|
|
|
|
Config.set(Config.USE_TIPS,self.use.get_active())
|
|
|
|
self.close()
|
|
|
|
|
2006-04-28 02:06:32 +05:30
|
|
|
def build_menu_names(self,obj):
|
|
|
|
return (_("Tip of the Day"), None)
|
2004-05-18 12:30:34 +05:30
|
|
|
|
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 = []
|
2006-03-18 00:45:16 +05:30
|
|
|
# Skip all tips with xml:lang attribute, as they are
|
|
|
|
# already in the translation catalog
|
|
|
|
self.skip = attrs.has_key('xml:lang')
|
2004-09-30 01:04:16 +05:30
|
|
|
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):
|
2006-03-18 00:45:16 +05:30
|
|
|
if tag == "tip" and not self.skip:
|
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
|