Make it easier to write python plugins
parent
57c86517b7
commit
74b6d5072e
|
@ -1,2 +1,62 @@
|
|||
"""moo.edit module"""
|
||||
from _moo_edit import *
|
||||
|
||||
class Plugin(object):
|
||||
class ActionInfo(object):
|
||||
def __init__(self, window_type, id, **kwargs):
|
||||
self.window_type = window_type
|
||||
self.id = id
|
||||
self.props = kwargs
|
||||
|
||||
class UIInfo(object):
|
||||
def __init__(self, parent, action, name=None, index=-1):
|
||||
self.parent = parent
|
||||
self.action = action
|
||||
self.name = name or action
|
||||
self.index = index
|
||||
|
||||
def __init__(self):
|
||||
object.__init__(self)
|
||||
|
||||
self.info = {
|
||||
"id" : "Plugin",
|
||||
"name" : "Plugin",
|
||||
"description" : "Plugin",
|
||||
"author" : "Uknown",
|
||||
"version" : "3.1415926",
|
||||
"enabled" : True,
|
||||
"visible" : True
|
||||
}
|
||||
|
||||
self.actions = []
|
||||
self.ui_merge_id = 0
|
||||
self.ui = []
|
||||
|
||||
def get_info(self):
|
||||
return self.info
|
||||
|
||||
def init(self):
|
||||
import moo
|
||||
|
||||
for a in self.actions:
|
||||
moo.utils.window_class_add_action(a.window_type, a.id, **a.props)
|
||||
|
||||
if self.ui:
|
||||
editor = editor_instance()
|
||||
xml = editor.get_ui_xml()
|
||||
self.ui_merge_id = xml.new_merge_id()
|
||||
for item in self.ui:
|
||||
xml.add_item(self.ui_merge_id, item.parent,
|
||||
item.name, item.action, item.index)
|
||||
|
||||
return True
|
||||
|
||||
def deinit(self):
|
||||
import moo
|
||||
for a in self.actions:
|
||||
moo.utils.window_class_remove_action(a.window_type, a.id)
|
||||
if self.ui_merge_id:
|
||||
editor = editor_instance()
|
||||
xml = editor.get_ui_xml()
|
||||
xml.remove_ui(self.ui_merge_id)
|
||||
self.ui_merge_id = 0
|
||||
|
|
|
@ -625,16 +625,17 @@ static void
|
|||
moo_py_plugin_instance_init (MooPyPlugin *plugin,
|
||||
MooPyPluginClass *klass)
|
||||
{
|
||||
PyObject *args;
|
||||
MooPlugin *moo_plugin = MOO_PLUGIN (plugin);
|
||||
|
||||
plugin->class_data = klass->data;
|
||||
|
||||
args = PyTuple_New (0);
|
||||
plugin->instance = PyType_GenericNew ((PyTypeObject*) klass->data->py_plugin_type, args, NULL);
|
||||
Py_DECREF (args);
|
||||
plugin->instance = PyObject_CallObject (klass->data->py_plugin_type, NULL);
|
||||
|
||||
g_return_if_fail (plugin->instance != NULL);
|
||||
if (!plugin->instance)
|
||||
{
|
||||
PyErr_Print ();
|
||||
g_warning ("%s: could not create plugin instance", G_STRLOC);
|
||||
}
|
||||
|
||||
moo_plugin->info = get_plugin_info (plugin->instance);
|
||||
|
||||
|
|
|
@ -3,9 +3,11 @@ import gtk
|
|||
|
||||
CONSOLE_PLUGIN_ID = "Console"
|
||||
|
||||
class Plugin(object):
|
||||
def get_info(self):
|
||||
return {
|
||||
class Plugin(moo.edit.Plugin):
|
||||
def __init__(self):
|
||||
moo.edit.Plugin.__init__(self)
|
||||
|
||||
self.info = {
|
||||
"id" : CONSOLE_PLUGIN_ID,
|
||||
"name" : "Console",
|
||||
"description" : "Console",
|
||||
|
@ -15,28 +17,15 @@ class Plugin(object):
|
|||
"visible" : True
|
||||
}
|
||||
|
||||
def init(self):
|
||||
editor = moo.edit.editor_instance()
|
||||
xml = editor.get_ui_xml()
|
||||
moo.utils.window_class_add_action (moo.edit.EditWindow, "ShowConsole",
|
||||
name="Show Console",
|
||||
label="Show Console",
|
||||
icon_stock_id=moo.utils.STOCK_TERMINAL,
|
||||
callback=self.show_console)
|
||||
self.ui_merge_id = xml.new_merge_id()
|
||||
xml.add_item(self.ui_merge_id, "Editor/Menubar/View",
|
||||
"ShowConsole", "ShowConsole", -1)
|
||||
return True
|
||||
a = moo.edit.Plugin.ActionInfo(moo.edit.EditWindow, "ShowConsole",
|
||||
name="Show Console",
|
||||
label="Show Console",
|
||||
icon_stock_id=moo.utils.STOCK_TERMINAL,
|
||||
callback=self.show_console)
|
||||
self.actions.append(a)
|
||||
|
||||
def deinit(self):
|
||||
editor = moo.edit.editor_instance()
|
||||
xml = editor.get_ui_xml()
|
||||
|
||||
moo.utils.window_class_remove_action(moo.edit.EditWindow, "ShowConsole");
|
||||
|
||||
if self.ui_merge_id:
|
||||
xml.remove_ui(self.ui_merge_id)
|
||||
self.ui_merge_id = 0
|
||||
i = moo.edit.Plugin.UIInfo("Editor/Menubar/View", "ShowConsole")
|
||||
self.ui.append(i)
|
||||
|
||||
def show_console(self, window):
|
||||
pane = window.get_pane(CONSOLE_PLUGIN_ID)
|
||||
|
|
|
@ -12,9 +12,11 @@ except ImportError:
|
|||
|
||||
PLUGIN_ID = "PyStuff"
|
||||
|
||||
class Plugin(object):
|
||||
def get_info(self):
|
||||
return {
|
||||
class Plugin(moo.edit.Plugin):
|
||||
def __init__(self):
|
||||
moo.edit.Plugin.__init__(self)
|
||||
|
||||
self.info = {
|
||||
"id" : PLUGIN_ID,
|
||||
"name" : "Python Stuff",
|
||||
"description" : "Python stuff",
|
||||
|
@ -24,35 +26,21 @@ class Plugin(object):
|
|||
"visible" : True
|
||||
}
|
||||
|
||||
def init(self):
|
||||
editor = moo.edit.editor_instance()
|
||||
xml = editor.get_ui_xml()
|
||||
|
||||
self.ui_merge_id = xml.new_merge_id()
|
||||
|
||||
if SHOW_LOG_WINDOW:
|
||||
moo.utils.window_class_add_action (moo.edit.EditWindow, "ShowLogWindow",
|
||||
name="Show Log Window",
|
||||
label="Show Log Window",
|
||||
callback=self.show_log_window)
|
||||
xml.add_item(self.ui_merge_id, "Editor/Menubar/Tools",
|
||||
"ShowLogWindow", "ShowLogWindow", -1)
|
||||
a = moo.edit.Plugin.ActionInfo(moo.edit.EditWindow, "ShowLogWindow",
|
||||
name="Show Log Window",
|
||||
label="Show Log Window",
|
||||
callback=self.show_log_window)
|
||||
self.actions.append(a)
|
||||
self.ui.append(moo.edit.Plugin.UIInfo("Editor/Menubar/Tools", "ShowLogWindow"))
|
||||
|
||||
if have_pyconsole:
|
||||
moo.utils.window_class_add_action (moo.edit.EditWindow, "ShowPythonConsole",
|
||||
name="Show Python Console",
|
||||
label="Show Python Console",
|
||||
callback=self.show_console)
|
||||
xml.add_item(self.ui_merge_id, "Editor/Menubar/Tools",
|
||||
"ShowPythonConsole", "ShowPythonConsole", -1)
|
||||
return True
|
||||
|
||||
def deinit(self):
|
||||
editor = moo.edit.editor_instance()
|
||||
xml = editor.get_ui_xml()
|
||||
moo.utils.window_class_remove_action(moo.edit.EditWindow, "ShowLogWindow");
|
||||
moo.utils.window_class_remove_action(moo.edit.EditWindow, "ShowPythonConsole");
|
||||
xml.remove_ui(self.ui_merge_id)
|
||||
a = moo.edit.Plugin.ActionInfo(moo.edit.EditWindow, "ShowPythonConsole",
|
||||
name="Show Python Console",
|
||||
label="Show Python Console",
|
||||
callback=self.show_console)
|
||||
self.actions.append(a)
|
||||
self.ui.append(moo.edit.Plugin.UIInfo("Editor/Menubar/Tools", "ShowPythonConsole"))
|
||||
|
||||
def show_log_window(self, window):
|
||||
moo.app.get_instance().show_python_console()
|
||||
|
|
Loading…
Reference in New Issue