Added predefined right click menu for exiting and self-editing. Removed older "RAM_Used" demo.
This commit is contained in:
parent
ed11316f18
commit
26ef16ca23
5 changed files with 21 additions and 82 deletions
|
@ -23,12 +23,11 @@ def human_size(bytes, units=(' bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB')):
|
|||
return str(bytes) + ' ' + units[0] if bytes < 1024 else human_size(bytes >> 10, units[1:])
|
||||
|
||||
|
||||
sg.theme(THEME)
|
||||
def main(location):
|
||||
graph = sg.Graph(GSIZE, (0, 0), GSIZE, key='-GRAPH-', enable_events=True)
|
||||
layout = [[graph]]
|
||||
|
||||
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, finalize=True, right_click_menu=[[''], 'Exit'])
|
||||
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, finalize=True, right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_EXIT)
|
||||
|
||||
text_id2 = graph.draw_text(f'CPU', (GSIZE[0] // 2, GSIZE[1] // 4), font='Any 20', text_location=sg.TEXT_LOCATION_CENTER, color=sg.theme_button_color()[0])
|
||||
|
||||
|
@ -41,7 +40,6 @@ def main(location):
|
|||
rect_id = graph.draw_rectangle((0, rect_height), (GSIZE[0], 0), fill_color=sg.theme_button_color()[1], line_width=0)
|
||||
# Draw the % used text and the close "X" on bottom
|
||||
text_id1 = graph.draw_text(f'{int(cpu_percent)}%', (GSIZE[0] // 2, GSIZE[1] // 2), font='Any 40', text_location=sg.TEXT_LOCATION_CENTER, color=sg.theme_button_color()[0])
|
||||
# text_id3 = graph.draw_text('❎', (0, 0), font='Any 8', text_location=sg.TEXT_LOCATION_BOTTOM_LEFT, color=sg.theme_button_color()[0])
|
||||
# put the bar behind everything else
|
||||
graph.send_figure_to_back(rect_id)
|
||||
|
||||
|
@ -49,17 +47,16 @@ def main(location):
|
|||
event, values = window.read(timeout=UPDATE_FREQUENCY_MILLISECONDS)
|
||||
if event == sg.WIN_CLOSED or event == 'Exit':
|
||||
break
|
||||
if event == '-GRAPH-': # exit if clicked in the bottom left 20 x 20 pixel area
|
||||
if values['-GRAPH-'][0] < 20 and values['-GRAPH-'][1] < 20:
|
||||
break
|
||||
if event == 'Edit Me':
|
||||
sg.execute_editor(__file__)
|
||||
# erase figures so they can be redrawn
|
||||
graph.delete_figure(rect_id)
|
||||
graph.delete_figure(text_id1)
|
||||
# graph.delete_figure(text_id3)
|
||||
window.close()
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
sg.theme(THEME)
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
location = sys.argv[1].split(',')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue