X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/2421eb827857325ff4886131c337391365986d6b..69d818954b5e6e7b4b4e5093dd26dbe2d5f8546c:/wxPython/demo/Joystick.py diff --git a/wxPython/demo/Joystick.py b/wxPython/demo/Joystick.py index 03ba8e98c7..219dbd139f 100644 --- a/wxPython/demo/Joystick.py +++ b/wxPython/demo/Joystick.py @@ -5,7 +5,7 @@ # Author: Jeff Grimmett (grimmtoo@softhome.net), adapted from original # .wdr-derived demo # -# Created: 01/02/04 +# Created: 02-Jan-2004 # RCS-ID: $Id$ # Copyright: # Licence: wxWindows license @@ -15,10 +15,14 @@ import math import wx +haveJoystick = True +if wx.Platform == "__WXMAC__": + haveJoystick = False + #---------------------------------------------------------------------------- -# For convenience -spacer = (10, 10) +# Once all supported versions of Python support 32-bit integers on all +# platforms, this can go up to 32. MAX_BUTTONS = 16 #---------------------------------------------------------------------------- @@ -963,14 +967,115 @@ class JoystickDemoPanel(wx.Panel): #---------------------------------------------------------------------------- def runTest(frame, nb, log): - win = JoystickDemoPanel(nb, log) - return win + if haveJoystick: + win = JoystickDemoPanel(nb, log) + return win + else: + dlg = wx.MessageDialog( + frame, 'wx.Joystick is not available on this platform.', + 'Sorry', wx.OK | wx.ICON_INFORMATION + ) + dlg.ShowModal() + dlg.Destroy() + #---------------------------------------------------------------------------- overview = """\ - - + +
+The data that can be retrieved from the joystick comes in four basic flavors. +All of these are illustrated in the demo. In fact, this demo illustrates everything +you can get from the wx.Joystick control. + +
Getting data from the joystick can be event-driven thanks to four event types associated +with wx.JoystickEvent, or the joystick can be polled programatically to get data on +a regular basis. + +
+ # assume buttonState is what the stick returned, and buttonBit + # is the bit you want to examine + + if (buttonState & ( 1 << buttonBit )) : + # button pressed, do something with it ++ +
The problem here is that some OSs return a 32-bit value for up to 32 buttons +(imagine that stick!). Python V2.3 will generate an exception for bit +values over 30. For that reason, this demo is limited to 16 buttons. + +
Note that more than one button can be pressed at a time, so be sure to check all of them! + + +
Different methods are provided to retrieve the POV data for a CTS hat +versus a four-way hat. + +
Fortunately, there is an easy workaround. In the top level frame, create a wx.Timer +that will poll the stick at a set interval. Of course, if you do this, you might as +well forgo catching wxEVT_JOYSTICK_* events at all and rely on the timer to do the +polling. + +
Ideally, the timer should be a one-shot; after it fires, collect and process data as +needed, then re-start the timer, possibly using wx.CallAfter(). + + + """ #---------------------------------------------------------------------------- @@ -978,4 +1083,4 @@ overview = """\ if __name__ == '__main__': import sys,os import run - run.main(['', os.path.basename(sys.argv[0])]) + run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])