~ubuntu-branches/ubuntu/saucy/pida/saucy

« back to all changes in this revision

Viewing changes to src/plugins/boss/plugin.py

  • Committer: Bazaar Package Importer
  • Author(s): Ante Karamatic
  • Date: 2005-09-27 10:19:38 UTC
  • Revision ID: james.westby@ubuntu.com-20050927101938-o7ak8uqyuvewfuw8
Tags: upstream-0.2.2
Import upstream version 0.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*- 
 
2
# vim:set shiftwidth=4 tabstop=4 expandtab textwidth=79:
 
3
# $Id: plugin.py 478 2005-08-02 11:36:48Z aafshar $
 
4
#Copyright (c) 2005 George Cristian Bîrzan gcbirzan@wolfheart.ro
 
5
 
 
6
#Permission is hereby granted, free of charge, to any person obtaining a copy
 
7
#of this software and associated documentation files (the "Software"), to deal
 
8
#in the Software without restriction, including without limitation the rights
 
9
#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
10
#copies of the Software, and to permit persons to whom the Software is
 
11
#furnished to do so, subject to the following conditions:
 
12
 
 
13
#The above copyright notice and this permission notice shall be included in
 
14
#all copies or substantial portions of the Software.
 
15
 
 
16
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
17
#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
18
#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
19
#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
20
#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
21
#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 
22
#SOFTWARE.
 
23
 
 
24
import os
 
25
import sys
 
26
import gtk
 
27
import logging
 
28
 
 
29
import pida.plugin as plugin
 
30
import pida.gtkextra as gtkextra
 
31
import pida.configuration.registry as registry
 
32
import pida.configuration.config as config
 
33
 
 
34
class Plugin(plugin.Plugin):
 
35
    NAME = "Boss"
 
36
    VISIBLE = False
 
37
    
 
38
    def configure(self, reg):
 
39
        self.ftregistry = reg.add_group('filetypes',
 
40
            'Determines which plugins are displayed for which filetypes.')
 
41
        self.ftregistry.add('all',
 
42
            registry.RegistryItem,
 
43
            'project, pastebin, gazpacho',
 
44
            'What plugins to always use (comma separated)')
 
45
        self.ftregistry.add('python',
 
46
            registry.RegistryItem,
 
47
            'python_browser, python_debugger, python_profiler',
 
48
            'What plugins to use only for python files (comma separated)')
 
49
        self.ftregistry.add('None',
 
50
            registry.RegistryItem,
 
51
            '',
 
52
            'What plugins to use on unknown files (comma separated)')
 
53
 
 
54
        self.plugregistry = reg.add_group('plugins',
 
55
            'Determines which plugins are loaded at startup.')
 
56
    
 
57
        for pluginname in self.prop_optional_pluginlist:
 
58
            self.plugregistry.add(pluginname,
 
59
                registry.Boolean,
 
60
                True,
 
61
                'Whether %s wil be loaded at startup (requires restart).' % \
 
62
                    pluginname)
 
63
 
 
64
    def do_init(self):
 
65
        self.filetypes = {}
 
66
        self.filetype_triggered = False
 
67
        self.filetype_current = 'None'
 
68
 
 
69
        self.log = logging.getLogger()
 
70
        self.loghandler = None
 
71
        #logging.basicConfig()
 
72
        self.evt_reset()
 
73
        #sys.stdout = sys.stderr = file('/dev/null', 'w')
 
74
 
 
75
        self.tips = gtk.Tooltips()
 
76
        self.tips.enable()
 
77
 
 
78
        self.child_processes = []
 
79
 
 
80
    def evt_populate(self):
 
81
        self.icons = gtkextra.Icons()
 
82
 
 
83
    def evt_shown(self):
 
84
        pass
 
85
 
 
86
    def evt_reset(self):
 
87
        self.reset_logger()
 
88
        self.reset_io()
 
89
 
 
90
 
 
91
    def reset_logger(self):
 
92
        logfile = self.prop_main_registry.files.log.value()
 
93
        if self.loghandler:
 
94
            self.log.removeHandler(self.loghandler)
 
95
        self.loghandler = logging.FileHandler(logfile)
 
96
        self.log.addHandler(self.loghandler)
 
97
        self.log.setLevel(self.prop_main_registry.log.level.value())
 
98
        
 
99
    def reset_io(self):
 
100
        stdiofile = '%s.io' % self.prop_main_registry.files.log.value()
 
101
        f = open(stdiofile, 'w')
 
102
        sys.stdout = sys.stderr = f
 
103
 
 
104
    def evt_bufferchange(self, buffernumber, buffername):
 
105
        if not self.filetype_triggered:
 
106
            self.filetypes[buffernumber] = 'None'
 
107
        if self.filetype_current != self.filetypes[buffernumber]:
 
108
            self.filetype_current = self.filetypes[buffernumber]
 
109
            self.pida.mainwindow.add_pages(self.get_pluginnames(self.filetype_current))
 
110
        self.filetype_triggered = False
 
111
        self.pida.mainwindow.set_title('PIDA %s' % buffername)
 
112
        
 
113
    def evt_filetype(self, buffernumber, filetype):
 
114
        self.filetype_triggered = True
 
115
        self.filetypes[buffernumber] = filetype
 
116
 
 
117
    def get_pluginnames(self, filetype):
 
118
        genplugins = [s.strip() for s in self.ftregistry.all.value().split(',')]
 
119
        ftplugins = []
 
120
        if hasattr(self.prop_main_registry.filetypes, filetype):
 
121
            fl = getattr(self.prop_main_registry.filetypes, filetype).value()
 
122
            ftplugins = [s.strip() for s in fl.split(',')]
 
123
            # No filetypes for the plugin
 
124
        return genplugins + ftplugins
 
125
 
 
126
    def get_named_plugin(self, name):
 
127
        for plugin in self.plugins:
 
128
            if plugin.NAME == name:
 
129
                return plugin
 
130
 
 
131
    def action_settip(self, widget, tiptext):
 
132
        self.tips.set_tip(widget, tiptext)
 
133
 
 
134
    def action_status(self, message):
 
135
        self.pida.mainwindow.statusbar.push(1, message)
 
136
 
 
137
    def do_log(self, source, message, level):
 
138
        """
 
139
        Log a message.
 
140
        """
 
141
        msg = '%s: %s' % (source, message)
 
142
        self.log.log(level, msg)
 
143
 
 
144
    def action_newbrowser(self, url):
 
145
        """
 
146
        Start a new browser
 
147
        """
 
148
 
 
149
    def action_showconfig(self, pagename=None):
 
150
        """ called to show the config editor """
 
151
        # Create a new configuration editor, and show it.
 
152
        self.configeditor = config.ConfigEditor()
 
153
        self.configeditor.show(pagename)
 
154
 
 
155
    def action_quit(self):
 
156
        """ Quit Pida. """
 
157
        # Tell plugins to die
 
158
        self.do_evt('die')
 
159
        # Fin
 
160
        for pid in self.child_processes:
 
161
            try:
 
162
                os.kill(pid, 15)
 
163
            except OSError:
 
164
                pass
 
165
        gtk.main_quit()
 
166
 
 
167
    def action_newterminal(self, commandline, **kw):
 
168
        """Open a new terminal, by issuing an event"""
 
169
        # Fire the newterm event, the terminal plugin will respond.
 
170
        self.do_evt('terminal', commandline, **kw)
 
171
 
 
172
    def action_fork(self, commandargs):
 
173
        print commandargs
 
174
        pid = os.fork()
 
175
        if pid == 0:
 
176
            try:
 
177
                os.execlp(commandargs[0], *commandargs)
 
178
            except Exception:
 
179
                pass
 
180
        else:
 
181
            self.child_processes.append(pid)
 
182
 
 
183
    def action_accountfork(self, pid):
 
184
        self.child_processes.append(pid)
 
185
 
 
186