Ejemplo n.º 1
0
    def deleteValueByDataPath(self, dataPath_: str, dataSet_: dict = None):
        if not self.dataPathValidation(dataPath_):
            return False

        _dataPathList: List[str] = None
        if dataPath_.find("."):
            _dataPathList = dataPath_.split(".")
        else:
            _dataPathList.append(dataPath_)

        _dataPositionParent: dict = None
        _dataKeyInParent: str = None

        # 路径初始为整体路径
        _dataPosition: dict = self.dataSet
        # 相对路径被赋值的话,就从相对路径开始查找
        if not dataSet_ is None:
            _dataPosition = dataSet_

        while len(_dataPathList) > 0:
            _currentKey: str = listUtils.list_shift(_dataPathList)
            if not _dataPosition:
                return False

            _dataPositionParent = dict(_dataPosition)  # 记录当前为父节点
            _dataKeyInParent = _currentKey
            _dataPosition = _dataPosition[_currentKey]  # 记录当前节点

        if _dataPositionParent:
            del _dataPositionParent[_dataKeyInParent]
            return True
        return False
Ejemplo n.º 2
0
def getValueByDataPath(
        dataPath_: str,
        dataSet_: dict
):
    if not dataPathValidation(dataPath_):
        return None

    _dataPathList: List[str] = []
    if dataPath_.find("."):
        _dataPathList = dataPath_.split(".")
    else:
        _dataPathList.append(dataPath_)

    # 路径初始为整体路径
    _dataPosition: dict = dataSet_
    # 相对路径被赋值的话,就从相对路径开始查找
    if not dataSet_ is None:
        _dataPosition = dataSet_

    while len(_dataPathList) > 0:
        _currentKey: str = listUtils.list_shift(_dataPathList)
        if _dataPosition is None:
            return None
        _dataPosition = _dataPosition[_currentKey]

    return _dataPosition
Ejemplo n.º 3
0
 def destroy(self):
     # 当前服务下创建的对象,都要随着清理掉
     while len(self.subObjects) > 0:
         _shiftItem: Base = listUtils.list_shift(self.subObjects)
         # 创建了,但是没销毁的,就销毁一次
         if _shiftItem._isCreated and not _shiftItem._isDestory:
             _shiftItem.destroy()
     super(BaseService, self).destroy()
     # 去除自己的引用
     self.sm.__delattr__(self.objectName)
Ejemplo n.º 4
0
def setValueToDataPath(dataPath_: str, value_, dataSet_: dict):
    if not dataPathValidation(dataPath_):
        return None
    # 发生变化的路径列表
    _changeList: List[str] = []
    # 路径切割层级列表
    _dataPathList: List[str] = []

    if not dataPath_ == "":
        if dataPath_.find(".") > 0:
            _dataPathList = dataPath_.split(".")
        else:
            _dataPathList.append(dataPath_)

    # 路径初始为整体路径
    _dataPosition: dict = dataSet_

    while len(_dataPathList) > 0:
        _currentKey = listUtils.list_shift(_dataPathList)
        if len(_dataPathList) == 0:
            if not value_ == "" and (not value_ == False) and not value_:  # Value_ 为空
                if str(_currentKey + "[0]") in _dataPosition:
                    _arrayLength = _dataPosition[_currentKey]
                    for i in range(_arrayLength + 1):  # 多清理一个 0 序号。[0]用来标示当前内容为数组
                        _tempKey = "[" + str(i) + "]"
                        del _dataPosition[_currentKey + _tempKey]
                        if not i == 0:  # 0位只是一个标示当前为数组的站位符号,用来在数组是0个元素时,指明当前字段为数组
                            _changeList.append(dataPath_ + _tempKey)
                    del _dataPosition[_currentKey]
                else:
                    del _dataPosition[_currentKey]
            elif isinstance(value_, list):
                resetlistOnDataPath(_dataPosition, dataPath_, _currentKey, value_, _changeList)
            elif isinstance(value_, bool):
                _dataPosition[_currentKey] = value_
                _changeList.append(dataPath_)
            elif isinstance(value_, str) or isinstance(value_, int) or isinstance(value_, float) or isinstance(
                    value_, complex):
                _dataPosition[_currentKey] = value_
                _changeList.append(dataPath_)
            elif isinstance(value_, dict):  # 不是数字,字符串,布尔,数组,其他的就是对象了
                if not _currentKey in _dataPosition:
                    _dataPosition[_currentKey] = dict({})
                recursiveDataPath(_dataPosition[_currentKey], value_, dataPath_, _changeList)
            else:
                raise pyUtils.AppError("意外的类型 : " + _currentKey)
        else:
            if not _currentKey in _dataPosition:
                _dataPosition[_currentKey] = dict({})
            _dataPosition = _dataPosition[_currentKey]

    return _changeList
Ejemplo n.º 5
0
 def splitDataStr(self, dataString_: str):
     self.dataPathListenerList = []
     self.otherStringList = []
     if dataString_ and dataString_.find("${") >= 0:
         _dataPathListSplit: List[str] = dataString_.split("${")
         self.otherStringList.append(
             listUtils.list_shift(_dataPathListSplit))
         _length: int = len(_dataPathListSplit)
         for _idx in range(_length):
             _string_item: str = _dataPathListSplit[_idx]
             _string_list: List[str] = _string_item.split("}")
             self.dataPathListenerList.append(_string_list[0])
             self.otherStringList.append(_string_list[1])
     else:
         self.dataPathListenerList.append(self.dataPath)
         self.otherStringList.append("")
         self.otherStringList.append("")
Ejemplo n.º 6
0
    def getValueByDataPath(self, dataPath_: str, dataSet_: dict = None):
        if not self.dataPathValidation(dataPath_):
            return None

        _dataPathList: List[str] = []
        if dataPath_.find("."):
            _dataPathList = dataPath_.split(".")
        else:
            _dataPathList.append(dataPath_)

        # 路径初始为整体路径
        _dataPosition: dict = self.dataSet
        # 相对路径被赋值的话,就从相对路径开始查找
        if not dataSet_ is None:
            _dataPosition = dataSet_

        while len(_dataPathList) > 0:
            _currentKey: str = listUtils.list_shift(_dataPathList)
            if _dataPosition is None:
                return None

            _dealedKeyList = self.dealKey(_currentKey)
            if not _dealedKeyList:  # 非数组路径
                if _currentKey in _dataPosition:
                    _dataPosition = _dataPosition[_currentKey]
                else:
                    _dataPosition = None
                    break
            else:
                _currentKey = _dealedKeyList[0]  # 获取键值
                del _dealedKeyList[0]  # 列表中移除键值
                if _currentKey in _dataPosition:
                    _dataPosition = _dataPosition[_currentKey]

                else:
                    _dataPosition = None
                    break
        return _dataPosition
Ejemplo n.º 7
0
    def setValueToDataPath(self,
                           dataPath_: str,
                           value_,
                           dataSet_: dict = None):
        if not self.dataPathValidation(dataPath_):
            return None
        # 发生变化的路径列表
        _changeList: List[str] = []
        # 路径切割层级列表
        _dataPathList: List[str] = []

        if not dataPath_ == "":
            if dataPath_.find(".") > 0:
                _dataPathList = dataPath_.split(".")
            else:
                _dataPathList.append(dataPath_)

        # 路径初始为整体路径
        _dataPosition: dict = self.dataSet
        # 相对路径被赋值的话,就从相对路径开始查找
        if not dataSet_ is None:
            _dataPosition = dataSet_

        while len(_dataPathList) > 0:
            _currentKey = listUtils.list_shift(_dataPathList)
            if len(_dataPathList) == 0:
                if not value_ == "" and not value_:  # Value_ 为空
                    if str(_currentKey + "[0]") in _dataPosition:
                        _arrayLength = _dataPosition[_currentKey]
                        for i in range(_arrayLength +
                                       1):  # 多清理一个 0 序号。[0]用来标示当前内容为数组
                            _tempKey = "[" + str(i) + "]"
                            del _dataPosition[_currentKey + _tempKey]
                            if not i == 0:  # 0位只是一个标示当前为数组的站位符号,用来在数组是0个元素时,指明当前字段为数组
                                _changeList.append(dataPath_ + _tempKey)
                        del _dataPosition[_currentKey]
                    else:
                        del _dataPosition[_currentKey]
                elif isinstance(value_, list):
                    _dataOnPath = dict({})
                    _dataPosition[_currentKey] = _dataOnPath
                    self.resetlistOnDataPath(
                        _dataOnPath,  # 数据源节点
                        dataPath_,  # 节点对应的数据路径
                        _currentKey,  # 要在节点上添加什么键
                        value_,  # 要在节点上添加什么值
                        _changeList)
                elif isinstance(value_, bool):
                    # if value_:
                    #     _dataPosition[_currentKey] = "True"
                    # else:
                    #     _dataPosition[_currentKey] = "False"
                    _dataPosition[_currentKey] = value_
                    _changeList.append(dataPath_)
                elif isinstance(
                        value_, str) or isinstance(value_, int) or isinstance(
                            value_, float) or isinstance(value_, complex):
                    # _dataPosition[_currentKey] = str(value_)
                    _dataPosition[_currentKey] = value_
                    _changeList.append(dataPath_)
                elif isinstance(value_, dict):  # 不是数字,字符串,布尔,数组,其他的就是对象了
                    if not _currentKey in _dataPosition:
                        _dataPosition[_currentKey] = dict({})
                    self.recursiveDataPath(_dataPosition[_currentKey], value_,
                                           dataPath_, _changeList)
                else:
                    self.raiseError(pyUtils.getCurrentRunningFunctionName(),
                                    "意外的类型 : " + _currentKey)
            else:
                if not _dataPosition[_currentKey]:
                    _dataPosition[_currentKey] = dict({})
                _dataPosition = _dataPosition[_currentKey]

        # 指定数据源动画,不用分发事件变更。因为数据源不一致
        if dataSet_ is None:
            for _idx in range(len(_changeList)):
                self.dataEventMgr.onDataChange(_changeList[_idx])
        return _changeList