def manage_breastfeeding(event, values): now = dtt.datetime.now() is_left = event == 'left' last_entry = get_last_row(Breastfeeding) table_is_empty = Breastfeeding.select().count() == 0 add_new_entry = table_is_empty or not is_breastfeeding() if add_new_entry: # new feed offset = PopupOffsetWindow( 'Άρχισε πριν πόσα λεπτά (αριθμός ή κενό);', 'Σφάλμα στην εισαγωγή, μόνο αριθμούς\n') Breastfeeding(start_time=now - offset, is_left=is_left, used_shield=True) elif is_left == last_entry.is_left: # finish ongoing feed offset = PopupOffsetWindow( 'Σταμάτησε πριν πόσα λεπτά (αριθμός ή κενό);', 'Σφάλμα στην εισαγωγή, μόνο αριθμούς\n') last_entry.end_time = now - offset last_entry.used_shield = sg.PopupYesNo('Προστασία;') comment = sg.PopupGetText('Άλλο σχόλιο;') last_entry.comment = '' if comment is None else comment elif is_left != last_entry.is_left: # cancel ongoing feed if sg.PopupYesNo('Ακύρωση;') == 'Yes': last_entry.delete()
def queue_render(presetname, queue_source_folder): """ Add a render job to the queue. :param presetname: the render preset to use for this job :param queue_source_folder: the source folder name for this job, will be added to queue_path, for the xml copy function :return: none """ global pending_queue global queue_paths proj.LoadRenderPreset(presetname) if int(valid_video_track_count(proj.GetCurrentTimeline())) != 0: set_output_path() proj.AddRenderJob() new_job_idx = get_newest_renderjob_index() if new_job_idx: pending_queue.append(new_job_idx) # There is already a render_status table for showing job info on the GUI. # This queue_path dictionary is added later, to correspond each job index to its source and output paths. # Maybe can use a better data structure to manage both? queue_paths.update({new_job_idx: [values['WATCHPATH'], queue_source_folder, latest_output_path]}) update_render_status() else: sg.Popup('Failed to add render job, check Resolve.') else: sg.Popup('Failed to add render job, empty folder?')
def main(): layout = [[sg.Text('Matplotlib Simple Plot', font='Any 20')], [sg.Image(key='-IMAGE-')], [sg.Button('Exit')]] window = sg.Window('Matplotlib Example', layout, finalize=True) fig = plt.figure() x = np.arange(0, 5, 0.1) y = np.sin(x) plt.plot(x, y) draw_figure(fig, window['-IMAGE-']) window.read(close=True)
def save_settings(settings_file, settings, values): if values: # if there are stuff specified by another window, fill in those values for key in SETTINGS_KEYS_TO_ELEMENT_KEYS: # update window with the values read from settings file try: settings[key] = values[SETTINGS_KEYS_TO_ELEMENT_KEYS[key]] except Exception as e: print( f'Problem updating settings from window values. Key = {key}' ) with open(settings_file, 'w') as f: jsondump(settings, f) sg.popup('Settings saved')
def load_settings(settings_file, default_settings): try: with open(settings_file, 'r') as f: settings = jsonload(f) except Exception as e: sg.popup_quick_message( f'exception {e}', 'No settings file found... will create one for you', keep_on_top=True, background_color='red', text_color='white') settings = default_settings save_settings(settings_file, settings, None) return settings
def openWindowImageSearch(): print('Image search') ROOT_DIR = os.path.dirname( os.path.abspath(__file__))[0:-7] + "\\data\\blohsaved.png" print(ROOT_DIR) image_elem = sg.Image(ROOT_DIR) layoutOperation = [[ sg.Text('An image says what a thousand words can\'t..') ], [sg.Text('The image :'), sg.InputText('path'), sg.FileBrowse()], [image_elem], [sg.Button('Search for me'), sg.Button('Cancel')]] windowOperation = sg.Window('Text it out').Layout(layoutOperation) while True: eventOperation, valuesOperation = windowOperation.Read(timeout=50) if eventOperation in (None, 'Cancel'): windowOperation.close() main() break elif eventOperation in ('Search for me'): windowOperation.close() searchByImageAlgorithm(valuesOperation[0]) if valuesOperation[0] != "path": image_elem.update(valuesOperation[0])
def app(): # global vvv # print(xxx) global vehicle_graph global vehicle_path_graph global vehicle_current_order window = sg.Window('OpenTCS Web Client', layout, web_ip='0.0.0.0', web_port=8089, finalize=True) window.Finalize() for i in points_pose: graph_elem.draw_circle((i[1],i[2]), 1, fill_color='black', line_color='red') for i in path_list: graph_elem.draw_line(points_dic[i[0]], points_dic[i[1]], color='black', width=1) for i in vehicles: vehicle_graph = graph_elem.draw_circle(points_dic[i[-2]], 5, fill_color='green', line_color='green') # draw_order() action_dic = {'无':"NOP", '卸货':"UNLOAD",'载货':'LOAD', '充电':'CHARGE'} while True: event, values = window.read(timeout=1) if event == '添加': vvv.append([len(vvv),values['Target'], values['action']]) window['transport'].Update(values=vvv) if event == '下单': print('下单'+values['Target']+values['action']) tcs.creat_order(locations=[[values['Target'], action_dic[values['action']]]])
def main(): layout = [ [sg.T('Matplotlib Example', font='Any 20')], [sg.Image(key='-IMAGE-')], [sg.B('Draw'), sg.B('Exit')], ] window = sg.Window('Title', layout) while True: event, values = window.read() if event == 'Exit' or event == sg.WIN_CLOSED: break if event == 'Draw': draw_figure(create_figure(), window['-IMAGE-']) window.close()
def searchByTextResultWindow(locations): layout = [[sg.Text('We found some great places for you..')], [sg.Listbox(values=locations, size=(30, 3))], [sg.Button("Find visiting route"), sg.Button('Cancel')]] windowTextResults = sg.Window('HOLIday').Layout(layout) while True: event, values = windowTextResults.Read() if event in (None, 'Cancel'): windowTextResults.close() main() print("Goodbye") break elif event in ("Find visiting route"): windowTextResults.close() searchRouteByLocationWindow(values[0])
def openWindowTextSearch(): print('Text search') layoutOperation = [[sg.Text('A few words to guide us..')], [sg.InputText('Couple of words')], [sg.Button('Search for me'), sg.Button('Cancel')]] windowOperation = sg.Window('Text it out').Layout(layoutOperation) while True: eventOperation, valuesOperation = windowOperation.Read() if eventOperation in (None, 'Cancel'): windowOperation.close() main() break else: windowOperation.close() searchByTextAlgorithm(valuesOperation[0])
def openWindowRoutesSearch(): print('Route search') layoutOperation = [[sg.Text('What place do you want to explore ?')], [sg.InputText('location')], [sg.Button('HERE !'), sg.Button('Cancel')]] windowOperation = sg.Window('Where ?').Layout(layoutOperation) while True: eventOperation, valuesOperation = windowOperation.Read() if eventOperation in (None, 'Cancel'): windowOperation.close() main() break else: windowOperation.close() searchRouteByLocationWindow(valuesOperation[0])
def searchByLocationRouteResult(param): layout = [[sg.Text('We found an amazing route for you..')], [sg.Listbox(values=param, size=(30, 3))], [sg.Button("Show me on map"), sg.Button('Cancel')]] windowTextResults = sg.Window('HOLIday').Layout(layout) while True: event, values = windowTextResults.Read() if event in (None, 'Cancel'): windowTextResults.close() main() print("Goodbye") break elif event in ("Show me on map"): windowTextResults.close() showMeTheMap(param)
def __init__(self): # initialize controller parameters (in dict) self.params = self.initialize_params() # FIWARE parameters self.cb_url = os.getenv("CB_URL", "http://localhost:1026") self.entity_id = None # will be read on the web GUI self.entity_type = "PID_Controller" self.service = os.getenv("FIWARE_SERVICE", '') self.service_path = os.getenv("FIWARE_SERVICE_PATH", '') # Create the fiware header fiware_header = FiwareHeader(service=self.service, service_path=self.service_path) # Create orion context broker client self.ORION_CB = ContextBrokerClient(url=self.cb_url, fiware_header=fiware_header) # initial pid controller list self.controller_list = [] try: self.refresh_list() except: pass # initialize gui window sg.theme("DarkBlue") pid_id_bar = [[ sg.Text("Controller ID", size=(10, 1)), sg.Combo(self.controller_list, key="controller_list"), sg.Button("Refresh") ]] param_bars = [[ sg.Text(param.capitalize(), size=(10, 1)), sg.InputText(self.params[param], key=param) ] for param in self.params.keys()] io_bars = [[sg.Button("Send"), sg.Button("Read")]] layout = pid_id_bar + param_bars + io_bars self.window = sg.Window("PID controller", layout, web_port=80, web_start_browser=True)
def run(self): layout = [[sg.Text("Choose what to do:")], [sg.Button("Add task")], [sg.Button("Current tasks")], [sg.Button("Manage tasks")]] menu_window = sg.Window("To-Do app", layout, resizable=True) while True: event, values = menu_window.read() if event == sg.WIN_CLOSED: break if event == "Add task": menu_window.hide() self.__add_task() if event == "Current tasks": menu_window.hide() self.__current() if event == "Manage tasks": menu_window.hide() self.__manage() menu_window.UnHide() menu_window.close()
def set_output_path(): """ Get the latest output path from the GUI and submit to Resolve. :return: none """ global latest_output_path latest_output_path = values['OUTPUTPATH'] if proj.IsRenderingInProgress(): sg.Popup('Rendering in progres,try later.') else: proj.SetRenderSettings({'TargetDir': latest_output_path})
def manage_bottlefeeding(): now = dtt.datetime.now() if not is_breastfeeding(): succesfully_got_ounces = False while not succesfully_got_ounces: ounces = sg.PopupGetText('Πόσο ήπιε (oz);') if ounces is not None: ounces = ounces.replace(',', '.') try: ounces = float(ounces) succesfully_got_ounces = True except ValueError: pass comment = sg.PopupGetText('Άλλο σχόλιο') if comment is not None: Bottlefeeding(time=now, ounces=ounces, comment=comment) else: sg.PopupTimed('Ακόμα θηλάζει, δοκιμάστε αφού τελειώσει')
def __add_task(self): layout1 = [[sg.Text("Write the task title:")], [sg.InputText()], [sg.Button("Next")]] window1 = sg.Window("To-Do app", layout1, resizable=True) while True: event, values = window1.read() if event == sg.WIN_CLOSED: return if event == "Next": break new_task = Task() new_task.title_ = values[0] window1.close() date_list = sg.popup_get_date() new_task.date_ = date(date_list[2], date_list[0], date_list[1]) str1 = "Is it a frog?" # + emoji.emojize(':frog:') layout2 = [[sg.Text(str1)], [ sg.Text("About 'Eat the frog' method.", text_color='#0645AD', enable_events=True, key='-LINK-') ], [sg.Button("Yes")], [sg.Button("No")]] window2 = sg.Window("To-Do app", layout2, resizable=True) while True: event, values = window2.read() if event == sg.WIN_CLOSED: return if event == '-LINK-': webbrowser.open( r'https://todoist.com/productivity-methods/eat-the-frog') if event == "Yes": new_task.is_frog_ = True break if event == "No": new_task.is_frog_ = False break window2.close() if not (new_task.date_ in self.undone_tasks_): self.undone_tasks_[new_task.date_] = [] self.undone_tasks_[new_task.date_].append(new_task)
def main(): minesInfo = getMineMap() mainLayout = [[ sg.Button('?', size=(4, 2), key=(i, j), pad=(0, 0)) for j in range(MAX_COLS) ] for i in range(MAX_ROWS)] window = sg.Window('扫雷', mainLayout) while True: event, values = window.read() if event in (sg.WIN_CLOSED, 'Exit'): break # window[(row, col)].update('New text') # To change a button's text, use this pattern # For this example, change the text of the button to the board's value and turn color black window[event].update(minesInfo[event[0]][event[1]], button_color=('Green', 'black')) #最后从屏幕上移除 window.close()
def get_poop_description(previous=None): colours = ['πράσινα', 'καφέ', 'κίτρινα', 'μαύρα'] consistencies = ['υγρά', 'στέρεα', 'σποράκια', 'βλέννα', 'αίμα'] attributes = colours + consistencies if previous is None: default_attr = {k: False for k in attributes} else: default_attr = {k: k in previous for k in attributes} win = sg.Window( 'Κακά', layout=( [[sg.CBox(k, default=v, key=k)] for k, v in default_attr.items()] + [[sg.Text('Άλλο:'), sg.Input(key='comment_text')], [sg.Button('OK', key='ok'), sg.Button('Άκυρο', key='cancel')]])) event, values = win.Read() if event == 'ok': desc = values.pop('comment_text', '') if len(desc) > 0: output_list = [desc] + [k for k, v in values.items() if v] else: output_list = [k for k, v in values.items() if v] output_str = ', '.join(output_list) else: output_str = None win.Close() return output_str
def main(): dictionary_of_figures = { 'Axis Grid': create_axis_grid, 'Subplot 3D': create_subplot_3d, 'Scales': create_pyplot_scales, 'Basic Figure': create_figure } layout = [ [sg.T('Matplotlib Example', font='Any 20')], [ sg.Listbox(dictionary_of_figures.keys(), size=(15, 5), key='-LB-'), sg.Image(key='-IMAGE-') ], [sg.B('Draw'), sg.B('Exit')], ] window = sg.Window('Title', layout, finalize=True) image_element = window['-IMAGE-'] # type: sg.Image while True: event, values = window.read() if event == 'Exit' or event == sg.WIN_CLOSED: break if event == 'Draw': func = dictionary_of_figures[values['-LB-'][0]] draw_figure(func(), image_element) window.close()
def detailed_view(window): layout2 = [ [ sg.Button(event, button_color=('white', color_map[event]), key=event, tooltip=color_map[color]), sg.Button(event, button_color=('black', color_map[event]), key=event + '1', tooltip=color_map[color]) ], [ sg.Text( 'Hover over button to see color value. Click to clocse and return to main interface.' ) ], ] sg.Window('Buttons with white and black text', layout2, keep_on_top=True).Read() window.close() return
def PopupOffsetWindow(main_string, first_pass_extra): first_pass = True found_valid = None while first_pass or not found_valid: offset_win = sg.Window('', layout=[ [sg.Text(('' if first_pass else first_pass_extra) + main_string)], [sg.Input(default_text='0', key='add_new_entry_offset')], [sg.Ok()] ]) event, values = offset_win.Read() offset_text = values['add_new_entry_offset'] if offset_text == '': offset_text = '0' offset = re.findall(r'(\d+)', offset_text) found_valid = len(offset) == 1 if found_valid: offset = int(offset[0]) offset_win.Close() first_pass = False return dtt.timedelta(minutes=offset)
def main(): layout = [[sg.Text('This is a text element')], [ sg.Input() ], [ sg.Combo(['Combo 1']) ], [sg.Text('If you close the browser tab, the app will exit gracefully')], [sg.InputText('Source')], [sg.InputText('Dest')], [sg.Ok(), sg.Cancel()]] window = sg.Window('Demo window..', layout) i = 0 while True: event, values = window.read(timeout=1) if event != sg.TIMEOUT_KEY: print(event, values) if event is None: break i += 1 window.close()
def main(): global g_interval, g_procs, g_exit # ---------------- Create Form ---------------- sg.change_look_and_feel('Black') layout = [[sg.Text('', size=(8, 1), font=('Helvetica', 20), text_color=sg.YELLOWS[0], justification='center', key='text')], [sg.Text('', size=(30, 8), font=('Courier New', 12), text_color='white', justification='left', key='processes')], [sg.Exit(button_color=('white', 'firebrick4'), pad=((15, 0), 0), size=(9, 1)), ] ] window = sg.Window('CPU Utilization', layout, no_titlebar=True, keep_on_top=True, alpha_channel=.8, grab_anywhere=True) # start cpu measurement thread thread = Thread(target=CPU_thread, args=(None,), daemon=True) thread.start() timeout_value = 1 # make first read really quick g_interval = 1 # ---------------- main loop ---------------- while True: # --------- Read and update window -------- event, values = window.read( timeout=timeout_value, timeout_key='Timeout') # --------- Do Button Operations -------- if event in (None, 'Exit'): break timeout_value = 1000 cpu_percent = g_cpu_percent display_string = '' if g_procs: # --------- Create list of top % CPU porocesses -------- try: top = {proc.name(): proc.cpu_percent() for proc in g_procs} except: pass top_sorted = sorted( top.items(), key=operator.itemgetter(1), reverse=True) if top_sorted: top_sorted.pop(0) display_string = '' for proc, cpu in top_sorted: display_string += '{:2.2f} {}\n'.format(cpu/10, proc) # --------- Display timer and proceses in window -------- window['text'].update('CPU {}'.format(cpu_percent)) window['processes'].update(display_string) window.close()
def manage_events(event, values): now = dtt.datetime.now() print(event) if event in ['left', 'right']: manage_breastfeeding(event, values) elif event == 'bottle': manage_bottlefeeding() elif event == 'peed': comment = sg.PopupGetText('Άλλο σχόλιο') if comment is not None: Peeing(time=now, comment=comment) elif event == 'pooped': n_pooped = Pooping.select().count() if n_pooped > 0: prev_comment = Pooping[n_pooped].comment else: prev_comment = None comment = get_poop_description(prev_comment) if comment is not None: Pooping(time=now, comment=comment)
def create_settings_window(settings): sg.theme(settings['theme']) def TextLabel(text): return sg.Text(text + ':', justification='r', size=(15, 1)) layout = [[sg.Text('Settings', font='Any 15')], [ TextLabel('Theme'), sg.Combo(sg.theme_list(), size=(20, 20), key='-THEME-') ], [sg.Button('Save'), sg.Button('Exit')]] window = sg.Window('Settings', layout, keep_on_top=True, finalize=True) for key in SETTINGS_KEYS_TO_ELEMENT_KEYS: # update window with the values read from settings file try: window[SETTINGS_KEYS_TO_ELEMENT_KEYS[key]].update( value=settings[key]) except Exception as e: print( f'Problem updating PySimpleGUI window from settings. Key = {key}' ) return window
import PySimpleGUIWeb as sg import datetime DEFAULT_BASE64_ICON = b'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' sg.ChangeLookAndFeel('GreenTan') layout = [ [sg.Text('PySimpleGUIWeb running on the web and in your browser!', size=(60,1), font=('Comic sans ms', 20), text_color='red')], [sg.Text('This program has been running for... ', size=(30,1)),sg.Text('', size=(30,1), key='_DATE_')], [sg.Text('', size=(30,1), key='_TEXT_')], [sg.Input('Single Line Input', do_not_clear=True, enable_events=True, size=(30,1))], [sg.Multiline('Multiline Input', do_not_clear=True, size=(40,4), enable_events=True)], [sg.Multiline('Multiline Output', size=(80,8), key='_MULTIOUT_', font='Courier 12')], [sg.Checkbox('Checkbox 1', enable_events=True, key='_CB1_'), sg.Checkbox('Checkbox 2', default=True, enable_events=True, key='_CB2_')], [sg.Combo(values=['Combo 1', 'Combo 2', 'Combo 3'], default_value='Combo 2', key='_COMBO_',enable_events=True, readonly=False, tooltip='Combo box', disabled=False, size=(12,1))], [sg.Listbox(values=('Listbox 1', 'Listbox 2', 'Listbox 3'), size=(10,3))], [sg.Slider((1,100), default_value=80, key='_SLIDER_', visible=True, enable_events=True, orientation='h')], [sg.Spin(values=(1,2,3),initial_value=2, size=(4,1))], [sg.Image(filename=r'dot:logo.jpg')], [sg.OK(), sg.Button('Exit', button_color=('white', 'red'))] ] window = sg.Window('My PySimpleGUIWeb Window', default_element_size=(30,1), font='Helvetica 18', background_image=r'dot:logo.jpg' ).Layout(layout) start_time = datetime.datetime.now()
HEIGHT = 7 #lines #Credit to aminusfu : https://github.com/cherrypy/cherrypy/blob/0857fa81eb0ab647c7b59a019338bab057f7748b/cherrypy/process/wspbus.py#L305 startup_cwd = os.getcwd() #Used in do_execv, to swap between projects #------------- Context Manager ------------# try: #If started from COMMAND, user can choose his directory directly SELECTED_DIR = sys.argv[1] except IndexError: SELECTED_DIR = '' #If no system argument is provided, provide GUI to choose if SELECTED_DIR == '': prompt_layout = [ [sg.Combo(PROJECTS)], [sg.Button('Open')], [sg.Text(key='-INFO-', size=(20, 1))], ] prompt_window = sg.Window( 'Select your project', prompt_layout, location=(80, 500), ) while True: event, values = prompt_window.Read() if event in (None, 'Exit'): break if event == 'Open':
def __current(self): current_index = 0 is_open = False while True: today = date.today() frogs = [] usual = [] if not (today in self.undone_tasks_): sg.popup( "Hooray! No tasks for today! You can chill and enjoy your life." ) if is_open: window.close() break for i in range(current_index, len(self.undone_tasks_[today])): x = self.undone_tasks_[today][i] if x.is_frog_: frogs.append(x) else: usual.append(x) for i in range(0, current_index): x = self.undone_tasks_[today][i] if x.is_frog_: frogs.append(x) else: usual.append(x) undone_amount = len(frogs) + len(usual) all_amount = undone_amount + (len(self.done_tasks_[today]) if (today in self.done_tasks_) else 0) layout = [[sg.Text("Today is " + str(today))]] if undone_amount == 0: sg.popup("Congratulations! You have done all tasks for today!") if is_open: window.close() break else: layout.append([ sg.Text( f'You have completed {all_amount - undone_amount} from {all_amount} tasks today.' f' Good work!') ]) if len(frogs) > 0: current_task = frogs[len(frogs) - 1] else: current_task = usual[len(usual) - 1] layout.append([sg.Text("Current task:")]) layout.append( [sg.Text(current_task.title_, font=tkinter.font.ITALIC)]) layout.append([sg.Text("Is frog?")]) # print("Is frog?", emoji.emojize(':frog:'), end="") if current_task.is_frog_: layout.append([sg.Text("Yes", text_color='#00FF00')]) else: layout.append([sg.Text("No", text_color='#FF0000')]) layout.append([sg.Button("Done")]) layout.append([sg.Button("Skip")]) layout.append([sg.Button("Return")]) window = sg.Window("Current wokflow", layout, resizable=True) is_open = True event, value = window.read() if event == "Done": if not (today in self.done_tasks_): self.done_tasks_[today] = [] self.done_tasks_[today].append(current_task) self.undone_tasks_[today].remove(current_task) if not self.undone_tasks_[today]: del self.undone_tasks_[today] window.close() is_open = False continue if event == "Skip": if current_task.is_frog_: sg.popup("You can't skip the frog!") window.close() continue current_index += 1 current_index %= len(self.undone_tasks_[today]) is_open = False window.close() continue if event == "Return" or event == sg.WIN_CLOSED: window.close() is_open = False break
def __manage(self): date_list = sg.popup_get_date() find_date = date(date_list[2], date_list[0], date_list[1]) if not (find_date in self.undone_tasks_): sg.popup("No tasks at this date!") return current_tasks = self.undone_tasks_[find_date] is_open = False while True: if len(current_tasks) == 0: del self.undone_tasks_[find_date] sg.popup("No tasks left for today!") if is_open: window.close() return layout = [[sg.Text("Tasks for " + str(find_date))]] i = 0 for task in current_tasks: i += 1 temp = [ sg.Text(str(i) + ")"), sg.Text(task.title_, font=tkinter.font.ITALIC), sg.Text("Is frog? ") ] if task.is_frog_: temp.append(sg.Text("Yes", text_color='#00FF00')) else: temp.append(sg.Text("No", text_color='#FF0000')) temp.append(sg.Button("Delete", key=i)) layout.append(temp) layout.append([sg.Button("Return")]) window = sg.Window("Manage", layout) is_open = True event, value = window.read() if event == "Return" or sg.WIN_CLOSED: window.close() return print(event) if 1 <= event <= len(current_tasks): self.undone_tasks_[find_date].pop(event - 1) sg.popup("Task was successfully deleted.") window.close() is_open = False continue