]> git.saurik.com Git - wxWidgets.git/blobdiff - wxPython/demo/Joystick.py
adapted to new font setter
[wxWidgets.git] / wxPython / demo / Joystick.py
index 219dbd139f0d59ba01c37308cd7f9cf16466ec21..c94e2155071aa36f3ab0d4096b2e849843067e43 100644 (file)
@@ -95,18 +95,18 @@ class JoyGauge(wx.Panel):
 
         # Restrict our drawing activities to the square defined
         # above.
 
         # Restrict our drawing activities to the square defined
         # above.
-        dc.SetClippingRegion((xorigin, yorigin), (edgeSize, edgeSize))
+        dc.SetClippingRegion(xorigin, yorigin, edgeSize, edgeSize)
 
         # Optimize drawing a bit (for Win)
         dc.BeginDrawing()
 
         dc.SetBrush(wx.Brush(wx.Colour(251, 252, 237)))
 
         # Optimize drawing a bit (for Win)
         dc.BeginDrawing()
 
         dc.SetBrush(wx.Brush(wx.Colour(251, 252, 237)))
-        dc.DrawRectangle((xorigin, yorigin), (edgeSize, edgeSize))
+        dc.DrawRectangle(xorigin, yorigin, edgeSize, edgeSize)
 
         dc.SetPen(wx.Pen(wx.BLACK, 1, wx.DOT_DASH))
 
 
         dc.SetPen(wx.Pen(wx.BLACK, 1, wx.DOT_DASH))
 
-        dc.DrawLine((xorigin, yorigin + center), (xorigin + edgeSize, yorigin + center))
-        dc.DrawLine((xorigin + center, yorigin), (xorigin + center, yorigin + edgeSize))
+        dc.DrawLine(xorigin, yorigin + center, xorigin + edgeSize, yorigin + center)
+        dc.DrawLine(xorigin + center, yorigin, xorigin + center, yorigin + edgeSize)
 
         if self.stick:
             # Get the joystick position as a float
 
         if self.stick:
             # Get the joystick position as a float
@@ -114,8 +114,21 @@ class JoyGauge(wx.Panel):
             joyy =  float(self.stick.GetPosition().y)
 
             # Get the joystick range of motion
             joyy =  float(self.stick.GetPosition().y)
 
             # Get the joystick range of motion
-            xrange = self.stick.GetXMax() - self.stick.GetXMin()
-            yrange = self.stick.GetYMax() - self.stick.GetYMin()
+            xmin = self.stick.GetXMin()
+            xmax = self.stick.GetXMax()
+            if xmin < 0:
+                xmax += abs(xmin)
+                joyx += abs(xmin)
+                xmin = 0
+            xrange = max(xmax - xmin, 1)
+
+            ymin = self.stick.GetYMin()
+            ymax = self.stick.GetYMax()
+            if ymin < 0:
+                ymax += abs(ymin)
+                joyy += abs(ymin)
+                ymin = 0
+            yrange = max(ymax - ymin, 1)
 
             # calc a ratio of our range versus the joystick range
             xratio = float(edgeSize) / xrange
 
             # calc a ratio of our range versus the joystick range
             xratio = float(edgeSize) / xrange
@@ -123,7 +136,7 @@ class JoyGauge(wx.Panel):
 
             # calc the displayable value based on position times ratio
             xval = int(joyx * xratio)
 
             # calc the displayable value based on position times ratio
             xval = int(joyx * xratio)
-            yval = int(joyy * xratio)
+            yval = int(joyy * yratio)
 
             # and normalize the value from our brush's origin
             x = xval + xorigin
 
             # and normalize the value from our brush's origin
             x = xval + xorigin
@@ -131,7 +144,7 @@ class JoyGauge(wx.Panel):
 
             # Now to draw it.
             dc.SetPen(wx.Pen(wx.RED, 2))
 
             # Now to draw it.
             dc.SetPen(wx.Pen(wx.RED, 2))
-            dc.CrossHair((x, y))
+            dc.CrossHair(x, y)
 
         # Turn off drawing optimization
         dc.EndDrawing()
 
         # Turn off drawing optimization
         dc.EndDrawing()
@@ -239,14 +252,14 @@ class POVGauge(wx.Panel):
 
         # our 'raster'.
         dc.SetBrush(wx.Brush(wx.WHITE))
 
         # our 'raster'.
         dc.SetBrush(wx.Brush(wx.WHITE))
-        dc.DrawCircle((xcenter, ycenter), diameter/2)
+        dc.DrawCircle(xcenter, ycenter, diameter/2)
         dc.SetBrush(wx.Brush(wx.BLACK))
         dc.SetBrush(wx.Brush(wx.BLACK))
-        dc.DrawCircle((xcenter, ycenter), 10)
+        dc.DrawCircle(xcenter, ycenter, 10)
 
         # fancy decorations
         dc.SetPen(wx.Pen(wx.BLACK, 1, wx.DOT_DASH))
 
         # fancy decorations
         dc.SetPen(wx.Pen(wx.BLACK, 1, wx.DOT_DASH))
-        dc.DrawLine((xorigin, ycenter), (xorigin + diameter, ycenter))
-        dc.DrawLine((xcenter, yorigin), (xcenter, yorigin + diameter))
+        dc.DrawLine(xorigin, ycenter, xorigin + diameter, ycenter)
+        dc.DrawLine(xcenter, yorigin, xcenter, yorigin + diameter)
 
         if self.stick:
             if self.avail:
 
         if self.stick:
             if self.avail:
@@ -284,11 +297,11 @@ class POVGauge(wx.Panel):
 
                 # Draw the line
                 dc.SetPen(wx.Pen(wx.BLUE, 2))
 
                 # Draw the line
                 dc.SetPen(wx.Pen(wx.BLUE, 2))
-                dc.DrawLine((xcenter, ycenter), (nx, ny))
+                dc.DrawLine(xcenter, ycenter, nx, ny)
 
                 # And a little thing to show the endpoint
                 dc.SetBrush(wx.Brush(wx.BLUE))
 
                 # And a little thing to show the endpoint
                 dc.SetBrush(wx.Brush(wx.BLUE))
-                dc.DrawCircle((nx, ny), 8)
+                dc.DrawCircle(nx, ny, 8)
 
         # Turn off drawing optimization
         dc.EndDrawing()
 
         # Turn off drawing optimization
         dc.EndDrawing()
@@ -462,7 +475,7 @@ class LED(wx.Panel):
         else:
             dc.SetBrush(wx.Brush(wx.BLACK))
 
         else:
             dc.SetBrush(wx.Brush(wx.BLACK))
 
-        dc.DrawCircle((center, center), bw/2)
+        dc.DrawCircle(center, center, bw/2)
 
         txt = str(self.number)
 
 
         txt = str(self.number)
 
@@ -483,7 +496,7 @@ class LED(wx.Panel):
         # functions. The pseudo-shadow gives the text contrast
         # regardless of whether the bar is under it or not.
         dc.SetTextForeground(wx.WHITE)
         # functions. The pseudo-shadow gives the text contrast
         # regardless of whether the bar is under it or not.
         dc.SetTextForeground(wx.WHITE)
-        dc.DrawText(txt, (tx, ty))
+        dc.DrawText(txt, tx, ty)
 
         # Turn off drawing optimization
         dc.EndDrawing()
 
         # Turn off drawing optimization
         dc.EndDrawing()
@@ -709,10 +722,10 @@ class AxisBar(wx.Gauge):
         # functions. The pseudo-shadow gives the text contrast
         # regardless of whether the bar is under it or not.
         dc.SetTextForeground(wx.BLACK)
         # functions. The pseudo-shadow gives the text contrast
         # regardless of whether the bar is under it or not.
         dc.SetTextForeground(wx.BLACK)
-        dc.DrawText(txt, (tx, ty))
+        dc.DrawText(txt, tx, ty)
 
         dc.SetTextForeground('white')
 
         dc.SetTextForeground('white')
-        dc.DrawText(txt, (tx-1, ty-1))
+        dc.DrawText(txt, tx-1, ty-1)
 
 
 #----------------------------------------------------------------------------
 
 
 #----------------------------------------------------------------------------
@@ -758,10 +771,8 @@ class Axis(wx.Panel):
             self.GetMax = eval('stick.Get%sMax' % token)
 
             # Create our displays and set them up.
             self.GetMax = eval('stick.Get%sMax' % token)
 
             # Create our displays and set them up.
-            self.Min = wx.StaticText(self, -1, str(self.GetMin()),
-                                     size=(40,-1), style=wx.ALIGN_RIGHT | wx.ST_NO_AUTORESIZE)
-            self.Max = wx.StaticText(self, -1, str(self.GetMax()),
-                                     size=(40,-1), style=wx.ALIGN_LEFT | wx.ST_NO_AUTORESIZE)
+            self.Min = wx.StaticText(self, -1, str(self.GetMin()), style=wx.ALIGN_RIGHT)
+            self.Max = wx.StaticText(self, -1, str(self.GetMax()), style=wx.ALIGN_LEFT)
             self.bar = AxisBar(self)
 
             sizer.Add(self.Min, 0, wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 1)
             self.bar = AxisBar(self)
 
             sizer.Add(self.Min, 0, wx.ALL | wx.ALIGN_RIGHT | wx.ALIGN_CENTER_VERTICAL, 1)
@@ -813,20 +824,25 @@ class Axis(wx.Panel):
         else:
             val = eval('self.stick.Get%sPosition()' % self.token)
 
         else:
             val = eval('self.stick.Get%sPosition()' % self.token)
 
+
         #
         # While we might be able to rely on a range of 0-FFFFFF on Win, that might
         # not be true of all drivers on all platforms. Thus, calc the actual full
         # range first.
         #
         #
         # While we might be able to rely on a range of 0-FFFFFF on Win, that might
         # not be true of all drivers on all platforms. Thus, calc the actual full
         # range first.
         #
+        if min < 0:
+            max += abs(min)
+            val += abs(min)
+            min = 0        
         range = float(max - min)
         range = float(max - min)
-
+        
         #
         # The relative value is used by the derived wx.Gauge since it is a
         # positive-only control.
         #
         relative = 0
         if range:
         #
         # The relative value is used by the derived wx.Gauge since it is a
         # positive-only control.
         #
         relative = 0
         if range:
-            relative = int(val / range * 1000)
+            relative = int( val / range * 1000)
 
         #
         # Pass both the raw and relative values to the derived Gauge
 
         #
         # Pass both the raw and relative values to the derived Gauge
@@ -941,9 +957,9 @@ class JoystickDemoPanel(wx.Panel):
 
         # Capture Joystick events (if they happen)
         self.Bind(wx.EVT_JOYSTICK_EVENTS, self.OnJoystick)
 
         # Capture Joystick events (if they happen)
         self.Bind(wx.EVT_JOYSTICK_EVENTS, self.OnJoystick)
-
         self.stick.SetMovementThreshold(10)
 
         self.stick.SetMovementThreshold(10)
 
+
     def Calibrate(self, evt=None):
         # Do not try this without a stick
         if not self.stick:
     def Calibrate(self, evt=None):
         # Do not try this without a stick
         if not self.stick:
@@ -954,6 +970,7 @@ class JoystickDemoPanel(wx.Panel):
         self.pov.Calibrate()
         self.buttons.Calibrate()
 
         self.pov.Calibrate()
         self.buttons.Calibrate()
 
+
     def OnJoystick(self, evt=None):
         if not self.stick:
             return
     def OnJoystick(self, evt=None):
         if not self.stick:
             return
@@ -961,9 +978,15 @@ class JoystickDemoPanel(wx.Panel):
         self.axes.Update()
         self.joy.Update()
         self.pov.Update()
         self.axes.Update()
         self.joy.Update()
         self.pov.Update()
-        self.buttons.Update()
+        if evt is not None and evt.IsButton():
+            self.buttons.Update()
 
 
 
 
+    def ShutdownDemo(self):
+        if self.stick:
+            self.stick.ReleaseCapture()
+        self.stick = None
+        
 #----------------------------------------------------------------------------
 
 def runTest(frame, nb, log):
 #----------------------------------------------------------------------------
 
 def runTest(frame, nb, log):
@@ -971,12 +994,10 @@ def runTest(frame, nb, log):
         win = JoystickDemoPanel(nb, log)
         return win
     else:
         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()
+        from Main import MessagePanel
+        win = MessagePanel(nb, 'wx.Joystick is not available on this platform.',
+                           'Sorry', wx.ICON_WARNING)
+        return win
     
 
 #----------------------------------------------------------------------------
     
 
 #----------------------------------------------------------------------------