MCPcopy
hub / github.com/PySimpleGUI/PySimpleGUI / main

Function main

DemoPrograms/Demo_Desktop_Widget_psutil_Dashboard.py:58–135  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

56
57
58def main():
59 # ---------------- Create Window ----------------
60 sg.theme('Black')
61 sg.set_options(element_padding=(0, 0), margins=(1, 1), border_width=0)
62 location = sg.user_settings_get_entry('-location-', (None, None))
63
64 def GraphColumn(name, key):
65 layout = [
66 [sg.Text(name, size=(18,1), font=('Helvetica 8'), key=key+'TXT_')],
67 [sg.Graph((GRAPH_WIDTH, GRAPH_HEIGHT),
68 (0, 0),
69 (GRAPH_WIDTH, 100),
70 background_color='black',
71 key=key+'GRAPH_')]]
72 return sg.Col(layout, pad=(2, 2))
73
74 layout = [
75 [sg.Text('System Status Dashboard'+' '*18)],
76 [GraphColumn('Net Out', '_NET_OUT_'),
77 GraphColumn('Net In', '_NET_IN_')],
78 [GraphColumn('Disk Read', '_DISK_READ_'),
79 GraphColumn('Disk Write', '_DISK_WRITE_')],
80 [GraphColumn('CPU Usage', '_CPU_'),
81 GraphColumn('Memory Usage', '_MEM_')], ]
82
83 window = sg.Window('PSG System Dashboard', layout,
84 keep_on_top=True,
85 grab_anywhere=True, no_titlebar=True,
86 return_keyboard_events=True, alpha_channel=ALPHA, enable_close_attempted_event=True,
87 use_default_focus=False, finalize=True, location=location,right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_VER_EXIT,)
88
89 # setup graphs & initial values
90 netio = psutil.net_io_counters()
91 net_in = window['_NET_IN_GRAPH_']
92 net_graph_in = DashGraph(net_in, netio.bytes_recv, '#23a0a0')
93 net_out = window['_NET_OUT_GRAPH_']
94 net_graph_out = DashGraph(net_out, netio.bytes_sent, '#56d856')
95
96 diskio = psutil.disk_io_counters()
97 disk_graph_write = DashGraph(window['_DISK_WRITE_GRAPH_'], diskio.write_bytes, '#be45be')
98 disk_graph_read = DashGraph(window['_DISK_READ_GRAPH_'], diskio.read_bytes, '#5681d8')
99
100 cpu_usage_graph = DashGraph(window['_CPU_GRAPH_'], 0, '#d34545')
101 mem_usage_graph = DashGraph(window['_MEM_GRAPH_'], 0, '#BE7C29')
102
103 # print(psutil.cpu_percent(percpu=True))
104 # ---------------- main loop ----------------
105 while True :
106 # --------- Read and update window once a second--------
107 event, values = window.read(timeout=1000)
108 if event in (sg.WIN_CLOSE_ATTEMPTED_EVENT, 'Exit'):
109 sg.user_settings_set_entry('-location-', window.current_location()) # save window location before exiting
110 break
111 elif event == 'Edit Me':
112 sp = sg.execute_editor(__file__)
113 elif event == 'Version':
114 sg.popup_scrolled(__file__, sg.get_versions(), keep_on_top=True, location=window.current_location())
115

Calls 8

readMethod · 0.95
current_locationMethod · 0.95
graph_valueMethod · 0.95
graph_percentage_absMethod · 0.95
GraphColumnFunction · 0.70
DashGraphClass · 0.70
human_sizeFunction · 0.70
updateMethod · 0.45

Tested by

no test coverage detected