summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKristian Frank Erikson <kristian@kristian-desktop.(none)>2008-12-18 09:49:26 +1300
committerKristian Frank Erikson <kristian@kristian-desktop.(none)>2008-12-18 09:49:26 +1300
commitbe046ce32cef98d22c58cf729b0cebb0632f6208 (patch)
treecbd4485fdc68911510012bcbc4dc8003f9eeb9f7
parenta1e6a876ec6fc1ab6c9c4833fe12bac96ccee68f (diff)
downloadpython-compiz-manager-be046ce32cef98d22c58cf729b0cebb0632f6208.tar.gz
python-compiz-manager-be046ce32cef98d22c58cf729b0cebb0632f6208.tar.bz2
Adding feature to check if Compiz is availiable and pluginDoAction function to CompizManager
-rwxr-xr-xCompizConnection.py2
-rw-r--r--CompizError.py5
-rwxr-xr-xCompizManager.py171
3 files changed, 96 insertions, 82 deletions
diff --git a/CompizConnection.py b/CompizConnection.py
index 9f034dd..4fa32e2 100755
--- a/CompizConnection.py
+++ b/CompizConnection.py
@@ -41,7 +41,7 @@ class CompizConnection( object ): # Handles everything going back and fourth w
def getPlugins(self):
remote_object = self.bus.get_object(_compizAddress, _compizObject)
return remote_object.getPlugins(_compizInterface)
-
+
def get(self, objectLocation):
remote_object = self.bus.get_object(_compizAddress, _compizObject + objectLocation)
return remote_object.get(_compizInterface)
diff --git a/CompizError.py b/CompizError.py
index f5b4bbc..28f5db8 100644
--- a/CompizError.py
+++ b/CompizError.py
@@ -21,7 +21,10 @@
class CompizError(Exception): pass
-class CompizPluginNameErr(CompizError):
+class CompizNotActiveError(CompizError):
+ def __str__(self):
+ return 'The library failed to connect to Compiz. Please ensure compiz is running and the dbus plugin is activated.'
+class CompizPluginNameError(CompizError):
def __str__(self):
return 'Plugin name not found in list of availiable plugins.'
class CompizPluginOptionError(CompizError):
diff --git a/CompizManager.py b/CompizManager.py
index 2b1e983..d537ec0 100755
--- a/CompizManager.py
+++ b/CompizManager.py
@@ -39,118 +39,129 @@ class CompizManager(object):
self.pluginDict = {}
self.pluginNameList = []
self.activePluginList = []
-
- self.loadPlugins()
+ self.active = False
+ self.connect()
self.buildPlugins()
- self.listActivePlugins()
-
- def active(self):
- """ Returns true if Compiz is active and accessible, otherwise false -- Not implemented yet """
- # TODO: implement
- pass
- def loadPlugins(self): # Connects to compiz and gets the list of plugins
- """ Internal function that gets the list of availiable plugins from Compiz """
- pluginTuple = self.connection.getPlugins()
- plugins = convertFromDbusToPython(pluginTuple)
- self.pluginNameList = sorted(plugins)
+ def connect(self): # Connects to compiz and gets the list of plugins
+ """ Function that connects to Compiz. Call this function to connect to Compiz
+ if the module was loaded at a time when Compiz was not running. """
+ try:
+ pluginTuple = self.connection.getPlugins()
+ plugins = convertFromDbusToPython(pluginTuple)
+ self.pluginNameList = sorted(plugins)
+ self.active = True
+ except dbus.exceptions.DBusException: # Catch the exception of compiz not responding
+ pass
def buildPlugins(self): # Creates new plugin objects for each of the plugins
""" Internal function that builds the plugins and their options and actions """
- tree = xml.etree.ElementTree.parse("plugins.xml")
+ tree = xml.etree.ElementTree.parse("plugins.xml") # Builds even is Compiz not running
for pluginName in self.pluginNameList:
plugin = CompizPlugin(pluginName, self)
actionsAndArgs = tree.find(pluginName)
plugin.setupActions(actionsAndArgs) # Further parse XML data
self.pluginDict[pluginName] = plugin # Save once parsed from XML
- def getPlugin(self, pluginName): # Returns specified plugin object
- """ Returns a representation of a Compiz plugin """
- return self.pluginDict[pluginName]
+ def getPlugin(self, pluginName): # Returns specified plugin object (if active)
+ """ Returns a representation of a Compiz plugin, if Compiz is running """
+ if self.active: return self.pluginDict[pluginName]
+ else: raise CompizNotActiveError
def listActivePlugins(self): # List all currently active plugins
""" Returns a list of currently active Compiz plugins """
- activePluginTuple = self.connection.get('/core/allscreens/active_plugins')
- activePlugins = convertFromDbusToPython(activePluginTuple)
- self.activePluginList = sorted(activePlugins)
- return self.activePluginList
+ if self.active:
+ activePluginTuple = self.connection.get('/core/allscreens/active_plugins')
+ activePlugins = convertFromDbusToPython(activePluginTuple)
+ self.activePluginList = sorted(activePlugins)
+ return self.activePluginList
+ else: raise CompizNotActiveError
def listAllPlugins(self): # List all avaible plugins
""" Returns a list of all availiable Compiz plugins (active and inactive) """
- return self.pluginNameList
+ if self.active: return self.pluginNameList
+ else: raise CompizNotActiveError
def listInactivePlugins(self): # List inactive plugins = pluginNameList - activePluginList
""" Returns a list of currently inactive Compiz plugins """
- self.listActivePlugins()
- self.inactivePluginList = []
- for pluginName in self.pluginNameList:
- if pluginName in self.activePluginList:
- pass
- else:
- self.inactivePluginList.append(pluginName)
- return self.inactivePluginList
+ if self.active:
+ self.listActivePlugins()
+ self.inactivePluginList = []
+ for pluginName in self.pluginNameList:
+ if pluginName in self.activePluginList:
+ pass
+ else:
+ self.inactivePluginList.append(pluginName)
+ return self.inactivePluginList
+ else: raise CompizNotActiveError
def activatePlugin(self, pluginNames): # takes a tuple of names (strings) or a single name
""" Activates plugins, either takes a single name or tuple of names """
- if type(pluginNames) == type('s'): # if it's a string
- if pluginNames in self.pluginNameList:
- if pluginNames not in self.activePluginList:
- self.activePluginList.append(pluginNames)
- # Convert and send off list
- dbusArray = convertFromPythonToDbus(self.activePluginList)
- self.connection.setActivePlugins(dbusArray)
- elif type(pluginNames) == type([]): # if it's a list
- check = 0
- for pluginName in pluginNames: # check all plugin names given are valid
- if pluginName in self.pluginNameList:
- check += 1
- if check != len(pluginNames):
- raise CompizPluginNameErr
- for plugin in pluginNames:
- if plugin not in self.activePluginList:
- self.activePluginList.append(plugin)
- # Convert and send off list
- dbusArray = convertFromPythonToDbus(self.activePluginList)
- self.connection.setActivePlugins(dbusArray)
- else:
- raise CompizPluginTypeArgError
+ if self.active:
+ if type(pluginNames) == type('s'): # if it's a string
+ if pluginNames in self.pluginNameList:
+ if pluginNames not in self.activePluginList:
+ self.activePluginList.append(pluginNames)
+ # Convert and send off list
+ dbusArray = convertFromPythonToDbus(self.activePluginList)
+ self.connection.setActivePlugins(dbusArray)
+ elif type(pluginNames) == type([]): # if it's a list
+ check = 0
+ for pluginName in pluginNames: # check all plugin names given are valid
+ if pluginName in self.pluginNameList:
+ check += 1
+ if check != len(pluginNames):
+ raise CompizPluginNameError
+ for plugin in pluginNames:
+ if plugin not in self.activePluginList:
+ self.activePluginList.append(plugin)
+ # Convert and send off list
+ dbusArray = convertFromPythonToDbus(self.activePluginList)
+ self.connection.setActivePlugins(dbusArray)
+ else: raise CompizPluginTypeArgError
+ else: raise CompizNotActiveError
def deactivatePlugin(self, pluginNames): # takes a tuple of names (strings) or a single name
""" Deactivates plugins, takes either a single name or tuple of names """
- if type(pluginNames) == type('s'): # if it's a string
- if pluginNames in self.pluginNameList:
- if pluginNames in self.activePluginList:
- self.activePluginList.remove(pluginNames)
- # Convert and send off list
- dbusArray = convertFromPythonToDbus(self.activePluginList)
- self.connection.setActivePlugins(dbusArray)
- elif type(pluginNames) == type([]): # if it's a list
- check = 0
- for pluginName in pluginNames: # check all plugin names given are valid
- if pluginName in self.pluginNameList:
- check += 1
- if check != len(pluginNames):
- raise CompizPluginNameErr
- for plugin in pluginNames:
- if plugin in self.activePluginList:
- self.activePluginList.remove(plugin)
- # Convert and send off list
- dbusArray = convertFromPythonToDbus(self.activePluginList)
- self.connection.setActivePlugins(dbusArray)
- else:
- raise CompizPluginTypeArgError
+ if self.active:
+ if type(pluginNames) == type('s'): # if it's a string
+ if pluginNames in self.pluginNameList:
+ if pluginNames in self.activePluginList:
+ self.activePluginList.remove(pluginNames)
+ # Convert and send off list
+ dbusArray = convertFromPythonToDbus(self.activePluginList)
+ self.connection.setActivePlugins(dbusArray)
+ elif type(pluginNames) == type([]): # if it's a list
+ check = 0
+ for pluginName in pluginNames: # check all plugin names given are valid
+ if pluginName in self.pluginNameList:
+ check += 1
+ if check != len(pluginNames):
+ raise CompizPluginNameError
+ for plugin in pluginNames:
+ if plugin in self.activePluginList:
+ self.activePluginList.remove(plugin)
+ # Convert and send off list
+ dbusArray = convertFromPythonToDbus(self.activePluginList)
+ self.connection.setActivePlugins(dbusArray)
+ else: raise CompizPluginTypeArgError
+ else: raise CompizNotActiveError
def setActivePluginList(self, pluginList):
""" Lets you set the list of currently active plugins. Proceed with caution. """
- dbusArray = convertFromPythonToDbus(pluginList)
- self.connection.setActivePlugins(dbusArray)
+ if self.active:
+ dbusArray = convertFromPythonToDbus(pluginList)
+ self.connection.setActivePlugins(dbusArray)
+ else: raise CompizNotActiveError
def pluginDoAction(self, pluginName, action, parameters=None):
- """ Get a plugin to do an action with parameters without having to get the plugin first -- Not implemented """
- # TODO: Implement
- pass
+ """ Get a plugin to do an action with parameters without having to get the plugin first """
+ if self.active:
+ plugin = self.pluginDict[pluginName]
+ plugin.doAction(action, parameters)
+ else: raise CompizNotActiveError
- def listAllWindows()
+ def listAllWindows():
""" Return a dictionary with attributes for each window, including info "xwininfo" returns as well as
Compiz Fusion specific details like which viewport or face of the cube, etc. -- Not implemented """
# TODO: Implement