(location)
| 268 | return str(bytes) + ' ' + units[0] if bytes < 1024 else human_size(bytes >> 10, units[1:]) |
| 269 | |
| 270 | def main(location): |
| 271 | sg.theme(THEME) |
| 272 | gsize = (100, 55) |
| 273 | layout = [ |
| 274 | [sg.T('RAM', font='Any 20', background_color='black')], |
| 275 | [sg.Graph(gsize, (-gsize[0] // 2, 0), (gsize[0] // 2, gsize[1]), key='-Graph-')], |
| 276 | [sg.T(size=(5, 1), font='Any 20', justification='c', background_color='black', k='-gauge VALUE-')], |
| 277 | [sg.T(size=(8, 1), font='Any 14', justification='c', background_color='black', k='-RAM USED-')], |
| 278 | ] |
| 279 | |
| 280 | window = sg.Window('CPU Usage Widget Square', layout, location=location, no_titlebar=True, grab_anywhere=True, margins=(0, 0), element_padding=(0, 0), alpha_channel=ALPHA, background_color='black', element_justification='c', finalize=True, right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_VER_EXIT, enable_close_attempted_event=True) |
| 281 | |
| 282 | gauge = Gauge(pointer_color=sg.theme_text_color(), clock_color=sg.theme_text_color(), major_tick_color=sg.theme_text_color(), |
| 283 | minor_tick_color=sg.theme_input_background_color(), pointer_outer_color=sg.theme_text_color(), major_tick_start_radius=45, |
| 284 | minor_tick_start_radius=45, minor_tick_stop_radius=50, major_tick_stop_radius=50, major_tick_step=30, clock_radius=50, pointer_line_width=3, |
| 285 | pointer_inner_radius=10, pointer_outer_radius=50, graph_elem=window['-Graph-']) |
| 286 | |
| 287 | gauge.change(degree=0) |
| 288 | |
| 289 | while True: # Event Loop |
| 290 | ram = psutil.virtual_memory() |
| 291 | ram_percent = ram.percent |
| 292 | |
| 293 | if gauge.change(): |
| 294 | new_angle = ram_percent*180/100 |
| 295 | window['-gauge VALUE-'].update(f'{ram_percent}%') |
| 296 | window['-RAM USED-'].update(f'{human_size(ram.used)}') |
| 297 | gauge.change(degree=new_angle, step=180) |
| 298 | gauge.change() |
| 299 | # ----------- update the graphics and text in the window ------------ |
| 300 | |
| 301 | # update the window, wait for a while, then check for exit |
| 302 | event, values = window.read(timeout=UPDATE_FREQUENCY_MILLISECONDS) |
| 303 | if event in (sg.WIN_CLOSE_ATTEMPTED_EVENT, 'Exit'): |
| 304 | sg.user_settings_set_entry('-location-', window.current_location()) # The line of code to save the position before exiting |
| 305 | break |
| 306 | if event == 'Edit Me': |
| 307 | sg.execute_editor(__file__) |
| 308 | elif event == 'Version': |
| 309 | sg.popup_scrolled(__file__, sg.get_versions(), location=window.current_location(), keep_on_top=True, non_blocking=True) |
| 310 | window.close() |
| 311 | |
| 312 | |
| 313 | if __name__ == '__main__': |
no test coverage detected