/
main.py
187 lines (156 loc) · 5.48 KB
/
main.py
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
import os
import pygame
from kivy.app import App
from kivy.core.window import Window
from kivy.lang import Builder
from kivy.uix.screenmanager import ScreenManager, Screen
from kivy.properties import ObjectProperty
from kivy.uix.slider import Slider
from kivy.animation import Animation, AnimationTransition
from threading import Thread
from time import sleep
from pidev.MixPanel import MixPanel
from pidev.kivy.PassCodeScreen import PassCodeScreen
import pidev.kivy.PauseScreen
from pidev.kivy import DPEAButton
from pidev.kivy import ImageButton
from pidev.Joystick import Joystick
MIXPANEL_TOKEN = "x"
MIXPANEL = MixPanel("Project Name", MIXPANEL_TOKEN)
joystick = Joystick(0, False)
SCREEN_MANAGER = ScreenManager()
MAIN_SCREEN_NAME = 'main'
ADMIN_SCREEN_NAME = 'admin'
IMAGE_SCREEN_NAME = 'image'
class ProjectNameGUI(App):
"""
Class to handle running the GUI Application
"""
def build(self):
"""
Build the application
:return: Kivy Screen Manager instance
"""
return SCREEN_MANAGER
Window.clearcolor = (1, 1, 1, 1) # White
class MainScreen(Screen):
"""
Class to handle the main screen and its associated touch events
"""
counter = ObjectProperty(None)
global x_value
x_value = 0
joy_x_val = ObjectProperty(None)
joy_y_val = ObjectProperty(None)
button_state = ObjectProperty(None)
def counter_button(self):
global x_value
x_value = x_value + 1
self.counter.text = "%d" % x_value
def pressed(self):
"""
Function called on button touch event for button with id: testButton
:return: None
"""
pidev.kivy.PauseScreen.PauseScreen.pause(pause_scene_name='pauseScene', transition_back_scene='main', text="Test", pause_duration=5)
def clicked(self):
SCREEN_MANAGER.current = 'image'
def admin_action(self):
"""
Hidden admin button touch event. Transitions to passCodeScreen.
This method is called from pidev/kivy/PassCodeScreen.kv
:return: None
"""
SCREEN_MANAGER.current = 'passCode'
def animation(self):
anim = Animation(x=50) + Animation(size=(0, 0), duration=1.)
anim.start(self.ids.animation_button)
def joy_update(self): # This should be inside the MainScreen Class
while True:
self.joy_x_val = joystick.get_axis('x')
# self.ids.joy_label_x.x = (self.joy_x_val)
# self.ids.joy_label_y.y = (self.joy_y_val)
self.joy_y_val = joystick.get_axis('y')
self.button_state = joystick.get_button_state(0)
# print("x= ", self.joy_x_val)
# print("y= ", self.joy_y_val)
print("button= ", str(self.button_state))
sleep(.1)
def start_joy_thread(self): # This should be inside the MainScreen Class
Thread(target=self.joy_update).start()
class AdminScreen(Screen):
"""
Class to handle the AdminScreen and its functionality
"""
def __init__(self, **kwargs):
"""
Load the AdminScreen.kv file. Set the necessary names of the screens for the PassCodeScreen to transition to.
Lastly super Screen's __init__
:param kwargs: Normal kivy.uix.screenmanager.Screen attributes
"""
Builder.load_file('AdminScreen.kv')
PassCodeScreen.set_admin_events_screen(ADMIN_SCREEN_NAME) # Specify screen name to transition to after correct password
PassCodeScreen.set_transition_back_screen(MAIN_SCREEN_NAME) # set screen name to transition to if "Back to Game is pressed"
super(AdminScreen, self).__init__(**kwargs)
@staticmethod
def transition_back():
"""
Transition back to the main screen
:return:
"""
SCREEN_MANAGER.current = MAIN_SCREEN_NAME
@staticmethod
def shutdown():
"""
Shutdown the system. This should free all steppers and do any cleanup necessary
:return: None
"""
os.system("sudo shutdown now")
@staticmethod
def exit_program():
"""
Quit the program. This should free all steppers and do any cleanup necessary
:return: None
"""
quit()
"""
Widget additions
"""
class ImageScreen(Screen):
def __init__(self, **kwargs):
"""
Load the AdminScreen.kv file. Set the necessary names of the screens for the PassCodeScreen to transition to.
Lastly super Screen's __init__
:param kwargs: Normal kivy.uix.screenmanager.Screen attributes
"""
Builder.load_file('ImageScreen.kv')
super(ImageScreen, self).__init__(**kwargs)
@staticmethod
def transition_back():
"""
Transition back to the main screen
:return:
"""
SCREEN_MANAGER.current = MAIN_SCREEN_NAME
Builder.load_file('main.kv')
SCREEN_MANAGER.add_widget(MainScreen(name=MAIN_SCREEN_NAME))
SCREEN_MANAGER.add_widget(PassCodeScreen(name='passCode'))
SCREEN_MANAGER.add_widget(pidev.kivy.PauseScreen.PauseScreen(name='pauseScene'))
SCREEN_MANAGER.add_widget(AdminScreen(name=ADMIN_SCREEN_NAME))
SCREEN_MANAGER.add_widget(ImageScreen(name=IMAGE_SCREEN_NAME))
"""
MixPanel
"""
def send_event(event_name):
"""
Send an event to MixPanel without properties
:param event_name: Name of the event
:return: None
"""
global MIXPANEL
MIXPANEL.set_event_name(event_name)
MIXPANEL.send_event()
if __name__ == "__main__":
# send_event("Project Initialized")
# Window.fullscreen = 'auto'
ProjectNameGUI().run()