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 import roslib
00034 roslib.load_manifest('elektron_dashboard')
00035
00036 import wx
00037
00038 from os import path
00039
00040 def non_zero(value):
00041 if value < 0.00001 and value > -0.00001:
00042 return 0.00001
00043 return value
00044
00045
00046 class MainPowerControl(wx.Window):
00047 def __init__(self, parent, id, icons_path):
00048 wx.Window.__init__(self, parent, id, wx.DefaultPosition, wx.Size(82, 32))
00049
00050 self._voltage = 0.0
00051
00052 self.Bind(wx.EVT_PAINT, self.on_paint)
00053
00054 def on_paint(self, evt):
00055 dc = wx.BufferedPaintDC(self)
00056
00057 dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
00058 dc.Clear()
00059
00060 w = self.GetSize().GetWidth()
00061 h = self.GetSize().GetHeight()
00062
00063 br_black = wx.Brush(wx.Colour(0, 0, 0, 255))
00064 br_white = wx.Brush(wx.Colour(255, 255, 255, 255))
00065
00066 pen_black = wx.Pen(wx.Colour(0, 0, 0, 255))
00067 pen_white = wx.Pen(wx.Colour(255, 255, 255, 255))
00068
00069 dc.SetBrush(br_black)
00070
00071 dc.DrawRectangle(0, 0, w, h)
00072
00073 cols = [wx.Colour(255, 0, 0),
00074 wx.Colour(255, 128, 0),
00075 wx.Colour(255, 255, 0),
00076 wx.Colour(128, 255, 0),
00077 wx.Colour(0, 255, 0),
00078 wx.Colour(0, 255, 0),
00079 wx.Colour(0, 255, 0) ]
00080
00081 fnt = dc.GetFont()
00082 fnt.SetFamily(wx.FONTFAMILY_MODERN)
00083 fnt.SetFaceName("FreeMono")
00084 fnt.SetWeight(wx.FONTWEIGHT_BOLD)
00085 fnt.SetPointSize(7)
00086 dc.SetFont(fnt)
00087
00088
00089 if (self._voltage > 26):
00090 dc.SetTextForeground(wx.Colour(255, 255, 255, 255))
00091 dc.DrawText(' Plugged in. ', 1, 1)
00092 else:
00093 dc.SetTextForeground(wx.Colour(255, 255, 255, 255))
00094 dc.DrawText(' %6.2fV' % self._voltage, 1, 1)
00095 dc.SetPen(pen_white)
00096 for i in range(7):
00097 dc.SetPen(wx.Pen(cols[i]))
00098 dc.DrawLine(11 + i * 10, h-3, 11 + i * 10, h-15)
00099
00100 dc.SetPen(pen_white)
00101 dc.SetBrush(br_white)
00102 xx = 11 + (self._voltage-20) * 10
00103 yy = h-10
00104 dc.DrawPolygon([wx.Point(xx, yy), wx.Point(xx+3, yy-3), wx.Point(xx+3, yy-9), wx.Point(xx-3, yy-9), wx.Point(xx-3, yy-3)])
00105
00106
00107 def set_power_state(self, msg):
00108 self._voltage = float(msg['Voltage'])
00109
00110 self.Refresh()
00111
00112 def set_stale(self):
00113 self._voltage = 0.0
00114
00115 self.Refresh()