The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Python Programming
|
My file generator does not work after building with py2app
Discuss My file generator does not work after building with py2app in the Python Programming forum on Dev Shed. My file generator does not work after building with py2app Python Programming forum discussing coding techniques, tips and tricks, and Zope related information. Python was designed from the ground up to be a completely object-oriented programming language.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

January 23rd, 2013, 01:13 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 5
Time spent in forums: 19 m 4 sec
Reputation Power: 0
|
|
|
My file generator does not work after building with py2app
My script generates a file and places it in in a directory. When I run it in IDLE it works perfectly. When I build it in py2app, it does not create the directory nor does is create the file.
Code:
from Tkinter import *
from decimal import *
import re
import os
class Application(Frame):
def __init__(self, parent):
Frame.__init__(self, parent)
self.parent = parent
self.grid()
self.create_widgets()
def create_widgets(self):
""" Create widgets to get file name, size and type. """
# create instruction label
Label(self,
text = "Enter file size and name"
).grid(row = 0, column = 1, columnspan = 2, sticky = W)
# create a label and text entry for the size of a file
Label(self,
text = "File size: "
).grid(row = 1, column = 0, sticky = E)
self.calc_ent = Entry(self, width=12)
self.calc_ent.grid(row = 1, column = 1, sticky = W)
# create a label and text entry for the name of a file
Label(self,
text = "File name: "
).grid(row = 2, column = 0, sticky = E)
self.type_ent = Entry(self, width=12)
self.type_ent.grid(row = 2, column = 1, sticky = W)
# create a label File extension
Label(self,
text = "File extension:"
).grid(row = 4, column = 1, sticky = W)
# create variable for single, extension
self.option = StringVar()
self.option.set(".txt")
# create radio buttons, extension
options = [".txt",".pdf", ".xml",".zip"]
row = 5
for ending in options:
Radiobutton(self,
text = ending,
variable = self.option,
value = ending
).grid(row = row, column = 1, sticky = W)
row += 1
# create variable for single, MB|MiB
self.variable = StringVar()
self.variable.set("MB")
# create a label MB|MiB radio buttons
Label(self,
text = "MB or MiB:"
).grid(row = 4, column = 2, sticky = W)
# create radio buttons, var
variables = ["MB", "MiB"]
row = 5
for var in variables:
Radiobutton(self,
text = var,
variable = self.variable,
value = var
).grid(row = row, column = 2, sticky = W)
row += 1
# create a submit button
Button(self,
text = "Generate",
command = self.create
).grid(row = 9, column = 1, sticky = W)
self.message_txt = Text(self, width = 45, height = 2, wrap = WORD)
self.message_txt.grid(row = 10, column = 0, columnspan = 4)
def create(self):
""" Assign variables based on user input. """
# get values from the GUI
size = self.calc_ent.get()
name = self.type_ent.get()
var = self.variable.get()
opt = self.option.get()
#check if size is not a string with a regular expression
check = re.compile('\d+(\.\d+)?')
if check.match(size) == None:
message="Please enter a float (9.2) or an integer (3). Strings are not allowed."
else:
size=Decimal(size)
if name=="":
name="untitled"
name+=opt
directory = "output/test_files/"
d = os.path.dirname(directory)
if not os.path.exists(directory):
os.makedirs(directory)
name=directory+name
check = os.path.abspath(name)
#the magic
if var=="MiB":
with open(name,"wb") as output:
output.truncate(size * 1024 * 1024)
else:
var="MB"
with open(name, "wb") as output:
output.truncate(size * 1000 * 1000)
message=name,size,var, check
self.message_txt.delete(0.0, END)
self.message_txt.insert(0.0, message)
# main
root = Tk()
root.title("File creator (c) David Baak")
app = Application(root)
root.mainloop()
|

January 24th, 2013, 01:38 PM
|
 |
Contributing User
|
|
|
|
|
Add this line for Python2
import FixTk
or for Python3
import Tkinter._fix
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25
|

January 24th, 2013, 01:49 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 5
Time spent in forums: 19 m 4 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by Dietrich Add this line for Python2
import FixTk
or for Python3
import Tkinter._fix |
The issue is not that the GUI does not work, the issue is that everything seemingly works, but my app does not generate the file/directory as it does in IDLE.
|

January 30th, 2013, 02:24 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 5
Time spent in forums: 36 m 12 sec
Reputation Power: 0
|
|
|
Hello,
Thought I'd post and let you know that you're not alone. I've written a small Python program to create svg files from user input - works fine in IDLE and creates the svg file, but after compilation the app won't create the svg file. I'll keep looking and post here if I find an answer.
Cheers,
Razzer
|

January 31st, 2013, 08:46 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 5
Time spent in forums: 19 m 4 sec
Reputation Power: 0
|
|
|
thanks
Quote: | Originally Posted by razzerman Hello,
Thought I'd post and let you know that you're not alone. I've written a small Python program to create svg files from user input - works fine in IDLE and creates the svg file, but after compilation the app won't create the svg file. I'll keep looking and post here if I find an answer.
Cheers,
Razzer |
Aha, so I am not alone...keep me posted if you find out what the solution is. It is py2qapp related but there seems no logical, straightforward answer.
|

February 12th, 2013, 01:11 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 5
Time spent in forums: 36 m 12 sec
Reputation Power: 0
|
|
|
Small progress...
Hey again,
Just a quick update. Still no joy with py2app, but tried with pyinstaller (which is cross platform). Still no joy on the Mac side, but got the app to compile and run as it should on the Windows side - which was good news (and offers a glimmer of hope!).
Still working on the mac side...
Cheers,
Ray
|

February 21st, 2013, 10:44 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 5
Time spent in forums: 36 m 12 sec
Reputation Power: 0
|
|
|
Good news!
Hey again,
Success! Finally got the Mac version to work. I was hoping the app would know where to put the created file. It didn't. Had to add the following:
name='/Users/python27/Desktop/RayMarch/Razzer.svg'
os.path.abspath(name)
Works just fine now.
Cheers,
Ray
|

February 24th, 2013, 01:05 PM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 5
Time spent in forums: 19 m 4 sec
Reputation Power: 0
|
|
|
Aha
Well done finding out 
The only issue is that it works on your own mac but if you install the app elsewhere it will not work because your path is hardcoded.
But OK, at least it does something, more than it did before.
|

March 5th, 2013, 04:24 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 5
Time spent in forums: 36 m 12 sec
Reputation Power: 0
|
|
|
Partial Success
Hey again,
I didn't point out that I only got it working with PyInstaller, not Py2App (which still refuses to work).
I looked through your code and noticed you already had the paths specified (more elegantly than my brute force method).
Cheers,
Ray
|

March 5th, 2013, 04:35 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 5
Time spent in forums: 19 m 4 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by razzerman Hey again,
I didn't point out that I only got it working with PyInstaller, not Py2App (which still refuses to work).
I looked through your code and noticed you already had the paths specified (more elegantly than my brute force method).
Cheers,
Ray |
Then it seems it is a stupid py2app bug no one knows how to solve. I asked on stack overflow, but one knew the answer either...
|

March 12th, 2013, 05:54 AM
|
|
Registered User
|
|
Join Date: Jan 2013
Posts: 5
Time spent in forums: 36 m 12 sec
Reputation Power: 0
|
|
|
Hey again,
More good news - it does work now with py2app. Updated to py2app 0.7.3, and it worked fine (as long as path exists leastways).
Ray
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|