summaryrefslogtreecommitdiff
path: root/CompizTools.py
diff options
context:
space:
mode:
Diffstat (limited to 'CompizTools.py')
-rw-r--r--CompizTools.py89
1 files changed, 46 insertions, 43 deletions
diff --git a/CompizTools.py b/CompizTools.py
index 8a613aa..e531a19 100644
--- a/CompizTools.py
+++ b/CompizTools.py
@@ -16,22 +16,22 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
# 02111-1307, USA.
#
-# Author: Kristian F. Erikson <kristian@erikson.dk>
+# Author: Kristian F. Erikson <kristian.erikson@eyemagnet.com>
#
import dbus
from CompizError import CompizPluginTypeArgError
def convertFromDbusToTypes(arg):
- if type(arg) == type(dbus.Boolean()):
+ if type(arg) == type(dbus.Boolean(True)):
return type(True) # "<type 'bool'>"
- elif type(arg) == type(dbus.Int32()):
+ elif type(arg) == type(dbus.Int32(1)):
return type(1) # "<type 'int'>"
- elif type(arg) == type(dbus.Double()):
+ elif type(arg) == type(dbus.Double(1.00)):
return type(1.012) # "<type 'float'>"
- elif type(arg) == type(dbus.String()):
+ elif type(arg) == type(dbus.String('Hello')):
return type("Hello World ;)") # "<type 'str'>"
- elif type(arg) == type(dbus.Array()):
+ elif type(arg) == type(dbus.Array([2,4])):
signature = arg.signature # If we get an array see what's inside
if signature == dbus.Signature('b'):
return [type(True)] # "<type 'bool'>" in an arrray
@@ -64,26 +64,26 @@ def convertFromStringToTypes(arg):
def convertFromSimpleDbusToPython(arg):
- if type(arg) == type(dbus.Boolean()):
+ if type(arg) == type(dbus.Boolean(True)):
return bool(arg)
- elif type(arg) == type(dbus.Int32()):
+ elif type(arg) == type(dbus.Int32(1)):
return int(arg)
- elif type(arg) == type(dbus.Double()):
+ elif type(arg) == type(dbus.Double(1.00)):
return float(arg)
- elif type(arg) == type(dbus.String()):
+ elif type(arg) == type(dbus.String("hello")):
return str(arg)
def convertFromDbusToPython(arg):
- if type(arg) == type(dbus.Boolean()):
+ if type(arg) == type(dbus.Boolean(True)):
return bool(arg)
- elif type(arg) == type(dbus.Int32()):
+ elif type(arg) == type(dbus.Int32(1)):
return int(arg)
- elif type(arg) == type(dbus.Double()):
+ elif type(arg) == type(dbus.Double(1.00)):
return float(arg)
- elif type(arg) == type(dbus.String()):
+ elif type(arg) == type(dbus.String("hello")):
return unicode(arg)
- elif type(arg) == type(dbus.Array()):
+ elif type(arg) == type(dbus.Array([2,4])):
signature = arg.signature # If we get an array convert what's inside
arg = list(arg) # First convert to a list
newlist = []
@@ -130,7 +130,7 @@ def convertFromSimplePythonToDbus(arg):
elif type(arg) == type(44.44):
return dbus.Double(arg)
elif type(arg) == type("s") or type(arg) == type('s') or type(arg) == type(unicode('s')):
- return dbus.String(unicode(arg))
+ return dbus.String(arg)
else:
raise CompizPluginTypeArgError
@@ -145,33 +145,36 @@ def convertFromPythonToDbus(arg):
elif type(arg) == (type("s") or type('s') or type(unicode('s'))):
return dbus.String(unicode(arg))
elif type(arg) == type([]) or type(arg) == type((1,2)):
- signature = convertPythonToDbusSignature(arg[0])
- newlist = []
- if signature == dbus.Signature('b'): # Convert each item on the list
- for item in arg:
- if type(item) == type(True): # Type check each item as well
- newlist.append(convertFromSimplePythonToDbus(item))
- else:
- raise CompizPluginTypeArgError
- elif signature == dbus.Signature('i'):
- for item in arg:
- if type(item) == type(123):
- newlist.append(convertFromSimplePythonToDbus(item))
- else:
- raise CompizPluginTypeArgError
- elif signature == dbus.Signature('d'):
- for item in arg:
- if type(item) == type(23.12):
- newlist.append(convertFromSimplePythonToDbus(item))
- else:
- raise CompizPluginTypeArgError
- elif signature == dbus.Signature('s'):
- for item in arg:
- if type(item) == type("s") or type(item) == type('s') or type(item) == type(unicode('s')):
- newlist.append(convertFromSimplePythonToDbus(item))
- else:
- raise CompizPluginTypeArgError
- return dbus.Array(newlist, signature)
+ try:
+ signature = convertPythonToDbusSignature(arg[0])
+ newlist = []
+ if signature == dbus.Signature('b'): # Convert each item on the list
+ for item in arg:
+ if type(item) == type(True): # Type check each item as well
+ newlist.append(convertFromSimplePythonToDbus(item))
+ else:
+ raise CompizPluginTypeArgError
+ elif signature == dbus.Signature('i'):
+ for item in arg:
+ if type(item) == type(123):
+ newlist.append(convertFromSimplePythonToDbus(item))
+ else:
+ raise CompizPluginTypeArgError
+ elif signature == dbus.Signature('d'):
+ for item in arg:
+ if type(item) == type(23.12):
+ newlist.append(convertFromSimplePythonToDbus(item))
+ else:
+ raise CompizPluginTypeArgError
+ elif signature == dbus.Signature('s'):
+ for item in arg:
+ if type(item) == type("s") or type(item) == type('s') or type(item) == type(unicode('s')):
+ newlist.append(convertFromSimplePythonToDbus(item))
+ else:
+ raise CompizPluginTypeArgError
+ return dbus.Array(newlist, signature)
+ except IndexError: # In case we need to convert an empty list
+ return dbus.Array([], dbus.Signature('s')) # Guessing it's ok to return empty array with a string signature
else:
raise CompizPluginTypeArgError # Unsupported type