/usr/share/medit-1/plugins/python.py is in medit 1.0.3-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | #
# python.py
#
# Copyright (C) 2004-2010 by Yevgen Muntyan <emuntyan@users.sourceforge.net>
#
# This file is part of medit. medit is free software; you can
# redistribute it and/or modify it under the terms of the
# GNU Lesser General Public License as published by the
# Free Software Foundation; either version 2.1 of the License,
# or (at your option) any later version.
#
# You should have received a copy of the GNU Lesser General Public
# License along with medit. If not, see <http://www.gnu.org/licenses/>.
#
import gtk
import gobject
import pango
import os
import moo
from moo import _
import medit.runpython
MASTER_FILE = 'PYTHON_MASTER_FILE'
try:
import pyconsole
have_pyconsole = True
except ImportError:
have_pyconsole = False
PLUGIN_ID = "Python"
class Plugin(moo.Plugin):
def do_init(self):
editor = moo.Editor.instance()
xml = editor.get_ui_xml()
if xml is None:
# standalone python module, not in medit
return False
self.ui_merge_id = xml.new_merge_id()
if have_pyconsole:
moo.window_class_add_action(moo.EditWindow, "PythonConsole",
display_name=_("Python Console"),
label=_("Python Console"),
callback=self.show_console)
xml.add_item(self.ui_merge_id, "ToolsMenu",
"PythonConsole", "PythonConsole", -1)
""" Run file """
moo.window_class_add_action(moo.EditWindow, "RunFile",
display_name=_("Run File"),
label=_("Run File"),
stock_id=moo.STOCK_EXECUTE,
default_accel="<shift>F9",
callback=self.run_file)
moo.edit_window_set_action_filter("RunFile", moo.ACTION_CHECK_SENSITIVE, "langs:python")
xml.add_item(self.ui_merge_id, "ToolsMenu",
"RunFile", "RunFile", -1)
return True
def do_deinit(self):
editor = moo.Editor.instance()
xml = editor.get_ui_xml()
xml.remove_ui(self.ui_merge_id)
moo.window_class_remove_action(moo.EditWindow, "PythonConsole")
moo.window_class_remove_action(moo.EditWindow, "RunFile")
moo.window_class_remove_action(moo.EditWindow, "ReloadPythonPlugins")
def show_console(self, window):
window = gtk.Window()
swin = gtk.ScrolledWindow()
swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS)
window.add(swin)
dic = {}
dic['editor'] = moo.Editor.instance()
dic['window'] = moo.Editor.instance().get_active_window()
dic['view'] = moo.Editor.instance().get_active_view()
dic['doc'] = moo.Editor.instance().get_active_doc()
console_type = pyconsole.ConsoleType(moo.TextView)
console = console_type(use_rlcompleter=False, start_script=
"import moo\nimport gtk\n", locals=dic)
console.set_property("highlight-current-line", False)
editor = moo.Editor.instance()
console.set_lang_by_id("python-console")
console.modify_font(pango.FontDescription("Monospace"))
swin.add(console)
window.set_default_size(400,300)
window.set_title("pythony")
window.show_all()
def run_file(self, window):
filename = os.environ.get(MASTER_FILE)
if filename is None:
doc = window.get_active_doc()
if not doc:
return
if not doc.get_filename() or doc.get_status() & moo.EDIT_MODIFIED:
if not doc.save():
return
filename = doc.get_filename()
r = medit.runpython.Runner(window)
r.run(filename)
def do_detach_win(self, window):
window.remove_pane(PLUGIN_ID)
gobject.type_register(Plugin)
__plugin__ = Plugin
|