~azzar1/unity/add-show-desktop-key

329 by mattgiuca
Converted Console from an "app" into a "plugin". It can now be plugged in to
1
# IVLE
2
# Copyright (C) 2007-2008 The University of Melbourne
3
#
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
8
#
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
13
#
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17
18
# Plugin: console
19
# Author: Matt Giuca
20
# Date: 30/1/2008
21
22
# Console plugin. This "mini-app" can be plugged in to another application.
23
# It exposes two functions: "present" and "insert_scripts_styles".
24
# These should both be called at the appropriate time by the implementing
25
# application. See docs on these functions for details.
331 by mattgiuca
Console: Configured console to display properly as a "floating" window in the
26
# Applications also need to call console_init in JavaScript from their own
27
# onload events.
329 by mattgiuca
Converted Console from an "app" into a "plugin". It can now be plugged in to
28
29
from common import util
332 by mattgiuca
console plugin: Now presents minimize/maximize buttons, allowing itself to be
30
import cgi
329 by mattgiuca
Converted Console from an "app" into a "plugin". It can now be plugged in to
31
32
def insert_scripts_styles(scripts, styles):
33
    """Given 2 lists of strings: scripts and styles. These lists are lists of
34
    pathnames, as expected on the "scripts" and "styles" attributes of a
35
    Request object.
36
    This function appends new strings to the ends of each list, as required by
37
    this plugin. It does not add duplicates.
38
    """
39
    _append_if_absent(scripts,
40
        "media/common/json2.js",
41
        "media/common/md5.js",
42
        "media/common/util.js",
43
        "media/console/console.js")
44
    _append_if_absent(styles,
45
        "media/console/console.css")
46
332 by mattgiuca
console plugin: Now presents minimize/maximize buttons, allowing itself to be
47
def present(req, windowpane=False):
329 by mattgiuca
Converted Console from an "app" into a "plugin". It can now be plugged in to
48
    """Writes the HTML for this plugin into a request stream.
49
    May utilise other properties of the Request object in generating the HTML.
332 by mattgiuca
console plugin: Now presents minimize/maximize buttons, allowing itself to be
50
    windowpane: If True, starts the console in "window pane" mode, where it
51
    will float over the page and have a "minimize" button.
329 by mattgiuca
Converted Console from an "app" into a "plugin". It can now be plugged in to
52
    """
332 by mattgiuca
console plugin: Now presents minimize/maximize buttons, allowing itself to be
53
    req.write("""<div id="console_body">
54
  <div id="console_heading">Python Console
55
""")
56
    if windowpane:
57
        req.write("""<span class="console_button minimize">
58
      <a onclick="console_minimize()"
59
        title="Minimize the Python console">
60
        <img src="%s" /></a>
61
    </span>
62
""" % cgi.escape(util.make_path("media/images/interface/minimize.png")))
63
    req.write("""</div>
64
  <div id="console_body2">
329 by mattgiuca
Converted Console from an "app" into a "plugin". It can now be plugged in to
65
  <div id="console_output">
66
  </div>
67
  <div id="console_input">
332 by mattgiuca
console plugin: Now presents minimize/maximize buttons, allowing itself to be
68
    <div id="console_inputArea">
69
    </div>
70
    <label id="console_prompt">&gt;&gt;&gt;&nbsp;</label>
71
    <input id="console_inputText"
339 by mattgiuca
console:
72
      type="text" size="80" onkeypress="return catch_input(event.keyCode)" />
332 by mattgiuca
console plugin: Now presents minimize/maximize buttons, allowing itself to be
73
""")
74
    if windowpane:
75
        req.write("""<span class="console_button maximize">
76
      <a onclick="console_maximize()"
77
        title="Open up the Python console">
78
        <img src="%s" /></a>
79
    </span>
80
""" % cgi.escape(util.make_path("media/images/interface/maximize.png")))
81
    req.write("""</div>
331 by mattgiuca
Console: Configured console to display properly as a "floating" window in the
82
</div></div>
332 by mattgiuca
console plugin: Now presents minimize/maximize buttons, allowing itself to be
83
""")
84
    if windowpane:
85
        req.write("""
331 by mattgiuca
Console: Configured console to display properly as a "floating" window in the
86
<!-- Console filler, provides extra vertical space to stop the console
87
     covering over the bottom content -->
88
<div id="console_filler"></div>
329 by mattgiuca
Converted Console from an "app" into a "plugin". It can now be plugged in to
89
""")
90
91
def _append_if_absent(list, *values):
92
    """Appends an arbitray number of values to a list, but omits values that
93
    are already contained within the list."""
94
    for value in values:
95
        if not value in list:
96
            list.append(value)