gramps/gramps2/src/TipOfDay.py

95 lines
2.7 KiB
Python
Raw Normal View History

#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2004 Donald N. Allingham
#
# 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
#
import xml.parsers.expat
import string
import gtk
import gtk.glade
import const
import GrampsCfg
class TipOfDay:
def __init__(self):
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()
* src/data/gramps.schemas: Cleanup. * src/data/Makefile.am: Clen up install rule. Add uninstall rule. * src/StartupDialog.py: Correct use of keys. * src/GrampsCfg.py: Correct usage of gconf. * src/DbPrompter.py: Remove unused module. * src/SelectChild.py: Remove unused module. * src/SelectObject.py: Remove unused module. * src/WriteXML.py: Remove unused module. * src/gramps_main.py: Convert to new gconf usage. * src/FamilyView.py: Convert to new gconf usage. * src/AddSpouse.py: Convert to new gconf usage. * src/ChooseParents.py: Convert to new gconf usage. * src/EditPerson.py: Convert to new gconf usage. * src/EditPlace.py: Convert to new gconf usage. * src/EditSource.py: Convert to new gconf usage. * src/EventEdit.py: Convert to new gconf usage. * src/ImageSelect.py: Convert to new gconf usage. * src/Marriage.py: Convert to new gconf usage. * src/MediaView.py: Convert to new gconf usage. * src/MergeData.py: Convert to new gconf usage. * src/PedView.py: Convert to new gconf usage. * src/Plugins.py: Convert to new gconf usage. * src/RelLib.py: Convert to new gconf usage. * src/TipOfDay.py: Convert to new gconf usage. * src/plugins/AncestorChart2.py: Remove unused module. * src/plugins/AncestorChart.py: Remove unused module. * src/plugins/BookReport.py: Remove unused module. * src/plugins/FanChart.py: Remove unused module. * src/plugins/Partition.py: Remove unused module. * src/plugins/Desbrowser.py: Convert to new gconf usage. * src/plugins/Merge.py: Convert to new gconf usage. * src/plugins/RelCalc.py: Convert to new gconf usage. * src/plugins/WebPage.py: Convert to new gconf usage. svn: r3274
2004-07-15 08:24:04 +05:30
use.set_active(GrampsCfg.get_usetips())
index = 0
rval = 0
while rval == 0:
tip.set_text(tip_list[index])
rval = top.run()
if index >= len(tip_list)-1:
index = 0
else:
index += 1
GrampsCfg.save_usetips(use.get_active())
top.destroy()
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 = []
file = open(const.tipdata)
self.tlist = []
p = xml.parsers.expat.ParserCreate()
p.StartElementHandler = self.startElement
p.EndElementHandler = self.endElement
p.CharacterDataHandler = self.characters
p.ParseFile(file)
file.close()
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\">
"""
self.tlist = []
def endElement(self,tag):
if tag == "tip":
self.mylist.append(string.join(self.tlist,''))
def characters(self, data):
self.tlist.append(data)