Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old January 23rd, 2013, 01:13 PM
daafith daafith is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 daafith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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()

Reply With Quote
  #2  
Old January 24th, 2013, 01:38 PM
Dietrich's Avatar
Dietrich Dietrich is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 482 Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level)Dietrich User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 3 Days 22 h 23 m 21 sec
Reputation Power: 63
Add this line for Python2
import FixTk
or for Python3
import Tkinter._fix
__________________
Real Programmers always confuse Christmas and Halloween because Oct31 == Dec25

Reply With Quote
  #3  
Old January 24th, 2013, 01:49 PM
daafith daafith is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 daafith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #4  
Old January 30th, 2013, 02:24 AM
razzerman razzerman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 razzerman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #5  
Old January 31st, 2013, 08:46 AM
daafith daafith is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 daafith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #6  
Old February 12th, 2013, 01:11 AM
razzerman razzerman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 razzerman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #7  
Old February 21st, 2013, 10:44 AM
razzerman razzerman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 razzerman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #8  
Old February 24th, 2013, 01:05 PM
daafith daafith is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 daafith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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.

Reply With Quote
  #9  
Old March 5th, 2013, 04:24 AM
razzerman razzerman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 razzerman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
  #10  
Old March 5th, 2013, 04:35 AM
daafith daafith is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 daafith User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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...

Reply With Quote
  #11  
Old March 12th, 2013, 05:54 AM
razzerman razzerman is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2013
Posts: 5 razzerman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
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

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPython Programming > My file generator does not work after building with py2app

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap