2 # -*- coding: UTF-8 -*-
5 # graphical user interface for pdf2swf
7 # Part of the swftools package.
9 # Copyright (c) 2008,2009 Matthias Kramm <kramm@quiss.org>
11 # This program is free software; you can redistribute it and/or modify
12 # it under the terms of the GNU General Public License as published by
13 # the Free Software Foundation; either version 2 of the License, or
14 # (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
29 from lib.wordwrap import wordwrap
30 from gui.boldstatictext import BoldStaticText
38 import viewers.flexpaper
39 import viewers.technoargia
59 #self.import_viewers()
61 #def list_viewers(self):
62 # for file in os.listdir('viewers'):
63 # if (file.startswith('.') or file.startswith('_')
64 # or file.endswith(".pyc") or not file.endswith('.py')):
66 # self.viewers.append(os.path.splitext(file)[0])
68 #def import_viewers(self):
69 # for file in self.viewers:
71 # _temp = imp.load_source("viewers.%s" % file, os.path.join(os.getcwdu(), "viewers/%s.py" % file))
72 # self.modules.append(_temp)
74 # print "Could not load %s" % file
78 class ViewerBook(wx.Listbook):
79 def __init__(self, parent):
80 wx.Listbook.__init__(self, parent, wx.ID_ANY, style=
85 self.__viewers = viewers = Viewers()
88 il = wx.ImageList(102, 102)
89 self.AssignImageList(il)
91 # Sort viewers by attribute order.
92 # The attribute order must be an int from 0..n
93 viewers.modules.sort(key=operator.attrgetter('order'))
95 # Make a bunch of panels for the list book
96 for idx, mod in enumerate(viewers.modules):
97 bmp = mod.preview.GetBitmap()
100 win = self.makePanel(mod)
101 self.AddPage(win, mod, imageId=idx)
104 def makePanel(self, mod):
106 sizer = wx.BoxSizer(wx.VERTICAL)
108 nameCtrl = BoldStaticText(p, label=mod.name)
109 sizer.Add(nameCtrl, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 10)
111 t = wordwrap(mod.desc, 400, wx.ClientDC(p))
112 descCtrl = wx.StaticText(p, label=t)
113 sizer.Add(descCtrl, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 10)
117 # Avoid showing an empty StaticBox
118 if (len(mod.swf_options) == 1
119 and isinstance(mod.swf_options[0], gui.fields.Hidden)
125 if mod.swf_options and not hidden:
126 box = wx.StaticBox(p, label=u"SWF")
127 bsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
129 flex = wx.FlexGridSizer(rows=len(mod.swf_options), cols=2, hgap=0, vgap=0)
130 flex.AddGrowableCol(1)
132 for option in mod.swf_options:
133 #swf_options.append(option)
134 label, ctrl = option.draw(p)
136 flex.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 4)
137 flex.Add(ctrl, 0, wx.EXPAND|wx.ALL, 4)
139 bsizer.Add(flex, 0, wx.EXPAND)
140 sizer.Add(bsizer, 0, wx.EXPAND)
143 if mod.viewer_options:
144 box = wx.StaticBox(p, label=u"Viewer")
145 bsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
147 flex = wx.FlexGridSizer(rows=len(mod.viewer_options),
148 cols=2, hgap=0, vgap=0)
149 flex.AddGrowableCol(1)
151 for option in mod.viewer_options:
152 #vie_options.append(option)
153 label, ctrl = option.draw(p)
155 flex.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 4)
156 flex.Add(ctrl, 0, wx.EXPAND|wx.ALL, 4)
158 bsizer.Add(flex, 0, wx.EXPAND)
159 sizer.Add(bsizer, 0, wx.EXPAND)
164 def AddPage(self, win, mod, select=False, imageId=-1):
165 wx.Listbook.AddPage(self, win, mod.name, select, imageId)
166 self.__mod.append(mod)
168 def __get_options(self):
169 page = self.GetSelection()
170 return self.__mod[page]
172 options = property(__get_options)
176 data['selected_viewer'] = self.GetSelection()
178 for viewer, module in zip(self.__viewers.viewers, self.__viewers.modules):
180 for opt in module.swf_options:
181 data[viewer][opt.name] = opt.value
182 for opt in module.viewer_options:
183 data[viewer][opt.name] = opt.value
187 def unpickle(self, data):
191 selected_viewer = data.pop('selected_viewer')
192 self.SetSelection(selected_viewer)
195 for viewer, module in zip(self.__viewers.viewers, self.__viewers.modules):
198 all_opts = module.swf_options + module.viewer_options
199 for field in all_opts:
200 _fields[viewer][field.name] = field
202 for modname, opts in data.items():
203 for k, v in opts.items():
204 _fields[modname][k].SetValue(v)