#!/usr/bin/env python
#-*- coding: UTF-8 -*-
 
import wx
from stomamisc import *

class CustomStatusBar(wx.StatusBar):
    ID_LED = wx.NewId()
    
    def __init__(self, parent):
        wx.StatusBar.__init__(self, parent, -1)
        self.parent = parent
        self.sizechanged = False
        self.Bind(wx.EVT_SIZE, self.onSize)
        self.Bind(wx.EVT_IDLE, self.onIdle)
        self.SetFieldsCount(4)
        if LINUX:
            self.SetStatusWidths([210, 25, 140, -1])
        else:
            self.SetStatusWidths([210, 20, 140, -1])
        self.leds = {RED   : loadIcon('red.bmp'),
                     GREEN : loadIcon('green.bmp'),
                     BLUE  : loadIcon('blue.bmp'),
                     YELLOW: loadIcon('yellow.bmp'),
                     LBLUE : loadIcon('lblue.bmp'),
                     LRED  : loadIcon('lred.bmp'),
                    }
        self.bm = wx.StaticBitmap(self, -1, self.leds[RED])
        self.rePosition()
    #-------------------------------------------------------------------------------------------------------

    def setLed(self, color):
        self.bm.SetBitmap(self.leds[color])
        self.rePosition()
    #-------------------------------------------------------------------------------------------------------

    def onSize(self, evt):
        self.rePosition()   # for normal size events
        self.sizechanged = True
    #-------------------------------------------------------------------------------------------------------

    def onIdle(self, evt):
        if self.sizechanged:
           self.rePosition()
    #-------------------------------------------------------------------------------------------------------

    def rePosition(self):
        rect = self.GetFieldRect(1)
        if LINUX:
            self.bm.SetPosition(wx.Point(rect.x + 3, rect.y + 3))
        else:
            self.bm.SetPosition(wx.Point(rect.x + 2, rect.y))

        self.sizechanged = False
# - CustomStatusBar(wx.StatusBar):-------------------------------------------------------------------------
