#!/usr/bin/python
#======================================================================
#
# Project	 : hpp_IOStressTest
# File 		 : Libs/IOST_WRun/IOST_WRun_StationInfo.py
# Date		 : Oct 25, 2016
# Author	 : HuuHoang Nguyen
# Contact	 : hhnguyen@apm.com
#            : hoangnh.hpp@gmail.com
# License    : MIT License
# Copyright  : 2016
# Description: The hpp_IOStressTest is under the MIT License, a copy of license which may be found in LICENSE
#
#======================================================================

import io
import os
import sys
import time

from IOST_Basic                         import *
from IOST_Config                        import *

import gtk
import gobject
import gtk.glade
import vte

#======================================================================
try:
    IOST_DBG_EN
    if IOST_DBG_EN:
        IOST_WRunStationInfo_DebugEnable =0
    else:
        IOST_WRunStationInfo_DebugEnable =0
except:
    IOST_DBG_EN = False
    IOST_WRunStationInfo_DebugEnable =0

#======================================================================
class IOST_WRun_StationInfo():
    """
    This is class to get all informtation of Station object from IOST_WRun_Skylark window and control to these
    component
    """
    #----------------------------------------------------------------------
    def __init__(self, glade_filename, window_name, builder=None):
        self.IOST_WRunStationInfo_WindowName = window_name
        if not builder:
            self.IOST_WRunStationInfo_Builder = gtk.Builder()
            self.IOST_WRunStationInfo_Builder.add_from_file(glade_filename)
            self.IOST_WRunStationInfo_Builder.connect_signals(self)
        else:
            self.IOST_WRunStationInfo_Builder = builder

    #----------------------------------------------------------------------
    def WRun_GetStationInfo_Obj(self, window_name):
        "Get all Station info objecs on WRun window and store into self.IOST_Objs"
        # self.IOST_Objs[window_name]["_Summary_StationInfo_ConsoleIP_Value_L"] = self.IOST_WRunStationInfo_Builder.get_object(self.IOST_Objs[window_name]["_Summary_StationInfo_ConsoleIP_Value_L"])

        # self.IOST_Objs[window_name]["_Summary_StationInfo_ConsolePort_Value_L"] = self.IOST_WRunStationInfo_Builder.get_object(self.IOST_Objs[window_name]["_Summary_StationInfo_ConsolePort_Value_L"])

        # self.IOST_Objs[window_name]["_Summary_StationInfo_SlimproPort_Value_L"] = self.IOST_WRunStationInfo_Builder.get_object(self.IOST_Objs[window_name]["_Summary_StationInfo_SlimproPort_Value_L"])

        # self.IOST_Objs[window_name]["_Summary_StationInfo_NPS_IP_Value_L"] = self.IOST_WRunStationInfo_Builder.get_object(self.IOST_Objs[window_name]["_Summary_StationInfo_NPS_IP_Value_L"])

        # self.IOST_Objs[window_name]["_Summary_StationInfo_NPS_Port_Value_L"] = self.IOST_WRunStationInfo_Builder.get_object(self.IOST_Objs[window_name]["_Summary_StationInfo_NPS_Port_Value_L"])

        # self.IOST_Objs[window_name]["_Summary_StationInfo_ThermalIP_Value_L"] = self.IOST_WRunStationInfo_Builder.get_object(self.IOST_Objs[window_name]["_Summary_StationInfo_ThermalIP_Value_L"])

        # self.IOST_Objs[window_name]["_Summary_StationInfo_ThermalPort_Value_L"] = self.IOST_WRunStationInfo_Builder.get_object(self.IOST_Objs[window_name]["_Summary_StationInfo_ThermalPort_Value_L"])

        # self.IOST_Objs[window_name]["_Summary_StationInfo_Temperature_Value_L"] = self.IOST_WRunStationInfo_Builder.get_object(self.IOST_Objs[window_name]["_Summary_StationInfo_Temperature_Value_L"])

        # self.IOST_Objs[window_name]["_Summary_StationInfo_TimeRun_Value_L"] = self.IOST_WRunStationInfo_Builder.get_object(self.IOST_Objs[window_name]["_Summary_StationInfo_TimeRun_Value_L"])

        # self.IOST_Objs[window_name]["_Summary_StationInfo_ServerIP_Value_L"] = self.IOST_WRunStationInfo_Builder.get_object(self.IOST_Objs[window_name]["_Summary_StationInfo_ServerIP_Value_L"])

        # self.IOST_Objs[window_name]["_Summary_StationInfo_OCD_Enable_L"] = self.IOST_WRunStationInfo_Builder.get_object(self.IOST_Objs[window_name]["_Summary_StationInfo_OCD_Enable_L"])

        # self.IOST_Objs[window_name]["_Summary_StationInfo_OCD_IP_Value_L"] = self.IOST_WRunStationInfo_Builder.get_object(self.IOST_Objs[window_name]["_Summary_StationInfo_OCD_IP_Value_L"])

        # self.IOST_Objs[window_name]["_Summary_StationInfo_BDI_Enable_L"] = self.IOST_WRunStationInfo_Builder.get_object(self.IOST_Objs[window_name]["_Summary_StationInfo_BDI_Enable_L"])

        # self.IOST_Objs[window_name]["_Summary_StationInfo_BDI_IP_Value_L"] = self.IOST_WRunStationInfo_Builder.get_object(self.IOST_Objs[window_name]["_Summary_StationInfo_BDI_IP_Value_L"])


    #----------------------------------------------------------------------
    def WRun_InitStationInfo_Obj(self, window_name):
        "Initialization all Station info objects when WRun start"
        self.IOST_Objs[window_name]["_Summary_StationInfo_ConsoleIP_Value_L"].set_text(self.IOST_Data["StationInfo"]["ConsoleIP"])
        FormatText(self.IOST_Objs[window_name]["_Summary_StationInfo_ConsoleIP_Value_L"], color=WRUN_STATION_INFO_COLOR)

        self.IOST_Objs[window_name]["_Summary_StationInfo_ConsolePort_Value_L"].set_text(self.IOST_Data["StationInfo"]["ConsolePort"])
        FormatText(self.IOST_Objs[window_name]["_Summary_StationInfo_ConsolePort_Value_L"], color=WRUN_STATION_INFO_COLOR)

        self.IOST_Objs[window_name]["_Summary_StationInfo_SlimproPort_Value_L"].set_text(self.IOST_Data["StationInfo"]["SlimproPort"])
        FormatText(self.IOST_Objs[window_name]["_Summary_StationInfo_SlimproPort_Value_L"], color=WRUN_STATION_INFO_COLOR)

        self.IOST_Objs[window_name]["_Summary_StationInfo_NPS_IP_Value_L"].set_text(self.IOST_Data["StationInfo"]["NPS_IP"])
        FormatText(self.IOST_Objs[window_name]["_Summary_StationInfo_NPS_IP_Value_L"], color=WRUN_STATION_INFO_COLOR)

        self.IOST_Objs[window_name]["_Summary_StationInfo_NPS_Port_Value_L"].set_text(self.IOST_Data["StationInfo"]["NPS_Port"])
        FormatText(self.IOST_Objs[window_name]["_Summary_StationInfo_NPS_Port_Value_L"], color=WRUN_STATION_INFO_COLOR)

        self.IOST_Objs[window_name]["_Summary_StationInfo_ThermalIP_Value_L"].set_text(self.IOST_Data["StationInfo"]["ThermalIP"])
        FormatText(self.IOST_Objs[window_name]["_Summary_StationInfo_ThermalIP_Value_L"], color=WRUN_STATION_INFO_COLOR)

        self.IOST_Objs[window_name]["_Summary_StationInfo_ThermalPort_Value_L"].set_text(self.IOST_Data["StationInfo"]["ThermalPort"])
        FormatText(self.IOST_Objs[window_name]["_Summary_StationInfo_ThermalPort_Value_L"], color=WRUN_STATION_INFO_COLOR)

        self.IOST_Objs[window_name]["_Summary_StationInfo_Temperature_Value_L"].set_text(self.IOST_Data["StationInfo"]["Temperature"])
        FormatText(self.IOST_Objs[window_name]["_Summary_StationInfo_Temperature_Value_L"], color=WRUN_STATION_INFO_COLOR)

        self.IOST_Objs[window_name]["_Summary_StationInfo_TimeRun_Value_L"].set_text(self.IOST_Data["StationInfo"]["TimeRunHour"])
        FormatText(self.IOST_Objs[window_name]["_Summary_StationInfo_TimeRun_Value_L"], color=WRUN_STATION_INFO_COLOR)

        self.IOST_Objs[window_name]["_Summary_StationInfo_ServerIP_Value_L"].set_text(self.IOST_Data["StationInfo"]["ServerIP"])
        FormatText(self.IOST_Objs[window_name]["_Summary_StationInfo_ServerIP_Value_L"], color=WRUN_STATION_INFO_COLOR)

        if self.IOST_Data["StationInfo"]["OCD_Enable"] == STATUS_ENABLE:
            self.IOST_Objs[window_name]["_Summary_StationInfo_OCD_Enable_L"].set_text(STATUS_AVAIL)
            FormatText(self.IOST_Objs[window_name]["_Summary_StationInfo_OCD_Enable_L"], color=WRUN_STATION_INFO_COLOR)
            self.IOST_Objs[window_name]["_Summary_StationInfo_OCD_IP_Value_L"].set_text(self.IOST_Data["StationInfo"]["OCD_IP"])
            FormatText(self.IOST_Objs[window_name]["_Summary_StationInfo_OCD_IP_Value_L"], color=WRUN_STATION_INFO_COLOR)
        else:
            self.IOST_Objs[window_name]["_Summary_StationInfo_OCD_Enable_L"].set_text(STATUS_NOT_AVAIL)
            FormatText(self.IOST_Objs[window_name]["_Summary_StationInfo_OCD_Enable_L"], color="red")
            self.IOST_Objs[window_name]["_Summary_StationInfo_OCD_IP_Value_L"].set_text(STATUS_N_A)

        if self.IOST_Data["StationInfo"]["BDI_Enable"] == STATUS_ENABLE:
            self.IOST_Objs[window_name]["_Summary_StationInfo_BDI_Enable_L"].set_text(STATUS_AVAIL)
            FormatText(self.IOST_Objs[window_name]["_Summary_StationInfo_BDI_Enable_L"], color=WRUN_STATION_INFO_COLOR)
            self.IOST_Objs[window_name]["_Summary_StationInfo_BDI_IP_Value_L"].set_text(self.IOST_Data["StationInfo"]["BDI_IP"])
            FormatText(self.IOST_Objs[window_name]["_Summary_StationInfo_BDI_IP_Value_L"], color=WRUN_STATION_INFO_COLOR)
        else:
            self.IOST_Objs[window_name]["_Summary_StationInfo_BDI_Enable_L"].set_text(STATUS_NOT_AVAIL)
            FormatText(self.IOST_Objs[window_name]["_Summary_StationInfo_BDI_Enable_L"], color="red")
            self.IOST_Objs[window_name]["_Summary_StationInfo_BDI_IP_Value_L"].set_text(STATUS_N_A)
        
        #
        station_info = self.IOST_WRunStationInfo_Builder.get_object("IOST_WRun_Summary_StationInfo_L").get_text()
        station_info +=  " : \n\tStation Name    :   " + self.IOST_Data["StationInfo"]["StationName"] \
                          + "\t| Board Number  :   " + self.IOST_Data["StationInfo"]["StationBoardNumber"] \
                          + "\t| Chip Number    :   " + self.IOST_Data["StationInfo"]["StationChipNumber"] + "\n"
        FormatText(self.IOST_WRunStationInfo_Builder.get_object("IOST_WRun_Summary_StationInfo_L"), color=WRUN_IP_COLOR_DEFAULT, bold=True, text=station_info)

        #  #0099ff        
        FormatText(self.IOST_WRunStationInfo_Builder.get_object("IOST_WRun_Summary_StationInfo_ConsoleIP_L"), color=WRUN_STATION_INFO_LABLE_COLOR)
        FormatText(self.IOST_WRunStationInfo_Builder.get_object("IOST_WRun_Summary_StationInfo_ConsolePort_L"), color=WRUN_STATION_INFO_LABLE_COLOR)
        FormatText(self.IOST_WRunStationInfo_Builder.get_object("IOST_WRun_Summary_StationInfo_SlimproPort_L"), color=WRUN_STATION_INFO_LABLE_COLOR)
        FormatText(self.IOST_WRunStationInfo_Builder.get_object("IOST_WRun_Summary_StationInfo_NPS_IP_L"), color=WRUN_STATION_INFO_LABLE_COLOR)
        FormatText(self.IOST_WRunStationInfo_Builder.get_object("IOST_WRun_Summary_StationInfo_NPS_Port_L"), color=WRUN_STATION_INFO_LABLE_COLOR)
        FormatText(self.IOST_WRunStationInfo_Builder.get_object("IOST_WRun_Summary_StationInfo_ThermalIP_L"), color=WRUN_STATION_INFO_LABLE_COLOR)
        FormatText(self.IOST_WRunStationInfo_Builder.get_object("IOST_WRun_Summary_StationInfo_ThermalPort_L"), color=WRUN_STATION_INFO_LABLE_COLOR)
        FormatText(self.IOST_WRunStationInfo_Builder.get_object("IOST_WRun_Summary_StationInfo_Temperature_L"), color=WRUN_STATION_INFO_LABLE_COLOR, text=TEMPERATURE_STR)
        FormatText(self.IOST_WRunStationInfo_Builder.get_object("IOST_WRun_Summary_StationInfo_TimeRun_L"), color=WRUN_STATION_INFO_LABLE_COLOR)
        FormatText(self.IOST_WRunStationInfo_Builder.get_object("IOST_WRun_Summary_StationInfo_ServerIP_L"), color=WRUN_STATION_INFO_LABLE_COLOR)
        FormatText(self.IOST_WRunStationInfo_Builder.get_object("IOST_WRun_Summary_StationInfo_OCD_L"), color=WRUN_STATION_INFO_LABLE_COLOR)
        FormatText(self.IOST_WRunStationInfo_Builder.get_object("IOST_WRun_Summary_StationInfo_OCD_IP_L"), color=WRUN_STATION_INFO_LABLE_COLOR)
        FormatText(self.IOST_WRunStationInfo_Builder.get_object("IOST_WRun_Summary_StationInfo_BDI_L"), color=WRUN_STATION_INFO_LABLE_COLOR)
        FormatText(self.IOST_WRunStationInfo_Builder.get_object("IOST_WRun_Summary_StationInfo_BDI_IP_L"), color=WRUN_STATION_INFO_LABLE_COLOR)


