More work on the GUI, creating a gui for enabling and disabling plugins

This commit is contained in:
bjschuma 2010-01-15 00:44:58 -05:00
parent 921003dea9
commit 1922bc78ec
13 changed files with 196 additions and 24 deletions

View File

@ -27,7 +27,7 @@ def error(text):
lineno = str(inspect.currentframe().f_back.f_lineno)
filename = inspect.currentframe().f_back.f_code.co_filename
filename = filename.rsplit(os.sep,1)[1]
write(filename+" ("+lineno+"): "+text,True)
write(filename+" ("+lineno+"): "+text)
settings.set("write", disp)

View File

@ -73,7 +73,10 @@ class Manager:
# Disable all plugins
def shutdown(self):
settings.get("loopquit")()
funcs = settings.get("loopquit",True)
if not funcs==None:
for func in funcs:
func()
write("Shutting down manager, disabling all active plugins", True)
session = self.findsession()
self.savesession(session)
@ -97,10 +100,14 @@ class Manager:
def run(self,name,args=None):
name = name.strip()
if (name in self.enabled)==True:
return self.enabled[name].run(args)
try:
return self.enabled[name].run(args)
except:
error("Plugin "+name+" has caused an error. Disabling.")
self.disablePlugin(name)
else:
write("Plugin either not loaded or doesn't exist: "+name)
return None
return None
def findsession(self):

View File

@ -124,6 +124,7 @@ def clean():
def save(path):
write("Saving settings",True)
clean()
global settings
path = join(path,"settings")
@ -143,6 +144,7 @@ def save(path):
def load(path):
write("Loading saved settings",True)
global settings
path = join(path,"settings")
xm.load(path)

View File

@ -16,8 +16,8 @@ def run(input):
prompt = input[0:4]
input = input[4:].strip()
#if len(input) == 0:
# return prompt
if len(input) == 0:
return prompt
split = input.split(' ')
if len(split)>1:

View File

@ -2,4 +2,4 @@ __author__="bjschuma"
__date__ ="$Jan 6, 2010 9:52:21 PM$"
__all__ = ["box", "button", "window"]
__all__ = ["box", "button", "label", "list", "menu", "window"]

View File

@ -11,13 +11,26 @@ import gtk
class HBox(gtk.HBox):
def __init__(self, homogeneous=False, spacing=0):
gtk.HBox.__init__(homogeneous, spacing)
gtk.HBox.__init__(self,homogeneous, spacing)
#manager.run("sgtk", (name,self))
self.show()
def pack(self, item, start=True, expand=False, fill=True, padding=0):
if start==True:
self.pack_start(item, expand, fill, padding)
else:
self.pack_end(item, expand, fill, padding)
class VBox(gtk.VBox):
def __init__(self, homogeneous=False, spacing=0):
gtk.VBox.__init__(homogeneous, spacing)
gtk.VBox.__init__(self,homogeneous, spacing)
#manager.run("sgtk", (name,self))
self.show()
self.show()
def pack(self, item, start=True, expand=False, fill=True, padding=0):
if start==True:
self.pack_start(item, expand, fill, padding)
else:
self.pack_end(item, expand, fill, padding)

View File

@ -8,11 +8,13 @@ __date__ ="$Jan 6, 2010 9:55:39 PM$"
import gtk
from box import HBox
class Button(gtk.Button):
def __init__(self,name,func,image=None,text=None):
gtk.Button.__init__(self)
box = gtk.HBox(True,0)
#box = gtk.HBox(True,0)
box = HBox()
# Add an image if we were given one
if image!= None:
box.pack_start(image,True,True,0)
@ -24,7 +26,7 @@ class Button(gtk.Button):
label.show()
box.pack_start(label,True,True,0)
# Show and add callback function
box.show()
#box.show()
self.add(box)
self.connect("clicked",func,name)
self.show()

14
src/extra/guiGTK/label.py Normal file
View File

@ -0,0 +1,14 @@
#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Jan 14, 2010 11:49:31 PM$"
import gtk
class Label(gtk.Label):
def __init__(self,text):
gtk.Label.__init__(self,text)
self.show()

33
src/extra/guiGTK/list.py Normal file
View File

@ -0,0 +1,33 @@
#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Jan 15, 2010 12:02:08 AM$"
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.show()
self.list = list
self.tree = gtk.TreeView(list)
self.add(self.tree)
self.tree.show()
self.addcols(cols)
def addcols(self,cols):
cell = gtk.CellRendererText()
for index,column in enumerate(cols):
col = gtk.TreeViewColumn(column,cell)
col.add_attribute(cell,'text',index)
self.tree.append_column(col)
def insert(self,items):
self.list.insert(len(self.list), items)

31
src/extra/guiGTK/menu.py Normal file
View File

@ -0,0 +1,31 @@
#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Jan 14, 2010 10:39:29 PM$"
import gtk
class Bar(gtk.MenuBar):
def __init__(self):
gtk.MenuBar.__init__(self)
self.show()
class Item(gtk.MenuItem):
def __init__(self,name, func=None, subs=[]):
gtk.MenuItem.__init__(self, name)
if not func == None:
self.connect("activate", func)
if len(subs) > 0:
menu = gtk.Menu()
for sub in subs:
menu.append(sub)
self.set_submenu(menu)
self.show()

View File

@ -19,8 +19,7 @@ class Window(gtk.Window):
def __init__(self, title, type=gtk.WINDOW_TOPLEVEL, icon=None):
gtk.Window.__init__(self,type)
self.set_title(title)
self.connect("delete_event",quit)
#manager.run("sgtk", (name,self))
self.qid = self.connect("delete_event",quit)
if not (icon == None):
self.set_icon_from_file(icon)
@ -29,7 +28,5 @@ class Window(gtk.Window):
def quit(self,func):
self.connect("delete_event",func)
#def quit(self,a,b):
# manager.run("exit")
self.disconnect(self.qid)
self.qid = self.connect("delete_event",func)

View File

@ -18,14 +18,11 @@ from manager import manager
# Called every time the plugin is enabled
def open():
pass
#write("Example plugin has been started",True)
#write("Example plugin has been changed",True)
# Called every time the plugin is stopped
def close():
pass
#write("Example plugin has been stopped",True)
# Called when the plugin needs to perform some action
@ -44,3 +41,5 @@ def run(args=None):
comma = ', '
list = comma.join(mods)
write(list)
return mods

View File

@ -13,12 +13,81 @@ opt = []
from bt.message import write
from manager import manager
import settings
from guiGTK import *
import gtk
global win
global vbox
global bar
def test(button, name):
write("Test!")
def hide(item,event):
item.hide()
def pluginWindow(item):
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():
global vbox,bar,win
manager.run("disable",["cli"])
win = window.Window(settings.get("appname").title())
vbox = box.VBox()
win.add(vbox)
bar = menu.Bar()
vbox.pack(bar)
plugins = menu.Item("Plugins",pluginWindow)
tools = menu.Item("Tools",None,[plugins])
bar.append(tools)
but = button.Button("button",test,None,"I'm a button!")
vbox.pack(but)
lab = label.Label("Hello, World!")
vbox.pack(lab)
settings.set("guirunning",True)
gtk.main()
# Called every time the plugin is enabled
def open():
settings.init("guirunning",False)
if settings.get("guirunning") == True:
settings.set("loop",loop)
pass
@ -30,7 +99,12 @@ def close():
# Called when the plugin needs to perform some action
def run(args=None):
manager.run("disable", ["cli"])
win = window.Window("Scion")
gtk.main()
global win,box
if args == None:
loop()
elif args[0] == "getwin":
return win
elif args[0] == "getbox":
return box