From a9c3c32bc9ba2604d0bab6a7a2df530396b6d965 Mon Sep 17 00:00:00 2001 From: Matthias Kramm Date: Wed, 2 Jun 2010 16:36:10 -0700 Subject: [PATCH] applied patch from Ricardo Pedroso --- wx/gpdf2swf.py | 61 ++++++++++++++++++---------------- wx/gui/gmain.py | 2 +- wx/gui/options/viewer.py | 79 ++++++++++++++++++++++++--------------------- wx/gui/plugin.py | 6 ++-- wx/lib/app.py | 11 +++++++ wx/viewers/flexpaper.py | 10 +++--- wx/viewers/rfx.py | 7 ++-- wx/viewers/technoargia.py | 7 ++-- 8 files changed, 106 insertions(+), 77 deletions(-) diff --git a/wx/gpdf2swf.py b/wx/gpdf2swf.py index e6941c2..4462884 100644 --- a/wx/gpdf2swf.py +++ b/wx/gpdf2swf.py @@ -26,40 +26,47 @@ from __future__ import division import __builtin__ import os import sys -import imp +#import imp -def main_is_frozen(): - return (hasattr(sys, "frozen") or # new py2exe - hasattr(sys, "importers") # old py2exe - or imp.is_frozen("__main__")) # tools/freeze - -#if not main_is_frozen(): -# try: -# import wxversion -# wxversion.select("2.6") -# except: -# wxversion.select("2.8") - -def get_main_dir(): - if main_is_frozen(): - return os.path.dirname(sys.executable) - return os.path.dirname(os.path.abspath(__file__)) -__builtin__.get_main_dir = get_main_dir -__builtin__.GPDF2SWF_BASEDIR = get_main_dir() - -pyver = "".join(map(str, sys.version_info[0:2])) -#print >>sys.stderr, pyver -if main_is_frozen(): - sys.path.insert(0, os.path.join("..", "python%s" % pyver)) -else: - sys.path.insert(0, os.path.join("..", "lib", "python")) - sys.path.insert(1, os.path.join("..", "python%s" % pyver)) +#def main_is_frozen(): +# return (hasattr(sys, "frozen") or # new py2exe +# hasattr(sys, "importers") # old py2exe +# or imp.is_frozen("__main__")) # tools/freeze +# +##if not main_is_frozen(): +## try: +## import wxversion +## wxversion.select("2.6") +## except: +## wxversion.select("2.8") +# +#def get_main_dir(): +# if main_is_frozen(): +# return os.path.dirname(sys.executable) +# return os.path.dirname(os.path.abspath(__file__)) +#__builtin__.get_main_dir = get_main_dir +#__builtin__.GPDF2SWF_BASEDIR = get_main_dir() +# +#pyver = "".join(map(str, sys.version_info[0:2])) +##print >>sys.stderr, pyver +#if main_is_frozen(): +# sys.path.insert(0, os.path.join("..", "python%s" % pyver)) +#else: +# sys.path.insert(0, os.path.join("..", "lib", "python")) +# sys.path.insert(1, os.path.join("..", "python%s" % pyver)) import wx #print >>sys.stderr, wx.VERSION from lib.app import Pdf2Swf +__builtin__.GPDF2SWF_BASEDIR = os.path.dirname(os.path.abspath(sys.argv[0])) + if __name__ == "__main__": + #print "sys.argv[0]", sys.argv[0] + #print "abspath sys.argv[0]", + #print "sys.executable", sys.executable + #print "abspath sys.executable", os.path.abspath(sys.executable) + #print "GPDF2SWF_BASEDIR", GPDF2SWF_BASEDIR app = wx.App(False) app.SetAppName(u"gpdf2swf") Pdf2Swf() diff --git a/wx/gui/gmain.py b/wx/gui/gmain.py index 85aa2d6..be2a0ba 100644 --- a/wx/gui/gmain.py +++ b/wx/gui/gmain.py @@ -344,7 +344,7 @@ class PdfFrame(wx.Frame): choices=["everything to bitmaps", "fonts to fonts, everything else to bitmaps", "polygons to polygons and fonts to fonts"], - size=(350,-1), style=wx.CB_DROPDOWN + size=(350,-1) ) # I'm not sure about the utility of this, so Show False self.toolbar_preview_type.Show(False) diff --git a/wx/gui/options/viewer.py b/wx/gui/options/viewer.py index e6693e6..e36eacc 100644 --- a/wx/gui/options/viewer.py +++ b/wx/gui/options/viewer.py @@ -25,53 +25,58 @@ import os import wx import operator -#import imp +import imp from lib.wordwrap import wordwrap from gui.boldstatictext import BoldStaticText import viewers import gui.fields + +# this two are only to satisfy some plugins requirements import gui.plugin +import shutil -import viewers.raw -import viewers.simple -import viewers.rfx -import viewers.flexpaper -import viewers.technoargia +#import viewers.raw +#import viewers.simple +#import viewers.rfx +#import viewers.flexpaper +#import viewers.technoargia class Viewers: def __init__(self): - self.viewers = [ - 'raw', - 'simple', - 'rfx', - 'flexpaper', - 'technoargia', - ] - self.modules = [ - viewers.raw, - viewers.simple, - viewers.rfx, - viewers.flexpaper, - viewers.technoargia, - ] + #self.viewers = [ + # 'raw', + # 'simple', + # 'rfx', + # 'flexpaper', + # 'technoargia', + #] + self.viewers = [] + #self.modules = [ + # viewers.raw, + # viewers.simple, + # viewers.rfx, + # viewers.flexpaper, + # viewers.technoargia, + #] + self.modules = [] - #self.list_viewers() - #self.import_viewers() - - #def list_viewers(self): - # for file in os.listdir('viewers'): - # if (file.startswith('.') or file.startswith('_') - # or file.endswith(".pyc") or not file.endswith('.py')): - # continue - # self.viewers.append(os.path.splitext(file)[0]) - - #def import_viewers(self): - # for file in self.viewers: - # try: - # _temp = imp.load_source("viewers.%s" % file, os.path.join(os.getcwdu(), "viewers/%s.py" % file)) - # self.modules.append(_temp) - # except: - # print "Could not load %s" % file + self.list_viewers() + self.import_viewers() + + def list_viewers(self): + for file in os.listdir('viewers'): + if (file.startswith('.') or file.startswith('_') + or file.endswith(".pyc") or not file.endswith('.py')): + continue + self.viewers.append(os.path.splitext(file)[0]) + + def import_viewers(self): + for file in self.viewers: + try: + _temp = imp.load_source("viewers.%s" % file, os.path.join(os.getcwdu(), "viewers/%s.py" % file)) + self.modules.append(_temp) + except Exception, e: + print "Could not load %s (%s)" % (file, e) diff --git a/wx/gui/plugin.py b/wx/gui/plugin.py index e20a87c..36f21e3 100644 --- a/wx/gui/plugin.py +++ b/wx/gui/plugin.py @@ -55,7 +55,10 @@ class Plugin: #print 'basedir', basedir opj = os.path.join - locations = [os.path.normpath(opj(basedir, '..', prog))] + locations = [ + os.path.normpath(opj(basedir, prog)), + os.path.normpath(opj(basedir, "..", "src", prog)), + ] if "wxMSW" in wx.PlatformInfo: try: system_drive = os.environ['SYSTEMDRIVE'] @@ -69,7 +72,6 @@ class Plugin: opj("c:", os.sep, "swftools", prog), opj("c:", os.sep, "Program Files", "SWFTools", prog), opj(system_drive, os.sep, program_files, "SWFTools", prog), - opj(basedir, prog), ]) else: locations.extend([ diff --git a/wx/lib/app.py b/wx/lib/app.py index 072b79d..f524cdd 100644 --- a/wx/lib/app.py +++ b/wx/lib/app.py @@ -143,6 +143,17 @@ class Pdf2Swf: self.view.statusbar.btn_cancel.Bind(wx.EVT_BUTTON, self.OnThumbnailCancel) + # Don't know where the problem is (python/xpython or wxwidgets/wxpython) + # but I found that this hack was necessary to avoid the app enter in a + # idle state. We must, for example, move the mouse inside the app + # for threads continue their job. + # There is no need for this when freezing with other utils, like + # py2exe, pyinstaller, cxfreeze + if "wxMSW" in wx.PlatformInfo: + self.timer = wx.Timer(self.view) + self.view.Bind(wx.EVT_TIMER, lambda evt: None) + self.timer.Start(50) + def OnFilesDroped(self, evt): dlg = wx.MessageDialog(self.view, u"You must drop only one file.", diff --git a/wx/viewers/flexpaper.py b/wx/viewers/flexpaper.py index bc55b20..4f1d1f6 100644 --- a/wx/viewers/flexpaper.py +++ b/wx/viewers/flexpaper.py @@ -112,7 +112,7 @@ viewer_options = [ html_template = open('viewers/flexpaper/FlexPaperViewer.html').read() from gui.plugin import Plugin -import os +import os, sys class FlexPaper(Plugin): def __init__(self, swf, filename): @@ -138,16 +138,14 @@ class FlexPaper(Plugin): htmlfilename = self._swap_extension(self.__filename, "html") f = open(htmlfilename, "wb") - try: - f.write(html_template % template_vars) - except Exception, e: - print e + f.write(html_template % template_vars) f.close() import shutil opj = os.path.join - src = opj(os.path.dirname(__file__), 'flexpaper') + basedir = GPDF2SWF_BASEDIR + src = opj(basedir, 'viewers', 'flexpaper') dst = os.path.dirname(self.__filename) shutil.copy(opj(src, 'FlexPaperViewer.swf'), dst) diff --git a/wx/viewers/rfx.py b/wx/viewers/rfx.py index 433f153..610b5a5 100644 --- a/wx/viewers/rfx.py +++ b/wx/viewers/rfx.py @@ -71,7 +71,7 @@ html_template = """ """ from gui.plugin import Plugin -import os +import os, sys class Rfx(Plugin): def __init__(self, swf, filename): @@ -86,7 +86,10 @@ class Rfx(Plugin): setattr(self, "_%s" % opt.name, opt.value) def after_save(self, page): - viewerfilename = self._swap_extension(__file__, "swf", self._flashversion) + basedir = GPDF2SWF_BASEDIR + viewerfilename = os.path.join(basedir, + "viewers", + "rfx%s.swf" % self._flashversion) self.swfcombine( u"%s" % viewerfilename, diff --git a/wx/viewers/technoargia.py b/wx/viewers/technoargia.py index 7d6afa2..f19e9e9 100644 --- a/wx/viewers/technoargia.py +++ b/wx/viewers/technoargia.py @@ -71,7 +71,7 @@ html_template = """ """ from gui.plugin import Plugin -import os +import os, sys class Technoargia(Plugin): def __init__(self, swf, filename): @@ -86,7 +86,10 @@ class Technoargia(Plugin): setattr(self, "_%s" % opt.name, opt.value) def after_save(self, page): - viewerfilename = self._swap_extension(__file__, "swf") + basedir = GPDF2SWF_BASEDIR + viewerfilename = os.path.join(basedir, + "viewers", + "technoargia.swf") self.swfcombine( u"%s" % viewerfilename, -- 1.7.10.4