#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    103
    Rep Power
    11

    wxPython script works,but not when compiled


    Greets,

    I have a program that uses wxPython to pop a "browse for file" window,then do things with the selected file,and finally copies the file path to my clipboard.It works fine while running it as a .py file thru IDLE.But if I compile the script,or simply double click the .py file(yes,I'm using XP) it doesn't work properly.This is what happens:

    1) Nothing is saved to my clipboard.Infact,if there was something there,it gets cleared.

    2) Whenever I try to print the selected file name to my console,it raises the exception from my previous "try" statement.But it is still acting properly on the selected file(IE: if its a tga converts it to jpg,uploads the file,etc).

    The whole intent behind my program,is to give my friends a simple exe to upload pics to our image server,then copy the url to their clipboard for quick and easy use.I use the wxPython "browse for file" window to save them from writing out file paths and names,same thing with the copy to clipboard feature.If I cannot get these 2 things to work properly,then I gotta scrap this program(since w/o these 2 things,it's not really saving any time or effort).Since it's kinda lengthy,I'll attach the script,instead of posting it.

    Its just weird that everything is working(converting the file,uploading it,etc) but python just can't display the actual selected file name from wxPython,nor copy it to my clipboard.

    I am using Python 2.3.4 on XP Home Edition
    Attached Files
    It is not important if the glass is half full or half empty.What is important,is who has been drinking from MY glass?!?!?
  2. #2
  3. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    This doesn't help your problem, but here's a note for the following line:
    Code:
    basename.endswith('jpg') or basename.endswith('bmp') or basename.endswith('gif'):
    You should include a period (.) before the file extension name. What is there was a file with an extension of .bgif? Your program would search it which is something you don't want.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    103
    Rep Power
    11
    Originally Posted by †Yegg†
    This doesn't help your problem, but here's a note for the following line:
    Code:
    basename.endswith('jpg') or basename.endswith('bmp') or basename.endswith('gif'):
    You should include a period (.) before the file extension name. What is there was a file with an extension of .bgif? Your program would search it which is something you don't want.
    Wow,never thought of that,thanks

    As far as my other problems,I may have found another way to do what I want.For the copy to clipboard problem:
    Code:
    import win32clipboard
    
    win32clipboard.OpenClipboard()
    win32clipboard.EmptyClipboard()
    win32clipboard.SetClipboardText('this is some text')
    win32clipboard.CloseClipboard()
    This works great so far,both as the .py file,and when compiled.I think this would limit my program to be run on Windows...But thats ok,I'm compiling my program as a exe anyways

    Poking around on Google,I came across this to browse for folders(It's close to what I want,but I need to find files,not directories.I would figure there is also something like this in the shell for finding files,but for the life of me,I can't find it ):

    Code:
    from win32com.shell import shell
    
    pidl,disp,imglist=shell.SHBrowseForFolder(0,None,"Please choose a directory. Thanks.")
    fullpath=shell.SHGetPathFromIDList(pidl)
    But since my target is for people on Windows,wouldn't I want to use the windows shell as opposed to wxPython or TK?I have found the open file dialog in TK,but wouldn't it be better to use what is already there in windows?
    It is not important if the glass is half full or half empty.What is important,is who has been drinking from MY glass?!?!?
  6. #4
  7. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Dec 2004
    Location
    Meriden, Connecticut
    Posts
    1,797
    Rep Power
    154
    Since your program will now run only on Win32 systems, you can simply use the os module's listdir function to list all current files/folders in the main system drive. To get the system drive letter do the following:
    Code:
    import os
    drive_letter = os.environ['SYSTEMDRIVE']
    drive_letter will equal the systems drive letter. You can search all files/folders within all directories located in drive_letter, and files\folders located in the directories of that directory, and so on. I believe the os module has an isdirectory function, or something that does the same? I think you'll figure it out. Hope this helps, and I'm glad you solved atleast one problem on your own so far.

IMN logo majestic logo threadwatch logo seochat tools logo