2002-10-20 19:55:16 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2007-07-01 00:28:14 +05:30
|
|
|
# Copyright (C) 2000-2007 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
|
|
|
|
#
|
|
|
|
|
2004-12-22 07:26:37 +05:30
|
|
|
# $Id$
|
|
|
|
|
2005-02-20 05:07:35 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2006-04-07 03:32:46 +05:30
|
|
|
from gettext import gettext as _
|
2005-02-20 05:07:35 +05:30
|
|
|
|
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
|
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
|
|
|
|
2006-05-31 08:11:46 +05:30
|
|
|
class PaperComboBox(gtk.ComboBox):
|
2002-10-20 19:55:16 +05:30
|
|
|
|
2004-12-28 05:53:49 +05:30
|
|
|
def __init__(self):
|
|
|
|
gtk.ComboBox.__init__(self,model=None)
|
|
|
|
|
|
|
|
def set(self,mapping,default):
|
|
|
|
self.store = gtk.ListStore(str)
|
|
|
|
self.set_model(self.store)
|
|
|
|
cell = gtk.CellRendererText()
|
|
|
|
self.pack_start(cell,True)
|
|
|
|
self.add_attribute(cell,'text',0)
|
|
|
|
self.mapping = {}
|
|
|
|
|
|
|
|
index = 0
|
|
|
|
start_index = 0
|
|
|
|
for key in mapping:
|
|
|
|
self.mapping[key.get_name()] = key
|
|
|
|
self.store.append(row=[key.get_name()])
|
2005-02-20 05:07:35 +05:30
|
|
|
if key.get_name() == default:
|
2004-12-28 05:53:49 +05:30
|
|
|
start_index = index
|
|
|
|
index += 1
|
|
|
|
|
|
|
|
self.set_active(start_index)
|
|
|
|
|
|
|
|
def get_value(self):
|
|
|
|
active = self.get_active()
|
|
|
|
if active < 0:
|
|
|
|
return None
|
|
|
|
key = self.store[active][0]
|
|
|
|
return (self.mapping[key],key)
|
|
|
|
|
2006-05-31 08:11:46 +05:30
|
|
|
class OrientationComboBox(gtk.ComboBox):
|
2004-12-28 05:53:49 +05:30
|
|
|
|
|
|
|
def __init__(self):
|
|
|
|
gtk.ComboBox.__init__(self,model=None)
|
|
|
|
|
|
|
|
def set(self,default=0):
|
|
|
|
self.store = gtk.ListStore(str)
|
|
|
|
self.set_model(self.store)
|
|
|
|
cell = gtk.CellRendererText()
|
|
|
|
self.pack_start(cell,True)
|
|
|
|
self.add_attribute(cell,'text',0)
|
|
|
|
self.mapping = {}
|
|
|
|
|
|
|
|
self.store.append(row=[_('Portrait')])
|
|
|
|
self.store.append(row=[_('Landscape')])
|
|
|
|
if default == BaseDoc.PAPER_PORTRAIT:
|
|
|
|
self.set_active(0)
|
|
|
|
else:
|
|
|
|
self.set_active(1)
|
|
|
|
|
|
|
|
def get_value(self):
|
|
|
|
active = self.get_active()
|
|
|
|
if active < 0:
|
|
|
|
return None
|
|
|
|
if active == 0:
|
|
|
|
return BaseDoc.PAPER_PORTRAIT
|
|
|
|
else:
|
|
|
|
return BaseDoc.PAPER_LANDSCAPE
|
2002-10-20 19:55:16 +05:30
|
|
|
|
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()
|
|
|
|
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()
|
|
|
|
myMenu.append(menuitem)
|
|
|
|
|
2004-12-22 07:26:37 +05:30
|
|
|
if value == BaseDoc.PAPER_PORTRAIT:
|
|
|
|
myMenu.set_active(0)
|
|
|
|
elif value == BaseDoc.PAPER_LANDSCAPE:
|
|
|
|
myMenu.set_active(1)
|
|
|
|
|
2002-10-20 19:55:16 +05:30
|
|
|
main_menu.set_menu(myMenu)
|
|
|
|
|
2002-11-19 09:45:02 +05:30
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2004-12-22 07:26:37 +05:30
|
|
|
# PageSizeParser
|
2002-11-19 09:45:02 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
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'])
|
2007-02-19 09:43:41 +05:30
|
|
|
self.paper_list.append(BaseDoc.PaperSize(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))
|
2007-09-08 11:24:02 +05:30
|
|
|
the_file = open(const.PAPERSIZE)
|
2007-07-01 00:28:14 +05:30
|
|
|
parser.parse(the_file)
|
|
|
|
the_file.close()
|
2007-02-19 09:43:41 +05:30
|
|
|
paper_sizes.append(BaseDoc.PaperSize(_("Custom Size"),-1,-1))
|
2002-11-19 09:45:02 +05:30
|
|
|
except (IOError,OSError,SAXParseException):
|
|
|
|
paper_sizes = [
|
2007-02-19 09:43:41 +05:30
|
|
|
BaseDoc.PaperSize("Letter",27.94,21.59),
|
|
|
|
BaseDoc.PaperSize("Legal",35.56,21.59),
|
|
|
|
BaseDoc.PaperSize("A0",118.9,84.1),
|
|
|
|
BaseDoc.PaperSize("A1",84.1,59.4),
|
|
|
|
BaseDoc.PaperSize("A2",59.4,42.0),
|
|
|
|
BaseDoc.PaperSize("A3",42.0,29.7),
|
|
|
|
BaseDoc.PaperSize("A4",29.7,21.0),
|
|
|
|
BaseDoc.PaperSize("A5",21.0,14.8),
|
|
|
|
BaseDoc.PaperSize("B0",141.4,100.0),
|
|
|
|
BaseDoc.PaperSize("B1",100.0,70.7),
|
|
|
|
BaseDoc.PaperSize("B2",70.7,50.0),
|
|
|
|
BaseDoc.PaperSize("B3",50.0,35.3),
|
|
|
|
BaseDoc.PaperSize("B4",35.3,25.0),
|
|
|
|
BaseDoc.PaperSize("B5",25.0,17.6),
|
|
|
|
BaseDoc.PaperSize("B6",17.6,12.5),
|
|
|
|
BaseDoc.PaperSize("B",43.18,27.94),
|
2007-09-28 17:54:27 +05:30
|
|
|
BaseDoc.PaperSize("C",55.88,43.18),
|
|
|
|
BaseDoc.PaperSize("D",86.36, 55.88),
|
2007-02-19 09:43:41 +05:30
|
|
|
BaseDoc.PaperSize("E",111.76,86.36),
|
|
|
|
BaseDoc.PaperSize(_("Custom Size"),-1,-1)
|
2007-09-28 17:54:27 +05:30
|
|
|
]
|