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
41 def list_viewers(self):
42 for file in os.listdir('viewers'):
43 if (file.startswith('.') or file.startswith('_')
44 or file.endswith(".pyc") or not file.endswith('.py')):
46 self.viewers.append(os.path.splitext(file)[0])
48 def import_viewers(self):
49 for file in self.viewers:
51 _temp = imp.load_source("viewers.%s" % file, os.path.join(os.getcwdu(), "viewers/%s.py" % file))
52 self.modules.append(_temp)
54 print "Could not load %s" % file
58 class ViewerBook(wx.Listbook):
59 def __init__(self, parent):
60 wx.Listbook.__init__(self, parent, wx.ID_ANY, style=
65 self.__viewers = viewers = Viewers()
68 il = wx.ImageList(102, 102)
69 self.AssignImageList(il)
71 # Sort viewers by attribute order.
72 # The attribute order must be an int from 0..n
73 viewers.modules.sort(key=operator.attrgetter('order'))
75 # Make a bunch of panels for the list book
76 for idx, mod in enumerate(viewers.modules):
77 bmp = mod.preview.GetBitmap()
80 win = self.makePanel(mod)
81 self.AddPage(win, mod, imageId=idx)
84 def makePanel(self, mod):
86 sizer = wx.BoxSizer(wx.VERTICAL)
88 nameCtrl = BoldStaticText(p, label=mod.name)
89 sizer.Add(nameCtrl, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 10)
91 t = wordwrap(mod.desc, 400, wx.ClientDC(p))
92 descCtrl = wx.StaticText(p, label=t)
93 sizer.Add(descCtrl, 0, wx.EXPAND|wx.TOP|wx.BOTTOM, 10)
97 # Avoid showing an empty StaticBox
98 if (len(mod.swf_options) == 1
99 and isinstance(mod.swf_options[0], gui.fields.Hidden)
105 if mod.swf_options and not hidden:
106 box = wx.StaticBox(p, label=u"SWF")
107 bsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
109 flex = wx.FlexGridSizer(rows=len(mod.swf_options), cols=2, hgap=0, vgap=0)
110 flex.AddGrowableCol(1)
112 for option in mod.swf_options:
113 #swf_options.append(option)
114 label, ctrl = option.draw(p)
116 flex.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 4)
117 flex.Add(ctrl, 0, wx.EXPAND|wx.ALL, 4)
119 bsizer.Add(flex, 0, wx.EXPAND)
120 sizer.Add(bsizer, 0, wx.EXPAND)
123 if mod.viewer_options:
124 box = wx.StaticBox(p, label=u"Viewer")
125 bsizer = wx.StaticBoxSizer(box, wx.VERTICAL)
127 flex = wx.FlexGridSizer(rows=len(mod.viewer_options),
128 cols=2, hgap=0, vgap=0)
129 flex.AddGrowableCol(1)
131 for option in mod.viewer_options:
132 #vie_options.append(option)
133 label, ctrl = option.draw(p)
135 flex.Add(label, 0, wx.ALIGN_CENTER_VERTICAL|wx.ALL, 4)
136 flex.Add(ctrl, 0, wx.EXPAND|wx.ALL, 4)
138 bsizer.Add(flex, 0, wx.EXPAND)
139 sizer.Add(bsizer, 0, wx.EXPAND)
144 def AddPage(self, win, mod, select=False, imageId=-1):
145 wx.Listbook.AddPage(self, win, mod.name, select, imageId)
146 self.__mod.append(mod)
148 def __get_options(self):
149 page = self.GetSelection()
150 return self.__mod[page]
152 options = property(__get_options)
156 data['selected_viewer'] = self.GetSelection()
158 for viewer, module in zip(self.__viewers.viewers, self.__viewers.modules):
160 for opt in module.swf_options:
161 data[viewer][opt.name] = opt.value
162 for opt in module.viewer_options:
163 data[viewer][opt.name] = opt.value
167 def unpickle(self, data):
171 selected_viewer = data.pop('selected_viewer')
172 self.SetSelection(selected_viewer)
175 for viewer, module in zip(self.__viewers.viewers, self.__viewers.modules):
178 all_opts = module.swf_options + module.viewer_options
179 for field in all_opts:
180 _fields[viewer][field.name] = field
182 for modname, opts in data.items():
183 for k, v in opts.items():
184 _fields[modname][k].SetValue(v)