-
Notifications
You must be signed in to change notification settings - Fork 0
/
stz-test.py
executable file
·192 lines (162 loc) · 7.17 KB
/
stz-test.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
#!/usr/bin/env python
import os
import pygame
import time
import math
import strazoloidwm as stz
#frame/desktop flag tester
def event_test(frameobj, data=None):
#note: you should make sure all non if-statement code is behind if statements. see comments on frame/desktop flags below.
if frameobj.statflg==1:
print(frameobj.name + " stat 1: init call")
elif frameobj.statflg==2:
print(frameobj.name + " stat 2: post-resize call")
elif frameobj.statflg==3:
print(frameobj.name + " stat 3: frame terminate call. type:")
if frameobj.runflg==0:
print(" run 0: wm quit call")
print(frameobj.pid)
print(frameobj.wo)
if frameobj.runflg==2:#the desktop class should never set runflg=2
print(" run 2: frame (window) close call")
print(frameobj.pid)
print(frameobj.wo)
elif frameobj.statflg==4:
print(frameobj.name + " stat 4: clickdown")
elif frameobj.statflg==5:
print(frameobj.name + " stat 5: clickup")
elif frameobj.statflg==6:
print(frameobj.name + " stat 6: keydown")
elif frameobj.statflg==7:
print(frameobj.name + " stat 7: keyup")
elif frameobj.statflg==8:
print(frameobj.name + " stat 8: desktop window resize")
elif frameobj.statflg==9:
print(frameobj.name + " stat 9: frame shade")
elif frameobj.statflg==10:
print(frameobj.name + " stat 10: frame unshade")
elif frameobj.statflg==11:
print(frameobj.name + " stat 11: frame Resizing")
elif frameobj.statflg==12:
print(frameobj.name + " stat 12: desktop quit check \n\t (called upon pygame.QUIT *IF* code12_askbeforequit=True")
return True
#SPECIAL NOTE: Return False here, if you want to, say, show a 'are you sure you want to quit' dialog. use framescape.shutdown() to close in that case.
stz.framestyle=2
#whether to run desktop callback code 12, asking wether to obey pygame.QUIT event and shutdown program.
#return True on code 12 to obey quit event, or False to Ignore quit event.
stz.code12_askbeforequit=True
#NOTE: use framescape.shutdown() method to manually shutdown program.
#if you want the multi-window enviornment to be resizable, set the resizable flag to 1 in the desktop instance.
desk=stz.desktop(800, 600, "Test desktop 1", pumpcall=event_test, resizable=1)
framesc=stz.framescape(desk)
def proccount(frameobj, data=None):
if frameobj.statflg==0:
frameobj.name="frames: " + str(len(framesc.proclist)) + " | ghosts: " + str(len(framesc.ghostproc))
if frameobj.statflg==3:
if frameobj.runflg==2:
#persistence
print("frames/ghosts counter: frame has closed, restoring frame")
#restore frame
framesc.add_frame(frameobj)
#make active frame.
#framesc.raise_frame(frameobj)
def shutdown_test(frameobj, data=None):
if frameobj.statflg==1:
frameobj.name="QUIT TEST: Close this frame to call framescape.shutdown()"
if frameobj.statflg==3:
if frameobj.runflg==2:
framesc.shutdown()
#the following flag values also apply to desktop class except where noted.
#statflg values:
#0=wm system pump call. (called every mainloop of framescape)
#1=startup. system should initialize
#2=frame resize. surface should be redrawn and positions recalibrated. (frames only)
#3=frame close/quit/halt check runflg value for condition.
#4=clickdown
#5=clickup
#6=keydown
#7=keyup
#8=desktop window resize (desktop only) (desktop must have realizability enabled)
#9=window has been shaded. (aka, shrunk to just a title bar. surface is HIDDEN.) (frames only)
#10=window has been unshaded. (aka returned to normal) (frames only)
#11=frame is resizing. render on this instead of code 2, to render while resizing.
# You might also render a simplified screen on code 11, and render the full display on code 2, if needed.
#12=desktop shutdown check, return True: shutdown instantly, return False, don't shutdown. (Must set code12_askbeforequit=True)
#runflg values:
#1=frame is running.
#0=frame has quit due to window manager shutting down.
#2=frame has been closed by user. (frames only)
#ghost tasks can't display anything, hence the name 'ghost'.
#they are useful for things like getting all keyboard events,
#getting all mouse events, etc.
#Also, they are 'pumped' every frame as well, and can be closed
#via their PID, or via passing the ghost instance to framescape.close_ghost(ghost)
#both frame and ghost tasks can be terminated via their unique PID:
#framescape.close_pid(pid)
#in addition frames can be closed via passing the framex instance to:
#ramescape.close_frame(framex)
testghost=stz.ghost("GHOST TASK 1", pumpcall=event_test)
testframe=stz.framex(200, 200, "test --REALLYLONGNAME-- -- -----------", resizable=1, pumpcall=event_test, xpos=10, ypos=0)
#setting xpos/ypos to none or not specifying them will cause strazoloid to try and randomly place the frame within the main window boundry.
testframe2=stz.framex(200, 100, "test2", pumpcall=event_test, xpos=None, ypos=None)
testframe4=stz.framex(400, 100, "quit test", pumpcall=shutdown_test, xpos=None, ypos=None)
tstfrm3_icon=pygame.image.load("testicon1_20px.png")
testframe3=stz.framex(235, 60, "frames: 0 | ghosts: 0", pumpcall=proccount, xpos=550, ypos=100, icon=tstfrm3_icon)
#### SIMPLE DOODLE APP EXAMPLE ####
class drawxq:
def __init__(self):
self.lineflg=0
return
def framecall(self, frameobj, data=None):
if frameobj.statflg==0:
if self.lineflg:
#remove xy position bias using mousehelper.
self.curpos=stz.mousehelper(pygame.mouse.get_pos(), frameobj)
pygame.draw.line(frameobj.surface, (255, 255, 255), self.prevpos, self.curpos, 1)
self.prevpos=self.curpos
elif frameobj.statflg==4:
if data.button==1:
self.prevpos=stz.mousehelper(data.pos, frameobj)
self.lineflg=1
elif data.button==3:
frameobj.surface.fill((0, 0, 0))
elif frameobj.statflg==5:
self.lineflg=0
drawicon=pygame.image.load("doodle.png")
drawinst=drawxq()
drawframe=stz.framex(300, 300, "draw (left=draw, right=reset)", pumpcall=drawinst.framecall, xpos=235, ypos=0, icon=drawicon)
########
#### 'colored' example from docs/events.md (EXAMPLE 2) ####
colorsicon=pygame.image.load("colors1.png")
class colored:
def __init__(self, color=(255, 0, 255)):
self.color=color
def drawdisp(self, frameobj):
frameobj.surface.fill(self.color)
def pumpcall1(self, frameobj, data=None):
if frameobj.statflg==1:
self.drawdisp(frameobj)
#PLEASE NOTE: make your code redraw on statflg 2 if you want to use less CPU when resizing!
#if frameobj.statflg==2:
# self.drawdisp(frameobj)
if frameobj.statflg==11:
self.drawdisp(frameobj)
#purple
colorpurple=colored()
purpleframe=stz.framex(400, 50, "colored (purple) (from docs/events.md)", pumpcall=colorpurple.pumpcall1, xpos=150, ypos=400, resizable=1, sizeminx=250, sizeminy=50, icon=colorsicon)
framesc.add_frame(purpleframe)
#orange
colororange=colored(color=(255, 127, 0))
orangeframe=stz.framex(400, 50, "colored (orange) (from docs/events.md)", pumpcall=colororange.pumpcall1, xpos=150, ypos=500, resizable=1, sizeminx=250, sizeminy=50, icon=colorsicon)
framesc.add_frame(orangeframe)
########
#once we create our framex task objects, we can start them like so:
framesc.add_frame(testframe)
framesc.add_frame(testframe3)
framesc.add_frame(testframe4)
framesc.add_frame(drawframe)
framesc.add_frame(testframe2)
#and for ghost task objects, we do:
framesc.add_ghost(testghost)
#begin wm mainloop.
framesc.process()