-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPassCodeScreen.py
More file actions
131 lines (106 loc) · 3.68 KB
/
PassCodeScreen.py
File metadata and controls
131 lines (106 loc) · 3.68 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
"""
@file PassCodeScreen.py
File that contains the PassCodeScreen Class to interact with the PassCodeScreen.
There is no need to copy the .kv file into your project simply import this class and set the main screen name as well as transition back screen
"""
from kivy.lang import Builder
from kivy.uix.screenmanager import Screen
import os.path
PASSWORD = '7266'
USERPW = '1234'
passcode_screen_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), "", "PassCodeScreen.kv")
Builder.load_file(passcode_screen_path)
ADMIN_EVENTS_SCREEN = None
TRANSITION_BACK_SCREEN = 'main'
"""
Class to display a passcode on screen to advance to admin screen
"""
class PassCodeScreen(Screen):
"""
Class used to enter the PassCodeScreen to enter the admin screen
"""
def __init__(self, **kw):
super(PassCodeScreen, self).__init__(**kw)
def add_num(self, num):
"""
Add a number to the current password entry
:param num: Number to add
:return: None
"""
global USERPW
self.ids.pw.text += '* '
USERPW += str(num)
def remove_num(self):
"""
Remove a number from the current password entry
:return: None
"""
global USERPW
self.ids.pw.text = self.ids.pw.text[:len(self.ids.pw.text) - 2]
USERPW = USERPW[:len(USERPW) - 1]
def check_pass(self):
"""
Check to see if the password was entered correctly
:return: None
"""
global USERPW
if PASSWORD == USERPW:
self.ids.pw.text = ' '
USERPW = ''
if ADMIN_EVENTS_SCREEN is None:
print("Specify the admin screen name by calling PassCodeScreen.set_admin_events_screen")
return
self.parent.current = ADMIN_EVENTS_SCREEN
def transition_back(self):
"""
Transition back to given transition back screen
:return: None
"""
global USERPW
self.ids.pw.text = ""
USERPW = ''
self.parent.current = TRANSITION_BACK_SCREEN
@staticmethod
def set_admin_events_screen(screen):
"""
Set the name of the screen to transition to when the password is correct
:param screen: Name of the screen to transition to
:return: None
"""
global ADMIN_EVENTS_SCREEN
ADMIN_EVENTS_SCREEN = screen
@staticmethod
def set_transition_back_screen(screen):
"""
Set the screen to transition back to when the "Back to Game" button is pressed
:param screen: Name of the screen to transition back to
:return: None
"""
global TRANSITION_BACK_SCREEN
TRANSITION_BACK_SCREEN = screen
@staticmethod
def set_password(pswd):
"""
Change the default password
:param pswd: New password
:return: None
"""
global PASSWORD
PASSWORD = pswd
@staticmethod
def change_main_screen_name(name):
"""
Change the name of the screen to add the hidden button to go to the admin screen
NOTE: This only needs to be run ONCE, once it is called with the new name you can remove the call from your code
:param name: Name of the main screen of the UI
:return: None
"""
if name == '':
return
with open(passcode_screen_path) as file:
data = file.readlines()
# This needs to be updated every time there are line changes in the PassCodeScreen.kv
# TODO implement a better way to dynamically change the main screen name
data[134] = '<' + name + '>\n'
with open(passcode_screen_path, 'w') as file:
file.writelines(data)