Added location parameter so that launchers can place these widgets at any location on multiple screens
This commit is contained in:
parent
8fc47b964a
commit
d2102c8b17
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
import PySimpleGUI as sg
|
||||
import sys
|
||||
import psutil
|
||||
|
||||
"""
|
||||
|
@ -49,13 +50,13 @@ class DashGraph(object):
|
|||
def text_display(self, text):
|
||||
self.text_elem.update(text)
|
||||
|
||||
def main():
|
||||
def main(location):
|
||||
# A couple of "User defined elements" that combine several elements and enable bulk edits
|
||||
def Txt(text, **kwargs):
|
||||
return(sg.Text(text, font=('Helvetica 8'), **kwargs))
|
||||
|
||||
def GraphColumn(name, key):
|
||||
return sg.Column([[Txt(name, size=(10,1), key=key+'_TXT_'), ],
|
||||
return sg.Column([[Txt(name, size=(10,1), key=key+'_TXT_')],
|
||||
[sg.Graph((GRAPH_WIDTH, GRAPH_HEIGHT), (0, 0), (GRAPH_WIDTH, 100), background_color='black', key=key+'_GRAPH_')]], pad=(2, 2))
|
||||
|
||||
num_cores = len(psutil.cpu_percent(percpu=True)) # get the number of cores in the CPU
|
||||
|
@ -74,7 +75,7 @@ def main():
|
|||
layout += [[GraphColumn('CPU '+str(rows*NUM_COLS+cols), '_CPU_'+str(rows*NUM_COLS+cols)) for cols in range(min(num_cores-rows*NUM_COLS, NUM_COLS))]]
|
||||
|
||||
# ---------------- Create Window ----------------
|
||||
window = sg.Window('PSG System Dashboard', layout,
|
||||
window = sg.Window('CPU Cores Usage Widget', layout,
|
||||
keep_on_top=True,
|
||||
auto_size_buttons=False,
|
||||
grab_anywhere=True,
|
||||
|
@ -83,7 +84,8 @@ def main():
|
|||
return_keyboard_events=True,
|
||||
alpha_channel=TRANSPARENCY,
|
||||
use_default_focus=False,
|
||||
finalize=True)
|
||||
finalize=True,
|
||||
location=location)
|
||||
|
||||
# setup graphs & initial values
|
||||
graphs = [DashGraph(window['_CPU_'+str(i)+'_GRAPH_'],
|
||||
|
@ -107,4 +109,10 @@ def main():
|
|||
window.close()
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
# when invoking this program, if a location is set on the command line, then the window will be created there. Use x,y with no ( )
|
||||
if len(sys.argv) > 1:
|
||||
location = sys.argv[1].split(',')
|
||||
location = (int(location[0]), int(location[1]))
|
||||
else:
|
||||
location = (None, None)
|
||||
main(location)
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import PySimpleGUI as sg
|
||||
import psutil
|
||||
import sys
|
||||
|
||||
"""
|
||||
Another simple Desktop Widget using PySimpleGUI
|
||||
|
@ -23,36 +24,46 @@ def human_size(bytes, units=(' bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB')):
|
|||
|
||||
|
||||
sg.theme(THEME)
|
||||
def main(location):
|
||||
graph = sg.Graph(GSIZE, (0, 0), GSIZE, key='-GRAPH-', enable_events=True)
|
||||
layout = [[graph]]
|
||||
|
||||
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, no_titlebar=True, grab_anywhere=True, margins=(0, 0), element_padding=(0, 0), alpha_channel=ALPHA, finalize=True)
|
||||
|
||||
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])
|
||||
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])
|
||||
|
||||
|
||||
while True: # Event Loop
|
||||
# ----------- update the graphics and text in the window ------------
|
||||
cpu_percent = psutil.cpu_percent(interval=1)
|
||||
# Draw the filled rectangle
|
||||
rect_height = int(GSIZE[1] * float(cpu_percent) / 100)
|
||||
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)
|
||||
while True: # Event Loop
|
||||
# ----------- update the graphics and text in the window ------------
|
||||
cpu_percent = psutil.cpu_percent(interval=1)
|
||||
# Draw the filled rectangle
|
||||
rect_height = int(GSIZE[1] * float(cpu_percent) / 100)
|
||||
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)
|
||||
|
||||
# update the window, wait for a while, then check for exit
|
||||
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:
|
||||
# update the window, wait for a while, then check for exit
|
||||
event, values = window.read(timeout=UPDATE_FREQUENCY_MILLISECONDS)
|
||||
if event == sg.WIN_CLOSED or event == 'Exit':
|
||||
break
|
||||
# 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 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
|
||||
# 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__':
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
location = sys.argv[1].split(',')
|
||||
location = (int(location[0]), int(location[1]))
|
||||
else:
|
||||
location = (None, None)
|
||||
main(location)
|
||||
|
|
|
@ -4,7 +4,7 @@ import psutil
|
|||
import time
|
||||
from threading import Thread
|
||||
import operator
|
||||
|
||||
import sys
|
||||
|
||||
"""
|
||||
PSUTIL Desktop Widget
|
||||
|
@ -36,7 +36,7 @@ def CPU_thread(args):
|
|||
pass
|
||||
|
||||
|
||||
def main():
|
||||
def main(location):
|
||||
global g_interval, g_procs, g_exit
|
||||
|
||||
# ---------------- Create Form ----------------
|
||||
|
@ -53,7 +53,7 @@ def main():
|
|||
]
|
||||
|
||||
window = sg.Window('Top CPU Processes', layout,
|
||||
no_titlebar=True, keep_on_top=True, use_default_focus=False, alpha_channel=.8, grab_anywhere=True)
|
||||
no_titlebar=True, keep_on_top=True,location=location, use_default_focus=False, alpha_channel=.8, grab_anywhere=True)
|
||||
|
||||
# start cpu measurement thread
|
||||
thread = Thread(target=CPU_thread, args=(None,))
|
||||
|
@ -96,6 +96,10 @@ def main():
|
|||
|
||||
window.close()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) > 1:
|
||||
location = sys.argv[1].split(',')
|
||||
location = (int(location[0]), int(location[1]))
|
||||
else:
|
||||
location = (None, None)
|
||||
main(location)
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
import PySimpleGUI as sg
|
||||
import psutil
|
||||
import sys
|
||||
|
||||
"""
|
||||
Desktop "Rainmeter" style widget - Drive usage
|
||||
|
@ -34,7 +35,7 @@ def update_window(window):
|
|||
pass
|
||||
|
||||
|
||||
def main():
|
||||
def main(location):
|
||||
sg.theme(THEME)
|
||||
|
||||
# ---------------- Create Layout ----------------
|
||||
|
@ -58,7 +59,7 @@ def main():
|
|||
layout += [[sg.Text('Refresh', font='Any 8', key='-REFRESH-', enable_events=True), sg.Text('❎', enable_events=True, key='Exit Text')]]
|
||||
|
||||
# ---------------- Create Window ----------------
|
||||
window = sg.Window('Drive Status Widget', layout, keep_on_top=True, grab_anywhere=True, no_titlebar=True, alpha_channel=ALPHA, use_default_focus=False,
|
||||
window = sg.Window('Drive Status Widget', layout, location=location, keep_on_top=True, grab_anywhere=True, no_titlebar=True, alpha_channel=ALPHA, use_default_focus=False,
|
||||
finalize=True)
|
||||
|
||||
update_window(window) # sets the progress bars
|
||||
|
@ -71,5 +72,11 @@ def main():
|
|||
update_window(window)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) > 1:
|
||||
location = sys.argv[1].split(',')
|
||||
location = (int(location[0]), int(location[1]))
|
||||
else:
|
||||
location = (None, None)
|
||||
main(location)
|
||||
|
||||
|
|
|
@ -0,0 +1,65 @@
|
|||
import PySimpleGUI as sg
|
||||
import psutil
|
||||
import sys
|
||||
|
||||
"""
|
||||
Another simple Desktop Widget using PySimpleGUI
|
||||
This time a RAM indicator. The Widget is square. The bottom section will be shaded to
|
||||
represent the total amount of RAM currently in use.
|
||||
The % and number of bytes in use is shown on top in text.
|
||||
Uses the theme's button color for colors.
|
||||
|
||||
Copyright 2020 PySimpleGUI.org
|
||||
"""
|
||||
|
||||
ALPHA = 0.5
|
||||
THEME = 'Dark Green 5'
|
||||
GSIZE = (160, 160)
|
||||
UPDATE_FREQUENCY_MILLISECONDS = 10 * 1000
|
||||
|
||||
|
||||
def human_size(bytes, units=(' bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB')):
|
||||
""" Returns a human readable string reprentation of bytes"""
|
||||
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('RAM 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'])
|
||||
|
||||
|
||||
while True: # Event Loop
|
||||
# ----------- update the graphics and text in the window ------------
|
||||
ram = psutil.virtual_memory()
|
||||
rect_height = int(GSIZE[1] * float(ram.percent) / 100)
|
||||
rect_id = graph.draw_rectangle((0, rect_height), (GSIZE[0], 0), fill_color=sg.theme_button_color()[1], line_width=0)
|
||||
text_id1 = graph.draw_text(f'{int(ram.percent)}%', (GSIZE[0] // 2, GSIZE[1] // 2), font='Any 40', text_location=sg.TEXT_LOCATION_CENTER,
|
||||
color=sg.theme_button_color()[0])
|
||||
text_id2 = graph.draw_text(f'{human_size(ram.used)} used', (GSIZE[0] // 2, GSIZE[1] // 4), font='Any 20', 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])
|
||||
|
||||
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
|
||||
graph.delete_figure(rect_id)
|
||||
graph.delete_figure(text_id1)
|
||||
graph.delete_figure(text_id2)
|
||||
# graph.delete_figure(text_id3)
|
||||
window.close()
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
if len(sys.argv) > 1:
|
||||
location = sys.argv[1].split(',')
|
||||
location = (int(location[0]), int(location[1]))
|
||||
else:
|
||||
location = (None, None)
|
||||
main(location)
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env python
|
||||
import PySimpleGUI as sg
|
||||
import psutil
|
||||
import sys
|
||||
|
||||
"""
|
||||
Desktop floating widget - System status dashboard
|
||||
|
@ -52,7 +53,7 @@ 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:])
|
||||
|
||||
|
||||
def main():
|
||||
def main(location):
|
||||
# ---------------- Create Window ----------------
|
||||
sg.theme('Black')
|
||||
sg.set_options(element_padding=(0, 0), margins=(1, 1), border_width=0)
|
||||
|
@ -82,7 +83,7 @@ def main():
|
|||
keep_on_top=True,
|
||||
grab_anywhere=True, no_titlebar=True,
|
||||
return_keyboard_events=True, alpha_channel=ALPHA,
|
||||
use_default_focus=False, finalize=True)
|
||||
use_default_focus=False, finalize=True, location=location)
|
||||
|
||||
# setup graphs & initial values
|
||||
netio = psutil.net_io_counters()
|
||||
|
@ -127,6 +128,11 @@ def main():
|
|||
mem_usage_graph.graph_percentage_abs(mem_used)
|
||||
window['_MEM_TXT_'].update('{}% Memory Used'.format(mem_used))
|
||||
|
||||
if __name__ == '__main__':
|
||||
if len(sys.argv) > 1:
|
||||
location = sys.argv[1].split(',')
|
||||
location = (int(location[0]), int(location[1]))
|
||||
else:
|
||||
location = (None, None)
|
||||
main(location)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
Loading…
Reference in New Issue