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
|
# IVLE
# Copyright (C) 2007-2008 The University of Melbourne
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
# Plugin: console
# Author: Matt Giuca
# Date: 30/1/2008
# Console plugin. This "mini-app" can be plugged in to another application.
# It exposes two functions: "present" and "insert_scripts_styles".
# These should both be called at the appropriate time by the implementing
# application. See docs on these functions for details.
from common import util
def insert_scripts_styles(scripts, styles):
"""Given 2 lists of strings: scripts and styles. These lists are lists of
pathnames, as expected on the "scripts" and "styles" attributes of a
Request object.
This function appends new strings to the ends of each list, as required by
this plugin. It does not add duplicates.
"""
_append_if_absent(scripts,
"media/common/json2.js",
"media/common/md5.js",
"media/common/util.js",
"media/console/console.js")
_append_if_absent(styles,
"media/console/console.css")
def present(req):
"""Writes the HTML for this plugin into a request stream.
May utilise other properties of the Request object in generating the HTML.
"""
req.write("""<div id="console_body">
<div id="console_output">
</div>
<div id="console_input">
<div id="console_inputArea">
</div>
<label id="console_prompt">>>> </label>
<input id="console_inputText"
type="text" size="80" onkeypress="catch_input(event.keyCode)" />
</div>
</div>
""")
def _append_if_absent(list, *values):
"""Appends an arbitray number of values to a list, but omits values that
are already contained within the list."""
for value in values:
if not value in list:
list.append(value)
|