Skip to content

Instantly share code, notes, and snippets.

@robsears
Created October 24, 2012 02:31
Show Gist options
  • Save robsears/3943373 to your computer and use it in GitHub Desktop.
Save robsears/3943373 to your computer and use it in GitHub Desktop.
wxPython Joystick Example 2
# wx.Joystick example number 2
# Import wx objects
import wx
# Taken from wxPython demos:
haveJoystick = True
if wx.Platform == "__WXMAC__":
haveJoystick = False
# Create a few global variables so we can tweak alignment, etc
X_LABEL = 10
X_QUANT = 120
Y = 10
LINE_HEIGHT = 15
# The main frame
class Example(wx.Frame):
def __init__(self, *args, **kw):
super(Example, self).__init__(*args, **kw)
global Y
# Create Joystick object
self.stick = wx.Joystick()
self.stick.SetCapture(self)
# Now we'll add some basic info about our joystick to the frame:
# Add the joystick status:
joystick_status = {True: 'Good', False: 'Fail'}[self.stick.IsOk() == True] # See: http://en.wikipedia.org/wiki/%3F:#Python
wx.StaticText(self, -1, 'Joystick Status', pos=(X_LABEL,Y))
wx.StaticText(self, -1, joystick_status, pos=(X_QUANT,Y))
Y = Y + LINE_HEIGHT
# Add the manufacturer ID:
wx.StaticText(self, -1, 'Manufacturer ID:', pos=(X_LABEL,Y))
wx.StaticText(self, -1, str(self.stick.GetManufacturerId()), pos=(X_QUANT,Y))
Y = Y + LINE_HEIGHT
# Add the product ID:
wx.StaticText(self, -1, 'Product ID:', pos=(X_LABEL,Y))
wx.StaticText(self, -1, str(self.stick.GetProductId()), pos=(X_QUANT,Y))
Y = Y + LINE_HEIGHT
# Set the frame size and title, center to the screen and load
self.SetSize((400, 200))
self.SetTitle('Joystick Info')
self.Centre()
self.Show(True)
def main():
if haveJoystick == False:
print 'wx.Joystick is not available on this platform.'
return
else:
ex = wx.App()
Example(None)
ex.MainLoop()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment