Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # py2any.py - A GUI to make executables from Python scripts ZZZ
- '''
- So far, as a work in progress, this works with Tkinter and cx-Freeze. Had quite a difficult time trying to
- figure py2exe out while cx-Freeze took very little time. Will now attempt to properly make this script make
- it a much easier transition, then up next... hopefully get this to also build apk for AndroidOS devices, if
- feasible.
- '''
- from Tkinter import *
- import tkFileDialog, tkMessageBox
- import subprocess, sys, os
- import time
- cmdrefa='''#!/usr/bin/python
- init=True
- '''
- # not sure "which" did the trick, however, the following is at your own risk...
- # set "TCL_LIBRARY=C:\Python27\tcl\tcl8.5" set "TK_LIBRARY=C:\Python27\tcl\tk8.5" <<< most likely this
- # cmd >>> pip uninstall PIL >>> pip install PIL
- # *** https://pypi.python.org/packages/2.7/P/Pillow/Pillow-2.1.0.win32-py2.7.exe <<< make a backup beforehand
- '''
- if CMD throws the error "ImportError: DLL load failed: %1 is not a valid Win32 application."...
- It means you have a 64 bit version of python, with a 32bit module, or the reverse
- '''
- root = Tk()
- root.title("py2any")
- ws = root.winfo_screenwidth()
- hs = root.winfo_screenheight()
- cvx=600
- cvy=300
- x = (ws/2) - (cvx/2)
- y = (hs/2) - (cvy/2)
- #root.geometry('%dx%d+%d+%d' % (cvx, cvy, x, y))
- shebang="#!/usr/bin/python" ### ZZZ if missing at top of target python script
- incl_path=excl_path=icon_path='None'
- def GetFile(event):
- file = tkFileDialog.askopenfilename()
- if file.split('.')[-1] in ('py','pyw'):
- if 'setup.py' not in file: src.set(file)
- if 1: ### interference glitch? ZZZ
- inFileBtn = Button(stepOne, text=browse)
- inFileBtn.bind("<Button>", GetFile)
- inFileBtn.grid(row=0, column=0, sticky='W', padx=5, pady=5)
- def GetIcon(event):
- icon = [tkFileDialog.askopenfilename()]
- def make_checkbutton(frame, text, tick=NORMAL):
- var = IntVar()
- widget = Checkbutton(frame, text=text, variable=var)
- widget.grid(sticky="NW")
- if tick is 1: widget.select()
- return var
- def makePackage(event):
- if src.get():
- create_setup()
- else: print('Host script not given')
- def create_setup():
- src_path=src.get()
- if 1: ### ZZZ Not quite yet implemented.
- excl_path='None'
- if __excl_path.get():
- excl_path="'C:\\Python27\\Lib'"
- print('Folder In Explorer Should Open Automatically')
- print('Double-click setup.bat to continue...\n')
- os.startfile('C:\\Python27\\projects')
- folder = "C:\\Python27\\projects\\" ### ZZZ
- setupfile = folder +'setup.py'
- source=src_path.split('\\')[-1]
- sourcepath = folder + source
- _ID_=source.split('.')[0]
- print(_ID_)
- cmdrefb="""if init:
- import sys
- from cx_Freeze import setup, Executable
- # Dependencies are automatically detected, but it might need fine tuning.
- build_exe_options = {'packages': ['os'], 'excludes': ['tkinter']}
- # GUI applications require a different base on Windows
- # (the default is for a console application).
- setup( name = '"""+_ID_+"""',
- version = '0.1',
- description = 'My GUI Application!',
- options = {'build_exe': build_exe_options},
- executables = [Executable('"""+_ID_+""".py')],
- target_name = '"""+_ID_+"""',
- target_dir='"""+_ID_+"""',
- icon="""+icon_path+""",
- data_files=None,
- includes=None,
- excludes=None,
- bin_includes=None,
- bin_excludes=None,
- bin_path_includes="""+incl_path+""",
- bin_path_excludes="""+excl_path+""")
- """
- data = open(setupfile, 'w')
- data.write(cmdrefa+cmdrefb)
- data.close()
- data = open(folder+'setup.bat', 'w')
- data.write("python C:\\Python27\\projects\\setup.py bdist_msi & pause")
- data.close()
- # execfile(folder+'setup.bat') ### ? ZZZ
- #
- mdetails=" Do Mouse Over For Details "
- browse=" Browse... "
- stepOne = LabelFrame(root, text=" 1. Script To Bundle: ")
- stepOne.grid(row=0, columnspan=7, sticky='WE', padx=5, pady=5)
- helpLf = LabelFrame(root, text=" Quick Help ")
- helpLf.grid(row=0, column=9, columnspan=2, rowspan=8, sticky='NS', padx=5, pady=5)
- helpLbl = Label(helpLf, text=mdetails)
- helpLbl.grid(row=0)
- stepTwo = LabelFrame(root, text=" 2. To Enter Details: ")
- stepTwo.grid(row=2, columnspan=7, sticky='WE', padx=5, pady=5, ipady=5)
- stepThree = LabelFrame(root, text=" 3. To Configure: ")
- stepThree.grid(row=3, columnspan=7, sticky='WE', padx=5, pady=5)
- stepFour = LabelFrame(root, text='Create Setup Command File (.bat)')
- stepFour.grid(row=4, columnspan=7, sticky='WE', padx=5, pady=5)
- src = StringVar()
- inFileTxt = Entry(stepOne, textvariable=src)
- inFileTxt.grid(row=0, column=1, columnspan=7, sticky="WE", pady=2)
- inFileBtn = Button(stepOne, text=browse)
- inFileBtn.bind("<Button>", GetFile)
- inFileBtn.grid(row=0, column=0, sticky='W', padx=5, pady=5)
- LabelText=(' demo ',)*6
- order=0
- fldRowTxt="fldRowTxt^* = Entry(stepTwo)\n\
- fldRowTxt^*.grid(row=order, column=1, columnspan=5, padx=5, pady=2, sticky='WE')"
- for i in LabelText:
- fldLbl = Label(stepTwo, text=i+str(order+1))
- fldLbl.grid(row=order, column=0, padx=1, pady=1, sticky='W')
- exec(fldRowTxt.replace('^*',str(order)))
- order+=1
- __excl_path=fldRowTxt0
- ChkBtnText=(' demo ',)*6
- order=0
- cfgspc=40
- chkstr="Chk^* = Checkbutton(stepThree, text=i+str(^*+1)+(' '*cfgspc))\n\
- Chk^*.grid(row=^*/2, column=^*%2, sticky='W', padx=1, pady=1)"
- for i in ChkBtnText:
- exec(chkstr.replace('^*',str(order)))
- order+=1
- okaybutton = Button(stepFour, text=" Make Package ")
- okaybutton.bind("<Button>", makePackage)
- okaybutton.grid(row=0, column=0, sticky='W', padx=5, pady=2)
- okaylabel = Label(stepFour, text="* Folder In Explorer Should Open Automatically ")
- okaylabel.grid(row=0, column=1, sticky='W', padx=5)
- mainloop( )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement