import Tkinter, threading, pickle, data.tkFileDialog as tkFileDialog, data.build as build
import time, os
import sys,time
##f = open('C:\\test.txt','a+')
##f.write("|"+str(time.time())+"|\n"+str(sys.path)+"\n")
##f.close()
VERSION = 0.3
def LAST():
try:
f = open('data\\last.dat', 'rb')
path = f.read()
f.close()
if not(os.path.exists(path)):
return ''
except:
path = ''
return path
def Ask(root,question,answer=''):
class ask:
def __init__(self, root,question,answer):
self.window = Tkinter.Toplevel(root)
self.window.title(question)
self.window.bind('<Return>', self.ok)
self.label = Tkinter.Label(self.window, text=question)
self.label.grid(row=1,column=1,columnspan=2)
self.entry = Tkinter.Entry(self.window, width=30)
self.entry.grid(row=2,column=1,columnspan=2)
self.entry.insert('end',answer)
self.button_ok = Tkinter.Button(self.window, text='Ok', command=self.ok)
self.button_ok.grid(row=3,column=1)
self.button_cancel = Tkinter.Button(self.window, text='Cancel', command=self.cancel)
self.button_cancel.grid(row=3,column=2)
self.waiting = 0
def ok(self,*args):
self.waiting = 1
def cancel(self):
self.waiting = -1
def wait(self):
while self.waiting == 0:
self.window.update()
time.sleep(0.1)
data = self.entry.get()
self.window.destroy()
if self.waiting == 1:
return data
else:
return ''
asking = ask(root, question,answer)
return asking.wait()
def all_files(startloc,orginal_dir,path='',dir=''): #JUMP1
if not(dir):
dir = orginal_dir
if not(path):
ls = os.listdir(startloc)
else:
ls = os.listdir(startloc+'\\'+path)
#print
#print dir, '+', path
if dir:
dir += '\\'+path
else:
dir = path
folders = {dir:[]}
for item in ls:
if path:
new_path = path+'\\'+item
else:
new_path = item
if not(os.path.splitext(new_path)[1]):
folders.update(all_files(startloc,orginal_dir,new_path,dir))
else:
#print
#print dir,'add', orginal_dir, '+', new_path
folders[dir].append(orginal_dir+'\\'+new_path)
return folders
class main:
def __init__(self):
self.data = {}
self.window = Tkinter.Tk()
self.window.title("PyBuilder %s" % VERSION)
threading.Thread(None, self.window.mainloop, 'Mainloop').start()
#Loc
self.frame_loc = Tkinter.Frame(self.window)
self.frame_loc.grid(row=1,column=1, pady=10)
self.text_loc = Tkinter.Label(self.frame_loc, text='Location')
self.text_loc.grid(row=1,column=1,sticky='W',padx=10)
self.data['loc'] = Tkinter.StringVar()
self.data['loc'].set(LAST())
self.entry_loc = Tkinter.Entry(self.frame_loc, width=50, textvariable=self.data['loc'])
self.entry_loc.grid(row=2,column=1,padx=10)
self.button_loc = Tkinter.Button(self.frame_loc, text='Browse', command=self.get_dir)
self.button_loc.grid(row=2,column=2,padx=10)
#Name/Version/Author
self.frame_nva = Tkinter.Frame(self.window)
self.frame_nva.grid(row=2,column=1)
self.text_name = Tkinter.Label(self.frame_nva, text='Name')
self.text_name.grid(row=1,column=1,padx=10,pady=10)
self.data['name'] = Tkinter.StringVar()
self.entry_name = Tkinter.Entry(self.frame_nva, width=20, textvariable=self.data['name'])
self.entry_name.grid(row=2,column=1,padx=10,pady=10)
self.text_version = Tkinter.Label(self.frame_nva, text='Version')
self.text_version.grid(row=1,column=2,padx=10,pady=10)
self.data['version'] = Tkinter.StringVar()
self.entry_version = Tkinter.Entry(self.frame_nva, width=20, textvariable=self.data['version'])
self.entry_version.grid(row=2,column=2,padx=10,pady=10)
self.text_author = Tkinter.Label(self.frame_nva, text='Author')
self.text_author.grid(row=1,column=3,padx=10,pady=10)
self.data['author'] = Tkinter.StringVar()
self.entry_author = Tkinter.Entry(self.frame_nva, width=20, textvariable=self.data['author'])
self.entry_author.grid(row=2,column=3,padx=10,pady=10)
#Window/Command Prompt
self.frame_wincom = Tkinter.Frame(self.window)
self.frame_wincom.grid(row=3,column=1)
self.data['displaymode'] = Tkinter.StringVar()
self.data['displaymode'].set('windows')
self.radio_windows = Tkinter.Radiobutton(self.frame_wincom, text='Windows', value='windows', variable=self.data['displaymode'])
self.radio_windows.grid(row=1,column=1,padx=10,pady=10)
self.radio_command = Tkinter.Radiobutton(self.frame_wincom, text='Console', value='console', variable=self.data['displaymode'])
self.radio_command.grid(row=1,column=2,padx=10,pady=10)
#Main file/Icon
self.frame_mainicon = Tkinter.Frame(self.window)
self.frame_mainicon.grid(row=4,column=1)
self.text_script = Tkinter.Label(self.frame_mainicon, text='Main Python File')
self.text_script.grid(row=1,column=1,padx=10,pady=10)
self.data['script'] = Tkinter.StringVar()
self.entry_script = Tkinter.Entry(self.frame_mainicon, width=20, textvariable=self.data['script'])
self.entry_script.grid(row=2,column=1,padx=10,pady=10)
self.button_script = Tkinter.Button(self.frame_mainicon, text='Browse', command=self.get_script)
self.button_script.grid(row=2,column=2,padx=10,pady=10)
self.text_icon = Tkinter.Label(self.frame_mainicon, text='Icon')
self.text_icon.grid(row=1,column=3,padx=10,pady=10)
self.data['icon'] = Tkinter.StringVar()
self.entry_icon = Tkinter.Entry(self.frame_mainicon, width=20, textvariable=self.data['icon'])
self.entry_icon.grid(row=2,column=3,padx=10,pady=10)
self.button_icon = Tkinter.Button(self.frame_mainicon, text='Browse', command=self.get_icon)
self.button_icon.grid(row=2,column=4,padx=10,pady=10)
#Files/Data
self.frame_filesdata = Tkinter.Frame(self.window)
self.frame_filesdata.grid(row=5,column=1)
#Files
self.frame_files = Tkinter.Frame(self.frame_filesdata)
self.frame_files.grid(row=1,column=1)
self.label_files = Tkinter.Label(self.frame_files, text='Files (Modules, etc.)')
self.label_files.grid(row=1,column=1,padx=10,pady=10)
self.data['files'] = Tkinter.Variable()
self.files_scrolly = Tkinter.Scrollbar(self.frame_files)
self.files_scrolly.grid(row=2,rowspan=3,column=2,sticky='NS')
self.files_scrollx = Tkinter.Scrollbar(self.frame_files,orient='horizontal')
self.files_scrollx.grid(row=5,column=1,sticky='WE')
self.list_files = Tkinter.Listbox(self.frame_files, width=20, height=7, xscrollcommand=self.files_scrollx.set, yscrollcommand=self.files_scrolly.set, listvariable=self.data['files'])
self.list_files.grid(row=2, rowspan=3, column=1)
self.files_scrolly.config(command=self.list_files.yview)
self.files_scrollx.config(command=self.list_files.xview)
self.button_files_add = Tkinter.Button(self.frame_files, text='Add File', command=self.files_add)
self.button_files_add.grid(row=2,column=3,padx=10,pady=10)
self.button_files_add_folder = Tkinter.Button(self.frame_files, text='Add Folder', command=self.files_addfolder)
self.button_files_add_folder.grid(row=3,column=3,padx=10)
self.button_files_remove = Tkinter.Button(self.frame_files, text='Remove', command=self.files_remove)
self.button_files_remove.grid(row=4,column=3,padx=10,pady=10)
#Data
self.frame_data = Tkinter.Frame(self.frame_filesdata)
self.frame_data.grid(row=1,column=2)
self.label_data = Tkinter.Label(self.frame_data, text='Data (Images, Data, etc.)')
self.label_data.grid(row=1,column=1,padx=10,pady=10)
self.data['data'] = Tkinter.Variable()
self.list_data = Tkinter.Listbox(self.frame_data, width=20, height=5, listvariable=self.data['data'])
self.list_data.grid(row=2, rowspan=3, column=1,padx=10,pady=10)
self.button_data_add = Tkinter.Button(self.frame_data, text='Add File', command=self.data_add)
self.button_data_add.grid(row=2,column=2,padx=10,pady=10)
self.button_data_add = Tkinter.Button(self.frame_data, text='Add Folder', command=self.data_addfolder)
self.button_data_add.grid(row=3,column=2,padx=10)
self.button_data_remove = Tkinter.Button(self.frame_data, text='Remove', command=self.data_remove)
self.button_data_remove.grid(row=4,column=2,padx=10,pady=10)
#Load/Save/Compile/Quit
self.frame_buttons = Tkinter.Frame(self.window)
self.frame_buttons.grid(row=6, column=1)
self.button_load = Tkinter.Button(self.frame_buttons, text='Load', command=self.load)
self.button_load.grid(row=1,column=1,padx=10,pady=10)
self.button_save = Tkinter.Button(self.frame_buttons, text='Save', command=self.save)
self.button_save.grid(row=1,column=2,padx=10,pady=10)
self.button_compile = Tkinter.Button(self.frame_buttons, text='Compile with py2exe', command=self.compile)
self.button_compile.grid(row=1,column=3,padx=10,pady=10)
self.button_quit = Tkinter.Button(self.frame_buttons, text='Quit', command=self.window.destroy)
self.button_quit.grid(row=1,column=4,padx=10,pady=10)
self.load()
def load(self):
try:
file = open(self.data['loc'].get()+'\\pymakefile.pmak', 'r')
except:
return
data = pickle.load(file)
file.close()
for i in data.keys():
try:
if i != 'loc':
self.data[i].set(data[i])
except:
pass
def save(self):
data = {}
for i in self.data.keys():
if i != 'loc':
data[i] = self.data[i].get()
try:
file = open(self.data['loc'].get()+'\\pymakefile.pmak', 'w')
except:
return
pickle.dump(data, file)
file.close()
try:
file = open('data\\last.dat', 'wb')
file.write(self.data['loc'].get())
file.close()
except:
pass
def get_dir(self):
loc = tkFileDialog.askdirectory(parent=self.window, initialdir=self.data['loc'].get(), title='Choose Location')
if loc.strip():
self.data['loc'].set(loc)
def get_icon(self):
icon = tkFileDialog.askopenfilename(parent=self.window, initialdir=self.data['loc'].get(), title='Choose an Icon', filetypes=[('Icon', '*.ico')])
if icon.strip():
if self.data['loc'].get() in icon:
icon = icon.split(self.data['loc'].get()+'/')[1]
self.data['icon'].set(icon)
def get_script(self):
script = tkFileDialog.askopenfilename(parent=self.window, initialdir=self.data['loc'].get(), title='Choose a Python Script', filetypes=[('Python Script', ('*.py', '*.pyw'))])
if script.strip():
if self.data['loc'].get() in script:
script = script.split(self.data['loc'].get()+'/')[1]
self.data['script'].set(script)
def files_add(self):
files_list = list(self.data['files'].get())
files = tkFileDialog.askopenfilename(parent=self.window, initialdir=self.data['loc'].get(), title='Choose an File', filetypes=[('Python Script', '*.py'),('All Files', '*.*')], multiple=True)
for file in files:
if file.strip():
if self.data['loc'].get() in file:
file = file.split(self.data['loc'].get()+'/')[1]
files_list.append(file)
self.data['files'].set('\n'.join(files_list))
def files_addfolder(self):
files_list = list(self.data['files'].get())
folder = tkFileDialog.askdirectory(parent=self.window, initialdir=self.data['loc'].get(), title='Choose Folder')
if folder.strip():
if self.data['loc'].get() in folder:
folder = folder.split(self.data['loc'].get()+'/')[1]
files_list.append(folder)
self.data['files'].set('\n'.join(files_list))
def files_remove(self):
files_list = list(self.data['files'].get())
for line in self.list_files.curselection():
files_list.pop(int(line))
self.data['files'].set('\n'.join(files_list))
def data_add(self):
data_list = list(self.data['data'].get())
files = tkFileDialog.askopenfilename(parent=self.window, initialdir=self.data['loc'].get(), title='Choose an File', filetypes=[('All Files', '*.*')], multiple=True)
for file in files:
if file.strip():
if self.data['loc'].get() in file:
file = file.split(self.data['loc'].get()+'/')[1]
path = Ask(self.window,"What is this file's Path after compiling ?",file)
data_list.append('='.join([file,path]))
self.data['data'].set('\n'.join(data_list))
def data_addfolder(self):
data_list = list(self.data['data'].get())
folder = tkFileDialog.askdirectory(parent=self.window, initialdir=self.data['loc'].get(), title='Choose Folder')
if folder.strip():
if self.data['loc'].get() in folder:
folder = folder.split(self.data['loc'].get()+'/')[1]
path = Ask(self.window,"What is this folder's Path after compiling ?",folder)
data_list.append('='.join([folder,path]))
self.data['data'].set('\n'.join(data_list))
def data_remove(self):
data_list = list(self.data['data'].get())
for line in self.list_data.curselection():
data_list.pop(int(line))
self.data['data'].set('\n'.join(data_list))
def compile(self):
self.save()
textwidget = self.display('')
building = build.build(self.data['loc'].get()+'\\pymakefile.pmak',[],textwidget)
threading.Thread(None, building.run, None).start()
## print '"'+sys.executable+'" "'+os.path.dirname(sys.argv[0])+'\\data\\build.py'+'" "'+self.data['loc'].get()+'\\pymakefile.pmak"'
## build = os.popen('"'+sys.executable+'" "'+os.path.dirname(sys.argv[0])+'\\data\\build.py'+'" "'+self.data['loc'].get()+'\\pymakefile.pmak"','r+')
## print build.read()
## build.close()
## #print os.spawnl(os.P_WAIT, os.path.dirname(sys.argv[0])+'\\data\\Binary\\build.exe','"'+self.data['loc'].get()+'\\pymakefile.pmak"')
## root = os.path.realpath('')
## os.chdir(self.data['loc'].get())
## #Data Files
## data = list(self.data['data'].get())
## data_dict = {}
##
## #print 'loc', os.path.realpath('')
## for line in data:
## line = '\\\\'.join(line.split('\\\\'))
## entry = line.strip().split('=')
## #print '|'+entry[1]+'|', os.path.isdir(entry[1]), os.path.isfile(entry[1])
## if os.path.isdir(entry[1]):
## folder = entry[1] #JUMP2
## folders = all_files(self.data['loc'].get()+'\\\\'+entry[0],folder)
## for folder in folders.keys():
## if not(folder in data_dict.keys()):
## data_dict[folder] = folders[folder]
## else:
## data_dict[folder].extend(folders[folder])
## else:
## folder = os.path.dirname(entry[1])
##
## if not(folder in data_dict.keys()):
## data_dict[folder] = [entry[1]]
## else:
## data_dict[folder].append(entry[1])
##
##
## data_list = []
##
## for key in data_dict.keys():
## data_list.append((key, data_dict[key]))
##
## #Files
## files = list(self.data['files'].get())
## files.append(self.data['icon'].get())
## #files.append(self.data['script'].get())
##
## for file in files:
## files[files.index(file)] = '\\\\'.join(file.split('\\\\'))
##
## f = open(self.data['loc'].get()+'\\setup.py', 'w')
## f.write("""
### setup.py
##from distutils.core import setup
##import py2exe
##
##import sys
##
##sys.stdout = open('screen.txt','w',0)
##sys.stderr = open('errors.txt','w',0)
##
##setup(name='%s',
## version='%s',
## author='%s',
## data_files=%s,
## %s=[{'script':'%s',
## 'icon_resources':[(1,'%s')],
## }])
##
##print "---Done---"
##""" % (self.data['name'].get(),
## self.data['version'].get(),
## self.data['author'].get(),
## str(data_list),
## self.data['displaymode'].get(),
## self.data['name'].get()+'.py',#self.data['script'].get(),
## self.data['icon'].get()))
## f.close()
##
## #Location
## loc = self.data['loc'].get()
##
## #Data
## for file in data:
## data[data.index(file)] = '\\\\'.join(file.split('\\\\'))
##
## os.chdir(root)
#build.build(loc, files, data, 'setup.py', 'Binary', [], textwidget)
def display(self, text):
window = Tkinter.Toplevel(self.window)
window.title('Output from build')
scrolly = Tkinter.Scrollbar(window)
scrolly.grid(row=1,column=2,sticky='NS')
scrollx = Tkinter.Scrollbar(window,orient='horizontal')
scrollx.grid(row=2,column=1,sticky='WE')
text_window = Tkinter.Text(window, width=80, height=30, wrap='none', xscrollcommand=scrollx.set, yscrollcommand=scrolly.set)
text_window.grid(row=1,column=1)
text_window.insert('end', text)
text_window.see('end')
scrolly.config(command=text_window.yview)
scrollx.config(command=text_window.xview)
button_close = Tkinter.Button(window, text="Close", command=window.destroy)
button_close.grid(row=3, column=1, columnspan=2)
return text_window
if __name__ == '__main__':
program = main()
|