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

Function main

DemoPrograms/Demo_Desktop_Widget_CPU_Dashboard.py:57–123  ·  view source on GitHub ↗
(location)

Source from the content-addressed store, hash-verified

55 self.text_elem.update(text)
56
57def main(location):
58 # A couple of "User defined elements" that combine several elements and enable bulk edits
59 def Txt(text, **kwargs):
60 return(sg.Text(text, font=('Helvetica 8'), **kwargs))
61
62 def GraphColumn(name, key):
63 return sg.Column([[Txt(name, size=(10,1), key=('-TXT-', key))],
64 [sg.Graph((GRAPH_WIDTH, GRAPH_HEIGHT), (0, 0), (GRAPH_WIDTH, 100), background_color='black', key=('-GRAPH-', key))]], pad=(2, 2))
65
66 num_cores = len(psutil.cpu_percent(percpu=True)) # get the number of cores in the CPU
67
68 sg.theme('Black')
69
70 layout = [[sg.Text('CPU Core Usage', justification='c', expand_x=True)] ]
71
72 # add on the graphs
73 for rows in range(num_cores//NUM_COLS+1):
74 # for cols in range(min(num_cores-rows*NUM_COLS, NUM_COLS)):
75 layout += [[GraphColumn('CPU '+str(rows*NUM_COLS+cols), (rows, cols)) for cols in range(min(num_cores-rows*NUM_COLS, NUM_COLS))]]
76
77 # ---------------- Create Window ----------------
78 window = sg.Window('CPU Cores Usage Widget', layout,
79 keep_on_top=True,
80 grab_anywhere=True,
81 no_titlebar=True,
82 return_keyboard_events=True,
83 alpha_channel=TRANSPARENCY,
84 use_default_focus=False,
85 finalize=True,
86 margins=(1,1),
87 element_padding=(0,0),
88 border_depth=0,
89 location=location,
90 enable_close_attempted_event=True,
91 right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_VER_EXIT)
92
93
94 graphs = []
95 for rows in range(num_cores//NUM_COLS+1):
96 for cols in range(min(num_cores-rows*NUM_COLS, NUM_COLS)):
97 graphs += [DashGraph(window[('-GRAPH-', (rows, cols))],
98 window[('-TXT-', (rows, cols))],
99 0, colors[(rows*NUM_COLS+cols)%len(colors)])]
100
101
102 # ---------------- main loop ----------------
103 while True :
104 # --------- Read and update window once every Polling Frequency --------
105 event, values = window.read(timeout=POLL_FREQUENCY)
106 if event in (sg.WIN_CLOSE_ATTEMPTED_EVENT, 'Exit'): # Be nice and give an exit
107 sg.user_settings_set_entry('-location-', window.current_location()) # save window location before exiting
108 break
109 elif event == sg.WIN_CLOSED:
110 break
111 elif event == 'Edit Me':
112 sg.execute_editor(__file__)
113 elif event == 'Version':
114 sg.popup_scrolled(__file__, sg.get_versions(), keep_on_top=True, location=window.current_location())

Calls 7

readMethod · 0.95
current_locationMethod · 0.95
closeMethod · 0.95
GraphColumnFunction · 0.70
DashGraphClass · 0.70
graph_percentage_absMethod · 0.45
text_displayMethod · 0.45

Tested by

no test coverage detected