[Pythonmac-SIG] app does not run when launched via main.py import was:py2app- python code packed in clear ascii
the Shelter
the_shelter at yahoo.com
Thu Nov 20 12:26:40 CET 2008
I tried via the import and it converts my main app to bytecode (see post on bottom). THANKS FOR THE HELP.
However, now I face a strange problem even before I build an app bundle. the mainfile.py runs perfect when launched alone.
But when run via main.py it hangs when Upload button is presses.
I susspect either wx.callback or the thread- but right now I am lost.
NOTE: I use a patched ftplib, so I get a callback from an upload proces, which ftplib by default only supports for download. I include the extra lines I added to ftplib.py.
my main.py looks like this:
# /usr/bin/pythonw
import mainfile
mainfile.py is a small ftp upload app which uses wx.Miniframe and thread
================================================================
# /usr/bin/pythonw
#gui elements
import wx
#os and sys interaction elements
import os
import sys
#ftp elements
from ftplib import FTP
# Apple XML propertylist parser
import plist
#str
import string
# make it threading capable
import thread
pdffile = None
xmlfile = None
pofile = "P0.dtreq"
#preset to Fo39
fo_choice = "F39"
# define where to fnd the necessary config files
f = open(os.getcwd() + "/pdffile.txt",'r')
for line in f:
line = line.rstrip()
pdffile = line
f.close()
xmlfile = os.getcwd() + "/POReq.dtreq"
#abort without the necessary files
if pdffile is None or xmlfile is None:
print "Sorry. Cannot go ahead without PDF-file and XML-file"
sys.exit(0)
# import and parse the XML property list
xmldata = plist.parse_plist(xmlfile)
#assign XML values to variables
dealer = xmldata['CMS_licDealer']
customer_lastname = xmldata['K_nachname']
customer_firstname = xmldata['K_vorname']
customer_city = xmldata['K_ort']
customer_postal = xmldata['K_plz']
customer_street = xmldata['K_strasse']
customer_email = xmldata['CMS_licName']
serial = xmldata['CMS_licSerial']
dec_email ="me at home.com"
dec_serial ="123456"
# create the GUI Window
class Window ( wx.MiniFrame ):
def __init__ ( self ):
#define default values for upload bar
statinfo = os.stat(pdffile)
self.filesize = statinfo.st_size
self.so_far = 0
#define 4 Fo profiles to choose from
fogra_list = ['Fo39','Fo28','Fo29','Fo30']
# No suprises here
# We only use a different cl
wx.MiniFrame.__init__ ( self, None, -1, 'ftp TEST Transfer',style=wx.DEFAULT_FRAME_STYLE | wx.TINY_CAPTION_HORIZ)
# Create a panel
self.panel = wx.Panel ( self, -1)
self.t1 = wx.StaticText(self.panel,-1," Username:",pos = (10,10))
self.t2 = wx.TextCtrl(self.panel,-1,dec_email,pos = (100,10),size=(135, 15),style=wx.TE_READONLY)
self.t3 = wx.StaticText(self.panel,-1," Password:",pos = (10,35))
self.t4 = wx.TextCtrl(self.panel,-1,dec_serial,pos = (100,35),size=(135, 15),style=wx.TE_PASSWORD | wx.TE_READONLY )
self.t5 = wx.StaticText(self.panel,-1," File:",pos = (10,60))
self.t6 = wx.StaticText(self.panel,-1,tail1,pos = (100,60))
self.t7 = wx.StaticText(self.panel,-1," FO:",pos = (10,85))
self.ch = wx.Choice(self.panel, -1, (100, 80), choices = fogra_list)
self.panel.Bind(wx.EVT_CHOICE, self.EvtChoice, self.ch)
#contruct the gauge for progress display
self.g1 = wx.Gauge(self.panel, -1, 100, (10, 110), (230, 25))
self.t9 = wx.StaticText(self.panel, -1, "Kb:", pos = (15,135))
self.t8 = wx.StaticText(self.panel, -1, "Percentt:", pos = (165,135))
#set the go button
self.start_upload_button = wx.Button(self.panel, -1, "Upload")
self.start_upload_button.SetPosition((15, 165))
self.panel.Bind(wx.EVT_BUTTON, self.OnStartUpload, self.start_upload_button)
#set the close button
self.close_window_button = wx.Button(self.panel, -1, "Fertig")
self.close_window_button.SetPosition((165, 165))
self.panel.Bind(wx.EVT_BUTTON, self.OnCloseMe, self.close_window_button)
self.close_window_button.Enable(False)
#set fonts - this time individually for later playing
self.t1.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.NORMAL))
self.t2.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.NORMAL))
self.t3.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.NORMAL))
self.t4.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.NORMAL))
self.t5.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.NORMAL))
self.t6.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.NORMAL))
self.t7.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.NORMAL))
self.ch.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.NORMAL))
self.t8.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.NORMAL))
self.t9.SetFont(wx.Font(10,wx.SWISS,wx.NORMAL,wx.NORMAL))
#Set Miniframe properties and launch it
self.SetSize((250,220))
self.CenterOnParent(wx.BOTH)
self.Show(True)
def wxcallback(self, buffer):
self.so_far = self.so_far+len(buffer)-1
#self.g1.SetValue(self.so_far)
#self.g1.Update(self.so_far)
pct = float(self.so_far)/self.filesize*100
self.g1.SetValue(pct)
pct2 = round(pct, 2)
self.t8.SetLabel("Prozent: " + str(pct2))
self.t9.SetLabel("Kb: " + str(self.so_far) + " von " + str(self.filesize))
#print "so far:", self.so_far, pct
return
def EvtChoice(self,event):
global fo_choice
fo_choice=event.GetString()
def OnCloseMe(self,evt):
self.Close(True)
def OnStartUpload(self,evt):
thread.start_new(self.FtpUp,())
def FtpUp(self):
#start pulsing the gauge
self.g1.Pulse()
#disable the Upload button
self.start_upload_button.Enable(False)
#the progress dialog
#connect to the ftp server
ftp = FTP("192.168.0.1")
ftp.login("username", "password")
trans_file = open(pdffile)
print trans_file
#FTPprogress = FTPProgressDialog(filename)
ftp.newstorbinary("STOR " + serial + "_" + fo_choice + "_" + tail1, trans_file, callback=self.wxcallback)
trans_file.close()
ftp.close()
#set gauge to 100% caus it hangs at 99.9% although 100%
self.g1.SetValue(230)
self.t8.SetLabel("Percent: 100.00")
self.t9.SetLabel("Kb: " + str(self.filesize) + " of " + str(self.filesize))
#let the user press Finish to close the window
self.close_window_button.SetForegroundColour("green")
self.close_window_button.Enable()
application = wx.PySimpleApp()
Window()
application.MainLoop()
================================================================
patch for ftplib.py to support a callback for uploads:
Append to your ftplib.py:
===========================================================
def newstorbinary(self, cmd, fp, blocksize=8192, callback = None):#this version includeds a callback
'''Store a file in binary mode.'''
#CRLF = ftplib.CRLF
self.voidcmd('TYPE I')
conn = self.transfercmd(cmd)
while 1:
buf = fp.read(blocksize)
if not buf: break
conn.sendall(buf)
if callback: callback(buf)
conn.close()
return self.voidresp()
================================================
--- On Tue, 8/5/08, Mike Covill <mcovill at mac.com> wrote:
> From: Mike Covill <mcovill at mac.com>
> Subject: Re: [Pythonmac-SIG] py2app- python code packed in clear ascii
> To: the_shelter at yahoo.com
> Cc: pythonmac-sig at python.org
> Date: Tuesday, August 5, 2008, 2:08 PM
> the shelter,
>
> The last time I built an app bundle, the only source file
> from my code in plain ascii was my main.py file. Everything
> else was precompiled and zipped up in a sub-folder. So the
> strategy to hide all source code was to create a main.py
> file which simply imports another file containing what used
> to be in the main.py file, and run it from there.
>
> Here are some py2app resources I found useful:
>
> http://svn.pythonmac.org/py2app/py2app/trunk/doc/index.html
> http://undefined.org/python/py2app.html
>
> Mike
>
>
> On 4-Aug-08, at 12:45 PM, the Shelter wrote:
>
> > Hi,
> >
> > after a lot of python programming on linux and windows
> I have now taken up the task of converting/ adapting my apps
> (python/wxPython) to the mac.
> > I tried to bundle my apps w/ py2app but had to find
> out that it seems like it packs my sources in clear ascii
> and not in binary form- somewhat unusual after having worked
> w/ py2exe ...
> >
> > Am I missing something?
> >
> > Right now I am on 10.4 w/ latest python and py2app-
> all from python.org- not the Apple versions.
> >
> > thanX
> >
> >
> >
> > _______________________________________________
> > Pythonmac-SIG maillist - Pythonmac-SIG at python.org
> > http://mail.python.org/mailman/listinfo/pythonmac-sig
More information about the Pythonmac-SIG
mailing list