ocarina/src/extra/guiGTK/window.py

129 lines
3.0 KiB
Python

#! /usr/bin/python
# To change this template, choose Tools | Templates
# and open the template in the editor.
__author__="bjschuma"
__date__ ="$Jan 6, 2010 10:07:31 PM$"
import gtk
import box
import list
import button
import label
from bt.message import write
import manager
from session import settings
def empty(text=None,verbose=None):
pass
def quit(a,b):
manager.run("plugins",["enable", "exit"])
manager.run("exit")
class Window(gtk.Window):
def __init__(self, title, type=gtk.WINDOW_TOPLEVEL, icon=None):
gtk.Window.__init__(self,type)
self.show()
self.set_title(title)
self.qid = self.connect("delete_event",quit)
if not (icon == None):
self.set_icon_from_file(icon)
def quit(self,func):
self.disconnect(self.qid)
self.qid = self.connect("delete_event",func)
def hide(self,item=None,event=None):
gtk.Window.hide(self)
def resize(self,size):
gtk.Window.resize(self,size[0],size[1])
class PluginWindow(Window):
def __init__(self):
Window.__init__(self,"Plugin Manager")
self.quit(self.hide)
self.vbox = box.VBox()
self.hbox = box.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.call("plugins",["list", "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.call("plugins",["list","disabled"])
for mod in disabledMods:
self.disabled.insert([mod])
#settings.pop("write")
enable = button.Button("button",self.enable,None,"<<<")
disable = button.Button("button", self.disable,None,">>>")
self.hbox.pack(self.enabled, 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()
list = row[0]
path = row[1][0]
plugin = list[path][0]
return list,path,plugin
def enable(self,button,name):
list, path, plugin = self.getPlugin(self.disabled)
manager.run("plugins", ["enable",plugin] )
if (plugin in manager.call("plugins", ["list","enabled"])) == True:
self.disabled.remove(path)
self.enabled.insert([plugin])
def disable(self,button,name):
list, path, plugin = self.getPlugin(self.enabled)
manager.run("plugins", ["disable",plugin])
if (plugin in manager.call("plugins",["list", "disabled"])) == True:
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.call("help",[plugin])
self.lbl.change(message)
#settings.pop("write")