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

Function main

DemoPrograms/Demo_Graph_Elem_CPU_Meter.py:67–142  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

65
66
67def main():
68 # ------------------------- Init the VU_Meter --------------------------
69
70
71 VU_METER_cont = [[sg.Graph ( canvas_size = ( 339,234 ),
72 graph_bottom_left=(0,0),
73 graph_top_right=(339,234),
74 background_color=module_background,
75 drag_submits=True,
76 enable_events=True,
77 float_values=True,
78 key=CANVAS_KEY )]]
79
80
81 # ------------------------- Tab Set Ups --------------------------------
82 layout = [[sg.Column(VU_METER_cont ,background_color=module_background )]]
83
84
85
86 location = sg.user_settings_get_entry('-location-', (None, None))
87
88 # ------------------------ Finalize Windows ----------------------------
89
90 window = sg.Window('CPU Usage as a VU Meter', layout,
91 no_titlebar=True,
92 auto_size_buttons=False,
93 keep_on_top=True,
94 grab_anywhere=True,
95 force_toplevel=False,
96 finalize=True,
97 location=location,
98 right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_VER_EXIT,
99 enable_close_attempted_event=True)
100
101 # ------------------------ Init the VU_Meter ---------------------------
102
103 CONT_CANVAS_vu_meter = window[CANVAS_KEY]
104 angle = angle_min
105 x_angle = math.cos(math.radians(180-angle))
106 y_angle = math.sin(math.radians(180-angle))
107 x_cur = x_needle_base+(x_angle * needle_length)
108 y_cur = y_needle_base+int((y_angle * needle_length)*0.7)
109 x_cur_low = int(x_needle_base+(x_angle * (needle_length/needle_multiply)))
110 y_cur_low = int(y_needle_base+int((y_angle * (needle_length/needle_multiply))*0.7))
111 OBJ_VU_meter_needle = CONT_CANVAS_vu_meter.draw_line( (x_cur_low,y_cur_low),(int(x_cur),int(y_cur)) ,color=needle_color,width=needle_width)
112 window.refresh()
113
114 ########################################################################
115 ## MAIN LOOP ##
116 ########################################################################
117 temp_angle = 0
118 angle_impulse = 2
119 angle_range = angle_max-angle_min
120 while True:
121 event, values = window.read(timeout=30)
122 if event in (sg.WIN_CLOSE_ATTEMPTED_EVENT, 'Exit'):
123 sg.user_settings_set_entry('-location-', window.current_location()) # The line of code to save the position before exiting
124 break

Callers 1

Calls 6

refreshMethod · 0.95
readMethod · 0.95
current_locationMethod · 0.95
VU_METER_updateFunction · 0.85
draw_lineMethod · 0.80
draw_textMethod · 0.80

Tested by

no test coverage detected