""" The End Treatment ui loader """ # Python import os import can import struct # Qt from PySide2 import QtCore, QtWidgets from PySide2.QtCore import Slot # parent from engine.dynamicloader import DynamicLoader # plugin specific from leahi_dialin.common.msg_defs import MsgIds from leahi_dialin.common.td_defs import TDTreatmentStates from leahi_dialin.protocols import CAN # hd Simulator from leahi_dialin.ui.td_messaging import TD_Messaging class Loader(DynamicLoader): """ The End Treatment ui loader """ def __init__(self): self.td_interface = TD_Messaging() self.can_interface = self.td_interface.can_interface super().__init__(os.path.dirname(__file__)) if self.can_interface is not None: channel_id = CAN.DenaliChannels.ui_to_td_ch_id message_id = MsgIds.MSG_ID_TD_END_TREATMENT_REQUEST.value self.can_interface.register_receiving_publication_function(channel_id, message_id, self.handle_end_tx_request) def _init_loader(self): """ finds and creates widgets :return: none """ self.tbSend = self.find_widget(QtWidgets.QToolButton , 'tbSend' ) self.sbReason = self.find_widget(QtWidgets.QSpinBox , 'reasonSpinBox' ) def _init_connections(self): """ initializes the widgets connections :return: none """ self.tbSend .clicked .connect(self.do_send) def _init_widgets(self): """ initializes the widgets' properties :return: none """ @Slot() def handle_end_tx_request(self, message, timestamp = 0.0): """ Called when the user requests to firmware from UI @return: None """ reason = self.sbReason.value() self.td_interface.td_end_tx_response(reason) if ( reason == 0 ): self.td_interface.td_tx_state( TDTreatmentStates.TREATMENT_RINSEBACK_STATE.value , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ) @Slot() def do_send(self): """ the slot for treatment set point Data :return: none """ self.handle_end_tx_request("")