Merge pull request #3197 from PySimpleGUI/Dev-latest
Added location parameter so that launchers can place these widgets at…
This commit is contained in:
commit
33ae9b34c8
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
|
import sys
|
||||||
import psutil
|
import psutil
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -49,13 +50,13 @@ class DashGraph(object):
|
||||||
def text_display(self, text):
|
def text_display(self, text):
|
||||||
self.text_elem.update(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
|
# A couple of "User defined elements" that combine several elements and enable bulk edits
|
||||||
def Txt(text, **kwargs):
|
def Txt(text, **kwargs):
|
||||||
return(sg.Text(text, font=('Helvetica 8'), **kwargs))
|
return(sg.Text(text, font=('Helvetica 8'), **kwargs))
|
||||||
|
|
||||||
def GraphColumn(name, key):
|
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))
|
[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
|
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))]]
|
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 ----------------
|
# ---------------- Create Window ----------------
|
||||||
window = sg.Window('PSG System Dashboard', layout,
|
window = sg.Window('CPU Cores Usage Widget', layout,
|
||||||
keep_on_top=True,
|
keep_on_top=True,
|
||||||
auto_size_buttons=False,
|
auto_size_buttons=False,
|
||||||
grab_anywhere=True,
|
grab_anywhere=True,
|
||||||
|
@ -83,7 +84,8 @@ def main():
|
||||||
return_keyboard_events=True,
|
return_keyboard_events=True,
|
||||||
alpha_channel=TRANSPARENCY,
|
alpha_channel=TRANSPARENCY,
|
||||||
use_default_focus=False,
|
use_default_focus=False,
|
||||||
finalize=True)
|
finalize=True,
|
||||||
|
location=location)
|
||||||
|
|
||||||
# setup graphs & initial values
|
# setup graphs & initial values
|
||||||
graphs = [DashGraph(window['_CPU_'+str(i)+'_GRAPH_'],
|
graphs = [DashGraph(window['_CPU_'+str(i)+'_GRAPH_'],
|
||||||
|
@ -107,4 +109,10 @@ def main():
|
||||||
window.close()
|
window.close()
|
||||||
|
|
||||||
if __name__ == "__main__":
|
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 PySimpleGUI as sg
|
||||||
import psutil
|
import psutil
|
||||||
|
import sys
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Another simple Desktop Widget using PySimpleGUI
|
Another simple Desktop Widget using PySimpleGUI
|
||||||
|
@ -23,16 +24,16 @@ def human_size(bytes, units=(' bytes', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB')):
|
||||||
|
|
||||||
|
|
||||||
sg.theme(THEME)
|
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)
|
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'])
|
||||||
layout = [[graph]]
|
|
||||||
|
|
||||||
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
|
while True: # Event Loop
|
||||||
# ----------- update the graphics and text in the window ------------
|
# ----------- update the graphics and text in the window ------------
|
||||||
cpu_percent = psutil.cpu_percent(interval=1)
|
cpu_percent = psutil.cpu_percent(interval=1)
|
||||||
# Draw the filled rectangle
|
# Draw the filled rectangle
|
||||||
|
@ -40,7 +41,7 @@ while True: # Event Loop
|
||||||
rect_id = graph.draw_rectangle((0, rect_height), (GSIZE[0], 0), fill_color=sg.theme_button_color()[1], line_width=0)
|
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
|
# 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_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])
|
# 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
|
# put the bar behind everything else
|
||||||
graph.send_figure_to_back(rect_id)
|
graph.send_figure_to_back(rect_id)
|
||||||
|
|
||||||
|
@ -54,5 +55,15 @@ while True: # Event Loop
|
||||||
# erase figures so they can be redrawn
|
# erase figures so they can be redrawn
|
||||||
graph.delete_figure(rect_id)
|
graph.delete_figure(rect_id)
|
||||||
graph.delete_figure(text_id1)
|
graph.delete_figure(text_id1)
|
||||||
graph.delete_figure(text_id3)
|
# graph.delete_figure(text_id3)
|
||||||
window.close()
|
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
|
import time
|
||||||
from threading import Thread
|
from threading import Thread
|
||||||
import operator
|
import operator
|
||||||
|
import sys
|
||||||
|
|
||||||
"""
|
"""
|
||||||
PSUTIL Desktop Widget
|
PSUTIL Desktop Widget
|
||||||
|
@ -36,7 +36,7 @@ def CPU_thread(args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main(location):
|
||||||
global g_interval, g_procs, g_exit
|
global g_interval, g_procs, g_exit
|
||||||
|
|
||||||
# ---------------- Create Form ----------------
|
# ---------------- Create Form ----------------
|
||||||
|
@ -53,7 +53,7 @@ def main():
|
||||||
]
|
]
|
||||||
|
|
||||||
window = sg.Window('Top CPU Processes', layout,
|
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
|
# start cpu measurement thread
|
||||||
thread = Thread(target=CPU_thread, args=(None,))
|
thread = Thread(target=CPU_thread, args=(None,))
|
||||||
|
@ -96,6 +96,10 @@ def main():
|
||||||
|
|
||||||
window.close()
|
window.close()
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
if __name__ == "__main__":
|
if len(sys.argv) > 1:
|
||||||
main()
|
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
|
#!/usr/bin/env python
|
||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
import psutil
|
import psutil
|
||||||
|
import sys
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Desktop "Rainmeter" style widget - Drive usage
|
Desktop "Rainmeter" style widget - Drive usage
|
||||||
|
@ -34,7 +35,7 @@ def update_window(window):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main(location):
|
||||||
sg.theme(THEME)
|
sg.theme(THEME)
|
||||||
|
|
||||||
# ---------------- Create Layout ----------------
|
# ---------------- 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')]]
|
layout += [[sg.Text('Refresh', font='Any 8', key='-REFRESH-', enable_events=True), sg.Text('❎', enable_events=True, key='Exit Text')]]
|
||||||
|
|
||||||
# ---------------- Create Window ----------------
|
# ---------------- 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)
|
finalize=True)
|
||||||
|
|
||||||
update_window(window) # sets the progress bars
|
update_window(window) # sets the progress bars
|
||||||
|
@ -71,5 +72,11 @@ def main():
|
||||||
update_window(window)
|
update_window(window)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == '__main__':
|
||||||
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
|
#!/usr/bin/env python
|
||||||
import PySimpleGUI as sg
|
import PySimpleGUI as sg
|
||||||
import psutil
|
import psutil
|
||||||
|
import sys
|
||||||
|
|
||||||
"""
|
"""
|
||||||
Desktop floating widget - System status dashboard
|
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:])
|
return str(bytes) + units[0] if bytes < 1024 else human_size(bytes >> 10, units[1:])
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main(location):
|
||||||
# ---------------- Create Window ----------------
|
# ---------------- Create Window ----------------
|
||||||
sg.theme('Black')
|
sg.theme('Black')
|
||||||
sg.set_options(element_padding=(0, 0), margins=(1, 1), border_width=0)
|
sg.set_options(element_padding=(0, 0), margins=(1, 1), border_width=0)
|
||||||
|
@ -82,7 +83,7 @@ def main():
|
||||||
keep_on_top=True,
|
keep_on_top=True,
|
||||||
grab_anywhere=True, no_titlebar=True,
|
grab_anywhere=True, no_titlebar=True,
|
||||||
return_keyboard_events=True, alpha_channel=ALPHA,
|
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
|
# setup graphs & initial values
|
||||||
netio = psutil.net_io_counters()
|
netio = psutil.net_io_counters()
|
||||||
|
@ -127,6 +128,11 @@ def main():
|
||||||
mem_usage_graph.graph_percentage_abs(mem_used)
|
mem_usage_graph.graph_percentage_abs(mem_used)
|
||||||
window['_MEM_TXT_'].update('{}% Memory Used'.format(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