Created a help function to give brief descriptions of plugins

This commit is contained in:
bjschuma 2010-01-16 02:25:47 -05:00
parent f08846df16
commit 607c15e0b6
13 changed files with 130 additions and 32 deletions

View File

@ -41,6 +41,10 @@ def close():
#cline.loop.quit()
def help():
return "This is a simple command line interface"
# Called when the plugin needs to perform some action
def run(args=None):

View File

@ -28,6 +28,10 @@ def close():
# Run this to prevent disable from ever being disabled
manager.run("enable",("disable"))
pass
def help():
return "This plugin is used to disable plugins"
# Called when the plugin needs to perform some action

View File

@ -29,6 +29,10 @@ def close():
pass
def help():
return "This plugin is used to reenable other plugins"
# Called when the plugin needs to perform some action
def run(args=None):
if args == None:

View File

@ -29,6 +29,10 @@ def close():
pass
def help():
return "This plugin will begin the proper shutdown procedure"
# Called when the plugin needs to perform some action
def run(args=None):
manager.shutdown()

54
src/core/help.py Normal file
View File

@ -0,0 +1,54 @@
# This is a simple test plugin, to make sure everything is working
__author__="bjschuma"
__date__ ="$Jan 16, 2010 1:45:27 AM$"
global name, app, type, path, opt
name = "help"
app = "scion"
type = "core"
path = ""
opt = []
from bt.message import write
from manager import manager
# Called every time the plugin is enabled
def open():
pass
# Called every time the plugin is stopped
def close():
pass
def help():
return "Returns a short description of the plugin"
# Called when the plugin needs to perform some action
def run(args=None):
if args == None:
plugin = "help"
else:
plugin = args[0]
module = None
if (plugin in manager.enabled.keys()) == True:
module = manager.enabled[plugin]
elif (plugin in manager.disabled.keys()) == True:
module = manager.disabled[plugin]
else:
message = "Plugin "+plugin+" does not appear to exist."
try:
if not module == None:
message = module.help()
write(message)
return message
except:
write("Plugin "+plugin+" has no help message.")
return ""

View File

@ -28,6 +28,10 @@ def close():
pass
def help():
return "Closes and then reopens a plugin"
# Called when the plugin needs to perform some action
def run(args=None):
if args == None:

View File

@ -25,6 +25,10 @@ def close():
write("Example plugin has been stopped",True)
def help():
return "Just a simple example plugin"
# Called when the plugin needs to perform some action
def run(args=None):
pass

View File

@ -12,3 +12,7 @@ class Label(gtk.Label):
def __init__(self,text):
gtk.Label.__init__(self,text)
self.show()
def change(self,text):
self.set_text(text)

View File

@ -12,12 +12,13 @@ import gtk
class List(gtk.ScrolledWindow):
def __init__(self, list, cols):
gtk.ScrolledWindow.__init__(self)
self.set_policy(gtk.POLICY_NEVER, gtk.POLICY_NEVER)
self.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
self.show()
self.list = list
self.tree = gtk.TreeView(list)
self.add(self.tree)
self.tree.show()
self.add(self.tree)
self.addcols(cols)
@ -26,6 +27,7 @@ class List(gtk.ScrolledWindow):
for index,column in enumerate(cols):
col = gtk.TreeViewColumn(column,cell)
col.add_attribute(cell,'text',index)
col.set_sort_column_id(index)
self.tree.append_column(col)
@ -39,4 +41,11 @@ class List(gtk.ScrolledWindow):
def selection(self):
return self.tree.get_selection().get_selected_rows()
return self.tree.get_selection().get_selected_rows()
def connect(self, signal, func, arg=None):
if arg == None:
self.tree.connect(signal, func)
else:
self.tree.connect(signal, func, arg)

View File

@ -10,6 +10,7 @@ import gtk
import box
import list
import button
import label
from bt.message import write
from manager import manager
import settings
@ -51,17 +52,21 @@ class PluginWindow(Window):
Window.__init__(self,"Plugin Manager")
self.quit(self.hide)
manager.run("enable", ["lsmod"])
self.vbox = box.VBox()
self.hbox = box.HBox()
self.add(self.hbox)
self.vbox.pack(self.hbox,True,True)
self.add(self.vbox)
settings.set("write",empty)
self.enabled = list.List(gtk.ListStore(str), ["Enabled"])
self.enabled.connect("cursor-changed", self.changeLabel, "enabled")
enabledMods = manager.run("lsmod","enabled")
for mod in enabledMods:
self.enabled.insert([mod])
self.disabled = list.List(gtk.ListStore(str), ["Disabled"])
self.disabled.connect("cursor-changed", self.changeLabel, "disabled")
disabledMods = manager.run("lsmod","disabled")
for mod in disabledMods:
self.disabled.insert([mod])
@ -73,13 +78,16 @@ class PluginWindow(Window):
self.hbox.pack(self.enabled, True, True)
vbox = box.VBox()
self.hbox.pack(vbox)
vbox.pack(enable,True,True)
vbox.pack(disable,True,True)
btnbox = box.VBox()
self.hbox.pack(btnbox)
btnbox.pack(enable,True,True)
btnbox.pack(disable,True,True)
self.hbox.pack(self.disabled, True, True)
self.lbl = label.Label("Test")
self.vbox.pack(self.lbl)
def getPlugin(self,pluginList):
row = pluginList.selection()
@ -102,3 +110,14 @@ class PluginWindow(Window):
self.enabled.remove(path)
self.disabled.insert([plugin])
def changeLabel(self,tree,name):
if name == "enabled":
list, path, plugin = self.getPlugin(self.enabled)
else:
list, path, plugin = self.getPlugin(self.disabled)
settings.set("write", empty)
message = manager.run("help",[plugin])
self.lbl.change(message)
settings.pop("write")

View File

@ -25,6 +25,10 @@ def close():
pass
def help():
return "Used to list currently loaded plugins"
# Called when the plugin needs to perform some action
def run(args=None):
mods = []

View File

@ -25,6 +25,10 @@ def close():
pass
def help():
return "Used to show the current state of settings"
# Called when the plugin needs to perform some action
def run(args=None):
keys = settings.settings.keys()

View File

@ -33,30 +33,6 @@ def test(button, name):
def pluginWindow(item):
plugins = window.PluginWindow()
# write("Creating plugin window!",True)
# plugins = window.Window("Plugin Manager")
# hbox = box.HBox(True)
# plugins.add(hbox)
#
# manager.run("enable","lsmod")
#
# enabled = list.List(gtk.ListStore(str), ["Enabled"])
# enabledMods = manager.run("lsmod","enabled")
# for mod in enabledMods:
# enabled.insert([mod])
#
# disabled = list.List(gtk.ListStore(str), ["Disabled"])
# disabledMods = manager.run("lsmod","disabled")
# for mod in disabledMods:
# disabled.insert([mod])
#
# enable = button.Button("button",test,None,"<<")
#
# hbox.pack(enabled, True, True)
# hbox.pack(enable)
# hbox.pack(disabled, True, True)
#
# plugins.quit(hide)
def loop():
@ -98,6 +74,10 @@ def close():
pass
def help():
return "Allows the usage of GTK"
# Called when the plugin needs to perform some action
def run(args=None):
global win,box