-
Notifications
You must be signed in to change notification settings - Fork 0
/
hello.py
188 lines (105 loc) · 2.74 KB
/
hello.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
#!/usr/bin/env python2
#-*- coding: utf-8 -*-
#lol bootstrap, © koo5
class Node(object):
pass
class Text(Node):
def __init__(self, value):
assert(isinstance(value, str)
self.value = value
class Print(Node):
def __init__(self, value):
assert(isinstance(value, str)
self.value = value
#Rule("importing X")
class Namespace(List):
pass
syntax = {'program': {'codes':Codes, 'name':Text
class Program(Node):
def __init__(self, imports, codes):
self.python_imports = List([Import(x) for x in ['__builtin__'] + imports
self.codes = codes
def run(self):
def python_module
program = Program(
imports=['os', 'pygame'],
codes = Codes(
items =
[
Namespace(items = List(
[
Import(
PythonCall(module = 'os', name = 'putenv', arguments = PythonTuple(["SDL_VIDEO_ALLOW_SCREENSAVER","1"]))
Function(
names = ["regenerate LICENSE file"],
codes = Codes([
Print(Text("boo!"))
]
)
done = False
contact = "irc: sirdancealot @ freenode"
def shit(gone_wrong):
print(gone_wrong)
print("\nfor support:",contact)
try:
import pygame
import pygame.gfxdraw
except Exception as e:
shit("i need pygame. please install pygame. sudo apt-get install pygame / yum install pygame ....")
raise(e)
try:
import Pyro4
except Exception as e:
shit("i need pyro4. please install. easy_install pyro4")
raise(e)
Pyro4.config.SERIALIZERS_ACCEPTED.add('pickle')
class Screen():
def __init__(s):
pygame.init()
pygame.display.set_caption("lol") #window title
#sdl, which pygame is based on, has its own keyboard delay and repeat rate
pygame.key.set_repeat(300,30) #first candidate for a settings block
s.w = 640
s.h = 480
s.s = pygame.display.set_mode((s.w,s.h))
s.f = pygame.font.SysFont('monospace', 18)
s.fw = s.f.render(" ",False,(0,0,0)).get_rect().width
s.fh = s.f.get_height()
s.setroot([['text', "Hi!", pygame.Color(255,150,0), 0, 0]])
def setroot(s,r):
s.root=r
def draw(s):
s.s.fill((0,0,0))
for i in s.root:
try:
if i[0] == 'text':
s.s.blit(s.f.render(i[1], True, i[2]), (i[3], i[4]))
if i[0] == 'rect':
pygame.gfxdraw.rectangle(s.s, i[1], i[2])
except Exception() as e:
print i
raise e
pygame.display.update()
def send(x):
print x
def process_event(e):
send(e)
if e.type == pygame.QUIT:
exit()
elif e.type == pygame.VIDEOEXPOSE:
draw()
def main():
scr = Screen()
daemon = pyro4.Daemon()
Pyro4.locateNS().register("lol.scr", daemon.register(scr))
scr.draw()
pygame.time.set_timer(pygame.USEREVENT, 1000)#40)#SIGINT timer
while not done:
try:
process_event(pygame.event.wait())
except KeyboardInterrupt() as e:
pygame.display.iconify()
raise e
except Exception() as e:
pass
main()