00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 import roslib
00038 roslib.load_manifest('nao_dashboard')
00039
00040 import wx
00041
00042 from os import path
00043
00044 class StatusControl(wx.Window):
00045 def __init__(self, parent, id, icons_path, base_name, toggleable):
00046 wx.Window.__init__(self, parent, id)
00047 self.SetSize(wx.Size(32, 32))
00048
00049 if (toggleable):
00050 self._ok = (wx.Bitmap(path.join(icons_path, "%s-green-untoggled.png"%(base_name)), wx.BITMAP_TYPE_PNG),
00051 wx.Bitmap(path.join(icons_path, "%s-green-toggled.png"%(base_name)), wx.BITMAP_TYPE_PNG))
00052 self._warn = (wx.Bitmap(path.join(icons_path, "%s-yellow-untoggled.png"%(base_name)), wx.BITMAP_TYPE_PNG),
00053 wx.Bitmap(path.join(icons_path, "%s-yellow-toggled.png"%(base_name)), wx.BITMAP_TYPE_PNG))
00054 self._error = (wx.Bitmap(path.join(icons_path, "%s-red-untoggled.png"%(base_name)), wx.BITMAP_TYPE_PNG),
00055 wx.Bitmap(path.join(icons_path, "%s-red-toggled.png"%(base_name)), wx.BITMAP_TYPE_PNG))
00056 self._stale = (wx.Bitmap(path.join(icons_path, "%s-grey-untoggled.png"%(base_name)), wx.BITMAP_TYPE_PNG),
00057 wx.Bitmap(path.join(icons_path, "%s-grey-toggled.png"%(base_name)), wx.BITMAP_TYPE_PNG))
00058 else:
00059 ok = wx.Bitmap(path.join(icons_path, "%s-green.png"%(base_name)), wx.BITMAP_TYPE_PNG)
00060 warn = wx.Bitmap(path.join(icons_path, "%s-yellow.png"%(base_name)), wx.BITMAP_TYPE_PNG)
00061 error = wx.Bitmap(path.join(icons_path, "%s-red.png"%(base_name)), wx.BITMAP_TYPE_PNG)
00062 stale = wx.Bitmap(path.join(icons_path, "%s-grey.png"%(base_name)), wx.BITMAP_TYPE_PNG)
00063 self._ok = (ok, ok)
00064 self._warn = (warn, warn)
00065 self._error = (error, error)
00066 self._stale = (stale, stale)
00067
00068 self._color = None
00069 self.set_stale()
00070
00071 self.Bind(wx.EVT_PAINT, self.on_paint)
00072 self.Bind(wx.EVT_LEFT_UP, self.on_left_up)
00073 self.Bind(wx.EVT_LEFT_DOWN, self.on_left_down)
00074 self.Bind(wx.EVT_LEAVE_WINDOW, self.on_leave_window)
00075 self.Bind(wx.EVT_ENTER_WINDOW, self.on_enter_window)
00076
00077 self._toggled = False
00078 self._left_down = False
00079
00080 def toggle(self, tog):
00081 if (self._toggled == tog):
00082 return False
00083
00084 self._toggled = tog
00085 self.Refresh()
00086
00087 return True
00088
00089 def on_left_down(self, evt):
00090 self.toggle(True)
00091 self._left_down = True
00092 self.Refresh()
00093
00094 def on_left_up(self, evt):
00095 self.toggle(False)
00096 self._left_down = False
00097 x = evt.GetX()
00098 y = evt.GetY()
00099 if (x >= 0 and y >= 0 and x < self.GetSize().GetWidth() and y < self.GetSize().GetHeight()):
00100 event = wx.CommandEvent(wx.EVT_BUTTON._getEvtType(), self.GetId())
00101 wx.PostEvent(self, event)
00102
00103 self.Refresh()
00104
00105 def on_leave_window(self, evt):
00106 self.toggle(False)
00107 self.Refresh()
00108
00109 def on_enter_window(self, evt):
00110 if (self._left_down):
00111 self.toggle(True)
00112
00113 self.Refresh()
00114
00115 def on_paint(self, evt):
00116 dc = wx.BufferedPaintDC(self)
00117 dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
00118 dc.Clear()
00119
00120 size = self.GetSize();
00121
00122 bitmap = None
00123 if (self._toggled):
00124 bitmap = self._color[1]
00125 else:
00126 bitmap = self._color[0]
00127
00128 dc.DrawBitmap(bitmap, (size.GetWidth() - bitmap.GetWidth()) / 2.0, (size.GetHeight() - bitmap.GetHeight()) / 2.0, True)
00129
00130 def set_ok(self):
00131 if (self._color == self._ok):
00132 return False
00133
00134 self._color = self._ok
00135 self.update()
00136
00137 return True
00138
00139 def set_warn(self):
00140 if (self._color == self._warn):
00141 return False
00142
00143 self._color = self._warn
00144 self.update()
00145
00146 return True
00147
00148 def set_error(self):
00149 if (self._color == self._error):
00150 return False
00151
00152 self._color = self._error
00153 self.update()
00154
00155 return True
00156
00157 def set_stale(self):
00158 if (self._color == self._stale):
00159 return False
00160
00161 self._color = self._stale
00162 self.update()
00163
00164 return True
00165
00166 def update(self):
00167 self.Refresh()