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
34 # this two are only to satisfy some plugins requirements
39 #import viewers.simple
41 #import viewers.flexpaper
42 #import viewers.technoargia
59 # viewers.technoargia,
66 def list_viewers(self):
67 for file in os.listdir('viewers'):
68 if (file.startswith('.') or file.startswith('_')
69 or file.endswith(".pyc") or not file.endswith('.py')):
71 self.viewers.append(os.path.splitext(file)[0])
73 def import_viewers(self):
74 for file in self.viewers:
76 _temp = imp.load_source("viewers.%s" % file, os.path.join(os.getcwdu(), "viewers/%s.py" % file))
77 self.modules.append(_temp)
79 print "Could not load %s (%s)" % (file, e)
83 class ViewerBook(wx.Listbook):
84 def __init__(self, parent):
85 wx.Listbook.__init__(self, parent, wx.ID_ANY, style=
90 self.__viewers = viewers = Viewers()
93 il = wx.ImageList(102, 102)
94 self.AssignImageList(il)
96 # Sort viewers by attribute order.
97 # The attribute order must be an int from 0..n
98 viewers.modules.sort(key=operator.attrgetter('order'))
100 # Make a bunch of panels for the list book
101 for idx, mod in enumerate(viewers.modules):
102 bmp = mod.preview.GetBitmap()
105 win = self.makePanel(mod)
106 self.AddPage(win, mod, imageId=idx)
107 if hasattr(mod, "default"):
108 self.SetSelection(idx)
111 def makePanel(self, mod):
113 sizer = wx.BoxSizer(wx.VERTICAL)
115 nameCtrl = BoldStaticText(p, label=mod.name)
116 sizer.Add(nameCtrl, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 10)
118 t = wordwrap(mod.desc, 400, wx.ClientDC(p))
119 descCtrl = wx.StaticText(p, label=t)
120 sizer.Add(descCtrl, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 10)
124 # Avoid showing an empty StaticBox
125 if (len(mod.swf_options) == 1
126 and isinstance(mod.swf_options[0], gui.fields.Hidden)
132 if mod.swf_options and not hidden:
133 box = wx.StaticBox(p, label=u"SWF")
134 bsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
136 flex = wx.FlexGridSizer(rows=len(mod.swf_options), cols=2, hgap=0, vgap=0)
137 flex.AddGrowableCol(1)
139 for option in mod.swf_options:
140 #swf_options.append(option)
141 label, ctrl = option.draw(p)
143 flex.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 4)
144 flex.Add(ctrl, 0, wx.EXPAND|wx.ALL, 4)
146 bsizer.Add(flex, 0, wx.EXPAND)
147 sizer.Add(bsizer, 0, wx.EXPAND)
150 if mod.viewer_options:
151 box = wx.StaticBox(p, label=u"Viewer")
152 bsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
154 flex = wx.FlexGridSizer(rows=len(mod.viewer_options),
155 cols=2, hgap=0, vgap=0)
156 flex.AddGrowableCol(1)
158 for option in mod.viewer_options:
159 #vie_options.append(option)
160 label, ctrl = option.draw(p)
162 flex.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 4)
163 flex.Add(ctrl, 0, wx.EXPAND|wx.ALL, 4)
165 bsizer.Add(flex, 0, wx.EXPAND)
166 sizer.Add(bsizer, 0, wx.EXPAND)
171 def AddPage(self, win, mod, select=False, imageId=-1):
172 wx.Listbook.AddPage(self, win, mod.name, select, imageId)
173 self.__mod.append(mod)
175 def __get_options(self):
176 page = self.GetSelection()
177 return self.__mod[page]
179 options = property(__get_options)
183 data['selected_viewer'] = self.GetSelection()
185 for viewer, module in zip(self.__viewers.viewers, self.__viewers.modules):
187 for opt in module.swf_options:
188 data[viewer][opt.name] = opt.value
189 for opt in module.viewer_options:
190 data[viewer][opt.name] = opt.value
194 def unpickle(self, data):
198 selected_viewer = data.pop('selected_viewer')
199 self.SetSelection(selected_viewer)
202 for viewer, module in zip(self.__viewers.viewers, self.__viewers.modules):
205 all_opts = module.swf_options + module.viewer_options
206 for field in all_opts:
207 _fields[viewer][field.name] = field
209 for modname, opts in data.items():
210 for k, v in opts.items():
211 _fields[modname][k].SetValue(v)