Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/terminal_gui.py
blob: 2d80806f6cc41f1f31f8d5674e2c57dbd2539efc (plain)
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
#!/usr/bin/env python
# Copyright (C) 2009, George Hunt <georgejhunt@gmail.com>
# Copyright (C) 2009, One Laptop Per Child
#
# 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

#major packages
from gettext import gettext as _
import gtk
from exceptions import NotImplementedError

#sugar stuff
from sugar.graphics.toolbutton import ToolButton
import sugar.graphics.toolbutton

#application stuff
from terminal import Terminal
import editor
from help import Help
import pytoolbar

from  pydebug_logging import _logger, log_environment

class TerminalGui(Terminal):
    def __init__(self,activity, top_level_toolbox):
        self._activity = activity
        self.toolbox = top_level_toolbox
        
        Terminal.__init__(self,self)

        #set up tool box/menu buttons
        activity_toolbar = self.toolbox.get_activity_toolbar()

        separator = gtk.SeparatorToolItem()
        separator.set_draw(True)
        separator.show()
        activity_toolbar.insert(separator, 0)
        
        activity_go = ToolButton()
        activity_go.set_stock_id('gtk-media-forward')
        activity_go.set_icon_widget(None)
        activity_go.set_tooltip(_('Start Debugging'))
        activity_go.connect('clicked', self.project_run_cb)
        activity_go.add_accelerator('clicked',self.get_accelerator(),ord('O'),gtk.gdk.CONTROL_MASK,gtk.ACCEL_VISIBLE)
        activity_go.show()
        activity_toolbar.insert(activity_go, 0)
        

        activity_copy_tb = ToolButton('edit-copy')
        activity_copy_tb.set_tooltip(_('Copy'))
        activity_copy_tb.connect('clicked', self._copy_cb)
        activity_toolbar.insert(activity_copy_tb, 3)
        activity_copy_tb.show()

        activity_paste_tb = ToolButton('edit-paste')
        activity_paste_tb.set_tooltip(_('Paste'))
        activity_paste_tb.connect('clicked', self._paste_cb)
        activity_paste_tb.add_accelerator('clicked',self.get_accelerator(),ord('V'),gtk.gdk.CONTROL_MASK,gtk.ACCEL_VISIBLE)
        activity_toolbar.insert(activity_paste_tb, 4)
        activity_paste_tb.show()

        activity_tab_tb = sugar.graphics.toolbutton.ToolButton('list-add')
        activity_tab_tb.set_tooltip(_("Open New Tab"))
        activity_tab_tb.add_accelerator('clicked',self.get_accelerator(),ord('T'),gtk.gdk.CONTROL_MASK,gtk.ACCEL_VISIBLE)
        activity_tab_tb.show()
        activity_tab_tb.connect('clicked', self._open_tab_cb)
        activity_toolbar.insert(activity_tab_tb, 5)

        activity_tab_delete_tv = sugar.graphics.toolbutton.ToolButton('list-remove')
        activity_tab_delete_tv.set_tooltip(_("Close Tab"))
        activity_tab_delete_tv.show()
        activity_tab_delete_tv.connect('clicked', self._close_tab_cb)
        activity_toolbar.insert(activity_tab_delete_tv, 6)


        activity_fullscreen_tb = sugar.graphics.toolbutton.ToolButton('view-fullscreen')
        activity_fullscreen_tb.set_tooltip(_("Fullscreen"))
        activity_fullscreen_tb.connect('clicked', self._activity._fullscreen_cb)
        activity_toolbar.insert(activity_fullscreen_tb, 7)
        activity_fullscreen_tb.hide()
        
        ###############################################################################
        
    def get_activity_toolbar(self):
        raise NotImplimentedError
        
    def get_accelerator(self):
        raise NotImplimentedError
        
    def project_run_cb(self,button):
        _logger.debug('entered project_run_cb')
        """
        start_script = ['python','import sys','from Rpyc import *','from Rpyc.Utils import remote_interpreter',
                        'c = SocketConnection("localhost")','remote_interpreter(c)']
        for l in start_script:
            self.feed_virtual_terminal(0,l+'\r\n')
        """
        self.start_debugging()
        
    def __keep_clicked_cb(self, button):
        self._keep_activity_info()

    def start_debugging(self): #check for a start up script in bundle root or bundle_root/bin
        command = self.activity_dict.get('command','')
        if command == '':
            self._activity.util.alert('No Activity Loaded')
            return
        _logger.debug("Command to execute:%s."%command)
        self.save_all()
        
        #try to restore a clean debugging environment
        #self.feed_virtual_terminal(0,'quit()\r\n\r\n')
        
        self._activity.set_visible_canvas(self.panes['TERMINAL'])
        #change the menus
        message = _('\n\n Use the HELP in the Ipython interpreter to learn to DEBUG your program.\n')
        self._activity.message_terminal(0,message)
        
        #get the ipython shell object
        """ this works but is not needed now
        ip = ipapi.get()
        arg_str = 'run -d -b %s %s'%(self.pydebug_path,self.child_path)
        ip.user_ns['go'] = arg_str
        _logger.debug('about to use "%s" to start ipython debugger\n'%(arg_str))
        """
        go_cmd = _('go')
        self.feed_virtual_terminal(0,'%s\n'%(go_cmd,))
        pass