-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
71 lines (68 loc) · 3.83 KB
/
main.py
File metadata and controls
71 lines (68 loc) · 3.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import PySimpleGUI as sg #gui
from sys import platform #operating system info
"""
if platform == "linux" or platform == "linux2":
#linux
print("Linux user")
elif platform == "darwin":
# OS X
print("Mac user")
elif platform == "win32":
# Windows...
print("Windows user")
"""
image_home = './ButtonGraphics/home.png'
sg.theme('LightGreen2') # Add a touch of color
# All the stuff inside your window.
layout = [ [sg.Text('LightSwitch', key='TITLE', text_color='green', font='Ubuntu 35', pad=((0,0),(50,15)))],
[sg.Text('Username:', key='USERNAME', font='Ubuntu 10'), sg.InputText('', key='Username', size=(20,1))],
[sg.Text('Password: ', key='PASSWORD', font='Ubuntu 10'), sg.InputText('', key='Password', password_char='*', size=(20,1))],
[sg.Button('Login', key='_LOGIN_', button_color=('white', 'blue'), font='Ubuntu 10', size=(25,1), pad=((0,0),(10,5)))],
[sg.Button('Create an account', key='_ACCOUNT_',button_color=('white', 'blue'), font='Ubuntu 10', size=(25,1), pad=((0,0),(5,10)))],
]
# Create the Window
main_window = sg.Window('LightSwitch::' + platform , layout,size=(600, 400), element_justification='c')
# Event Loop to process "events" and get the "values" of the inputs
devices_window_active = False
login = True #username and password acceptable
while True:
event, values = main_window.read()
if event in (sg.WIN_CLOSED, None): # if user closes window
break
if event == '_LOGIN_' and len(values['Username']) > 20 or len(values['Password']) > 20 or len(values['Username']) < 4 or len(values['Password']) < 4:
sg.popup_error('Username and password must be less than 21 characters and at least 4 characters', title='Length Error')
login = False
else:
login = True
if not devices_window_active and event == '_LOGIN_' and login:
main_window.Hide()
devices_window_active = True
devices_layout = [
[sg.Button('', key='_HOME_', button_color=(sg.theme_background_color(),sg.theme_background_color()),
image_filename=image_home, image_size=(50, 60), image_subsample=10, border_width=0), sg.Text('Devices', key='DEVICES', font='Ubuntu 35')],
[sg.Button('Add a device', key='_ADD_', button_color=('white', 'blue'), pad=((5,10),(5,10)), font='Ubuntu 10', size=(25,1))],
]
# New window after login
devices_window = sg.Window('LightSwitch::' + platform + "::devices", devices_layout, size=(600, 400), element_justification='c')
num_buttons = 0
MAX_BUTTONS = 3
while True:
event, values = devices_window.Read()
if event in ('_HOME_', None):
devices_window_active = False
devices_window.Close()
main_window.UnHide()
break
if event == '_ADD_':
if num_buttons < MAX_BUTTONS:
num_buttons+=1
devices_layout_1 = [
[sg.Button('', key='_HOME_', button_color=(sg.theme_background_color(),sg.theme_background_color()),
image_filename=image_home, image_size=(50, 60), image_subsample=10, border_width=0), sg.Text('Devices', key='DEVICES', font='Ubuntu 35')],
[sg.Button('Add a device', key='_ADD_', button_color=('white', 'blue'), font='Ubuntu 10', pad=((5,10),(5,10)), size=(25,1))],
[*[sg.InputOptionMenu(('Peripheral 0', 'Peripheral 1', 'Peripheral 2', 'Peripheral 3', 'Peripheral 4')) for i in range(num_buttons)]],
]
devices_window_with_device = sg.Window('LightSwitch::' + platform + "::devices", devices_layout_1, size=(600, 400), element_justification='c')
devices_window.Close()
devices_window = devices_window_with_device
main_window.close()