def main(): global g_exit, g_response_time # start ping measurement thread sg.ChangeLookAndFeel('Black') sg.SetOptions(element_padding=(0, 0)) layout = [ [ sg.Quit(button_color=('white', 'black')), sg.T('', font='Helvetica 25', key='output') ], [ sg.Graph(CANVAS_SIZE, (0, 0), (SAMPLES, SAMPLE_MAX), background_color='black', key='graph') ], ] window = sg.Window('CPU Graph', grab_anywhere=True, keep_on_top=True, background_color='black', no_titlebar=True, use_default_focus=False, location=(0, 0)).Layout(layout) graph = window.FindElement('graph') output = window.FindElement('output') # start cpu measurement thread thread = Thread(target=CPU_thread, args=(None, )) thread.start() last_cpu = i = 0 prev_x, prev_y = 0, 0 while True: # the Event Loop event, values = window.Read(timeout=500) if event == 'Quit' or event is None: # always give ths user a way out break # do CPU measurement and graph it current_cpu = int(g_cpu_percent * 10) if current_cpu == last_cpu: continue output.Update(current_cpu / 10) # show current cpu usage at top if current_cpu > SAMPLE_MAX: current_cpu = SAMPLE_MAX new_x, new_y = i, current_cpu if i >= SAMPLES: graph.Move(-STEP_SIZE, 0) # shift graph over if full of data prev_x = prev_x - STEP_SIZE graph.DrawLine((prev_x, prev_y), (new_x, new_y), color='white') prev_x, prev_y = new_x, new_y i += STEP_SIZE if i < SAMPLES else 0 last_cpu = current_cpu g_exit = True window.Close()
def GraphColumn(name, key): col = sg.Column([[ Txt(name, key=key + '_TXT_'), ], [ sg.Graph((GRAPH_WIDTH, GRAPH_HEIGHT), (0, 0), (GRAPH_WIDTH, 100), background_color='black', key=key + '_GRAPH_') ]], pad=(2, 2)) return col
def main(): sg.ChangeLookAndFeel('GreenTan') # sg.SetOptions(element_padding=(0,0)) # ------ Menu Definition ------ # menu_def = [ ['&File', ['&Open', '&Save', '&Properties', 'E&xit']], [ '&Edit', ['&Paste', [ 'Special', 'Normal', ], 'Undo'], ], ['&Toolbar', ['Command &1', 'Command &2', 'Command &3', 'Command &4']], ['&Help', '&About...'], ] treedata = sg.TreeData() treedata.Insert( "", '_A_', 'Tree Item 1', [1, 2, 3], ) treedata.Insert( "", '_B_', 'B', [4, 5, 6], ) treedata.Insert( "_A_", '_A1_', 'Sub Item 1', ['can', 'be', 'anything'], ) treedata.Insert( "", '_C_', 'C', [], ) treedata.Insert( "_C_", '_C1_', 'C1', ['or'], ) treedata.Insert("_A_", '_A2_', 'Sub Item 2', [None, None]) treedata.Insert("_A1_", '_A3_', 'A30', ['getting deep']) treedata.Insert("_C_", '_C2_', 'C2', ['nothing', 'at', 'all']) for i in range(100): treedata.Insert('_C_', i, i, []) frame1 = [ [sg.Input('Input Text', size=(250, 35)), sg.Stretch()], [ sg.Multiline(size=(250, 75), default_text='Multiline Input'), sg.MultilineOutput(size=(250, 75), default_text='Multiline Output') ], ] frame2 = [ [sg.Listbox(['Listbox 1', 'Listbox 2', 'Listbox 3'], size=(200, 85))], [ sg.Combo(['Combo item 1', 'Combo item 2', 'Combo item 3'], size=(200, 35)) ], [sg.Spin([1, 2, 3], size=(40, 30))], ] frame3 = [ [sg.Checkbox('Checkbox1', True), sg.Checkbox('Checkbox1')], [ sg.Radio('Radio Button1', 1), sg.Radio('Radio Button2', 1, default=True), sg.Stretch() ], ] frame4 = [ [ sg.Slider(range=(0, 100), orientation='v', size=(3, 30), default_value=40), sg.Dial(range=(0, 100), tick_interval=50, size=(150, 150), default_value=40), sg.Stretch() ], ] matrix = [[str(x * y) for x in range(4)] for y in range(3)] frame5 = [ [ sg.Table(values=matrix, max_col_width=25, auto_size_columns=True, display_row_numbers=True, change_submits=False, bind_return_key=True, justification='right', num_rows=8, alternating_row_color='lightblue', key='_table_', text_color='black'), sg.Tree(data=treedata, headings=['col1', 'col2', 'col3'], change_submits=True, auto_size_columns=True, num_rows=10, col0_width=10, key='_TREE_', show_expanded=True, size=(200, 150)), sg.Stretch() ], ] graph_elem = sg.Graph((880, 150), (0, 0), (600, 300), key='+GRAPH+') frame6 = [ [graph_elem, sg.Stretch()], ] tab1 = sg.Tab('Graph Number 1', frame6) tab2 = sg.Tab('Graph Number 2', [[]]) layout = [ [sg.Menu(menu_def)], [ sg.Image(data_base64=logo), sg.Frame('Input Text Group', frame1, title_color='red'), sg.Stretch() ], [ sg.Frame('Multiple Choice Group', frame2, title_color='green'), sg.Frame('Binary Choice Group', frame3, title_color='purple'), sg.Frame('Variable Choice Group', frame4, title_color='blue'), sg.Stretch() ], [ sg.Frame('Structured Data Group', frame5, title_color='red'), ], # [sg.Frame('Graphing Group', frame6)], [sg.TabGroup([[tab1, tab2]])], [ sg.ProgressBar(max_value=600, start_value=400, size=(600, 25), key='+PROGRESS+'), sg.Stretch(), sg.ButtonMenu('&Menu', ['Menu', ['&Pause Graph', 'Menu item']], key='_MENU_'), sg.Button('Button'), sg.Button('Exit') ], ] window = sg.Window('Window Title', font=('Helvetica', 13), default_button_element_size=(100, 30), auto_size_buttons=False, default_element_size=(200, 22)).Layout(layout).Finalize() graph_elem.DrawCircle((200, 200), 50, 'blue') i = 0 graph_paused = False while True: # Event Loop # sg.TimerStart() event, values = window.Read(timeout=0) if event is None or event == 'Exit': break if event == 'Button': print(event, values) if values['_MENU_'] == 'Pause Graph': graph_paused = not graph_paused if not graph_paused: i += 1 if i >= 600: graph_elem.Move(-1, 0) graph_elem.DrawLine((i, 0), (i, randint(0, 300)), width=1, color='#{:06x}'.format(randint(0, 0xffffff))) window.FindElement('+PROGRESS+').UpdateBar(i % 600) # sg.TimerStop() window.Close()
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')
import PySimpleGUIQt as sg sg.theme('dark blue 2') #dark blue 2 left_menu = sg.Column([ [sg.Button('Home')], [sg.Button('Foo')], [sg.Button('Help')], ]) graph_col = [[sg.Graph((100, 100), (0, 0), (1, 1))], [sg.Graph((100, 100), (0, 0), (1, 1))]] main_col = [[ sg.MultilineOutput( 'This is some text so see how the font looks that I am using.') ]] main_pane = sg.Column([ [sg.Text('Progress'), sg.ProgressBar(100)], [sg.Col(graph_col), sg.Col(main_col)], # [sg.MultilineOutput()] ]) #layout = [[left_menu, main_pane]] layout = [[main_pane]] window = sg.Window('ml4all', layout, font='Helvetica 14', element_padding=(5, 5))