status_control.py
Go to the documentation of this file.
00001 # Software License Agreement (BSD License)
00002 #
00003 # Copyright (c) 2008, Willow Garage, Inc.
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions
00008 # are met:
00009 #
00010 #  * Redistributions of source code must retain the above copyright
00011 #    notice, this list of conditions and the following disclaimer.
00012 #  * Redistributions in binary form must reproduce the above
00013 #    copyright notice, this list of conditions and the following
00014 #    disclaimer in the documentation and/or other materials provided
00015 #    with the distribution.
00016 #  * Neither the name of the Willow Garage nor the names of its
00017 #    contributors may be used to endorse or promote products derived
00018 #    from this software without specific prior written permission.
00019 #
00020 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00021 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00022 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00023 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00024 # COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00025 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00026 # BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00027 # LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00028 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00030 # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00031 # POSSIBILITY OF SUCH DAMAGE.
00032 
00033 import roslib
00034 roslib.load_manifest('pr2_dashboard')
00035 
00036 import wx
00037 
00038 from os import path
00039 
00040 class StatusControl(wx.Window):
00041   def __init__(self, parent, id, icons_path, base_name, toggleable):
00042     wx.Window.__init__(self, parent, id)
00043     self.SetSize(wx.Size(32, 32))
00044     
00045     if (toggleable):
00046       self._ok = (wx.Bitmap(path.join(icons_path, "%s-green-untoggled.png"%(base_name)), wx.BITMAP_TYPE_PNG), 
00047                   wx.Bitmap(path.join(icons_path, "%s-green-toggled.png"%(base_name)), wx.BITMAP_TYPE_PNG))
00048       self._warn = (wx.Bitmap(path.join(icons_path, "%s-yellow-untoggled.png"%(base_name)), wx.BITMAP_TYPE_PNG), 
00049                     wx.Bitmap(path.join(icons_path, "%s-yellow-toggled.png"%(base_name)), wx.BITMAP_TYPE_PNG))
00050       self._error = (wx.Bitmap(path.join(icons_path, "%s-red-untoggled.png"%(base_name)), wx.BITMAP_TYPE_PNG), 
00051                    wx.Bitmap(path.join(icons_path, "%s-red-toggled.png"%(base_name)), wx.BITMAP_TYPE_PNG))
00052       self._stale = (wx.Bitmap(path.join(icons_path, "%s-grey-untoggled.png"%(base_name)), wx.BITMAP_TYPE_PNG), 
00053                      wx.Bitmap(path.join(icons_path, "%s-grey-toggled.png"%(base_name)), wx.BITMAP_TYPE_PNG))
00054     else:
00055       ok = wx.Bitmap(path.join(icons_path, "%s-green.png"%(base_name)), wx.BITMAP_TYPE_PNG)
00056       warn = wx.Bitmap(path.join(icons_path, "%s-yellow.png"%(base_name)), wx.BITMAP_TYPE_PNG)
00057       error = wx.Bitmap(path.join(icons_path, "%s-red.png"%(base_name)), wx.BITMAP_TYPE_PNG)
00058       stale = wx.Bitmap(path.join(icons_path, "%s-grey.png"%(base_name)), wx.BITMAP_TYPE_PNG)
00059       self._ok = (ok, ok)
00060       self._warn = (warn, warn)
00061       self._error = (error, error)
00062       self._stale = (stale, stale)
00063     
00064     self._color = None
00065     self.set_stale()
00066     
00067     self.Bind(wx.EVT_PAINT, self.on_paint)
00068     self.Bind(wx.EVT_LEFT_UP, self.on_left_up)
00069     self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down)
00070     self.Bind(wx.EVT_LEAVE_WINDOW, self.on_leave_window)
00071     self.Bind(wx.EVT_ENTER_WINDOW, self.on_enter_window)
00072     
00073     self._toggled = False
00074     self._left_down = False
00075     
00076   def toggle(self, tog):
00077     if (self._toggled == tog):
00078         return False
00079     
00080     self._toggled = tog
00081     self.Refresh()
00082     
00083     return True
00084 
00085   def on_left_down(self, evt):
00086     self.toggle(True)
00087     self._left_down = True
00088     self.Refresh()
00089 
00090   def on_left_up(self, evt):
00091     self.toggle(False)
00092     self._left_down = False
00093     x = evt.GetX()
00094     y = evt.GetY()
00095     if (x >= 0 and y >= 0 and x < self.GetSize().GetWidth() and y < self.GetSize().GetHeight()):
00096       event = wx.CommandEvent(wx.EVT_BUTTON._getEvtType(), self.GetId())
00097       wx.PostEvent(self, event)
00098       
00099     self.Refresh()
00100 
00101   def on_leave_window(self, evt):
00102     self.toggle(False)
00103     self.Refresh()
00104     
00105   def on_enter_window(self, evt):
00106     if (self._left_down):
00107       self.toggle(True)
00108       
00109     self.Refresh()
00110 
00111   def on_paint(self, evt):
00112     dc = wx.BufferedPaintDC(self)
00113     dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
00114     dc.Clear()
00115     
00116     size = self.GetSize();
00117     
00118     bitmap = None
00119     if (self._toggled):
00120       bitmap = self._color[1]
00121     else:
00122       bitmap = self._color[0]
00123     
00124     dc.DrawBitmap(bitmap, (size.GetWidth() - bitmap.GetWidth()) / 2.0, (size.GetHeight() - bitmap.GetHeight()) / 2.0, True)
00125 
00126   def set_ok(self):
00127     if (self._color == self._ok):
00128         return False
00129     
00130     self._color = self._ok
00131     self.update()
00132     
00133     return True
00134     
00135   def set_warn(self):
00136     if (self._color == self._warn):
00137         return False
00138       
00139     self._color = self._warn
00140     self.update()
00141     
00142     return True
00143     
00144   def set_error(self):
00145     if (self._color == self._error):
00146         return False
00147       
00148     self._color = self._error
00149     self.update()
00150     
00151     return True
00152     
00153   def set_stale(self):
00154     if (self._color == self._stale):
00155         return False
00156       
00157     self._color = self._stale
00158     self.update()
00159     
00160     return True
00161     
00162   def update(self):
00163     self.Refresh()


pr2_dashboard
Author(s): Josh Faust
autogenerated on Sat Dec 28 2013 17:24:13