2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2003-08-08 20:58:59 +05:30
|
|
|
# Copyright (C) 2000-2003 Donald N. Allingham
|
2002-10-20 19:55:16 +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
|
|
|
|
#
|
|
|
|
|
2002-11-19 09:45:02 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GNOME modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2002-10-20 19:55:16 +05:30
|
|
|
import gtk
|
2002-11-19 09:45:02 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-09-02 06:17:09 +05:30
|
|
|
import BaseDoc
|
2002-11-19 09:45:02 +05:30
|
|
|
import const
|
2003-06-14 22:41:11 +05:30
|
|
|
import Utils
|
2003-08-17 07:44:33 +05:30
|
|
|
from gettext import gettext as _
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-11-19 09:45:02 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Try to abstract SAX1 from SAX2
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
try:
|
|
|
|
from xml.sax import make_parser,handler,SAXParseException
|
|
|
|
except:
|
|
|
|
from _xmlplus.sax import make_parser,handler,SAXParseException
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-11-19 09:45:02 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
paper_sizes = []
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2002-11-19 09:45:02 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# make_paper_menu
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-10-31 06:56:58 +05:30
|
|
|
def make_paper_menu(main_menu,default=""):
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
index = 0
|
|
|
|
myMenu = gtk.Menu()
|
|
|
|
for paper in paper_sizes:
|
|
|
|
name = paper.get_name()
|
|
|
|
menuitem = gtk.MenuItem(name)
|
|
|
|
menuitem.set_data("i",paper)
|
|
|
|
menuitem.show()
|
|
|
|
myMenu.append(menuitem)
|
2003-10-31 06:56:58 +05:30
|
|
|
if default == name:
|
2002-10-20 19:55:16 +05:30
|
|
|
myMenu.set_active(index)
|
|
|
|
index = index + 1
|
|
|
|
main_menu.set_menu(myMenu)
|
|
|
|
|
2002-11-19 09:45:02 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# make_orientation_menu
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2003-10-31 06:56:58 +05:30
|
|
|
def make_orientation_menu(main_menu,value=0):
|
2002-10-20 19:55:16 +05:30
|
|
|
|
|
|
|
myMenu = gtk.Menu()
|
|
|
|
menuitem = gtk.MenuItem(_("Portrait"))
|
2003-09-02 06:17:09 +05:30
|
|
|
menuitem.set_data("i",BaseDoc.PAPER_PORTRAIT)
|
2002-10-20 19:55:16 +05:30
|
|
|
menuitem.show()
|
2003-10-31 06:56:58 +05:30
|
|
|
if value == BaseDoc.PAPER_PORTRAIT:
|
|
|
|
menuitem.select()
|
2002-10-20 19:55:16 +05:30
|
|
|
myMenu.append(menuitem)
|
|
|
|
|
|
|
|
menuitem = gtk.MenuItem(_("Landscape"))
|
2003-09-02 06:17:09 +05:30
|
|
|
menuitem.set_data("i",BaseDoc.PAPER_LANDSCAPE)
|
2002-10-20 19:55:16 +05:30
|
|
|
menuitem.show()
|
2003-10-31 06:56:58 +05:30
|
|
|
if value == BaseDoc.PAPER_LANDSCAPE:
|
|
|
|
menuitem.select()
|
2002-10-20 19:55:16 +05:30
|
|
|
myMenu.append(menuitem)
|
|
|
|
|
|
|
|
main_menu.set_menu(myMenu)
|
|
|
|
|
2002-11-19 09:45:02 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# FilterParser
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
class PageSizeParser(handler.ContentHandler):
|
|
|
|
"""Parses the XML file and builds the list of page sizes"""
|
|
|
|
|
|
|
|
def __init__(self,paper_list):
|
|
|
|
handler.ContentHandler.__init__(self)
|
|
|
|
self.paper_list = paper_list
|
|
|
|
|
|
|
|
def setDocumentLocator(self,locator):
|
|
|
|
self.locator = locator
|
|
|
|
|
|
|
|
def startElement(self,tag,attrs):
|
|
|
|
if tag == "page":
|
|
|
|
name = attrs['name']
|
2003-06-14 22:41:11 +05:30
|
|
|
height = Utils.gfloat(attrs['height'])
|
|
|
|
width = Utils.gfloat(attrs['width'])
|
2003-09-02 06:17:09 +05:30
|
|
|
self.paper_list.append(BaseDoc.PaperStyle(name,height,width))
|
2002-11-19 09:45:02 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Parse XML file. If failed, used default
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
try:
|
|
|
|
parser = make_parser()
|
|
|
|
parser.setContentHandler(PageSizeParser(paper_sizes))
|
|
|
|
parser.parse(const.papersize)
|
2003-09-02 06:17:09 +05:30
|
|
|
paper_sizes.append(BaseDoc.PaperStyle(_("Custom Size"),-1,-1))
|
2002-11-19 09:45:02 +05:30
|
|
|
except (IOError,OSError,SAXParseException):
|
|
|
|
paper_sizes = [
|
2003-09-02 06:17:09 +05:30
|
|
|
BaseDoc.PaperStyle("Letter",27.94,21.59),
|
|
|
|
BaseDoc.PaperStyle("Legal",35.56,21.59),
|
|
|
|
BaseDoc.PaperStyle("A3",42.0,29.7),
|
|
|
|
BaseDoc.PaperStyle("A4",29.7,21.0),
|
|
|
|
BaseDoc.PaperStyle("A5",21.0,14.8),
|
|
|
|
BaseDoc.PaperStyle("B4",35.3,25.0),
|
|
|
|
BaseDoc.PaperStyle("B6",17.6,12.5),
|
|
|
|
BaseDoc.PaperStyle("C4",32.4,22.9),
|
|
|
|
BaseDoc.PaperStyle("C5",22.9,16.2),
|
|
|
|
BaseDoc.PaperStyle("C6",16.2,11.4),
|
|
|
|
BaseDoc.PaperStyle(_("Custom Size"),-1,-1)
|
2002-11-19 09:45:02 +05:30
|
|
|
]
|