mirror of
https://github.com/KenanZhu/AutoLibrary.git
synced 2026-06-18 07:23:03 +08:00
style(gui): 规范编排对话框属性命名并消除冗余代码
This commit is contained in:
@@ -79,9 +79,9 @@ class ConditionalBlock(QGroupBox):
|
|||||||
condLayout.setContentsMargins(4, 4, 4, 4)
|
condLayout.setContentsMargins(4, 4, 4, 4)
|
||||||
condLayout.setSpacing(6)
|
condLayout.setSpacing(6)
|
||||||
|
|
||||||
self._condRowsLayout = QVBoxLayout()
|
self.condRowsLayout = QVBoxLayout()
|
||||||
self._condRowsLayout.setSpacing(4)
|
self.condRowsLayout.setSpacing(4)
|
||||||
condLayout.addLayout(self._condRowsLayout)
|
condLayout.addLayout(self.condRowsLayout)
|
||||||
self.addCondBtn = QPushButton("+ 添加条件", self.conditionWidget)
|
self.addCondBtn = QPushButton("+ 添加条件", self.conditionWidget)
|
||||||
self.addCondBtn.setFixedHeight(25)
|
self.addCondBtn.setFixedHeight(25)
|
||||||
condLayout.addWidget(self.addCondBtn)
|
condLayout.addWidget(self.addCondBtn)
|
||||||
@@ -89,9 +89,9 @@ class ConditionalBlock(QGroupBox):
|
|||||||
self.actionLabel = QLabel("执行步骤:", self)
|
self.actionLabel = QLabel("执行步骤:", self)
|
||||||
self.actionLabel.setFixedHeight(25)
|
self.actionLabel.setFixedHeight(25)
|
||||||
mainLayout.addWidget(self.actionLabel)
|
mainLayout.addWidget(self.actionLabel)
|
||||||
self._actionsLayout = QVBoxLayout()
|
self.actionsLayout = QVBoxLayout()
|
||||||
self._actionsLayout.setSpacing(4)
|
self.actionsLayout.setSpacing(4)
|
||||||
mainLayout.addLayout(self._actionsLayout)
|
mainLayout.addLayout(self.actionsLayout)
|
||||||
self.addActionBtn = QPushButton("+ 添加执行步骤", self)
|
self.addActionBtn = QPushButton("+ 添加执行步骤", self)
|
||||||
self.addActionBtn.setFixedHeight(25)
|
self.addActionBtn.setFixedHeight(25)
|
||||||
mainLayout.addWidget(self.addActionBtn)
|
mainLayout.addWidget(self.addActionBtn)
|
||||||
@@ -116,7 +116,7 @@ class ConditionalBlock(QGroupBox):
|
|||||||
isFirst=True, parent=self
|
isFirst=True, parent=self
|
||||||
)
|
)
|
||||||
self._conditionRows.append(row)
|
self._conditionRows.append(row)
|
||||||
self._condRowsLayout.addWidget(row)
|
self.condRowsLayout.addWidget(row)
|
||||||
|
|
||||||
|
|
||||||
def addConditionRow(
|
def addConditionRow(
|
||||||
@@ -129,7 +129,7 @@ class ConditionalBlock(QGroupBox):
|
|||||||
)
|
)
|
||||||
row.deleteBtn.clicked.connect(lambda: self.removeConditionRow(row))
|
row.deleteBtn.clicked.connect(lambda: self.removeConditionRow(row))
|
||||||
self._conditionRows.append(row)
|
self._conditionRows.append(row)
|
||||||
self._condRowsLayout.addWidget(row)
|
self.condRowsLayout.addWidget(row)
|
||||||
|
|
||||||
|
|
||||||
def removeConditionRow(
|
def removeConditionRow(
|
||||||
@@ -139,7 +139,7 @@ class ConditionalBlock(QGroupBox):
|
|||||||
|
|
||||||
if row in self._conditionRows and len(self._conditionRows) > 1:
|
if row in self._conditionRows and len(self._conditionRows) > 1:
|
||||||
self._conditionRows.remove(row)
|
self._conditionRows.remove(row)
|
||||||
self._condRowsLayout.removeWidget(row)
|
self.condRowsLayout.removeWidget(row)
|
||||||
row.hide()
|
row.hide()
|
||||||
row.deleteLater()
|
row.deleteLater()
|
||||||
|
|
||||||
@@ -151,7 +151,7 @@ class ConditionalBlock(QGroupBox):
|
|||||||
step = ActionStepFrame(self._varMgr, self.blockIndex, parent=self)
|
step = ActionStepFrame(self._varMgr, self.blockIndex, parent=self)
|
||||||
step.deleteBtn.clicked.connect(lambda: self.removeActionStep(step))
|
step.deleteBtn.clicked.connect(lambda: self.removeActionStep(step))
|
||||||
self._actionWidgets.append(step)
|
self._actionWidgets.append(step)
|
||||||
self._actionsLayout.addWidget(step)
|
self.actionsLayout.addWidget(step)
|
||||||
|
|
||||||
|
|
||||||
def removeActionStep(
|
def removeActionStep(
|
||||||
@@ -161,7 +161,7 @@ class ConditionalBlock(QGroupBox):
|
|||||||
|
|
||||||
if step in self._actionWidgets:
|
if step in self._actionWidgets:
|
||||||
self._actionWidgets.remove(step)
|
self._actionWidgets.remove(step)
|
||||||
self._actionsLayout.removeWidget(step)
|
self.actionsLayout.removeWidget(step)
|
||||||
step.hide()
|
step.hide()
|
||||||
step.deleteLater()
|
step.deleteLater()
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ class ALAutoScriptOrchDialog(QDialog):
|
|||||||
self.loadFromScript(existingScript)
|
self.loadFromScript(existingScript)
|
||||||
else:
|
else:
|
||||||
self.addBlock()
|
self.addBlock()
|
||||||
self._scrollLayout.addStretch()
|
self.scrollLayout.addStretch()
|
||||||
|
|
||||||
|
|
||||||
def setupUi(
|
def setupUi(
|
||||||
@@ -61,8 +61,8 @@ class ALAutoScriptOrchDialog(QDialog):
|
|||||||
scroll.setWidgetResizable(True)
|
scroll.setWidgetResizable(True)
|
||||||
scroll.setFrameShape(QFrame.NoFrame)
|
scroll.setFrameShape(QFrame.NoFrame)
|
||||||
scrollContent = QWidget()
|
scrollContent = QWidget()
|
||||||
self._scrollLayout = QVBoxLayout(scrollContent)
|
self.scrollLayout = QVBoxLayout(scrollContent)
|
||||||
self._scrollLayout.setSpacing(5)
|
self.scrollLayout.setSpacing(5)
|
||||||
scroll.setWidget(scrollContent)
|
scroll.setWidget(scrollContent)
|
||||||
mainLayout.addWidget(scroll)
|
mainLayout.addWidget(scroll)
|
||||||
self.addBlockBtn = QPushButton("+ 添加判断块")
|
self.addBlockBtn = QPushButton("+ 添加判断块")
|
||||||
@@ -108,16 +108,16 @@ class ALAutoScriptOrchDialog(QDialog):
|
|||||||
block.addActionStep()
|
block.addActionStep()
|
||||||
self._blocks.append(block)
|
self._blocks.append(block)
|
||||||
self._updateBlockTypeRestrictions()
|
self._updateBlockTypeRestrictions()
|
||||||
if self._scrollLayout.count() > 0:
|
if self.scrollLayout.count() > 0:
|
||||||
lastItem = self._scrollLayout.itemAt(
|
lastItem = self.scrollLayout.itemAt(
|
||||||
self._scrollLayout.count() - 1
|
self.scrollLayout.count() - 1
|
||||||
)
|
)
|
||||||
if lastItem and lastItem.spacerItem():
|
if lastItem and lastItem.spacerItem():
|
||||||
self._scrollLayout.insertWidget(
|
self.scrollLayout.insertWidget(
|
||||||
self._scrollLayout.count() - 1, block
|
self.scrollLayout.count() - 1, block
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
self._scrollLayout.addWidget(block)
|
self.scrollLayout.addWidget(block)
|
||||||
|
|
||||||
|
|
||||||
def removeBlock(
|
def removeBlock(
|
||||||
@@ -130,7 +130,7 @@ class ALAutoScriptOrchDialog(QDialog):
|
|||||||
return
|
return
|
||||||
if block in self._blocks:
|
if block in self._blocks:
|
||||||
self._blocks.remove(block)
|
self._blocks.remove(block)
|
||||||
self._scrollLayout.removeWidget(block)
|
self.scrollLayout.removeWidget(block)
|
||||||
block.hide()
|
block.hide()
|
||||||
block.deleteLater()
|
block.deleteLater()
|
||||||
for i, blk in enumerate(self._blocks):
|
for i, blk in enumerate(self._blocks):
|
||||||
@@ -200,8 +200,8 @@ class ALAutoScriptOrchDialog(QDialog):
|
|||||||
typeIdxMap = {"IF": 0, "ELSE IF": 1, "ELSE": 2}
|
typeIdxMap = {"IF": 0, "ELSE IF": 1, "ELSE": 2}
|
||||||
parsedBlocks = parseBlocks(script)
|
parsedBlocks = parseBlocks(script)
|
||||||
self._blocks.clear()
|
self._blocks.clear()
|
||||||
while self._scrollLayout.count():
|
while self.scrollLayout.count():
|
||||||
item = self._scrollLayout.takeAt(0)
|
item = self.scrollLayout.takeAt(0)
|
||||||
if item.widget():
|
if item.widget():
|
||||||
item.widget().deleteLater()
|
item.widget().deleteLater()
|
||||||
try:
|
try:
|
||||||
@@ -222,8 +222,8 @@ class ALAutoScriptOrchDialog(QDialog):
|
|||||||
self._parseConditions(block, condition)
|
self._parseConditions(block, condition)
|
||||||
except Exception:
|
except Exception:
|
||||||
self._blocks.clear()
|
self._blocks.clear()
|
||||||
while self._scrollLayout.count():
|
while self.scrollLayout.count():
|
||||||
item = self._scrollLayout.takeAt(0)
|
item = self.scrollLayout.takeAt(0)
|
||||||
if item.widget():
|
if item.widget():
|
||||||
item.widget().deleteLater()
|
item.widget().deleteLater()
|
||||||
self._updateBlockTypeRestrictions()
|
self._updateBlockTypeRestrictions()
|
||||||
@@ -255,7 +255,7 @@ class ALAutoScriptOrchDialog(QDialog):
|
|||||||
allLogics.append(".AND.")
|
allLogics.append(".AND.")
|
||||||
allSubConds.append(ap)
|
allSubConds.append(ap)
|
||||||
for row in list(block._conditionRows):
|
for row in list(block._conditionRows):
|
||||||
block._condRowsLayout.removeWidget(row)
|
block.condRowsLayout.removeWidget(row)
|
||||||
row.hide()
|
row.hide()
|
||||||
row.deleteLater()
|
row.deleteLater()
|
||||||
block._conditionRows.clear()
|
block._conditionRows.clear()
|
||||||
@@ -278,7 +278,7 @@ class ALAutoScriptOrchDialog(QDialog):
|
|||||||
row.logicCombo.setCurrentIndex(li)
|
row.logicCombo.setCurrentIndex(li)
|
||||||
break
|
break
|
||||||
block._conditionRows.append(row)
|
block._conditionRows.append(row)
|
||||||
block._condRowsLayout.addWidget(row)
|
block.condRowsLayout.addWidget(row)
|
||||||
subUp = subCond.upper()
|
subUp = subCond.upper()
|
||||||
if subUp in (".TRUE.", ".FALSE."):
|
if subUp in (".TRUE.", ".FALSE."):
|
||||||
row.loadFromParts(subUp, "", "")
|
row.loadFromParts(subUp, "", "")
|
||||||
|
|||||||
@@ -3,7 +3,11 @@ Helper utilities and constants for the AutoScript orchestration dialog.
|
|||||||
"""
|
"""
|
||||||
import re
|
import re
|
||||||
|
|
||||||
from PySide6.QtCore import QObject, QDate, QTime
|
from PySide6.QtCore import (
|
||||||
|
QObject,
|
||||||
|
QDate,
|
||||||
|
QTime
|
||||||
|
)
|
||||||
from PySide6.QtWidgets import (
|
from PySide6.QtWidgets import (
|
||||||
QComboBox,
|
QComboBox,
|
||||||
QDateEdit,
|
QDateEdit,
|
||||||
@@ -18,7 +22,14 @@ from PySide6.QtWidgets import (
|
|||||||
QWidget,
|
QWidget,
|
||||||
)
|
)
|
||||||
|
|
||||||
from autoscript import ALL_VARIABLES
|
from autoscript import (
|
||||||
|
ALL_VARIABLES,
|
||||||
|
splitTopLevel
|
||||||
|
)
|
||||||
|
from autoscript.ASOperator import (
|
||||||
|
ARITH_TYPES,
|
||||||
|
COMPARISON_OPERATORS
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
VAR_TYPE_ORDER = [
|
VAR_TYPE_ORDER = [
|
||||||
@@ -40,14 +51,19 @@ PRESET_VARIABLES = [
|
|||||||
PRESET_NAMES = {
|
PRESET_NAMES = {
|
||||||
p["name"] for p in PRESET_VARIABLES
|
p["name"] for p in PRESET_VARIABLES
|
||||||
}
|
}
|
||||||
COMPARE_OPERATORS = sorted([
|
# Operator display names (UI-specific), symbols derived from engine
|
||||||
("等于", ".EQ."),
|
_COMPARE_DISPLAY_MAP = {
|
||||||
("不等于", ".NEQ."),
|
".EQ.": "等于",
|
||||||
("大于", ".BGT."),
|
".NEQ.": "不等于",
|
||||||
("小于", ".BLT."),
|
".BGT.": "大于",
|
||||||
("大于等于", ".BGE."),
|
".BLT.": "小于",
|
||||||
("小于等于", ".BLE."),
|
".BGE.": "大于等于",
|
||||||
], key=lambda x: len(x[1]), reverse=True)
|
".BLE.": "小于等于",
|
||||||
|
}
|
||||||
|
COMPARE_OPERATORS = sorted(
|
||||||
|
[(name, op) for op, name in _COMPARE_DISPLAY_MAP.items() if op in COMPARISON_OPERATORS],
|
||||||
|
key=lambda x: len(x[1]), reverse=True
|
||||||
|
)
|
||||||
LOGIC_OPERATORS = [
|
LOGIC_OPERATORS = [
|
||||||
("并且 (.AND.)", ".AND."),
|
("并且 (.AND.)", ".AND."),
|
||||||
("或者 (.OR.)", ".OR."),
|
("或者 (.OR.)", ".OR."),
|
||||||
@@ -57,12 +73,6 @@ ACTION_TYPES = [
|
|||||||
("增加", "add"),
|
("增加", "add"),
|
||||||
("减少", "sub"),
|
("减少", "sub"),
|
||||||
]
|
]
|
||||||
ARITH_TYPES = {
|
|
||||||
"Date",
|
|
||||||
"Time",
|
|
||||||
"Int",
|
|
||||||
"Float"
|
|
||||||
}
|
|
||||||
DATE_RELATIVE_OPTIONS = [
|
DATE_RELATIVE_OPTIONS = [
|
||||||
("前天", "day_before_yesterday"),
|
("前天", "day_before_yesterday"),
|
||||||
("昨天", "yesterday"),
|
("昨天", "yesterday"),
|
||||||
@@ -310,21 +320,17 @@ class _DateInputContainer(QWidget):
|
|||||||
):
|
):
|
||||||
|
|
||||||
s = expr.strip().upper()
|
s = expr.strip().upper()
|
||||||
if s == "CURRENT_DATE - 2":
|
_RELATIVE_MAP = {
|
||||||
|
"CURRENT_DATE": 0, "TODAY": 0,
|
||||||
|
"CURRENT_DATE + 1": 1, "TOMORROW": 1,
|
||||||
|
"CURRENT_DATE + 2": 2,
|
||||||
|
"CURRENT_DATE - 1": 3,
|
||||||
|
"CURRENT_DATE - 2": 4,
|
||||||
|
}
|
||||||
|
idx = _RELATIVE_MAP.get(s)
|
||||||
|
if idx is not None:
|
||||||
self._modeCombo.setCurrentIndex(0)
|
self._modeCombo.setCurrentIndex(0)
|
||||||
self._relCombo.setCurrentIndex(4)
|
self._relCombo.setCurrentIndex(idx)
|
||||||
elif s == "CURRENT_DATE - 1":
|
|
||||||
self._modeCombo.setCurrentIndex(0)
|
|
||||||
self._relCombo.setCurrentIndex(3)
|
|
||||||
elif s in ("CURRENT_DATE", "TODAY"):
|
|
||||||
self._modeCombo.setCurrentIndex(0)
|
|
||||||
self._relCombo.setCurrentIndex(0)
|
|
||||||
elif s == "CURRENT_DATE + 1" or s == "TOMORROW":
|
|
||||||
self._modeCombo.setCurrentIndex(0)
|
|
||||||
self._relCombo.setCurrentIndex(1)
|
|
||||||
elif s == "CURRENT_DATE + 2":
|
|
||||||
self._modeCombo.setCurrentIndex(0)
|
|
||||||
self._relCombo.setCurrentIndex(2)
|
|
||||||
elif s.startswith("DATE("):
|
elif s.startswith("DATE("):
|
||||||
self._modeCombo.setCurrentIndex(1)
|
self._modeCombo.setCurrentIndex(1)
|
||||||
m = re.match(r"DATE\((\d{4}-\d{2}-\d{2})\)", s)
|
m = re.match(r"DATE\((\d{4}-\d{2}-\d{2})\)", s)
|
||||||
@@ -585,38 +591,6 @@ def encodeValueStr(
|
|||||||
return raw_value
|
return raw_value
|
||||||
|
|
||||||
|
|
||||||
def splitTopLevel(
|
|
||||||
text: str,
|
|
||||||
delimiter: str
|
|
||||||
) -> list:
|
|
||||||
|
|
||||||
parts = []
|
|
||||||
depth = 0
|
|
||||||
buf = ""
|
|
||||||
i = 0
|
|
||||||
textUpper = text.upper()
|
|
||||||
delimUpper = delimiter.upper()
|
|
||||||
dlen = len(delimUpper)
|
|
||||||
while i < len(text):
|
|
||||||
if text[i] == "(":
|
|
||||||
depth += 1
|
|
||||||
buf += text[i]
|
|
||||||
elif text[i] == ")":
|
|
||||||
depth -= 1
|
|
||||||
buf += text[i]
|
|
||||||
elif depth == 0 and textUpper[i:i + dlen] == delimUpper:
|
|
||||||
parts.append(buf)
|
|
||||||
buf = ""
|
|
||||||
i += dlen
|
|
||||||
continue
|
|
||||||
else:
|
|
||||||
buf += text[i]
|
|
||||||
i += 1
|
|
||||||
if buf.strip():
|
|
||||||
parts.append(buf)
|
|
||||||
return parts
|
|
||||||
|
|
||||||
|
|
||||||
def stripOuterParens(
|
def stripOuterParens(
|
||||||
s: str
|
s: str
|
||||||
) -> str:
|
) -> str:
|
||||||
|
|||||||
@@ -80,21 +80,21 @@ class ConditionRowFrame(QFrame):
|
|||||||
("变量", "variable"),
|
("变量", "variable"),
|
||||||
], min_width=70, parent=self)
|
], min_width=70, parent=self)
|
||||||
layout.addWidget(self._compTypeCombo)
|
layout.addWidget(self._compTypeCombo)
|
||||||
self._rhsStack = QStackedWidget(self)
|
self.rhsStack = QStackedWidget(self)
|
||||||
self._rhsStack.setFixedHeight(25)
|
self.rhsStack.setFixedHeight(25)
|
||||||
self._literalStack = QStackedWidget(self)
|
self.literalStack = QStackedWidget(self)
|
||||||
self._literalStack.setFixedHeight(25)
|
self.literalStack.setFixedHeight(25)
|
||||||
self._literalWidgets = {}
|
self.literalWidgets = {}
|
||||||
for vt in VAR_TYPE_ORDER:
|
for vt in VAR_TYPE_ORDER:
|
||||||
w = makeValueWidget(vt, self._literalStack)
|
w = makeValueWidget(vt, self.literalStack)
|
||||||
self._literalWidgets[vt] = w
|
self.literalWidgets[vt] = w
|
||||||
self._literalStack.addWidget(w)
|
self.literalStack.addWidget(w)
|
||||||
self._literalStack.setCurrentWidget(self._literalWidgets.get("String"))
|
self.literalStack.setCurrentWidget(self.literalWidgets.get("String"))
|
||||||
self._rhsStack.addWidget(self._literalStack)
|
self.rhsStack.addWidget(self.literalStack)
|
||||||
self.rhsVarCombo = makeVarRefCombo(self)
|
self.rhsVarCombo = makeVarRefCombo(self)
|
||||||
self._rhsStack.addWidget(self.rhsVarCombo)
|
self.rhsStack.addWidget(self.rhsVarCombo)
|
||||||
self._rhsStack.setCurrentIndex(0)
|
self.rhsStack.setCurrentIndex(0)
|
||||||
layout.addWidget(self._rhsStack)
|
layout.addWidget(self.rhsStack)
|
||||||
if not self._isFirst:
|
if not self._isFirst:
|
||||||
self.deleteBtn = QPushButton("×", self)
|
self.deleteBtn = QPushButton("×", self)
|
||||||
self.deleteBtn.setFixedSize(25, 25)
|
self.deleteBtn.setFixedSize(25, 25)
|
||||||
@@ -127,7 +127,6 @@ class ConditionRowFrame(QFrame):
|
|||||||
self.leftVarCombo.currentIndexChanged.connect(self.onLeftVarChanged)
|
self.leftVarCombo.currentIndexChanged.connect(self.onLeftVarChanged)
|
||||||
self._compTypeCombo.currentIndexChanged.connect(self.onCompTypeChanged)
|
self._compTypeCombo.currentIndexChanged.connect(self.onCompTypeChanged)
|
||||||
|
|
||||||
|
|
||||||
@Slot(int)
|
@Slot(int)
|
||||||
def onLeftVarChanged(
|
def onLeftVarChanged(
|
||||||
self,
|
self,
|
||||||
@@ -148,10 +147,9 @@ class ConditionRowFrame(QFrame):
|
|||||||
vartype: str
|
vartype: str
|
||||||
):
|
):
|
||||||
|
|
||||||
if vartype not in self._literalWidgets:
|
if vartype not in self.literalWidgets:
|
||||||
vartype = "String"
|
vartype = "String"
|
||||||
self._literalStack.setCurrentWidget(self._literalWidgets[vartype])
|
self.literalStack.setCurrentWidget(self.literalWidgets[vartype])
|
||||||
|
|
||||||
|
|
||||||
@Slot(int)
|
@Slot(int)
|
||||||
def onCompTypeChanged(
|
def onCompTypeChanged(
|
||||||
@@ -160,7 +158,7 @@ class ConditionRowFrame(QFrame):
|
|||||||
):
|
):
|
||||||
|
|
||||||
isVar = (self._compTypeCombo.currentData() == "variable")
|
isVar = (self._compTypeCombo.currentData() == "variable")
|
||||||
self._rhsStack.setCurrentIndex(1 if isVar else 0)
|
self.rhsStack.setCurrentIndex(1 if isVar else 0)
|
||||||
if isVar:
|
if isVar:
|
||||||
self.populateRhsVarCombo()
|
self.populateRhsVarCombo()
|
||||||
|
|
||||||
@@ -191,7 +189,7 @@ class ConditionRowFrame(QFrame):
|
|||||||
if rhsText:
|
if rhsText:
|
||||||
return f"{name} {opSym} {rhsText}"
|
return f"{name} {opSym} {rhsText}"
|
||||||
return ""
|
return ""
|
||||||
w = self._literalWidgets.get(vartype)
|
w = self.literalWidgets.get(vartype)
|
||||||
if w:
|
if w:
|
||||||
rawVal = getValueFromWidget(w)
|
rawVal = getValueFromWidget(w)
|
||||||
encoded = encodeValueStr(rawVal, vartype)
|
encoded = encodeValueStr(rawVal, vartype)
|
||||||
@@ -232,7 +230,7 @@ class ConditionRowFrame(QFrame):
|
|||||||
self.rhsVarCombo.setCurrentIndex(self.rhsVarCombo.count() - 1)
|
self.rhsVarCombo.setCurrentIndex(self.rhsVarCombo.count() - 1)
|
||||||
else:
|
else:
|
||||||
self._compTypeCombo.setCurrentIndex(0)
|
self._compTypeCombo.setCurrentIndex(0)
|
||||||
w = self._literalWidgets.get(vartype)
|
w = self.literalWidgets.get(vartype)
|
||||||
if w:
|
if w:
|
||||||
setWidgetValue(w, vartype, valueExpr)
|
setWidgetValue(w, vartype, valueExpr)
|
||||||
|
|
||||||
@@ -291,15 +289,15 @@ class ActionStepFrame(QFrame):
|
|||||||
self.buildTargetCombo()
|
self.buildTargetCombo()
|
||||||
layout.addWidget(self.targetCombo)
|
layout.addWidget(self.targetCombo)
|
||||||
layout.addWidget(makeLabel("为", self))
|
layout.addWidget(makeLabel("为", self))
|
||||||
self._valueSrcCombo = makeComboWidget([
|
self.valueSrcCombo = makeComboWidget([
|
||||||
("特定值", "literal"),
|
("特定值", "literal"),
|
||||||
("变量", "variable"),
|
("变量", "variable"),
|
||||||
], min_width=70, parent=self)
|
], min_width=70, parent=self)
|
||||||
layout.addWidget(self._valueSrcCombo)
|
layout.addWidget(self.valueSrcCombo)
|
||||||
self._valueStack = QStackedWidget(self)
|
self.valueStack = QStackedWidget(self)
|
||||||
self._valueStack.setFixedHeight(25)
|
self.valueStack.setFixedHeight(25)
|
||||||
self.initValueStacks()
|
self.initValueStacks()
|
||||||
layout.addWidget(self._valueStack)
|
layout.addWidget(self.valueStack)
|
||||||
self.existingVarCombo = makeVarRefCombo(self)
|
self.existingVarCombo = makeVarRefCombo(self)
|
||||||
self.existingVarCombo.setVisible(False)
|
self.existingVarCombo.setVisible(False)
|
||||||
layout.addWidget(self.existingVarCombo)
|
layout.addWidget(self.existingVarCombo)
|
||||||
@@ -335,16 +333,16 @@ class ActionStepFrame(QFrame):
|
|||||||
self._literalWidgets = {}
|
self._literalWidgets = {}
|
||||||
self._offsetWidgets = {}
|
self._offsetWidgets = {}
|
||||||
for vt in VAR_TYPE_ORDER:
|
for vt in VAR_TYPE_ORDER:
|
||||||
self._literalWidgets[vt] = makeValueWidget(vt, self._valueStack)
|
self._literalWidgets[vt] = makeValueWidget(vt, self.valueStack)
|
||||||
self._valueStack.addWidget(self._literalWidgets[vt])
|
self.valueStack.addWidget(self._literalWidgets[vt])
|
||||||
if vt in ARITH_TYPES:
|
if vt in ARITH_TYPES:
|
||||||
self._offsetWidgets[vt] = makeOffsetWidget(vt, self._valueStack)
|
self._offsetWidgets[vt] = makeOffsetWidget(vt, self.valueStack)
|
||||||
self._valueStack.addWidget(self._offsetWidgets[vt])
|
self.valueStack.addWidget(self._offsetWidgets[vt])
|
||||||
else:
|
else:
|
||||||
lbl = QLabel("(不支持该操作)", self._valueStack)
|
lbl = QLabel("(不支持该操作)", self.valueStack)
|
||||||
lbl.setFixedHeight(25)
|
lbl.setFixedHeight(25)
|
||||||
self._offsetWidgets[vt] = lbl
|
self._offsetWidgets[vt] = lbl
|
||||||
self._valueStack.addWidget(lbl)
|
self.valueStack.addWidget(lbl)
|
||||||
|
|
||||||
|
|
||||||
def connectSignals(
|
def connectSignals(
|
||||||
@@ -353,7 +351,7 @@ class ActionStepFrame(QFrame):
|
|||||||
|
|
||||||
self.opTypeCombo.currentIndexChanged.connect(self.onOpTypeChanged)
|
self.opTypeCombo.currentIndexChanged.connect(self.onOpTypeChanged)
|
||||||
self.targetCombo.currentIndexChanged.connect(self.onTargetChanged)
|
self.targetCombo.currentIndexChanged.connect(self.onTargetChanged)
|
||||||
self._valueSrcCombo.currentIndexChanged.connect(self.onValueSrcChanged)
|
self.valueSrcCombo.currentIndexChanged.connect(self.onValueSrcChanged)
|
||||||
|
|
||||||
@Slot(int)
|
@Slot(int)
|
||||||
def onTargetChanged(
|
def onTargetChanged(
|
||||||
@@ -369,7 +367,7 @@ class ActionStepFrame(QFrame):
|
|||||||
_, vartype = data
|
_, vartype = data
|
||||||
self._currentTargetType = vartype
|
self._currentTargetType = vartype
|
||||||
self.updateRHSWidget()
|
self.updateRHSWidget()
|
||||||
self.onValueSrcChanged(self._valueSrcCombo.currentIndex())
|
self.onValueSrcChanged(self.valueSrcCombo.currentIndex())
|
||||||
|
|
||||||
@Slot(int)
|
@Slot(int)
|
||||||
def onOpTypeChanged(
|
def onOpTypeChanged(
|
||||||
@@ -388,11 +386,11 @@ class ActionStepFrame(QFrame):
|
|||||||
isArith = (op in ("add", "sub"))
|
isArith = (op in ("add", "sub"))
|
||||||
actualType = self._currentTargetType
|
actualType = self._currentTargetType
|
||||||
if isArith and actualType in self._offsetWidgets:
|
if isArith and actualType in self._offsetWidgets:
|
||||||
self._valueStack.setCurrentWidget(self._offsetWidgets[actualType])
|
self.valueStack.setCurrentWidget(self._offsetWidgets[actualType])
|
||||||
elif actualType in self._literalWidgets:
|
elif actualType in self._literalWidgets:
|
||||||
self._valueStack.setCurrentWidget(self._literalWidgets[actualType])
|
self.valueStack.setCurrentWidget(self._literalWidgets[actualType])
|
||||||
else:
|
else:
|
||||||
self._valueStack.setCurrentWidget(self._literalWidgets.get("String"))
|
self.valueStack.setCurrentWidget(self._literalWidgets.get("String"))
|
||||||
|
|
||||||
@Slot(int)
|
@Slot(int)
|
||||||
def onValueSrcChanged(
|
def onValueSrcChanged(
|
||||||
@@ -400,8 +398,8 @@ class ActionStepFrame(QFrame):
|
|||||||
idx
|
idx
|
||||||
):
|
):
|
||||||
|
|
||||||
isVar = (self._valueSrcCombo.currentData() == "variable")
|
isVar = (self.valueSrcCombo.currentData() == "variable")
|
||||||
self._valueStack.setVisible(not isVar)
|
self.valueStack.setVisible(not isVar)
|
||||||
self.existingVarCombo.setVisible(isVar)
|
self.existingVarCombo.setVisible(isVar)
|
||||||
if isVar:
|
if isVar:
|
||||||
self._varMgr.populateCombo(self.existingVarCombo)
|
self._varMgr.populateCombo(self.existingVarCombo)
|
||||||
@@ -437,20 +435,20 @@ class ActionStepFrame(QFrame):
|
|||||||
return f" SET {target} = {encoded}"
|
return f" SET {target} = {encoded}"
|
||||||
elif op == "add":
|
elif op == "add":
|
||||||
vartype = self._currentTargetType
|
vartype = self._currentTargetType
|
||||||
if vartype == "Date" and hasattr(self._valueStack.currentWidget(), "getOffsetDays"):
|
if vartype == "Date" and hasattr(self.valueStack.currentWidget(), "getOffsetDays"):
|
||||||
days = self._valueStack.currentWidget().getOffsetDays()
|
days = self.valueStack.currentWidget().getOffsetDays()
|
||||||
return f" {target} .ADD. {days}"
|
return f" {target} .ADD. {days}"
|
||||||
if vartype == "Time" and hasattr(self._valueStack.currentWidget(), "getOffsetHours"):
|
if vartype == "Time" and hasattr(self.valueStack.currentWidget(), "getOffsetHours"):
|
||||||
hours = self._valueStack.currentWidget().getOffsetHours()
|
hours = self.valueStack.currentWidget().getOffsetHours()
|
||||||
return f" {target} .ADD. {hours}"
|
return f" {target} .ADD. {hours}"
|
||||||
return f" {target} .ADD. {rawVal}"
|
return f" {target} .ADD. {rawVal}"
|
||||||
elif op == "sub":
|
elif op == "sub":
|
||||||
vartype = self._currentTargetType
|
vartype = self._currentTargetType
|
||||||
if vartype == "Date" and hasattr(self._valueStack.currentWidget(), "getOffsetDays"):
|
if vartype == "Date" and hasattr(self.valueStack.currentWidget(), "getOffsetDays"):
|
||||||
days = self._valueStack.currentWidget().getOffsetDays()
|
days = self.valueStack.currentWidget().getOffsetDays()
|
||||||
return f" {target} .SUB. {days}"
|
return f" {target} .SUB. {days}"
|
||||||
if vartype == "Time" and hasattr(self._valueStack.currentWidget(), "getOffsetHours"):
|
if vartype == "Time" and hasattr(self.valueStack.currentWidget(), "getOffsetHours"):
|
||||||
hours = self._valueStack.currentWidget().getOffsetHours()
|
hours = self.valueStack.currentWidget().getOffsetHours()
|
||||||
return f" {target} .SUB. {hours}"
|
return f" {target} .SUB. {hours}"
|
||||||
return f" {target} .SUB. {rawVal}"
|
return f" {target} .SUB. {rawVal}"
|
||||||
return ""
|
return ""
|
||||||
@@ -460,9 +458,9 @@ class ActionStepFrame(QFrame):
|
|||||||
self
|
self
|
||||||
) -> str:
|
) -> str:
|
||||||
|
|
||||||
if self._valueSrcCombo.currentData() == "variable":
|
if self.valueSrcCombo.currentData() == "variable":
|
||||||
return self.existingVarCombo.currentText().strip()
|
return self.existingVarCombo.currentText().strip()
|
||||||
w = self._valueStack.currentWidget()
|
w = self.valueStack.currentWidget()
|
||||||
if w:
|
if w:
|
||||||
return getValueFromWidget(w)
|
return getValueFromWidget(w)
|
||||||
return ""
|
return ""
|
||||||
@@ -504,7 +502,7 @@ class ActionStepFrame(QFrame):
|
|||||||
return
|
return
|
||||||
up = s.upper()
|
up = s.upper()
|
||||||
if isVarReference(s):
|
if isVarReference(s):
|
||||||
self._valueSrcCombo.setCurrentIndex(1)
|
self.valueSrcCombo.setCurrentIndex(1)
|
||||||
self._varMgr.populateCombo(self.existingVarCombo)
|
self._varMgr.populateCombo(self.existingVarCombo)
|
||||||
idx = self._varMgr.findExactNameEntry(self.existingVarCombo, up)
|
idx = self._varMgr.findExactNameEntry(self.existingVarCombo, up)
|
||||||
if idx >= 0:
|
if idx >= 0:
|
||||||
@@ -513,8 +511,8 @@ class ActionStepFrame(QFrame):
|
|||||||
self.existingVarCombo.addItem(up, (up, "String"))
|
self.existingVarCombo.addItem(up, (up, "String"))
|
||||||
self.existingVarCombo.setCurrentIndex(self.existingVarCombo.count() - 1)
|
self.existingVarCombo.setCurrentIndex(self.existingVarCombo.count() - 1)
|
||||||
else:
|
else:
|
||||||
self._valueSrcCombo.setCurrentIndex(0)
|
self.valueSrcCombo.setCurrentIndex(0)
|
||||||
w = self._valueStack.currentWidget()
|
w = self.valueStack.currentWidget()
|
||||||
if w:
|
if w:
|
||||||
setWidgetValue(w, self._currentTargetType, expr)
|
setWidgetValue(w, self._currentTargetType, expr)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user