Go to the documentation of this file.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 class WifiControl(wx.Window):
00041 def __init__(self, parent, id, icons_path, wlan_interface, wlan_power):
00042 wx.Window.__init__(self, parent, id, wx.DefaultPosition, wx.Size(60, 50))
00043
00044 self._base_bitmap = wx.Bitmap(path.join(icons_path, "wifi_bars.png"), wx.BITMAP_TYPE_PNG)
00045 self._off_bitmap = wx.Bitmap(path.join(icons_path, "wifi_off.png"), wx.BITMAP_TYPE_PNG)
00046 self._bar_bitmap = wx.Bitmap(path.join(icons_path, "bar_on.png"), wx.BITMAP_TYPE_PNG)
00047
00048 self._signal_power = 3
00049 self._max_signal_power = wlan_power
00050 self.ip = "not connected"
00051
00052 self.SetSize(wx.Size(self._base_bitmap.GetWidth(), 50))
00053
00054 self.Bind(wx.EVT_PAINT, self.on_paint)
00055
00056 def on_paint(self, evt):
00057 dc = wx.BufferedPaintDC(self)
00058
00059 dc.SetBackground(wx.Brush(self.GetBackgroundColour()))
00060 dc.Clear()
00061
00062 w = self.GetSize().GetWidth()
00063 h = self._base_bitmap.GetHeight()
00064
00065 if (self.ip == "not connected"):
00066 dc.DrawBitmap(self._off_bitmap, 0, 0, True)
00067 else:
00068 dc.DrawBitmap(self._base_bitmap, 0, 0, True)
00069
00070 bars = int(5 * self._signal_power / self._max_signal_power)
00071
00072 for i in range(bars):
00073 dc.DrawBitmap(self._bar_bitmap, 36 + i * self._bar_bitmap.GetWidth(), 1, True)
00074
00075 fnt = dc.GetFont()
00076 fnt.SetPointSize(7)
00077 dc.SetFont(fnt)
00078 dc.DrawText("IP:", 0, 32)
00079 dc.DrawText('%s' % self.ip, 30, 32)
00080
00081
00082 def set_wifi_state(self, msg):
00083 self._signal_power = float(msg["Quality"])
00084 self.ip = msg["IP"]
00085 if (self.ip == "not connected"):
00086 self.SetToolTip(wx.ToolTip("Not connected"))
00087 else:
00088 self.SetToolTip(wx.ToolTip("Quality: %.2f%%"%(self._signal_power)))
00089
00090 self.Refresh()
00091
00092 def set_stale(self):
00093 self._signal_power = 0
00094 self.SetToolTip(wx.ToolTip("WiFi: Stale"))
00095
00096 self.Refresh()