Created
April 25, 2022 01:05
-
-
Save KenoLeon/22379c62c032a1b03a0d5b9270f9ae41 to your computer and use it in GitHub Desktop.
GUI Tests before Integration
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import PySimpleGUI as sg | |
| _VARS = {'Networks': ['Network 01', 'Network 02', 'Network 03', 'Network 04'], | |
| 'NetworkStrength': ['-84', '-91', '-53', '-100']} | |
| EDGE_OFFSET = 8 # offset from the left edge for first bar | |
| GRAPH_SIZE = DATA_SIZE = (600, 600) # size in pixels | |
| GLOBAL_FONT = ('Helvetica', 14) | |
| sg.theme('DarkAmber') | |
| layout = [[sg.Text('WIFI SCANNER', font=GLOBAL_FONT)], | |
| [sg.Graph(GRAPH_SIZE, (0, 0), DATA_SIZE, k='-GRAPH-')], | |
| [sg.Button('SCAN FOR WIFI NETWORKS', font=GLOBAL_FONT), | |
| sg.Exit(font=GLOBAL_FONT)]] | |
| window = sg.Window('Bar Graph', layout, finalize=True) | |
| graph = window['-GRAPH-'] # type: sg.Graph | |
| while True: | |
| graph.erase() | |
| print('Getting Networks') | |
| numNetworks = len(_VARS['Networks']) | |
| bar_width = (GRAPH_SIZE[0]/numNetworks)-EDGE_OFFSET | |
| bar_spacing = (GRAPH_SIZE[0]/numNetworks) | |
| for i in range(numNetworks): | |
| graph_value = -int(_VARS['NetworkStrength'][i]) | |
| networkName = _VARS['Networks'][i] | |
| graph.draw_rectangle(top_left=(i * bar_spacing + EDGE_OFFSET, | |
| graph_value), | |
| bottom_right=(i * bar_spacing + | |
| EDGE_OFFSET + bar_width, 0), | |
| fill_color='lightgreen') | |
| graph.draw_text(text=networkName, location=( | |
| i*bar_spacing+EDGE_OFFSET+100, graph_value+10), | |
| font=GLOBAL_FONT, color='white') | |
| # Normally at the top of the loop, | |
| # but because we're drawing the graph first, making it at the bottom | |
| event, values = window.read() | |
| if event in (sg.WIN_CLOSED, 'Exit'): | |
| break | |
| window.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment