main_power_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('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     # plugged in
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()


elektron_dashboard
Author(s): Maciej StefaƄczyk
autogenerated on Sun Oct 5 2014 23:42:23