2018-10-15 00:51:18 +00:00
|
|
|
import PySimpleGUI as sg
|
|
|
|
import subprocess
|
|
|
|
from shutil import copyfile
|
|
|
|
import shutil
|
|
|
|
import os
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
'''
|
|
|
|
Make a "Windows os" executable with PyInstaller
|
|
|
|
'''
|
2018-10-15 00:51:18 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
def Launcher():
|
|
|
|
sg.change_look_and_feel('LightGreen')
|
|
|
|
|
|
|
|
layout = [[sg.Text('PyInstaller EXE Creator', font='Any 15')],
|
|
|
|
[sg.Text('Source Python File'), sg.Input(key='-sourcefile-', size=(45, 1)),
|
|
|
|
sg.FileBrowse(file_types=(("Python Files", "*.py"),))],
|
|
|
|
[sg.Text('Icon File'), sg.Input(key='-iconfile-', size=(45, 1)),
|
|
|
|
sg.FileBrowse(file_types=(("Icon Files", "*.ico"),))],
|
|
|
|
[sg.Frame('Output', font='Any 15', layout=[
|
|
|
|
[sg.Output(size=(65, 15), font='Courier 10')]])],
|
|
|
|
[sg.ReadFormButton('Make EXE', bind_return_key=True),
|
|
|
|
sg.SimpleButton('Quit', button_color=('white', 'firebrick3')), ]]
|
2018-10-15 00:51:18 +00:00
|
|
|
|
2018-10-15 01:12:59 +00:00
|
|
|
window = sg.Window('PySimpleGUI EXE Maker',
|
2019-10-23 20:10:03 +00:00
|
|
|
layout,
|
2018-10-15 00:51:18 +00:00
|
|
|
auto_size_text=False,
|
|
|
|
auto_size_buttons=False,
|
2019-10-23 20:10:03 +00:00
|
|
|
default_element_size=(20, 1,),
|
2018-10-15 00:51:18 +00:00
|
|
|
text_justification='right')
|
|
|
|
|
|
|
|
# ---===--- Loop taking in user input --- #
|
|
|
|
while True:
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
event, values = window.read()
|
|
|
|
if event in ('Exit', 'Quit', None):
|
|
|
|
break
|
|
|
|
|
|
|
|
source_file = values['-sourcefile-']
|
|
|
|
icon_file = values['-iconfile-']
|
2018-10-15 00:51:18 +00:00
|
|
|
|
|
|
|
icon_option = '-i "{}"'.format(icon_file) if icon_file else ''
|
|
|
|
source_path, source_filename = os.path.split(source_file)
|
|
|
|
workpath_option = '--workpath "{}"'.format(source_path)
|
|
|
|
dispath_option = '--distpath "{}"'.format(source_path)
|
|
|
|
specpath_option = '--specpath "{}"'.format(source_path)
|
2019-10-23 20:10:03 +00:00
|
|
|
folder_to_remove = os.path.join(source_path, source_filename[:-3])
|
|
|
|
file_to_remove = os.path.join(
|
|
|
|
source_path, source_filename[:-3]+'.spec')
|
|
|
|
command_line = 'pyinstaller -wF "{}" {} {} {} {}'.format(
|
|
|
|
source_file, icon_option, workpath_option, dispath_option, specpath_option)
|
2018-10-15 00:51:18 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
if event == 'Make EXE':
|
2018-10-15 01:20:33 +00:00
|
|
|
try:
|
|
|
|
print(command_line)
|
2019-10-23 20:10:03 +00:00
|
|
|
print(
|
|
|
|
'Making EXE...the program has NOT locked up...')
|
|
|
|
window.refresh()
|
2018-10-15 01:20:33 +00:00
|
|
|
# print('Running command {}'.format(command_line))
|
|
|
|
runCommand(command_line)
|
|
|
|
shutil.rmtree(folder_to_remove)
|
|
|
|
os.remove(file_to_remove)
|
|
|
|
print('**** DONE ****')
|
|
|
|
except:
|
2019-10-23 20:10:03 +00:00
|
|
|
sg.popup_error('Something went wrong')
|
2018-10-15 00:51:18 +00:00
|
|
|
|
|
|
|
|
|
|
|
def runCommand(cmd, timeout=None):
|
2019-10-23 20:10:03 +00:00
|
|
|
"""
|
|
|
|
run shell command
|
2018-10-15 00:51:18 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
@param cmd: command to execute
|
|
|
|
@param timeout: timeout for command execution
|
2018-10-15 00:51:18 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
@return: (return code from command, command output)
|
|
|
|
"""
|
2018-10-15 00:51:18 +00:00
|
|
|
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
|
|
out, err = p.communicate()
|
|
|
|
p.wait(timeout)
|
|
|
|
return (out, err)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
Launcher()
|