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
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:
13
#The above copyright notice and this permission notice shall be included in
14
#all copies or substantial portions of the Software.
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
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
34
class Plugin(plugin.Plugin):
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,
52
'What plugins to use on unknown files (comma separated)')
54
self.plugregistry = reg.add_group('plugins',
55
'Determines which plugins are loaded at startup.')
57
for pluginname in self.prop_optional_pluginlist:
58
self.plugregistry.add(pluginname,
61
'Whether %s wil be loaded at startup (requires restart).' % \
66
self.filetype_triggered = False
67
self.filetype_current = 'None'
69
self.log = logging.getLogger()
70
self.loghandler = None
71
#logging.basicConfig()
73
#sys.stdout = sys.stderr = file('/dev/null', 'w')
75
self.tips = gtk.Tooltips()
78
self.child_processes = []
80
def evt_populate(self):
81
self.icons = gtkextra.Icons()
91
def reset_logger(self):
92
logfile = self.prop_main_registry.files.log.value()
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())
100
stdiofile = '%s.io' % self.prop_main_registry.files.log.value()
101
f = open(stdiofile, 'w')
102
sys.stdout = sys.stderr = f
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)
113
def evt_filetype(self, buffernumber, filetype):
114
self.filetype_triggered = True
115
self.filetypes[buffernumber] = filetype
117
def get_pluginnames(self, filetype):
118
genplugins = [s.strip() for s in self.ftregistry.all.value().split(',')]
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
126
def get_named_plugin(self, name):
127
for plugin in self.plugins:
128
if plugin.NAME == name:
131
def action_settip(self, widget, tiptext):
132
self.tips.set_tip(widget, tiptext)
134
def action_status(self, message):
135
self.pida.mainwindow.statusbar.push(1, message)
137
def do_log(self, source, message, level):
141
msg = '%s: %s' % (source, message)
142
self.log.log(level, msg)
144
def action_newbrowser(self, url):
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)
155
def action_quit(self):
157
# Tell plugins to die
160
for pid in self.child_processes:
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)
172
def action_fork(self, commandargs):
177
os.execlp(commandargs[0], *commandargs)
181
self.child_processes.append(pid)
183
def action_accountfork(self, pid):
184
self.child_processes.append(pid)