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
|
# Copyright (C) 2009, Tutorius.org
# Greatly influenced by sugar/activity/namingalert.py
#
# 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
""" Tutorial Editor Interpreter Module
"""
import gtk
import pango
from sugar.tutorius.ipython_view import *
from gettext import gettext as _
class EditorInterpreter(gtk.Window):
"""
Interpreter that will be shown to the user
"""
__gtype_name__ = 'TutoriusEditorInterpreter'
def __init__(self, activity=None):
gtk.Window.__init__(self)
self._activity = activity
# Set basic properties of window
self.set_decorated(False)
self.set_resizable(False)
self.set_modal(False)
# Connect to realize signal from ?
self.connect('realize', self.__realize_cb)
# Use an expander widget to allow minimizing
self._expander = gtk.Expander(_("Editor Interpreter"))
self._expander.set_expanded(True)
self.add(self._expander)
self._expander.connect("notify::expanded", self.__expander_cb)
# Use the IPython widget to embed
self.interpreter = IPythonView()
self.interpreter.set_wrap_mode(gtk.WRAP_CHAR)
# Expose the activity object in the interpreter
self.interpreter.updateNamespace({'activity':self._activity})
# Use a scroll window to permit scrolling of the interpreter prompt
swd = gtk.ScrolledWindow()
swd.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
swd.add(self.interpreter)
self.interpreter.show()
# Notify GTK that expander is ready
self._expander.add(swd)
self._expander.show()
# Notify GTK that the scrolling window is ready
swd.show()
def __expander_cb(self, *args):
"""Callback for the window expander toggling"""
if self._expander.get_expanded():
self.__move_expanded()
else:
self.__move_collapsed()
def __move_expanded(self):
"""Move the window to it's expanded position"""
swidth = gtk.gdk.screen_width()
sheight = gtk.gdk.screen_height()
# leave room for the scrollbar at the right
width = swidth - 20
height = 200
self.set_size_request(width, height)
# Put at the bottom of the screen
self.move(0, sheight-height)
def __move_collapsed(self):
"""Move the window to it's collapsed position"""
width = 150
height = 40
swidth = gtk.gdk.screen_width()
sheight = gtk.gdk.screen_height()
self.set_size_request(width, height)
self.move(((swidth-width)/2)-150, sheight-height)
def __realize_cb(self, widget):
"""Callback for realize"""
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DIALOG)
self.window.set_accept_focus(True)
self.__move_expanded()
|