Advertisement
Guest User

marcell

a guest
Oct 8th, 2008
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.99 KB | None | 0 0
  1. from PyQt4.QtCore import *
  2. from swig import readjoy
  3. from PyQt4.QtGui import *
  4. import sys
  5.                                                                                                      
  6. class Bridge(QObject):
  7.     def __init__(self, parent = None):
  8.         super(Bridge, self).__init__(parent)
  9.     def emitMessage(self, type, param, value):
  10.         self.emit(SIGNAL("gamepad"), type, param, value)
  11.  
  12.  
  13. class Gamepad(QThread):
  14.     def __init__(self, parent=None):
  15.         QThread.__init__(self, parent)
  16.         self.bridge = Bridge()
  17.         self.gamepad = readjoy.Joystick('/dev/input/js0')
  18.  
  19.     def run(self):
  20.         self.readGamepad()
  21.         self.exec_()
  22.     def readGamepad(self):
  23.         while True:
  24.             a = self.gamepad.getEvent()
  25.             self.bridge.emitMessage(str(a[0]), str(a[1]), str(a[2]))
  26.  
  27.  
  28. gamepad = Gamepad()
  29.  
  30. '''
  31. def pisi(type, param, value):
  32.    print type, param, value
  33.  
  34.  
  35. QObject.connect(gamepad.bridge, SIGNAL('gamepad'), pisi)
  36. gamepad.start()
  37. '''
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement