test
This commit is contained in:
		
							parent
							
								
									d75044f702
								
							
						
					
					
						commit
						e28652a548
					
				
					 1 changed files with 51 additions and 54 deletions
				
			
		|  | @ -1,54 +1,51 @@ | ||||||
| #!/usr/bin/env python | #!/usr/bin/env python | ||||||
| import sys | import sys | ||||||
| 
 | 
 | ||||||
| if sys.version_info[0] >= 3: | if sys.version_info[0] >= 3: | ||||||
|     import PySimpleGUI as sg |     import PySimpleGUI as sg | ||||||
| else: | else: | ||||||
|     import PySimpleGUI27 as sg |     import PySimpleGUI27 as sg | ||||||
| import time | import time | ||||||
| import random | import random | ||||||
| 
 | 
 | ||||||
| """ | """ | ||||||
|     Demo program showing how to create your own "LED Indicators" |     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 |     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 |     After the Window is created, use the SetLED function to access the LED and set the color | ||||||
| 
 | 
 | ||||||
| """ | """ | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def LEDIndicator(key=None, radius=30): | def LEDIndicator(key=None, radius=30): | ||||||
|     return sg.Graph(canvas_size=(radius, radius), |     return sg.Graph(canvas_size=(radius, radius), | ||||||
|              graph_bottom_left=(-radius, -radius), |              graph_bottom_left=(-radius, -radius), | ||||||
|              graph_top_right=(radius, radius), |              graph_top_right=(radius, radius), | ||||||
|              pad=(0, 0), key=key) |              pad=(0, 0), key=key) | ||||||
| 
 | 
 | ||||||
| def SetLED(window, key, color): | def SetLED(window, key, color): | ||||||
|     graph = window.FindElement(key) |     graph = window.FindElement(key) | ||||||
|     graph.Erase() |     graph.Erase() | ||||||
|     graph.DrawCircle((0, 0), 12, fill_color=color, line_color=color) |     graph.DrawCircle((0, 0), 12, fill_color=color, line_color=color) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| layout = [[sg.Text('My LED Status Indicators', size=(20,1))], | layout = [[sg.Text('My LED Status Indicators', size=(20,1))], | ||||||
|           [sg.Text('CPU Use'), LEDIndicator('_cpu_')], |           [sg.Text('CPU Use'), LEDIndicator('_cpu_')], | ||||||
|           [sg.Text('RAM'), LEDIndicator('_ram_')], |           [sg.Text('RAM'), LEDIndicator('_ram_')], | ||||||
|           [sg.Text('Temperature'), LEDIndicator('_temp_')], |           [sg.Text('Temperature'), LEDIndicator('_temp_')], | ||||||
|           [sg.Text('Server 1'), LEDIndicator('_server1_')], |           [sg.Text('Server 1'), LEDIndicator('_server1_')], | ||||||
|           [sg.RButton('Exit')]] |           [sg.RButton('Exit')]] | ||||||
| 
 | 
 | ||||||
| window = sg.Window('My new window', default_element_size=(12, 1), auto_size_text=False).Layout(layout).Finalize() | window = sg.Window('My new window', default_element_size=(12, 1), auto_size_text=False).Layout(layout).Finalize() | ||||||
| 
 | 
 | ||||||
| i = 0 | i = 0 | ||||||
| while True:  # Event Loop | while True:  # Event Loop | ||||||
|     event, value = window.ReadNonBlocking() |     event, value = window.Read(timeout=400) | ||||||
|     if event == 'Exit': |     if event == 'Exit' or event is None: | ||||||
|         window.CloseNonBlocking() |         break | ||||||
|         break |     if value is None: | ||||||
|     if value is None: |         break | ||||||
|         break |     i += 1 | ||||||
|     i += 1 |     SetLED(window, '_cpu_', 'green' if random.randint(1, 10) > 5 else 'red') | ||||||
|     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, '_ram_', 'green' if random.randint(1, 10) > 5 else 'red') |     SetLED(window, '_temp_', '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') | ||||||
|     SetLED(window, '_server1_', 'green' if random.randint(1, 10) > 5 else 'red') |  | ||||||
| 
 |  | ||||||
|     time.sleep(.400) |  | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue