-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathphotonmain.py
228 lines (175 loc) · 9.16 KB
/
photonmain.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
# ************************************************************************************************#
# ************************************************************************************************#
# Directory Structure
# ************************************************************************************************#
# ************************************************************************************************#
# /photonmain.py # primary program
# /pgvar.py # global variable declarations
# /pgui.py # photon gui elements and buttons
# /pfunc.py # functions
# /pclass.py # button processing class that handles drawing / displaying UI
# /pbproc.py # processing sticky, group, dropdown etc button actions
# /photon_ref.py # references, dev notes, style guide, modification instructions
# ************************************************************************************************#
# ************************************************************************************************#
# Import Modules
# ************************************************************************************************#
# ************************************************************************************************#
# # public python modules
import pygame
import random
import math
import sys
import time # for FPS functions
import inspect # for displaying the line number of the code in print commands
# # unique modules for this app
import pgvar
import pfunc
import pgui
import pclass
import pbproc
# ************************************************************************************************#
# ************************************************************************************************#
# inistial variables (for this module)
# ************************************************************************************************#
# ************************************************************************************************#
moduleName = "photonmain.py"
screen = pygame.display.set_mode((pgvar.pygame_window_width, pgvar.pygame_window_height))
# ************************************************************************************************#
# ************************************************************************************************#
# MAIN CODE
# ************************************************************************************************#
# ************************************************************************************************#
####### INITIALIZE DISPLAY ##########
pfunc.initializeDisplay()
####### MAIN PROGRAM LOOP ##########
running = True
while running:
if pgui.buttonFPS["enabled"] == True:
pygame.draw.rect(screen, pgvar.color_blue, (pgvar.pygame_window_width - 100, pgvar.pygame_window_height - 30, 80, 20))
pfunc.count_fps()
pfunc.show_fps()
for event in pygame.event.get():
if event.type == pygame.QUIT:
running = False
if event.type == pygame.MOUSEBUTTONDOWN:
(mouseX, mouseY) = pygame.mouse.get_pos() # will run continually while button is held down
print moduleName, pfunc.lineNum(), "mouseX = ", mouseX, "mouseY = ", mouseY # this if.even MOUSEBUTTONDOWN **MUST** be under the for event in pygame.event.get() to run only once
selected_button = pfunc.findButton(pfunc.my_buttons, mouseX, mouseY)
print moduleName, pfunc.lineNum(), "selected button = ", selected_button
if selected_button != None:
if selected_button.button_label_txt == "EXIT":
print moduleName, pfunc.lineNum(), "you pressed exit"
running = False
# # # PUSHY EVENT processing # # #
if selected_button.buttonType == "pushy":
print moduleName, pfunc.lineNum(), "running MOUSEBUTTONDOWN pushy event"
print moduleName, pfunc.lineNum(), "selected_button.color was :", selected_button.color
selected_button.color = pgvar.UI_button_click_color
print moduleName, pfunc.lineNum(), "selected_button.color now : ", selected_button.color
selected_button.buttonEnabled = True
print moduleName, pfunc.lineNum(), "clicked button is a pushy temporary button"
if selected_button.button_name == "command01":
print moduleName, pfunc.lineNum(), "you clicked command01"
pgui.buttonCommand01["enabled"] = True
pgui.buttonCommand01["color"] = pgvar.UI_button_click_color
pfunc.defineButtons()
print moduleName, pfunc.lineNum(), "____drawing buttons from pushy event"
for i, button in enumerate(pfunc.my_buttons):
button.display()
print moduleName, pfunc.lineNum(), "running code for Command01"
# command01 function call goes here:
if selected_button.button_name == "command02":
print moduleName, pfunc.lineNum(), "you clicked command02"
pgui.buttonCommand02["enabled"] = True
pgui.buttonCommand02["color"] = pgvar.UI_button_click_color
pfunc.defineButtons()
print moduleName, pfunc.lineNum(), "____drawing buttons from pushy event"
for i, button in enumerate(pfunc.my_buttons):
button.display()
print moduleName, pfunc.lineNum(), "running code for Command02"
# command02 function call goes here:
if selected_button.button_name == "command03":
print moduleName, pfunc.lineNum(), "you clicked command03"
pgui.buttonCommand03["enabled"] = True
pgui.buttonCommand03["color"] = pgvar.UI_button_click_color
pfunc.defineButtons()
print moduleName, pfunc.lineNum(), "____drawing buttons from pushy event"
for i, button in enumerate(pfunc.my_buttons):
button.display()
print moduleName, pfunc.lineNum(), "running code for Command03"
# command03 function call goes here:
# # # OTHER BUTTON TYPES # # #
if selected_button.buttonType == "sticky":
print moduleName, pfunc.lineNum(), "running sticky event"
pbproc.updateStickyButtons(selected_button.button_name)
if selected_button.buttonType == "group":
print moduleName, pfunc.lineNum(), "running group type button event"
pbproc.updateGroupButtons(selected_button.button_name)
if selected_button.buttonType == "dropdown":
print moduleName, pfunc.lineNum(), "running dropdown button event"
pbproc.updateDropdownButtons(selected_button.button_name)
if selected_button.buttonType == "textEntry":
print moduleName, pfunc.lineNum(), "running text entry event"
pbproc.updateTextEntry(selected_button.button_name)
if selected_button.buttonType == "menu":
print pfunc.lineNum(), "running menu button event"
pbproc.updateMenuButtons(selected_button.button_name)
if event.type == pygame.KEYDOWN:
print "you pressed a key"
if pgui.textField01["enabled"] == True:
if event.key == pygame.K_RETURN:
print(pgvar.entered_text)
#entered_text = ""
pgui.textField01["label_txt"] = pgvar.entered_text
pgui.textField01["enabled"] = False
pgui.textField01["color"] = pgvar.UI_text_entry_box_color
pfunc.defineButtons()
pfunc.enumerateButtons()
elif event.key == pygame.K_BACKSPACE:
pgvar.entered_text = pgvar.entered_text[:-1]
pgui.textField01["label_txt"] = pgvar.entered_text
pfunc.defineButtons()
pfunc.enumerateButtons()
else:
if len(pgvar.entered_text) <= 15:
pgvar.entered_text += event.unicode
print "entered_text", pgvar.entered_text
pgui.textField01["label_txt"] = pgvar.entered_text
pfunc.defineButtons()
pfunc.enumerateButtons()
if event.type == pygame.MOUSEBUTTONUP:
if selected_button != None:
if selected_button.buttonType == "pushy":
print moduleName,pfunc.lineNum(), "running MOUSEBUTTONUP pushy event"
print moduleName, pfunc.lineNum(), "selected_button.color was :", selected_button.color
selected_button.color = pgvar.UI_button_color #reverts button back to normal color after letting go of mouse
print moduleName, pfunc.lineNum(), "selected_button.color now : ", selected_button.color
if selected_button.button_name == "command01":
print moduleName, pfunc.lineNum(), "you clicked command01"
pgui.buttonCommand01["enabled"] = False
pgui.buttonCommand01["color"] = pgvar.UI_button_color
pfunc.defineButtons()
print moduleName, pfunc.lineNum(), "____drawing buttons from pushy event command01"
for i, button in enumerate(pfunc.my_buttons):
button.display()
if selected_button.button_name == "command02":
print moduleName, pfunc.lineNum(), "you clicked command02"
pgui.buttonCommand02["enabled"] = False
pgui.buttonCommand02["color"] = pgvar.UI_button_color
pfunc.defineButtons()
print moduleName, pfunc.lineNum(), "____drawing buttons from pushy event command02"
for i, button in enumerate(pfunc.my_buttons):
button.display()
if selected_button.button_name == "command03":
print moduleName, pfunc.lineNum(), "you clicked command03"
pgui.buttonCommand03["enabled"] = False
pgui.buttonCommand03["color"] = pgvar.UI_button_color
pfunc.defineButtons()
print moduleName, pfunc.lineNum(), "____drawing buttons from pushy event command03"
for i, button in enumerate(pfunc.my_buttons):
button.display()
for i, button in enumerate(pfunc.my_buttons):
button.display()
# always do this last
pygame.display.flip()