From f5181b0ff5b6c57a002353b143c82b82f40394c0 Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Mon, 1 Oct 2018 21:22:06 -0400 Subject: [PATCH 1/2] NEW demo program LED Status Indicators --- Demo_LED_Indicators.py | 50 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 Demo_LED_Indicators.py diff --git a/Demo_LED_Indicators.py b/Demo_LED_Indicators.py new file mode 100644 index 00000000..b1f64eca --- /dev/null +++ b/Demo_LED_Indicators.py @@ -0,0 +1,50 @@ +#!/usr/bin/env python +import sys + +if sys.version_info[0] >= 3: + import PySimpleGUI as sg +else: + import PySimpleGUI27 as sg +import time +import random + +""" + Demo program showing how to create your own "LED Indicators" + The LEDIndicator function acts like a new Element that is directly placed in a window's layout + After the Window is created, use the SetLED function to access the LED and set the color + +""" + + +def LEDIndicator(key): + return sg.Graph(canvas_size=(30, 30), graph_bottom_left=(-20, -20), graph_top_right=(20, 20), + pad=(0, 0), key=key) + + +def SetLED(window, key, color): + graph = window.FindElement(key) + graph.Erase() + graph.DrawCircle((0, 0), 10, fill_color=color, line_color=color) + + +layout = [[sg.Text('My layout')], + [sg.Text('CPU Use'), LEDIndicator('_cpu_')], + [sg.Text('RAM'), LEDIndicator('_ram_')], + [sg.Text('Temperature'), LEDIndicator('_temp_')], + [sg.Text('Server 1'), LEDIndicator('_server1_')], + [sg.RButton('Read The Window'), sg.Exit()]] + +window = sg.Window('My new window', default_element_size=(12, 1), auto_size_text=False).Layout(layout).Finalize() + +i = 0 +while True: # Event Loop + button, value = window.ReadNonBlocking() + if value is None: + break + i += 1 + SetLED(window, '_cpu_', 'green' if random.randint(1, 10) > 5 else 'red') + SetLED(window, '_ram_', 'green' if random.randint(1, 10) > 5 else 'red') + SetLED(window, '_temp_', 'green' if random.randint(1, 10) > 5 else 'red') + SetLED(window, '_server1_', 'green' if random.randint(1, 10) > 5 else 'red') + + time.sleep(.400) From da5c8f5bc80ab4e68f6d8edfcd13eff1be68ea8a Mon Sep 17 00:00:00 2001 From: MikeTheWatchGuy Date: Mon, 1 Oct 2018 21:29:18 -0400 Subject: [PATCH 2/2] Changed window layout --- Demo_LED_Indicators.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Demo_LED_Indicators.py b/Demo_LED_Indicators.py index b1f64eca..5754c653 100644 --- a/Demo_LED_Indicators.py +++ b/Demo_LED_Indicators.py @@ -27,12 +27,12 @@ def SetLED(window, key, color): graph.DrawCircle((0, 0), 10, fill_color=color, line_color=color) -layout = [[sg.Text('My layout')], +layout = [[sg.Text('My Status Report')], [sg.Text('CPU Use'), LEDIndicator('_cpu_')], [sg.Text('RAM'), LEDIndicator('_ram_')], [sg.Text('Temperature'), LEDIndicator('_temp_')], [sg.Text('Server 1'), LEDIndicator('_server1_')], - [sg.RButton('Read The Window'), sg.Exit()]] + [sg.Exit()]] window = sg.Window('My new window', default_element_size=(12, 1), auto_size_text=False).Layout(layout).Finalize()