Source

pida-hacks / pida / services / manhole / manhole.py

Full commit
# -*- coding: utf-8 -*-
"""
    The debug python shell

    :copyright: 2005-2008 by The PIDA Project
    :license: GPL 2 or later (see README/COPYING/LICENSE)
"""
import py
import gtk

# PIDA Imports
from pida.core.environment import home, workspace_name
from pida.core.service import Service
from pida.core.actions import ActionsConfig
from pida.ui.views import PidaView

from pygtkhelpers.debug.console import Console

# locale
from pida.core.locale import Locale
locale = Locale('manhole')
_ = locale.gettext


class ManholeActionsConfig(ActionsConfig):


    actions = [
        gtk.ToggleAction('show_manhole',
            _('PIDA Internal Shell'),
            _('Open the PIDA Internal Shell'),
            'face-monkey'),
    ]

    accels = {
        'show_manhole': '<Shift><Control>M',
    }

    def on_show_manhole(self, action):
        if action.get_active():
            self.svc.show_manhole()
        else:
            self.svc.hide_manhole()

class ManholeView(PidaView):

    key = 'manhole.shell'
    icon_name = 'face-monkey'

    label_text = _('Debug PIDA')

    def create_ui(self):
        console = Console(locals=self.svc.get_local_dict(),
                          banner=_("PIDA Shell. Keep breathing."),
                          use_rlcompleter=False)
        sw = gtk.ScrolledWindow()
        sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        sw.add(console)
        sw.show_all()
        self.add_main_widget(sw)
        for path in (py.path.local(__file__).dirpath()/"manholerc.py",
                      home()/"manhole.rc",
                      home()/("manhole.%s.rc" %workspace_name())):
            if path.check():
                #console.do_raw_input(line)
                console.execfile(str(path))

    def can_be_closed(self):
        self.svc.get_action('show_manhole').set_active(False)

# Service class
class Manhole(Service):
    """Describe your Service Here""" 

    actions_config = ManholeActionsConfig
    
    def start(self):
        self._view = ManholeView(self)

    def show_manhole(self):
        self.boss.cmd('window', 'add_view', paned='Terminal', view=self._view)

    def hide_manhole(self):
        self.boss.cmd('window', 'remove_view', view=self._view)

    def get_local_dict(self):
        return dict(boss=self.boss)

# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79: