MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / main

Function main

DemoPrograms/Demo_EXE_Maker.py:14–60  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

12'''
13
14def main():
15 sg.theme('LightGreen')
16
17 layout = [[sg.Text('PyInstaller EXE Creator', font='Any 15')],
18 [sg.Text('Source Python File'), sg.Input(key='-sourcefile-', size=(45, 1)),
19 sg.FileBrowse(file_types=(("Python Files", "*.py"),))],
20 [sg.Text('Icon File'), sg.Input(key='-iconfile-', size=(45, 1)),
21 sg.FileBrowse(file_types=(("Icon Files", "*.ico"),))],
22 [sg.Frame('Output', font='Any 15', layout=[
23 [sg.Output(size=(65, 15), font='Courier 10')]])],
24 [sg.Button('Make EXE', bind_return_key=True),
25 sg.Button('Quit', button_color=('white', 'firebrick3')) ],
26 [sg.Text('Made with PySimpleGUI (www.PySimpleGUI.org)', auto_size_text=True, font='Courier 8')]]
27
28 window = sg.Window('PySimpleGUI EXE Maker', layout, auto_size_text=False, auto_size_buttons=False, default_element_size=(20,1), text_justification='right')
29 # ---===--- Loop taking in user input --- #
30 while True:
31
32 event, values = window.read()
33 if event in ('Exit', 'Quit', None):
34 break
35
36 source_file = values['-sourcefile-']
37 icon_file = values['-iconfile-']
38
39 icon_option = '-i "{}"'.format(icon_file) if icon_file else ''
40 source_path, source_filename = os.path.split(source_file)
41 workpath_option = '--workpath "{}"'.format(source_path)
42 dispath_option = '--distpath "{}"'.format(source_path)
43 specpath_option = '--specpath "{}"'.format(source_path)
44 folder_to_remove = os.path.join(source_path, source_filename[:-3])
45 file_to_remove = os.path.join(source_path, source_filename[:-3]+'.spec')
46 command_line = 'pyinstaller -wF --clean "{}" {} {} {} {}'.format(source_file, icon_option, workpath_option, dispath_option, specpath_option)
47
48 if event == 'Make EXE':
49 try:
50 print(command_line)
51 print('Making EXE...the program has NOT locked up...')
52 window.refresh()
53 # print('Running command {}'.format(command_line))
54 out, err = runCommand(command_line, window=window)
55 shutil.rmtree(folder_to_remove)
56 os.remove(file_to_remove)
57 print('**** DONE ****')
58 except:
59 sg.PopupError('Something went wrong', 'close this window and copy command line from text printed out in main window','Here is the output from the run', out)
60 print('Copy and paste this line into the command prompt to manually run PyInstaller:\n\n', command_line)
61
62
63def runCommand(cmd, timeout=None, window=None):

Callers 1

Demo_EXE_Maker.pyFile · 0.70

Calls 4

readMethod · 0.95
refreshMethod · 0.95
runCommandFunction · 0.85
removeMethod · 0.80

Tested by

no test coverage detected