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 */
28 from wx.lib.pubsub import Publisher
29 from subprocess import Popen, PIPE
32 one_page_per_file = False
34 def before_render(self):
37 def before_save(self, page):
40 def after_save(self, page):
43 def _swap_extension(self, filename, newext, flashversion=""):
44 name, ext = os.path.splitext(filename)
45 return u"%s%s.%s" % (name, flashversion, newext)
47 def __find_swfcombine(self):
49 if "wxMSW" in wx.PlatformInfo:
50 prog = "swfcombine.exe"
53 #basedir = os.path.dirname(__file__)
54 basedir = GPDF2SWF_BASEDIR
55 #print 'basedir', basedir
59 os.path.normpath(opj(basedir, prog)),
60 os.path.normpath(opj(basedir, "..", "src", prog)),
62 if "wxMSW" in wx.PlatformInfo:
64 system_drive = os.environ['SYSTEMDRIVE']
68 program_files = os.environ['PROGRAMFILES']
72 opj("c:", os.sep, "swftools", prog),
73 opj("c:", os.sep, "Program Files", "SWFTools", prog),
74 opj(system_drive, os.sep, program_files, "SWFTools", prog),
78 opj("/usr", "local", "bin", prog),
79 opj("/usr", "bin", prog),
80 opj(basedir, '..', 'src', prog),
94 def swfcombine(self, *args):
96 self.__swfcombine(*args)
98 wx.CallAfter(Publisher.sendMessage,
99 "SWF_COMBINE_ERROR", unicode(e))
102 def __swfcombine(self, *args):
103 exe, found = self.__find_swfcombine()
104 # uncoment to test a failed swfcombine find
108 raise Exception(u"Could not execute %s: %s not found" % (exe, exe))
110 # Create a command line
114 if "wxMSW" in wx.PlatformInfo:
117 # To avoid an ugly "DOS Window" to show up
118 flags = win32process.CREATE_NO_WINDOW
120 # See http://msdn.microsoft.com/en-us/library/ms684863(VS.85).aspx
121 # for this flag (CREATE_NO_WINDOW) value
125 output = Popen(cmd, stdin=PIPE, stdout=PIPE,
126 stderr=PIPE, creationflags=flags).communicate()[0]
128 # Check the process output
130 raise Exception(u"Error executing %s:%s%s" %
131 (u" ".join(cmd), os.linesep, output))