Description:
merge with brython
Commit status:
[Not Reviewed]
References:
merge bootstrap
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r583:8d31c8c43cb3 - - 3 files changed: 232 inserted, 1 deleted

@@ -34,6 +34,7
34 //= require jquery-tablesorter
34 //= require jquery-tablesorter
35 //= require best_in_place
35 //= require best_in_place
36 //= require best_in_place.jquery-ui
36 //= require best_in_place.jquery-ui
37 + //= require brython
37
38
38 // since this is after blank line, it is not downloaded
39 // since this is after blank line, it is not downloaded
39 //x= require prototype
40 //x= require prototype
@@ -32,3 +32,233
32 - if @submission
32 - if @submission
33 = render :partial => 'submission_short',
33 = render :partial => 'submission_short',
34 :locals => {:submission => @submission, :problem_name => @problem.name }
34 :locals => {:submission => @submission, :problem_name => @problem.name }
35 + .row
36 + .col-md-12
37 + %h2 Console
38 + %textarea#console{style: 'height: 100%; width: 100%;background-color:#000;color:#fff;font-family: consolas, monaco, "Droid Sans Mono";',rows: 20}
39 +
40 + :javascript
41 + $(document).ready(function() {
42 + brython();
43 + });
44 +
45 +
46 + %script#__main__{type:'text/python3'}
47 + :plain
48 + import sys
49 + import traceback
50 +
51 + from browser import document as doc
52 + from browser import window, alert, console
53 +
54 + _credits = """ Thanks to CWI, CNRI, BeOpen.com, Zope Corporation and a cast of thousands
55 + for supporting Python development. See www.python.org for more information."""
56 +
57 + _copyright = """Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com
58 + All Rights Reserved.
59 +
60 + Copyright (c) 2001-2013 Python Software Foundation.
61 + All Rights Reserved.
62 +
63 + Copyright (c) 2000 BeOpen.com.
64 + All Rights Reserved.
65 +
66 + Copyright (c) 1995-2001 Corporation for National Research Initiatives.
67 + All Rights Reserved.
68 +
69 + Copyright (c) 1991-1995 Stichting Mathematisch Centrum, Amsterdam.
70 + All Rights Reserved."""
71 +
72 + _license = """Copyright (c) 2012, Pierre Quentel pierre.quentel@gmail.com
73 + All rights reserved.
74 +
75 + Redistribution and use in source and binary forms, with or without
76 + modification, are permitted provided that the following conditions are met:
77 +
78 + Redistributions of source code must retain the above copyright notice, this
79 + list of conditions and the following disclaimer. Redistributions in binary
80 + form must reproduce the above copyright notice, this list of conditions and
81 + the following disclaimer in the documentation and/or other materials provided
82 + with the distribution.
83 + Neither the name of the <ORGANIZATION> nor the names of its contributors may
84 + be used to endorse or promote products derived from this software without
85 + specific prior written permission.
86 +
87 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
88 + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
89 + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
90 + ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
91 + LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
92 + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
93 + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
94 + INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
95 + CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
96 + ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
97 + POSSIBILITY OF SUCH DAMAGE.
98 + """
99 +
100 + def credits():
101 + print(_credits)
102 + credits.__repr__ = lambda:_credits
103 +
104 + def copyright():
105 + print(_copyright)
106 + copyright.__repr__ = lambda:_copyright
107 +
108 + def license():
109 + print(_license)
110 + license.__repr__ = lambda:_license
111 +
112 + def write(data):
113 + doc['console'].value += str(data)
114 +
115 +
116 + sys.stdout.write = sys.stderr.write = write
117 + history = []
118 + current = 0
119 + _status = "main" # or "block" if typing inside a block
120 +
121 + # execution namespace
122 + editor_ns = {'credits':credits,
123 + 'copyright':copyright,
124 + 'license':license,
125 + '__name__':'__main__'}
126 +
127 + def cursorToEnd(*args):
128 + pos = len(doc['console'].value)
129 + doc['console'].setSelectionRange(pos, pos)
130 + doc['console'].scrollTop = doc['console'].scrollHeight
131 +
132 + def get_col(area):
133 + # returns the column num of cursor
134 + sel = doc['console'].selectionStart
135 + lines = doc['console'].value.split('\n')
136 + for line in lines[:-1]:
137 + sel -= len(line) + 1
138 + return sel
139 +
140 +
141 + def myKeyPress(event):
142 + global _status, current
143 + if event.keyCode == 9: # tab key
144 + event.preventDefault()
145 + doc['console'].value += " "
146 + elif event.keyCode == 13: # return
147 + src = doc['console'].value
148 + if _status == "main":
149 + currentLine = src[src.rfind('>>>') + 4:]
150 + elif _status == "3string":
151 + currentLine = src[src.rfind('>>>') + 4:]
152 + currentLine = currentLine.replace('\n... ', '\n')
153 + else:
154 + currentLine = src[src.rfind('...') + 4:]
155 + if _status == 'main' and not currentLine.strip():
156 + doc['console'].value += '\n>>> '
157 + event.preventDefault()
158 + return
159 + doc['console'].value += '\n'
160 + history.append(currentLine)
161 + current = len(history)
162 + if _status == "main" or _status == "3string":
163 + try:
164 + _ = editor_ns['_'] = eval(currentLine, editor_ns)
165 + if _ is not None:
166 + write(repr(_)+'\n')
167 + doc['console'].value += '>>> '
168 + _status = "main"
169 + except IndentationError:
170 + doc['console'].value += '... '
171 + _status = "block"
172 + except SyntaxError as msg:
173 + if str(msg) == 'invalid syntax : triple string end not found' or \
174 + str(msg).startswith('Unbalanced bracket'):
175 + doc['console'].value += '... '
176 + _status = "3string"
177 + elif str(msg) == 'eval() argument must be an expression':
178 + try:
179 + exec(currentLine, editor_ns)
180 + except:
181 + traceback.print_exc()
182 + doc['console'].value += '>>> '
183 + _status = "main"
184 + elif str(msg) == 'decorator expects function':
185 + doc['console'].value += '... '
186 + _status = "block"
187 + else:
188 + traceback.print_exc()
189 + doc['console'].value += '>>> '
190 + _status = "main"
191 + except:
192 + traceback.print_exc()
193 + doc['console'].value += '>>> '
194 + _status = "main"
195 + elif currentLine == "": # end of block
196 + block = src[src.rfind('>>>') + 4:].splitlines()
197 + block = [block[0]] + [b[4:] for b in block[1:]]
198 + block_src = '\n'.join(block)
199 + # status must be set before executing code in globals()
200 + _status = "main"
201 + try:
202 + _ = exec(block_src, editor_ns)
203 + if _ is not None:
204 + print(repr(_))
205 + except:
206 + traceback.print_exc()
207 + doc['console'].value += '>>> '
208 + else:
209 + doc['console'].value += '... '
210 +
211 + cursorToEnd()
212 + event.preventDefault()
213 +
214 + def myKeyDown(event):
215 + global _status, current
216 + if event.keyCode == 37: # left arrow
217 + sel = get_col(doc['console'])
218 + if sel < 5:
219 + event.preventDefault()
220 + event.stopPropagation()
221 + elif event.keyCode == 36: # line start
222 + pos = doc['console'].selectionStart
223 + col = get_col(doc['console'])
224 + doc['console'].setSelectionRange(pos - col + 4, pos - col + 4)
225 + event.preventDefault()
226 + elif event.keyCode == 38: # up
227 + if current > 0:
228 + pos = doc['console'].selectionStart
229 + col = get_col(doc['console'])
230 + # remove current line
231 + doc['console'].value = doc['console'].value[:pos - col + 4]
232 + current -= 1
233 + doc['console'].value += history[current]
234 + event.preventDefault()
235 + elif event.keyCode == 40: # down
236 + if current < len(history) - 1:
237 + pos = doc['console'].selectionStart
238 + col = get_col(doc['console'])
239 + # remove current line
240 + doc['console'].value = doc['console'].value[:pos - col + 4]
241 + current += 1
242 + doc['console'].value += history[current]
243 + event.preventDefault()
244 + elif event.keyCode == 8: # backspace
245 + src = doc['console'].value
246 + lstart = src.rfind('\n')
247 + if (lstart == -1 and len(src) < 5) or (len(src) - lstart < 6):
248 + event.preventDefault()
249 + event.stopPropagation()
250 +
251 +
252 + doc['console'].bind('keypress', myKeyPress)
253 + doc['console'].bind('keydown', myKeyDown)
254 + doc['console'].bind('click', cursorToEnd)
255 + v = sys.implementation.version
256 + doc['console'].value = "Brython %s.%s.%s on %s %s\n>>> " % (
257 + v[0], v[1], v[2], window.navigator.appName, window.navigator.appVersion)
258 + #doc['console'].value += 'Type "copyright", "credits" or "license" for more information.'
259 + doc['console'].focus()
260 + cursorToEnd()
261 +
262 +
263 +
264 +
@@ -36,5 +36,5
36 config.assets.debug = true
36 config.assets.debug = true
37
37
38 # Prevents assets from rendering twice
38 # Prevents assets from rendering twice
39 - config.serve_static_assets = false
39 + config.serve_static_assets = true
40 end
40 end
You need to be logged in to leave comments. Login now