-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor.py
executable file
·264 lines (157 loc) · 4.14 KB
/
editor.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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
#!/usr/bin/env python2
#-*- coding: utf-8 -*-
#lol bootstrap, © koo5
"""
current attack plan:
create the ast nodes and an interpreter in python
codify syntax and write an ide in lemon
"""
class Node(object):
pass
class Rule(Node):
def __init__(self, codes, time, name):
self.codes = codes
self.time = time
self.name = name
def run(self):
self.codes.run()
class Import(Node):
"an import of a python module"
def __init__(self, name):
self.name = name
def run(self):
self.module = __import__(self.name)
class Program(Node):
"""the root of what the interpreter interprets"""
def __init__(self, imports, codes):
imps = ['__builtin__'] + imports
self.imports = [Import(i) for i in imps]
def get_rules(self):
result = {'before':{}, 'after':{}, 'instead of':{}}
for i in self.codes.items:
if isinstance(i, Rule):
result[i.time][i.name] = i
return result
def call_rule(self, time, name):
if self.get_rules()[time].has_key(name):
self.get_rules()[time][name].run()
def run(self):
"do eeet"
self.call_rule(['before']['doing imports'])
for i in self.imports.items:
self.statements.run()
Rule("doing imports")
class Codes(List):
def top_level_objects(self):
"return objects defined in the first level only"
"items of type Object in self.items"
"Objects in self.items"
for i in self.items:
if isinstance(i, Object):
yield i
def run(self):
for i in self.items:
i.run()
class Import(Node):
def __init__(self, name):
self.name = name
def run(self):
self.loaded = __import__(name)
class Imports(Node):
def __init__(self, items):
self.items = items
def run(self):
class PythonCall(Node):
def __init__(self, module, name, arguments):
self.module = module
self.name = name
self.arguments = arguments
class PythonTuple(Node):
def __init__(self, items):
self.items = items
#Rule("importing X")
class Namespace(List):
pass
syntax = {'program': {'codes':Codes, 'name':Text
program = Program(
imports = List((List(items=['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()