From ea03abb6d00d578298207d3e3c6f70246cd5879e Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Mon, 12 Oct 2020 17:24:14 -0400 Subject: [PATCH 1/2] Changed demo to directly call user_settings within the layout --- DemoPrograms/Demo_User_Settings.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/DemoPrograms/Demo_User_Settings.py b/DemoPrograms/Demo_User_Settings.py index efbd4a98..9dd42c9d 100644 --- a/DemoPrograms/Demo_User_Settings.py +++ b/DemoPrograms/Demo_User_Settings.py @@ -79,23 +79,26 @@ def settings_window(): def save_previous_filename_demo(): """ Saving the previously selected filename.... - A 2-line demo of one of the likely most popular use of user settings - * Get the previously entered filename - * Use previous as default for Input + A demo of one of the likely most popular use of user settings + * Use previous input as default for Input * When a new filename is chosen, write the filename to user settings """ - prior_filename = sg.user_settings_get_entry('filename', '') - + # Notice that the Input element has a default value given (first parameter) that is read from the user settings layout = [[sg.Text('Enter a filename:')], - [sg.Input(prior_filename, key='-IN-'), sg.FileBrowse()], - [sg.B('OK')]] + [sg.Input(sg.user_settings_get_entry('filename', ''), key='-IN-'), sg.FileBrowse()], + [sg.B('Save'), sg.B('Exit Without Saving', key='Exit')]] - event, values = sg.Window('Filename Example', layout).read(close=True) + window = sg.Window('Filename Example', layout) - # If user clicked OK, then save the filename for next time - if event == 'OK': - sg.user_settings_set_entry('filename', values['-IN-']) + while True: + event, values = window.read() + if event in(sg.WINDOW_CLOSED, 'Exit'): + break + elif event == 'Save': + sg.user_settings_set_entry('filename', values['-IN-']) + + window.close() if __name__ == '__main__': From 930747a3247c52bce2583c964bc5084f9bbe0612 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Mon, 12 Oct 2020 17:24:29 -0400 Subject: [PATCH 2/2] New Demo Program - GitHub file copier --- DemoPrograms/Demo_GitHub_File_Copier.py | 146 ++++++++++++++++++++++++ 1 file changed, 146 insertions(+) create mode 100644 DemoPrograms/Demo_GitHub_File_Copier.py diff --git a/DemoPrograms/Demo_GitHub_File_Copier.py b/DemoPrograms/Demo_GitHub_File_Copier.py new file mode 100644 index 00000000..494e7ff2 --- /dev/null +++ b/DemoPrograms/Demo_GitHub_File_Copier.py @@ -0,0 +1,146 @@ +import os.path +import shutil +import subprocess +import sys + +import PySimpleGUI as sg + +""" + Demo - GitHub File Management + + A program that helps manage the demo programs on a local PC. This is done by copying files from your working folder to a folder that is kept in sync with GitHub. + It works well when used in conjunction with the GUI version of GitHub. + + Two folders are shown... + * the left side is your local "working copy" + * the right side is the GitHub folder + + The basic file operations are + * Copy from working folder to GitHub folder + * Edit a file in PyCharm + * Run a file (in either folder) + + Additional operations + * Edit this file in PyCharm + * Launch GitHub GUI program + + Copyright 2020 PySimpleGUI.org +""" + +DEMO_PATH = r'C:\Python\PycharmProjects\PSG\DemoPrograms' +GIT_DEMO_PATH = r'C:\Python\PycharmProjects\GitHub\PySimpleGUI\DemoPrograms' +GITHUB_PROGRAM = r'C:/Users/mike/AppData/Local/GitHubDesktop/GitHubDesktop.exe' +PYCHARM_BATCHFILE = r"C:\Program Files\JetBrains\PyCharm Community Edition 2019.1.1\bin\pycharm.bat" +ML_KLEY = '-ML-' + +# --------------------------------- Main Program Layout --------------------------------- + +def main(): + + # First the window layout...2 columns + + demo_files = os.listdir(DEMO_PATH) + + left_col = [ + [sg.Text('Demo Programs', font='Any 20')], + [sg.Listbox(values=demo_files, select_mode=sg.SELECT_MODE_EXTENDED, size=(40, 20), key='-DEMO LIST-')], + [sg.Text('Filter:'), sg.Input(size=(15, 1), enable_events=True, key='-FILTER-')], + + [sg.Button('Run'),sg.Button('Copy'), sg.B('Edit')] + ] + + git_demo_files = os.listdir(GIT_DEMO_PATH) + + right_col = [ + [sg.Text('GitHub Demo Programs', font='Any 20')], + [sg.Listbox(values=git_demo_files, select_mode=sg.SELECT_MODE_EXTENDED, size=(40, 20), key='-GIT DEMO LIST-')], + [sg.Button('Run', key='Run Git Version')], + ] + + # ----- Full layout ----- + layout = [[sg.vtop(sg.Column(left_col, element_justification='c')), sg.VSeperator() ,sg.vtop(sg.Column(right_col, element_justification='c'))], + [sg.HorizontalSeparator()], + [sg.Multiline(size=(90, 10), write_only=True, key=ML_KLEY, reroute_stdout=True)], + [ sg.Button('Edit Me (this program) in PyCharm'), sg.B('Launch GitHub', button_color=(sg.theme_input_background_color(), sg.theme_input_text_color())), sg.Button('Exit')], + ] + + # --------------------------------- Create Window --------------------------------- + window = sg.Window('GitHub Demo Copier', layout, icon=icon) + + sg.cprint_set_output_destination(window, ML_KLEY) + + while True: + event, values = window.read() + if event == sg.WINDOW_CLOSED or event == 'Exit': + break + if event == 'Copy': + confirm = sg.popup_yes_no('Are you sure you want to copy:', *values['-DEMO LIST-'], keep_on_top=True) + if confirm == 'Yes': + sg.cprint('Copying....', c='white on red') + for file in values['-DEMO LIST-']: + sg.cprint(f'{os.path.join(DEMO_PATH, file)}', text_color='blue') + sg.cprint('TO', text_color='red', background_color='white') + sg.cprint(f'{os.path.join(GIT_DEMO_PATH, file)}', text_color='green') + shutil.copyfile(os.path.join(DEMO_PATH, file), os.path.join(GIT_DEMO_PATH, file)) + sg.cprint('Copy complete', background_color='red', text_color='white') + elif event == 'Edit': + for file in values['-DEMO LIST-']: + sg.cprint(f'opening (in PyCharm)', text_color='white', background_color='red', end='') + sg.cprint(f' {os.path.join(DEMO_PATH, file)}', text_color='purple') + execute_command_subprocess(f'{PYCHARM_BATCHFILE}', os.path.join(DEMO_PATH, file)) + elif event == 'Run': + sg.cprint('Running local program....', c='white on green') + for file in values['-DEMO LIST-']: + sg.cprint(os.path.join(DEMO_PATH, file)) + run_py(os.path.join(DEMO_PATH, file)) + elif event == 'Run Git Version': + sg.cprint('Running GitHub version of program....', c='white on green') + for file in values['-GIT DEMO LIST-']: + sg.cprint(os.path.join(GIT_DEMO_PATH, file)) + run_py(os.path.join(GIT_DEMO_PATH, file)) + elif event.startswith('Edit Me'): + execute_command_subprocess(f'{PYCHARM_BATCHFILE}', __file__) + elif event == 'Launch GitHub': + run(GITHUB_PROGRAM) + elif event == '-FILTER-': + new_list = [i for i in demo_files if values['-FILTER-'].lower() in i.lower()] + window['-DEMO LIST-'].update(values=new_list) + + window.close() + + +def run(app_name, parm=''): + execute_command_subprocess(app_name, parm) + + +def run_py(pyfile, parms=None): + if parms is not None: + execute_command_subprocess('python', pyfile, parms) + else: + execute_command_subprocess('python', pyfile) + + +def execute_command_subprocess(command, *args, wait=False): + + if sys.platform == 'linux': + arg_string = '' + for arg in args: + arg_string += ' ' + str(arg) + sp = subprocess.Popen(['python3' + arg_string, ], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + else: + expanded_args = ' '.join(args) + sp = subprocess.Popen([command, expanded_args], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) + if wait: + out, err = sp.communicate() + if out: + print(out.decode("utf-8")) + if err: + print(err.decode("utf-8")) + + +if __name__ == '__main__': + icon = b'iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAAMAUExURQAAAB69LymqOSm6LSq2OTSrOjS2Ox28RjqdQC6qSiy3Riu3UTisRzirVDi1STq0UiuyYz6pYz62ZCjDNyjQPzTAOxrIQinARTXDRzXBVEWsP1ieZ0OrSUaqV0S0SkOzVFKnSVKrWlK0W0iqZUWmcEe0a1eoZ1apclW0Z1uzd2G8X2W8Z2i3dXStdnS/ZHW7dkXCTEnCWVnDbF3Gc1zUc2bGbGjId2fRbWjQfnLFbnTGeHfReXu6hWzFgWzRgXfGhn3Jk3bShHvWkd5HPNhYJ9RWPtRbPdxVOtlbM9xdPM5iPNRjO9VsMtNoOttiPOFVNOVUPeNZNOJbPelVPelZN+pcO/ZYPeNjPeFqPOlgNOpiPfBkO8xcR85ZUtZOUNJXQdNcQtNcTNpTRdxVT9xdQ95cSdlbUsBgR8xkRctkTc1oQ81pS8tmVMtxTsx3XtVjQdRjStRoQtNqStxiRNtjSdxpQ9toS9NkU9diWdFqUtVsW9xiU9xlXN5uVtZzWsptZ8Z3Y8p2ddBuY9duat1qY9Nvcdh3Z+VOQ+NUROJcQ+NcSutTROlcQ+pdSuhdVPJcQ/FbS/heQvZbVuFhReJjSeJpRORpTOpiRepiS+toTeVlU/RhRfJhUuZnYeBvaeR4aoPCfN+Hb9eHfNmQfeaIbOKIeOWSefaHbP+Ia/CMffCSePigeoTHhovJmIjWiYXXl5HMnpbYmY3bp4fes5PHoJnapJzUspDhnozjpo3lspnjqaLTm6HOsaPYp7XOuLbduajkqavpuLTpt7f2uKvbwbLYw7nmx7f1ybjw1tqIhtiThtiSkNasnNuimeSLhOWPkOWThuicl/mdiPKbku6fouWjl+Oinuaom+ynl+yjmuqpl+qqm/OllfOlmPSqnf6mkvqhneekoPOho8buuNPtvtbd08bpyMro1cT2ysj109XozNXo2NHzydT52M/45tvs4tj8497+8eD6y+b82+bq6Of+5+n+9fnq7f/p//b96fv7+gAAAAAAAAAAAAAAAAAAAFSfM6AAAAEAdFJOU////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////wBT9wclAAAACXBIWXMAAA7DAAAOwwHHb6hkAAAMlUlEQVR4Xu2Zf5gbRRnHtd5Fm+Z2FUQOuWQplXI+oAVqA0RrAKUlRGINlkCpei2b2EI1187eFUitBfFgc0nah5m7pFsFnvJD1FIseoDFk1/agj+wpz5gBX8geu31ODmtqb39J76zO5vb/Lzsnjw8Pt7nLpfZmcnMd99533dmc28rvMXMCJgRMCNgRsCMgP9tAQdv23jDTYm72JU9piPg5U29W8OB1O2Jl1mFHaYh4I+dS7NAbkeg8yCrsoF9AS9Ge6++Ik6k4BV9qVW/ZJXWsS3gwf4ORDAWZYQwRsqDrNoydgUc7EcwP8KEEEyQiJQh1mAVmwJeIaKI+5EoUiMggpbYVmBPwFDmk0QiWBaxjCmEoCsz9hTYE/D8J65FGIl0AegawGqQCE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