Skip to content

Commit d383a3e

Browse files
committed
improve mapping generator dockwidget UI
1 parent bc3e792 commit d383a3e

2 files changed

Lines changed: 30 additions & 9 deletions

File tree

src/dialogs/dialog_check_map.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,10 @@
1414

1515

1616
class CheckMapDialog(QDialog):
17-
def __init__(self, parent, *args, **kwargs):
17+
def __init__(self, parent, title, cancel, *args, **kwargs):
1818
super().__init__(parent, *args, **kwargs)
1919

20-
self.setWindowTitle("Check tile configurations")
20+
self.setWindowTitle(title)
2121
self.layout = QGridLayout()
2222
self.layout.setHorizontalSpacing(0)
2323
self.layout.setVerticalSpacing(0)
@@ -58,11 +58,15 @@ def __init__(self, parent, *args, **kwargs):
5858
self.layout.addWidget(tile, grid_y, grid_x, 1, 1)
5959

6060
# add ok and cancel button
61-
q_btn = QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
61+
if cancel:
62+
q_btn = QDialogButtonBox.StandardButton.Ok | QDialogButtonBox.StandardButton.Cancel
63+
else:
64+
q_btn = QDialogButtonBox.StandardButton.Ok
6265

6366
self.buttonBox = QDialogButtonBox(q_btn)
6467
self.buttonBox.accepted.connect(self.accept)
65-
self.buttonBox.rejected.connect(self.reject)
68+
if cancel:
69+
self.buttonBox.rejected.connect(self.reject)
6670
self.layout.addWidget(self.buttonBox, height + 2, 0, 1, width, Qt.AlignmentFlag.AlignHCenter)
6771
self.setLayout(self.layout)
6872
self.setModal(True)

src/widgets/widget_mapper_generator.py

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ def __init__(self, parent=None):
5454
self.image_label = QLabel("No Image")
5555
self.layout.addWidget(self.image_label)
5656

57-
# check ddnet
58-
self.ddnet_push_button = QPushButton("Check with ddnet")
57+
# check map
58+
self.check_map_button = QPushButton("Check mapping rules")
59+
self.layout.addWidget(self.check_map_button)
60+
61+
# check map with ddnet
62+
self.ddnet_push_button = QPushButton("Check mapping rules with ddnet")
5963
self.layout.addWidget(self.ddnet_push_button)
6064
if ConfigManager.instance().config()["client_path"] is None:
6165
self.ddnet_push_button.setDisabled(True)
@@ -65,6 +69,7 @@ def __init__(self, parent=None):
6569

6670
# Generate button
6771
self.generate_button = QPushButton("Generate")
72+
self.generate_button.setEnabled(False) # no rule name yet
6873
self.layout.addWidget(self.generate_button)
6974

7075
self.setLayout(self.layout)
@@ -74,8 +79,10 @@ def __init__(self, parent=None):
7479
# handle connections
7580
for radio_button in self.radio_buttons:
7681
radio_button.toggled.connect(self.ruleNameToggle)
77-
self.generate_button.clicked.connect(self.openFileDialog)
82+
self.generate_button.clicked.connect(self.startRuleGeneration)
7883
self.ddnet_push_button.clicked.connect(self.startDDNetCheck)
84+
self.check_map_button.clicked.connect(self.checkMappingRules)
85+
self.new_mapper_line_edit.textChanged.connect(self.mappingRuleNameChanged)
7986

8087
# some configuration
8188
# configure validator new_mapper_line_edit
@@ -94,11 +101,11 @@ def setImage(self, image_path):
94101
self.image_label.setScaledContents(True)
95102
self.image_label.setMaximumSize(200, 200)
96103

97-
def openFileDialog(self):
104+
def startRuleGeneration(self):
98105
rule_name = self.new_mapper_line_edit.text()
99106
if not AppState.imagePath() or not len(rule_name):
100107
return
101-
cmd = CheckMapDialog(self)
108+
cmd = CheckMapDialog(self, title=f"Do you want to save your mapping rule '{rule_name}'?", cancel=True)
102109
ret = cmd.exec()
103110
if ret:
104111
loaded_image_path = Path(AppState.imagePath())
@@ -115,6 +122,16 @@ def openFileDialog(self):
115122
else:
116123
QMessageBox.warning(self, "Warning", "Please select an image first.")
117124
"""
125+
def checkMappingRules(self):
126+
cmd = CheckMapDialog(self, title="Check Mapping Rules", cancel=False)
127+
cmd.exec()
128+
129+
def mappingRuleNameChanged(self):
130+
rule_name = self.new_mapper_line_edit.text()
131+
if not rule_name or len(rule_name) == 0:
132+
self.generate_button.setDisabled(True)
133+
else:
134+
self.generate_button.setEnabled(True)
118135

119136
def ruleNameToggle(self):
120137
if self.radio_buttons[0].isChecked():

0 commit comments

Comments
 (0)