Copyright (c) 2007, Gizmo Daemon Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
############################
# PowermateFirefox Class definition
##########################
class PowermateFirefox(GizmoScriptActiveApplication):
"""
Firefox Powermate Event Mapping
"""
############################
# Public Functions
##########################
def onDeviceEvent(self, Event, Gizmo = None):
"""
Called from Base Class' onEvent method.
See GizmodDispatcher.onEvent documention for an explanation of this function
"""
Gizmo.setRotateSensitivity(5)
# Only interact with Firefox if it's the first Powermate
if Gizmo.DeviceClassID == 0:
# Check for rotations
if Event.Type == GizmoEventType.EV_REL:
# scroll the window slowly if the button isn't pressed
# and fast if the button is down
if not Gizmo.getKeyState(GizmoKey.BTN_0):
# scroll slowly
Gizmod.Mice[0].createEventRaw(GizmoEventType.EV_REL, GizmoMouseAxis.WHEEL, -Event.Value)
else:
# scroll quickly (by pages using the page up / page down keys)
if Event.Value > 0:
for repeat in range(abs(Event.Value)):
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_PAGEDOWN)
else:
for repeat in range(abs(Event.Value)):
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_PAGEUP)
return True
elif Event.Type == GizmoEventType.EV_KEY:
if Event.Value == 0 and not Gizmo.Rotated:
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_RIGHTCTRL,1)
Gizmod.Keyboards[0].createEventPress(GizmoEventType.EV_KEY, GizmoKey.KEY_W)
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_RIGHTCTRL,0)
#Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_PAGEDOWN)
return True
else:
return False
else:
return False
############################
# PowermateFirefox class end
##########################
# register the user script
PowermateFirefox()
====END====
The error message is:
====BEGIN====
Traceback (most recent call last):
File "/home/ch/.gizmod/GizmodDispatcher.py", line 109, in onEvent
if UserScript.onEvent(Event, Gizmo):
File "/home/ch/.gizmod/modules.d/bases/GizmoScriptActiveApplication.py", line 65, in onEvent
return self.onDeviceEvent(Event, Gizmo)
File "/home/ch/.gizmod/modules.d/210-Powermate-Firefox.py", line 87, in onDeviceEvent
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_RIGHTCTRL,1)
TypeError: object of type 'int' has no len()
Error in sys.excepthook:
Traceback (most recent call last):
File "/var/lib/python-support/python2.5/apport_python_hook.py", line 44, in apport_excepthook
binary = os.path.realpath(os.path.join(os.getcwdu(), sys.argv[0]))
AttributeError: 'module' object has no attribute 'argv'
Original exception was:
Traceback (most recent call last):
File "/home/ch/.gizmod/GizmodDispatcher.py", line 109, in onEvent
if UserScript.onEvent(Event, Gizmo):
File "/home/ch/.gizmod/modules.d/bases/GizmoScriptActiveApplication.py", line 65, in onEvent
return self.onDeviceEvent(Event, Gizmo)
File "/home/ch/.gizmod/modules.d/210-Powermate-Firefox.py", line 87, in onDeviceEvent
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_RIGHTCTRL,1)
TypeError: object of type 'int' has no len()
Failed to call GizmodDispatcher.onEvent for deserializeMessage
====END====
I believe it is something to do with these commands where I am attempting to do a CTRL-W to close the open tab in Firefox:
You've got the right idea!. To make that work replace createEvent, with createEventRaw, and that should do the trick. Or alternately you can replace all three commands with a single one:
That would result in a press, and release of Ctrl-Alt-W.
This is also the reason for the (cryptic) error you received. The createEvent command is expecting a list of values if there is a third parameter. Since you gave an integer (not a list), an internal call to check the value of the list (that's not a list) failed. (I should really put in a better error message there).
Let me know if that helps!
Tim.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
btw I've put this into svn, and your change will be in the next release! Great idea on closing the tab when you press the button. If you come up with any more changes let me know!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thanks again for this Tim. I knew it would be something simple like this!
I have just grabbed your version from svn - the only thing I would ask you to consider altering would be to add Swiftfox/Iceweasel to the list of INTERESTED_WINDOWS since Swiftfox/Iceweasel are really only a modified versions of Firefox and both have a reasonably large following to warrant their addition IMO.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I have just hacked the script a little more... instead of scrolling in larger steps when you press down on the button it scrolls through the open tabs (this is usually done with CTRL-PageUp/PageDown).
Copyright (c) 2007, Gizmo Daemon Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
############################
# PowermateFirefox Class definition
##########################
class PowermateFirefox(GizmoScriptActiveApplication):
"""
Firefox Powermate Event Mapping
"""
############################
# Public Functions
##########################
def onDeviceEvent(self, Event, Gizmo = None):
"""
Called from Base Class' onEvent method.
See GizmodDispatcher.onEvent documention for an explanation of this function
"""
# Only interact with Firefox if it's the first Powermate
if Gizmo.DeviceClassID == 0:
# Check for rotations
if Event.Type == GizmoEventType.EV_REL:
# scroll the window slowly if the button isn't pressed
# and scrolls through the open tabs if the button is down
if not Gizmo.getKeyState(GizmoKey.BTN_0):
# scroll slowly (create a mouse wheel event)
Gizmod.Mice[0].createEventRaw(GizmoEventType.EV_REL, GizmoMouseAxis.WHEEL, -Event.Value)
else:
# scroll tabs (by pages using CTRL- pageup / pagedown )
if Event.Value > 0:
for repeat in range(abs(Event.Value)):
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_PAGEDOWN, [GizmoKey.KEY_LEFTCTRL])
else:
for repeat in range(abs(Event.Value)):
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_PAGEUP, [GizmoKey.KEY_LEFTCTRL])
return True
# check for button press
elif Event.Type == GizmoEventType.EV_KEY:
if Event.Value == 0 and not Gizmo.Rotated:
# issue a close tab if the button is pressed
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_W, [GizmoKey.KEY_LEFTCTRL])
return True
else:
return False
else:
return False
This has given me an idea, so before implementing I want to add some functionality to the scripting API. As soon as that's done I'll add this into SVN (albeit slightly modified).
Thanks for the ideas!
Tim.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hello again,
I am attempting to add a command that closes the open tab in Firefox when I press my powermate but I am getting an error message.
The script I am using is:
====BEGIN====
#***
#*********************************************************************
#*************************************************************************
#***
#*** GizmoDaemon Config Script
#*** Powermate Firefox config
#***
#*****************************************
#*****************************************
#***
"""
Copyright (c) 2007, Gizmo Daemon Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
############################
# Imports
##########################
from GizmoDaemon import *
from GizmoScriptActiveApplication import *
ENABLED = True
VERSION_NEEDED = 3.2
INTERESTED_CLASSES = [GizmoEventClass.Powermate]
INTERESTED_WINDOWS = ["firefox","swiftfox"]
############################
# PowermateFirefox Class definition
##########################
class PowermateFirefox(GizmoScriptActiveApplication):
"""
Firefox Powermate Event Mapping
"""
############################
# Public Functions
##########################
def onDeviceEvent(self, Event, Gizmo = None):
"""
Called from Base Class' onEvent method.
See GizmodDispatcher.onEvent documention for an explanation of this function
"""
Gizmo.setRotateSensitivity(5)
# Only interact with Firefox if it's the first Powermate
if Gizmo.DeviceClassID == 0:
# Check for rotations
if Event.Type == GizmoEventType.EV_REL:
# scroll the window slowly if the button isn't pressed
# and fast if the button is down
if not Gizmo.getKeyState(GizmoKey.BTN_0):
# scroll slowly
Gizmod.Mice[0].createEventRaw(GizmoEventType.EV_REL, GizmoMouseAxis.WHEEL, -Event.Value)
else:
# scroll quickly (by pages using the page up / page down keys)
if Event.Value > 0:
for repeat in range(abs(Event.Value)):
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_PAGEDOWN)
else:
for repeat in range(abs(Event.Value)):
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_PAGEUP)
return True
elif Event.Type == GizmoEventType.EV_KEY:
if Event.Value == 0 and not Gizmo.Rotated:
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_RIGHTCTRL,1)
Gizmod.Keyboards[0].createEventPress(GizmoEventType.EV_KEY, GizmoKey.KEY_W)
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_RIGHTCTRL,0)
#Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_PAGEDOWN)
return True
else:
return False
else:
return False
############################
# Private Functions
##########################
def __init__(self):
"""
Default Constructor
"""
GizmoScriptActiveApplication.__init__(self, ENABLED, VERSION_NEEDED, INTERESTED_CLASSES, INTERESTED_WINDOWS)
############################
# PowermateFirefox class end
##########################
# register the user script
PowermateFirefox()
====END====
The error message is:
====BEGIN====
Traceback (most recent call last):
File "/home/ch/.gizmod/GizmodDispatcher.py", line 109, in onEvent
if UserScript.onEvent(Event, Gizmo):
File "/home/ch/.gizmod/modules.d/bases/GizmoScriptActiveApplication.py", line 65, in onEvent
return self.onDeviceEvent(Event, Gizmo)
File "/home/ch/.gizmod/modules.d/210-Powermate-Firefox.py", line 87, in onDeviceEvent
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_RIGHTCTRL,1)
TypeError: object of type 'int' has no len()
Error in sys.excepthook:
Traceback (most recent call last):
File "/var/lib/python-support/python2.5/apport_python_hook.py", line 44, in apport_excepthook
binary = os.path.realpath(os.path.join(os.getcwdu(), sys.argv[0]))
AttributeError: 'module' object has no attribute 'argv'
Original exception was:
Traceback (most recent call last):
File "/home/ch/.gizmod/GizmodDispatcher.py", line 109, in onEvent
if UserScript.onEvent(Event, Gizmo):
File "/home/ch/.gizmod/modules.d/bases/GizmoScriptActiveApplication.py", line 65, in onEvent
return self.onDeviceEvent(Event, Gizmo)
File "/home/ch/.gizmod/modules.d/210-Powermate-Firefox.py", line 87, in onDeviceEvent
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_RIGHTCTRL,1)
TypeError: object of type 'int' has no len()
Failed to call GizmodDispatcher.onEvent for deserializeMessage
====END====
I believe it is something to do with these commands where I am attempting to do a CTRL-W to close the open tab in Firefox:
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_RIGHTCTRL,1)
Gizmod.Keyboards[0].createEventPress(GizmoEventType.EV_KEY, GizmoKey.KEY_W)
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_RIGHTCTRL,0)
If I use just:
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_PAGEDOWN)
everything appears to work fine (except this isn't what I am trying to do!).
Any ideas?
You've got the right idea!. To make that work replace createEvent, with createEventRaw, and that should do the trick. Or alternately you can replace all three commands with a single one:
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_W, [GizmoKey.KEY_LEFTCTRL])
createEvent takes a key code, then a list of modifiers. So you could do the following if you wanted as well:
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_W, [GizmoKey.KEY_LEFTCTRL, GizmoKey.KEY_LEFTALT])
That would result in a press, and release of Ctrl-Alt-W.
This is also the reason for the (cryptic) error you received. The createEvent command is expecting a list of values if there is a third parameter. Since you gave an integer (not a list), an internal call to check the value of the list (that's not a list) failed. (I should really put in a better error message there).
Let me know if that helps!
Tim.
btw I've put this into svn, and your change will be in the next release! Great idea on closing the tab when you press the button. If you come up with any more changes let me know!
Thanks again for this Tim. I knew it would be something simple like this!
I have just grabbed your version from svn - the only thing I would ask you to consider altering would be to add Swiftfox/Iceweasel to the list of INTERESTED_WINDOWS since Swiftfox/Iceweasel are really only a modified versions of Firefox and both have a reasonably large following to warrant their addition IMO.
Thanks! Done, and in SVN.
Tim.
I have just hacked the script a little more... instead of scrolling in larger steps when you press down on the button it scrolls through the open tabs (this is usually done with CTRL-PageUp/PageDown).
#***
#*********************************************************************
#*************************************************************************
#***
#*** GizmoDaemon Config Script
#*** Powermate Firefox config
#***
#*****************************************
#*****************************************
#***
"""
Copyright (c) 2007, Gizmo Daemon Team
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""
############################
# Imports
##########################
from GizmoDaemon import *
from GizmoScriptActiveApplication import *
ENABLED = True
VERSION_NEEDED = 3.2
INTERESTED_CLASSES = [GizmoEventClass.Powermate]
INTERESTED_WINDOWS = ["firefox","swiftfox","iceweasel"]
############################
# PowermateFirefox Class definition
##########################
class PowermateFirefox(GizmoScriptActiveApplication):
"""
Firefox Powermate Event Mapping
"""
############################
# Public Functions
##########################
def onDeviceEvent(self, Event, Gizmo = None):
"""
Called from Base Class' onEvent method.
See GizmodDispatcher.onEvent documention for an explanation of this function
"""
# Only interact with Firefox if it's the first Powermate
if Gizmo.DeviceClassID == 0:
# Check for rotations
if Event.Type == GizmoEventType.EV_REL:
# scroll the window slowly if the button isn't pressed
# and scrolls through the open tabs if the button is down
if not Gizmo.getKeyState(GizmoKey.BTN_0):
# scroll slowly (create a mouse wheel event)
Gizmod.Mice[0].createEventRaw(GizmoEventType.EV_REL, GizmoMouseAxis.WHEEL, -Event.Value)
else:
# scroll tabs (by pages using CTRL- pageup / pagedown )
if Event.Value > 0:
for repeat in range(abs(Event.Value)):
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_PAGEDOWN, [GizmoKey.KEY_LEFTCTRL])
else:
for repeat in range(abs(Event.Value)):
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_PAGEUP, [GizmoKey.KEY_LEFTCTRL])
return True
# check for button press
elif Event.Type == GizmoEventType.EV_KEY:
if Event.Value == 0 and not Gizmo.Rotated:
# issue a close tab if the button is pressed
Gizmod.Keyboards[0].createEvent(GizmoEventType.EV_KEY, GizmoKey.KEY_W, [GizmoKey.KEY_LEFTCTRL])
return True
else:
return False
else:
return False
############################
# Private Functions
##########################
def __init__(self):
"""
Default Constructor
"""
GizmoScriptActiveApplication.__init__(self, ENABLED, VERSION_NEEDED, INTERESTED_CLASSES, INTERESTED_WINDOWS)
############################
# PowermateFirefox class end
##########################
# register the user script
PowermateFirefox()
This has given me an idea, so before implementing I want to add some functionality to the scripting API. As soon as that's done I'll add this into SVN (albeit slightly modified).
Thanks for the ideas!
Tim.