def main_loop(window: sg.Window): """ Função que executa o loop principal da janela da aplicação. Arguments: window (sg.Window): objeto de janela do PySimpleGUI """ while True: event, values = window.read() if event == 'Gerar planilha': input_file = values['_FILE_INPUT_'] output_file = values['_FILE_OUTPUT_'] try: if output_file[-5:] != '.xlsx': output_file += '.xlsx' generate_worksheet(input_file, output_file, window=window) print() window.refresh() except Exception as exc: sg.Popup(str(exc), title='Erro ao tentar executar') sg.Popup('Garanta que você tenha selecionado uma planilha no formato\ncorreto e tenha selecionado um local adequado para salvar a\nplanilha que será gerada.', title='Dica') if (event == sg.WINDOW_CLOSED) or (event == 'Quit'): break window.refresh()
def run_window_loop(self) -> None: # Event loop while True: event, values = self.window.Read(timeout=Const.timeout_ui) # Exits program cleanly if user clicks "X" or "Quit" buttons if event in (sg.WIN_CLOSED, 'Quit'): seconds_left = self.core.updateTime()[2] if seconds_left < 0: self.core.reset() self.window.close() break elif event in ["Start", "Stop", "Reset"]: self.core.changeEvents(event) if event == "Reset": self.window[self.msgKey].Update('') self.bringToFrontReset() elif event in ["Set"]: edit = self.window[self.durationKey] duration: List[Union[str, int]] = edit.Get().split(":") hasError: bool = False for _i in range(1): # a fake loop to have breaking mechanism if len(duration) not in [1, 2, 3]: hasError = True break if len(duration) == 2: duration.insert(0, "0") elif len(duration) == 1: duration = ["0", duration[0], "0"] try: duration = [int(i) for i in duration] except ValueError: hasError = True break if hasError: sg.Popup( f"Invalid duration format! It must be in the form of {self.durationFormat}.", keep_on_top=True) else: self.core.set( timedelta(hours=duration[0], minutes=duration[1], seconds=duration[2])) elif event == "__TIMEOUT__": pass else: pass self.updateTime()
def run(self): if mainWindow_q.qsize(): temp = mainWindow_q.get() if temp == 'exit': self.close() elif temp == 'restart': self.restart() # restart window if self.isActive: event, values = self.window.Read(timeout=10) if event in (None, 'Ok'): self.close() elif event == 'info': sg.Popup('Github notifier \nby: Mahmoud Elshahat\nager', non_blocking=True) elif event == 'open_url': webbrowser.open('https://github.com/notifications') elif event == 'read_all': mark_all_as_read(notif_url) self.update_notifications()
def systray(self): menu_def = ['BLANK', ['&Άνοιγμα φακέλου', '&Πληροφορίες', '&Έξοδος']] tray = sg.SystemTray(menu=menu_def, filename=r'icon.ico', tooltip='Κλικ για Simple Print Screen') while True: menu_item = tray.Read() if menu_item == 'Έξοδος': break elif menu_item == 'Άνοιγμα φακέλου': home = os.environ.get('USERPROFILE') dir = 'Simple Print Screen' if os.path.isdir(home + '/' + dir) is not True: path = os.path.join(home, dir) os.mkdir(path) os.startfile(home + '/' + dir) elif menu_item == '__ACTIVATED__': self.screenShot() self.notificationSave() elif menu_item == 'Πληροφορίες': sg.Popup( ' Πληροφορίες', ' Simple Print Screen Έκδοση 3.2 \n\n Ευχαριστώ που χρησιμοποιείτε την εφαρμογή. \n Η εφαρμογή αναπτύχθηκε από τον \n Κωνσταντίνο Καρακασίδη. \n\n Επικοινωνία: [email protected] \n', icon='icon.ico')
event, values = window.Read(timeout=500) if event is None or event == 'Exit': break if event != sg.TIMEOUT_KEY: # print(f'ev1 {event}') in_val = values['_INPUT_'] prediction_list = predict_text(str(in_val), choices) if prediction_list: try: fwindow.Close() except: pass fwindow = autocomplete_popup_show(prediction_list) list_elem = fwindow.Element('_FLOATING_LISTBOX_') if event == '_COMBO_': sg.Popup('Chose', values['_COMBO_']) if event.startswith('Down') or event.startswith('special 16777237'): sel_item = sel_item + (sel_item < len(prediction_list)) list_elem.Update(set_to_index=sel_item) skip_event = True elif event.startswith('Up') or event.startswith('special 16777235'): sel_item = sel_item - (sel_item > 0) list_elem.Update(set_to_index=sel_item) skip_event = True if event == '\r' or event.startswith('special 16777220'): chosen = vals2['_FLOATING_LISTBOX_'] window.Element('_INPUT_').Update(vals2['_FLOATING_LISTBOX_'][0], select=True) fwindow.Close() sel_item = -1 if event.startswith('Escape') or event.startswith('special 16777216'):
"rtscts": None, "xonxoff": None, "timeout": timeout, "server": is_server } if is_server: thread_weight = weight window['activate'].Update(button_color=('white', 'green')) window['deactivate'].Update(disabled=False) window['Textbox'].Update(get_balance_info()) window['Textbox2'].Update(f'{get_last_weight()} KG') window['last_weight'].Update(get_last_weight()) window.Refresh() elif not weight['result']: sg.Popup(weight['message'], title="Erro", location=(420, 350)) window['Textbox'].Update('') window['Textbox2'].Update('') window['last_weight'].Update(get_last_weight()) window.Refresh() else: window['Textbox'].Update(get_balance_info()) window['Textbox2'].Update(f'{get_last_weight()} KG') window['last_weight'].Update(get_last_weight()) window.Refresh() else: sg.Popup(f"Porta '{values['serial_port']}' ,não é válida!!! ", title="Erro", location=(width // 2 + x - 100, height // 2 + y - 100) ) if button == 'deactivate':
#print to debug window # print = sg.EasyPrint sg.EasyPrint(do_not_reroute_stdout=False) music_directory = sg.PopupGetFolder('Select Plex Music Folder to Search', title="Select Folder") if music_directory: Config.load_config() try: Config.set_dir('source_dir', music_directory) Config.save() except Exception as e: print(e) if not Config.check(): sg.Popup('Config Error', 'Something is not right. Please check the source directory chosen.') song_list = [Song(song_path) for song_path in get_song_list(Config.source_dir)] print(len(song_list), 'songs detected.') print('Metadata extracted for', (str(Song.valid_metadata_count) + '/' + str(len(song_list))), 'songs.') for song in song_list: # Only download lyrics if 'title' and 'artist' is present # Error str is already present in song.error if song.artist and song.title: song.download_lyrics() # Show immidiate log in console else: # If title was present, use that if song.title:
sg.Button('Popup'), sg.Button('Exit')] ] window = sg.Window('Window Title', location=(800, 600)).Layout(layout) win2_active = False i = 0 while True: # Event Loop event, values = window.Read(timeout=100) if event != sg.TIMEOUT_KEY: print(i, event, values) if event is None or event == 'Exit': break elif event == 'Popup': sg.Popup('This is a BLOCKING popup', 'all windows remain inactive while popup active') i += 1 if event == 'Launch 2nd Window' and not win2_active: # only run if not already showing a window2 win2_active = True # window 2 layout - note - must be "new" every time a window is created layout2 = [[sg.Text('The second window'), sg.Text('', key='_OUTPUT_')], [sg.Input(do_not_clear=True, key='_IN_')], [sg.Button('Show'), sg.Button('Exit')]] window2 = sg.Window('Second Window').Layout(layout2) # Read window 2's events. Must use timeout of 0 if win2_active: # print("reading 2") event, values = window2.Read(timeout=100) # print("win2 ", event) if event != sg.TIMEOUT_KEY:
event, values = window.Read() # Checks which of the buttons has been clicked and calls the requestColor function with the according value if event is None or event == 'exit': requestColor(off) break elif event == 'red': requestColor(red) elif event == 'green': requestColor(green) elif event == 'blue': requestColor(blue) elif event == 'purple': requestColor(purple) elif event == 'Off': requestColor(off) elif event == 'apply': if values["rgbSelect"] != None: requestColor((values["rgbSelect"])[1:]) else: sg.Popup("Select a color first!", no_titlebar=True) window.Close() # Exits from the gui loop ser.close() # Closes the serial connection
sg.Slider(range=(1, 100), orientation='v', default_value=10), sg.Column(column1, background_color='lightblue') ]], background_color='black'), sg.Stretch() ], [sg.Text('_' * 50, justification='c')], [sg.Text('Choose A Folder')], [ sg.Text('Your Folder'), sg.InputText('Default Folder', size=(300, 22)), sg.FolderBrowse(), sg.Stretch() ], [sg.Submit(tooltip='Click to submit this form', ), sg.Cancel()] ] window = sg.Window('Everything bagel', grab_anywhere=False, font=('Helvetica', 12), no_titlebar=False, alpha_channel=1, keep_on_top=False, element_padding=(2, 3), default_element_size=(100, 23), default_button_element_size=(120, 30)).Layout(layout) event, values = window.Read() print(event, values) window.Close() sg.Popup('Title', 'The results of the window.', 'The button clicked was "{}"'.format(event), 'The values are', values)
def getPopup(text: str): sg.Popup(text)
def pick_a_TC(instrument): ''' Graphical User interface - prompts the user for instrument, command and value then calls MakeTCfile to assemble the TC file based on the users choices ''' params, enums, defaults, num_vals, val_max, val_min, notes = read_parameter_file( tc_filename, instrument) param_layout = [[ sg.Listbox(values=params, key='_param_', tooltip='Select command to send', size=(20, 6), font=Font) ]] #param_layout = [[sg.InputCombo(values=params, key = '_param_', font = Font)]] layout_pick_parameter = [ [sg.Frame('Select Parameter to Update: ', param_layout, font=Font)], #[sg.Frame('Input new value: ', value_layout, font = Font)], [ sg.Submit(font=Font, pad=(10, 10)), sg.Cancel(font=Font, pad=(10, 10)) ] ] param_window = sg.Window('Select Parameter', layout_pick_parameter) event, values = param_window.Read() param_window.Close() tcString = values['_param_'][0] print(tcString) indx = 0 enumeration = 999 for words in params: if words == tcString: enumeration = enums[indx] break else: indx += 1 if num_vals[indx] == 0: confirm_layout = [[sg.Text('Confirm: ' + notes[indx], font=Font)], [ sg.Submit(pad=(10, 10), font=Font), sg.Cancel(pad=(10, 10), font=Font) ]] confirm_window = sg.Window('Confirm Command', confirm_layout) event, values = confirm_window.Read() confirm_window.Close() if event is None or event == 'Cancel': return None, None if event == 'Submit': filename = instrument + time.strftime("%Y%m%d-%H%M%S") + '.tc' cmnd = str(enumeration) + ';' MakeTCFile(filename, cmnd) send_layout = [[ sg.Text('Command is valid: ' + cmnd + '. Save or send now', font=Font) ], [ sg.Button(button_text='Save TC File', pad=(10, 10), font=Font), sg.Button(button_text='Send TC to CCMz', pad=(10, 10), font=Font) ]] send_window = sg.Window('Send TC', send_layout) event, values = send_window.Read() send_window.Close() if event == 'Send TC to CCMz': desc = notes[indx].split(':')[0] SendTC(filename, instrument, desc) else: sg.Popup('Values within range \nWriting ' + cmnd + '\nTo: ' + instrument + ' TC file: ' + filename, font=Font) return True, 0, filename if num_vals[indx] == 1: value_layout = [ [sg.Text(notes[indx], font=Font)], [sg.Text('Default Value ' + str(defaults[indx]), font=Font)], [sg.Text('Value:', font=Font), sg.InputText(key='_val_')] ] layout_enter_value = [[ sg.Frame('Input new value: ', value_layout, font=Font) ], [ sg.Submit(font=Font, pad=(10, 10)), sg.Cancel(font=Font, pad=(10, 10)) ]] value_window = sg.Window('Enter Value', layout_enter_value) event, values = value_window.Read() value_window.Close() new_param_value = float(values['_val_']) print(new_param_value) if new_param_value < float(val_max[indx]) and new_param_value > float( val_min[indx]): print('New value is within range') else: sg.Popup('Value(s) out of Range!\nNo TC File Created', font=Font) print('New Value out of Range!') return 'error', 0 filename = instrument + time.strftime("%Y%m%d-%H%M%S") + '.tc' cmnd = str(enumeration) + ',' + str(new_param_value) + ';' MakeTCFile(filename, cmnd) send_layout = [[ sg.Text('Command is valid: ' + cmnd + '. Save or send now', font=Font) ], [ sg.Button(button_text='Save TC File', pad=(10, 10), font=Font), sg.Button(button_text='Send TC to CCMz', pad=(10, 10), font=Font) ]] send_window = sg.Window('Send TC', send_layout) event, values = send_window.Read() send_window.Close() if event == 'Send TC to CCMz': desc = notes[indx].split(':')[0] + ': ' + str(new_param_value) SendTC(filename, instrument, desc) else: sg.Popup('Values within range \nWriting ' + cmnd + '\nTo: ' + instrument + ' TC file: ' + filename, font=Font) return True, 1, filename if num_vals[indx] == 2: value_layout = [ [sg.Text(notes[indx], font=Font)], [ sg.Text('Default Value ' + str(defaults[indx]) + 'No Limit Checking for values!', font=Font) ], [sg.Text('Value 1:', font=Font), sg.InputText(key='_val1_')], [sg.Text('Value 2:', font=Font), sg.InputText(key='_val2_')] ] layout_enter_value = [[ sg.Frame('Input new value: ', value_layout, font=Font) ], [ sg.Submit(font=Font, pad=(10, 10)), sg.Cancel(font=Font, pad=(10, 10)) ]] value_window = sg.Window('Enter Value', layout_enter_value) event, values = value_window.Read() value_window.Close() new_param_value_1 = float(values['_val1_']) new_param_value_2 = float(values['_val2_']) if new_param_value_1 < int(val_max[indx]) and new_param_value_1 > int( val_min[indx]): print('Value one is within range') if new_param_value_2 < int(val_max[indx]) and new_param_value_2 > int( val_min[indx]): print('Value two is within range') else: sg.Popup('Value(s) out of Range!\nNo TC File Created', font=Font) print('Value out of Range!') return 'error', 0 filename = instrument + time.strftime("%Y%m%d-%H%M%S") + '.tc' cmnd = str(enumeration) + ',' + str(new_param_value_1) + ',' + str( new_param_value_2) + ';' MakeTCFile(filename, cmnd) send_layout = [[ sg.Text('Command is valid: ' + cmnd + 'save or send now', font=Font) ], [ sg.Button(button_text='Save TC File', pad=(10, 10), font=Font), sg.Button(button_text='Send TC to CCMz', pad=(10, 10), font=Font) ]] send_window = sg.Window('Send TC', send_layout) event, values = send_window.Read() send_window.Close() if event == 'Send TC to CCMz': desc = notes[indx].split(':')[0] + ': ' + str( new_param_value_1) + ',' + str(new_param_value_2) SendTC(filename, instrument, desc) else: sg.Popup('Values within range \nWriting ' + cmnd + '\nTo: ' + instrument + ' TC file: ' + filename, font=Font) return True, 2, filename if num_vals[indx] == 3: value_layout = [ [sg.Text(notes[indx], font=Font)], [ sg.Text('Default Value ' + str(defaults[indx]) + 'No Limit Checking for values!', font=Font) ], [sg.Text('Value 1:', font=Font), sg.InputText(key='_val1_')], [sg.Text('Value 2:', font=Font), sg.InputText(key='_val2_')], [sg.Text('Value 3:', font=Font), sg.InputText(key='_val3_')] ] layout_enter_value = [[ sg.Frame('Input new value: ', value_layout, font=Font) ], [ sg.Submit(font=Font, pad=(10, 10)), sg.Cancel(font=Font, pad=(10, 10)) ]] value_window = sg.Window('Enter Value', layout_enter_value) event, values = value_window.Read() value_window.Close() new_param_value_1 = int(values['_val1_']) new_param_value_2 = int(values['_val2_']) new_param_value_3 = int(values['_val3_']) if new_param_value_1 < int(val_max[indx]) and new_param_value_1 > int( val_min[indx]): print('Value one is within range') if new_param_value_2 < int(val_max[indx]) and new_param_value_2 > int( val_min[indx]): print('Value two is within range') if new_param_value_3 < int(val_max[indx]) and new_param_value_3 > int( val_min[indx]): print('Value three is within range') else: sg.Popup('Value(s) out of Range!\nNo TC File Created', font=Font) print('Value out of Range!') return 'error', 0 filename = instrument + time.strftime("%Y%m%d-%H%M%S") + '.tc' cmnd = str(enumeration) + ',' + str(new_param_value_1) + ',' + str( new_param_value_2) + ',' + str(new_param_value_3) + ';' MakeTCFile(filename, cmnd) send_layout = [[ sg.Text('Command is valid: ' + cmnd + '. Save or send now', font=Font) ], [ sg.Button(button_text='Save TC File', pad=(10, 10), font=Font), sg.Button(button_text='Send TC to CCMz', pad=(10, 10), font=Font) ]] send_window = sg.Window('Send TC', send_layout) event, values = send_window.Read() send_window.Close() if event == 'Send TC to CCMz': desc = notes[indx].split(':')[0] + ': ' + str( new_param_value_1) + ',' + str(new_param_value_2) + ',' + str( new_param_value_3) SendTC(filename, instrument, desc) else: sg.Popup('Values within range \nWriting ' + cmnd + '\nTo: ' + instrument + ' TC file: ' + filename, font=Font) return True, 3, filename if num_vals[indx] == 4: value_layout = [ [sg.Text(notes[indx], font=Font)], [ sg.Text('Default Value ' + str(defaults[indx]) + 'No Limit Checking for values!', font=Font) ], [sg.Text('Value 1:', font=Font), sg.InputText(key='_val1_')], [sg.Text('Value 2:', font=Font), sg.InputText(key='_val2_')], [sg.Text('Value 3:', font=Font), sg.InputText(key='_val3_')], [sg.Text('Value 4:', font=Font), sg.InputText(key='_val4_')] ] layout_enter_value = [[ sg.Frame('Input new value: ', value_layout, font=Font) ], [ sg.Submit(font=Font, pad=(10, 10)), sg.Cancel(font=Font, pad=(10, 10)) ]] value_window = sg.Window('Enter Value', layout_enter_value) event, values = value_window.Read() value_window.Close() new_param_value_1 = int(values['_val1_']) new_param_value_2 = int(values['_val2_']) new_param_value_3 = int(values['_val3_']) new_param_value_4 = int(values['_val4_']) if new_param_value_1 < int(val_max[indx]) and new_param_value_1 > int( val_min[indx]): print('Value one is within range') if new_param_value_2 < int(val_max[indx]) and new_param_value_2 > int( val_min[indx]): print('Value two is within range') if new_param_value_3 < int(val_max[indx]) and new_param_value_4 > int( val_min[indx]): print('Value three is within range') if new_param_value_4 < int(val_max[indx]) and new_param_value_3 > int( val_min[indx]): print('Value four is within range') else: sg.Popup('Value(s) out of Range!\nNo TC File Created', font=Font) print('Value out of Range!') return False, 0 filename = instrument + time.strftime("%Y%m%d-%H%M%S") + '.tc' cmnd = str(enumeration) + ',' + str(new_param_value_1) + ',' + str( new_param_value_2) + ',' + str(new_param_value_3) + ',' + str( new_param_value_4) + ';' MakeTCFile(filename, cmnd) send_layout = [[ sg.Text('Command is valid: ' + cmnd + 'save or send now', font=Font) ], [ sg.Button(button_text='Save TC File', pad=(10, 10), font=Font), sg.Button(button_text='Send TC to CCMz', pad=(10, 10), font=Font) ]] send_window = sg.Window('Send TC', send_layout) event, values = send_window.Read() send_window.Close() if event == 'Send TC to CCMz': desc = notes[indx].split(':')[0] + ': ' + str( new_param_value_1) + ',' + str(new_param_value_2) + ',' + str( new_param_value_3) + ',' + str(new_param_value_4) SendTC(filename, instrument, desc) else: sg.Popup('Values within range \nWriting ' + cmnd + '\nTo: ' + instrument + ' TC file: ' + filename, font=Font) return True, 4, filename if num_vals[indx] == 5: value_layout = [ [sg.Text(notes[indx], font=Font)], [ sg.Text('Default Value ' + str(defaults[indx]) + 'No Limit Checking for values!', font=Font) ], [sg.Text('Value 1:', font=Font), sg.InputText(key='_val1_')], [sg.Text('Value 2:', font=Font), sg.InputText(key='_val2_')], [sg.Text('Value 3:', font=Font), sg.InputText(key='_val3_')], [sg.Text('Value 4:', font=Font), sg.InputText(key='_val4_')], [sg.Text('Value 5:', font=Font), sg.InputText(key='_val5_')] ] layout_enter_value = [[ sg.Frame('Input new value: ', value_layout, font=Font) ], [ sg.Submit(font=Font, pad=(10, 10)), sg.Cancel(font=Font, pad=(10, 10)) ]] value_window = sg.Window('Enter Value', layout_enter_value) event, values = value_window.Read() value_window.Close() new_param_value_1 = int(values['_val1_']) new_param_value_2 = int(values['_val2_']) new_param_value_3 = int(values['_val3_']) new_param_value_4 = int(values['_val4_']) new_param_value_5 = int(values['_val5_']) if new_param_value_1 < int(val_max[indx]) and new_param_value_1 > int( val_min[indx]): print('Value one is within range') if new_param_value_2 < int(val_max[indx]) and new_param_value_2 > int( val_min[indx]): print('Value two is within range') if new_param_value_3 < int(val_max[indx]) and new_param_value_3 > int( val_min[indx]): print('Value three is within range') if new_param_value_4 < int(val_max[indx]) and new_param_value_4 > int( val_min[indx]): print('Value four is within range') if new_param_value_5 < int(val_max[indx]) and new_param_value_5 > int( val_min[indx]): print('Value four is within range') else: sg.Popup('Value(s) out of Range!\nNo TC File Created', font=Font) print('Value out of Range!') return False, 0 filename = instrument + time.strftime("%Y%m%d-%H%M%S") + '.tc' cmnd = str(enumeration) + ',' + str(new_param_value_1) + ',' + str( new_param_value_2) + ',' + str(new_param_value_3) + ',' + str( new_param_value_4) + ',' + str(new_param_value_5) + ';' MakeTCFile(filename, cmnd) send_layout = [[ sg.Text('Command is valid: ' + cmnd + '. Save or send now', font=Font) ], [ sg.Button(button_text='Save TC File', pad=(10, 10), font=Font), sg.Button(button_text='Send TC to CCMz', pad=(10, 10), font=Font) ]] send_window = sg.Window('Send TC', send_layout) event, values = send_window.Read() send_window.Close() if event == 'Send TC to CCMz': desc = notes[indx].split(':')[0] + ': ' + str( new_param_value_1) + ',' + str(new_param_value_2) + ',' + str( new_param_value_3) + ',' + str( new_param_value_4) + ',' + str(new_param_value_5) SendTC(filename, instrument, desc) else: sg.Popup('Values within range \nWriting ' + cmnd + '\nTo: ' + instrument + ' TC file: ' + filename, font=Font) return True, 5, filename
def _show_result(self, text): self.start_stop_button.update(text=RECORD_BUTTON, disabled=False) sg.Popup(text or EMPTY_RESULT_TEXT, title="Result", keep_on_top=True)
import PySimpleGUIQt as sg sg.Popup('Hello From PySimpleGUI!', 'This is the shortest GUI program ever!') # event, values = sg.Window('Get filename example', [[sg.Text('Filename')], [sg.Input(), sg.FileBrowse()], [sg.OK(), sg.Cancel()] ]).Read() sg.theme('Dark Blue 3') # please make your creations colorful layout = [[sg.Text('Filename')], [sg.Input(), sg.FileBrowse()], [sg.OK(), sg.Cancel()]] window = sg.Window('Get filename example', layout) event, values = window.Read() window.close()
import sys import PySimpleGUIQt as sg layout = [[sg.Image(filename="/Users/netbox-wangdong/Downloads/42-logo.png")], [sg.Text(' 请登录')], [sg.InputText()], [sg.InputText()], [sg.Button("ok"), sg.Cancel()]] window = sg.Window('登录', layout) ''' event, values = window.Read() window.Close() text_input = values[0] print(text_input) ''' while True: event, values = window.read() print(event, values) if event == 'exit' or event is None: window.close() sys.exit(0) else: print("user:"******" pass:"******"will go on to chat.")
def process_tray(): menu_item = tray.Read() if menu_item == "Exit": exit() elif menu_item == "Open": sg.Popup("Menu item chosen", menu_item)
def process_window(): global window global theme event, values = window.read() print("Event:", event) print("Values:", values) if event in (None, "Cancel", "Exit"): # if user closes window or clicks cancel exit() elif event == "About": sg.Popup("About this software.") elif event == "_config_set_extensions_": ext_string = sg.PopupGetText("Extensions (separated by commas)") exts = ext_string.lower().replace(" ", "").replace(".", "").split(",") ## set extensions elif event == "_config_set_whitelist_": whitelist_string = sg.PopupGetText("Whitelist Files (separated by commas)") whitelist = whitelist_string.split(",") ## set whitelist elif event == "_config_set_blacklist_": blacklist_string = sg.PopupGetText("Blacklist Files (separated by commas)") blacklist = blacklist_string.split(",") ## set blacklist elif event == "_config_set_logfile_": logfile = sg.PopupGetText("Logfile", default_text=values["_selected_dir_"]) ## set logfile elif event == "_backup_location_": if values[event]: sg.Popup(values[event]) # run backup elif event == "_move_location_": if values[event]: sg.Popup(values[event]) # run move elif event == "_copy_location_": if values[event]: sg.Popup(values[event]) # run copy elif event == "_zip_location_": if values[event]: sg.Popup(values[event]) # run zip elif event.find("::"): if event.split("::")[1].startswith("_change_theme_"): theme = event.split("::_change_theme_")[1] create_window() elif event.split("::")[1].startswith("_tools_"): if event.split("::_tools")[1] == "_afx_": window.FindElement("_frm_tools_afx_").Update(visible=True) window.FindElement("_frm_tools_name_").Update(visible=False) window.FindElement("_frm_tools_convert_").Update(visible=False) window.FindElement("_frm_tools_export_").Update(visible=False) window.VisibilityChanged() pass elif event.split("::_tools")[1] == "_name_": window.FindElement("_frm_tools_afx_").Update(visible=False) window.FindElement("_frm_tools_name_").Update(visible=True) window.FindElement("_frm_tools_convert_").Update(visible=False) window.FindElement("_frm_tools_export_").Update(visible=False) window.VisibilityChanged() pass elif event.split("::_tools")[1] == "_convert_": window.FindElement("_frm_tools_afx_").Update(visible=False) window.FindElement("_frm_tools_name_").Update(visible=False) window.FindElement("_frm_tools_convert_").Update(visible=True) window.FindElement("_frm_tools_export_").Update(visible=False) window.VisibilityChanged() pass elif event.split("::_tools")[1] == "_export_": window.FindElement("_frm_tools_afx_").Update(visible=False) window.FindElement("_frm_tools_name_").Update(visible=False) window.FindElement("_frm_tools_convert_").Update(visible=False) window.FindElement("_frm_tools_export_").Update(visible=True) window.VisibilityChanged() pass else: print("EVENT NOT FOUND: ", event)
def main(): # List to sort num_bars = DATA_SIZE[0] // (BAR_WIDTH + 1) arr = [DATA_SIZE[1] // num_bars * i for i in range(1, num_bars)] # Window layout graph = sg.Graph(GRAPH_SIZE, (0, 0), DATA_SIZE, background_color='#F5F6F4') layout = [[ sg.Text('Visualization', size=(30, 1), font=("Helvetica", 25), background_color='#8F90A0', text_color='#FFFFFF') ], [graph], [ sg.Button('Select sorting method', button_color=['#FFFFFF', '#35343B'], font=("Helvetica", 12)), sg.Button('Generate new array', button_color=['#FFFFFF', '#35343B'], font=("Helvetica", 12)) ]] window = sg.Window('Algorithm Visualizer', layout) window.Finalize() draw_bars(graph, arr) while True: event, values = window.read() if event in (None, 'Exit'): break if event == 'Generate new array': graph.Erase() random.shuffle(arr) draw_bars(graph, arr) if event == 'Select sorting method': l2 = [[ sg.T('Choose sorting method', font=("Helvetica", 12), background_color='#8F90A0', text_color='#FFFFFF') ], [ sg.Listbox(['Bubble', 'Insertion', 'Selection'], size=(16, 3)) ], [sg.Ok()]] w2 = sg.Window('Choose sorting method', l2) button, values = w2() w2.close() try: if values[0][0] == 'Bubble': sort = bubblesort.bubbleSort(arr) sortmethod = 'Bubble' elif values[0][0] == 'Insertion': sort = insertionsort.insertionSort(arr) sortmethod = 'Insertion' else: sort = selectionsort.selectionSort(arr) sortmethod = 'Selection' except: sg.Popup('None selected.', font=("Helvetica", 12), background_color='#8F90A0', text_color='#FFFFFF') continue timeout = 10 for partially_sorted_list in sort: event, values = window.read(timeout=timeout) if event is None: break graph.Erase() draw_bars(graph, partially_sorted_list) timeout = int(10) sg.Popup(f'{sortmethod} sort done.', font=("Helvetica", 12), background_color='#8F90A0', text_color='#FFFFFF')
# cnt = len(list_type) + 1 # print(cnt) # best format has to be *.png if values['_SKIPPROCESS_']: img_ori, img_sqr, y1, y2, x1, x2 = ct.just_projection( image_location) else: img_ori, img_sqr, y1, y2, x1, x2 = ct.make_it_square( image_location) # ct.make_it_square(image_location, store_folder + '/' # + marker_type + '_' + str(cnt) + '.png') pixel_limit = 32 if y2 - y1 < pixel_limit or x2 - x1 < pixel_limit: sg.Popup(title='Warning!', custom_text='Character is below limit', keep_on_top=True) img_rc = cv2.imread(image_location) img_rgb = img_rc[y1:y2, x1:x2] # Write image now = datetime.now() dt_string = now.strftime("%y%m%d%H%M%S") output_name_ori = store_folder_ori + '/' + marker_type \ + '_' + dt_string + '.png' output_name_sqr = store_folder_sqr + '/' + marker_type \ + '_' + dt_string + '.png' # output_name_rgb = store_folder_rgb + '/' + marker_type \ # + '_' + dt_string + '.png' output_name_rc = store_folder_rc + '/' + marker_type \ + '_' + dt_string + '.png'
font=('Helvetica', 12), no_titlebar=False, alpha_channel=1, keep_on_top=False, element_padding=(2, 3), default_element_size=(100, 23), default_button_element_size=(120, 30), # background_image='colors.png', ).Layout(layout) event, values = window.Read() print(event, values) print(values[0].replace('file:///', '')) # this gets rid of file:/// filename = values[0].replace('file:///', '') window.Close() if os.path.isfile(filename): manage(filename) sg.Popup('Done!', 'the data in ' + filename + ' has been updated!', ) else: sg.Popup('Title', 'your filename was inaccurate') # todo load small/mid-sized images into a file system # todo create file that saves and logs images # todo create layer in GUI that reads file and loads image # todo progress bar # todo settings bar # todo I don't like how huge the file is # todo I don't like how f*****g slow the boot time is
window = sg.Window('Add New Courses', default_element_size=(40, 2)).Layout(layout) while 'add_new_courses_button': event, values = window.Read() if event is None or event == 'Exit': break v_course_code = values[0] v_period_num = values[1] v_year = values[2] print(v_course_code, v_period_num, v_year) cur.execute("select * from EOM_CLASS") for row in cur: if v_course_code == (row[0]): sg.Popup("INVALID") break break window.Close() cur.execute(""" insert into EOM_CLASS (CLASS, YEAR, PERIOD_NUM) values (:v_course_code, :v_year, :v_period_num)""", v_course_code=values[0], v_year=values[2], v_period_num=values[1] )
elif values[2]: go_to_case(values) elif values[3]: letter_setup("CC-JT letter sent.", "/documents/new?document_template_id=20426") elif values[4]: letter_setup("CC letter sent.", "/documents/new?document_template_id=20787") elif values[5]: go_to_case(values) if try_find_element( "//*[contains(text(), 'Evidence Request Form 9-5-17')]"): sg.Popup( "Evidence request already created.", title='Tracker Interface - Case Search', icon="SEAL.jpg", keep_on_top=True, line_width=40, ) continue else: erq_setup("/documents/new?document_template_id=17572") # Click on word icon. try_click_on_load( "/html/body/div[1]/div[2]/div[1]/table/tbody/tr/th/table/tbody/tr[2]/td[2]/span/img" ) # Wait for launch of office program. time.sleep(1) # Kill program.