#!/usr/bin/python

#============================ adjust path =====================================

import sys
import os
if __name__ == '__main__':
    here = sys.path[0]
    sys.path.insert(0, os.path.join(here, '..'))

#============================ imports =========================================

import Tkinter
import time

import dustGuiLib
import dustFrame
from   dustStyle import dustStyle

#============================ body ============================================

class hartFrameSensorData(dustFrame.dustFrame):

    def __init__(self,parentElem,guiLock,frameName="sensor data",row=0,column=0):

        # record variables

        # init parent
        dustFrame.dustFrame.__init__(self,parentElem,guiLock,frameName,row,column)

        #row 0: slide
        self.slide = Tkinter.Scale(self.container,
                                   from_=0,
                                   to=0xffff,
                                   state=Tkinter.DISABLED,
                                   orient=Tkinter.HORIZONTAL)
        self._add(self.slide,0,0,columnspan=2)

        #row 1: sourceMac
        temp = dustGuiLib.Label(self.container,
                             text='source MAC:')
        self._add(temp,1,0)
        self.sourceMac = dustGuiLib.Label(self.container)
        self._add(self.sourceMac,1,1)

    #======================== public ==========================================

    def update(self,sensorData):

        # display/hide connection forms
        self.guiLock.acquire()

        # slide
        temp = sensorData['payload'][0]*256+sensorData['payload'][1]
        self.slide.config(state=Tkinter.NORMAL)
        self.slide.set(temp)
        self.slide.config(state=Tkinter.DISABLED)

        # sourceMac
        temp = ''
        self.sourceMac.configure(text=str(sensorData['macAddr']))


        self.guiLock.release()
