#!D:\IDE\Anaconda3\envs\Microscope_Scan python
# -*- coding: UTF-8 -*-
"""
 @Author: Administrator
 @FileName: LibraryContext.py
 @DateTime: 2025/4/8 19:49
 @SoftWare: PyCharm
 @Author  ：xsh
"""
import sys
from PyQt5                              import Qt
from AppInterfaces.ModelInterface       import ContextModelInterface
from AppCore.Levels                     import *
from AppUtils.utils                     import *
from AppCore.Requests                   import *


class LibraryContext(ContextModelInterface):
    __slots__ = ('DllFile', 'IsOpen', 'IsConnected', 'LibStatus')
    __types__ = (
        str     ,
        bool    ,
        bool    ,
        bool
    )
    DllFile     : str
    IsOpen      : bool
    IsConnected : bool
    LibStatus   : bool
    def __init__(self, *args, **kwargs):
        super(LibraryContext, self).__init__(*args, **kwargs)
        self.initialization("动态库上下文")

    def initValue(self):
        super(LibraryContext, self).initValue()
        self.DllFile        = "Resource/DLL/Hitbot/small_scara_interface.dll"  # 连接地址
        self.IsOpen         = False  # 打开状态
        self.IsConnected    = False  # 连接状态
        self.LibStatus      = False  # 加载状态

    def initParameter(self, **args):
        super(LibraryContext, self).initParameter(**args)
        if not isinstance(args, dict) or len(args) <= 0:
            return
        for index, _property in enumerate(self.__slots__):
            setattr(self, _property, AppConvert.ObjectConvert(args.get(_property, getattr(self, _property, None)),
                                                              self.__types__[index]))

    @property
    def absoluteFilePath(self) -> str:
        return "{0}/{1}".format(Qt.QFileInfo(sys.argv[0]).absolutePath(), self.DllFile)

    @absoluteFilePath.setter
    def absoluteFilePath(self, filename: str):
        if AppConvert.isEmpty(filename):
            return
        file_name: str = Qt.QFileInfo(filename)
        file_name = file_name.replace("{0}/".format(Qt.QFileInfo(sys.argv[0]).absolutePath()), "")
        if AppConvert.isEmpty(file_name):
            return
        self.DllFile = file_name


AppFactory.GetInstance().Register(LibraryContext.__name__, LibraryContext.__module__.__str__())