Skip to content

Commit e962b6c

Browse files
Allow to use more than 10 MDI Commands.
Additional commands can be added with "Add MDI Command" button.
1 parent cc45e0a commit e962b6c

File tree

7 files changed

+151
-170
lines changed

7 files changed

+151
-170
lines changed

mesact/src/libmesact/buildini.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
from PyQt5.QtWidgets import QSpinBox
55

6+
from libmesact import mdi
7+
8+
69
def build(parent):
710
buildErrors = []
811
iniFilePath = os.path.join(parent.configPath, parent.configNameUnderscored + '.ini')
@@ -155,9 +158,10 @@ def build(parent):
155158
# build the [HALUI] section
156159
if parent.haluiCB.isChecked():
157160
iniContents.append('\n[HALUI]\n')
158-
for i in range(10):
159-
if getattr(parent, f"mdiCmdLE_{i}").text():
160-
iniContents.append(f'MDI_COMMAND = {getattr(parent, f"mdiCmdLE_{i}").text()}\n')
161+
for i in range(mdi.get_mdi_commands_count(parent)):
162+
cmd = mdi.get_mdi_command(parent, i)
163+
if cmd:
164+
iniContents.append(f'MDI_COMMAND = {cmd}\n')
161165

162166
# build the axes and joints
163167
axes = [] # use only one axis letter with multiple joint axis

mesact/src/libmesact/check.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from libmesact import mdi
2+
13

24
def checkit(parent):
35
parent.mainTW.setCurrentIndex(11)
@@ -230,13 +232,13 @@ def checkit(parent):
230232
# end of SS Cards Tab
231233

232234
# check the Options Tab for errors
233-
mdi = []
234-
for i in range(9):
235-
cmd = getattr(parent, f'mdiCmdLE_{i}').text()
235+
mdi_commands = []
236+
for i in range(mdi.get_mdi_commands_count(parent)):
237+
cmd = mdi.get_mdi_command(parent, i)
236238
if len(cmd) > 0:
237-
mdi.append(i)
238-
if len(mdi) > 0:
239-
if len(mdi) != max(mdi) + 1:
239+
mdi_commands.append(i)
240+
if len(mdi_commands) > 0:
241+
if len(mdi_commands) != max(mdi_commands) + 1:
240242
tabError = True
241243
configErrors.append(f'\tMDI commands must start at 0 and not skip any')
242244
if not parent.haluiCB.isChecked():

mesact/src/libmesact/mdi.py

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from PyQt5.QtWidgets import QGridLayout, QLabel, QLineEdit
2+
3+
4+
def get_mdi_commands_count(parent):
5+
# Workaround for QGridLayout.rowCount() that returns 1 for empty grid
6+
grid_layout: QGridLayout = parent.mdiCommandsListGL
7+
rows = 0
8+
grid_layout.rowCount()
9+
for i in range(grid_layout.count()):
10+
row, _, span, _ = grid_layout.getItemPosition(i)
11+
rows = max(1, row + span)
12+
return rows
13+
14+
15+
def add_mdi_command_row(parent):
16+
grid_layout: QGridLayout = parent.mdiCommandsListGL
17+
row = get_mdi_commands_count(parent)
18+
__add_mdi_command_row(grid_layout, row)
19+
20+
21+
def set_mdi_command(parent, command_number, value):
22+
row_count = get_mdi_commands_count(parent)
23+
i = row_count
24+
while i <= command_number:
25+
add_mdi_command_row(parent)
26+
i += 1
27+
text_box: QLineEdit = parent.findChild(QLineEdit, __get_mdi_command_control_name(command_number))
28+
text_box.setText(value)
29+
30+
31+
def get_mdi_command(parent, command_number):
32+
rows_count = get_mdi_commands_count(parent)
33+
if rows_count == 0 or command_number >= rows_count:
34+
return ""
35+
text_box: QLineEdit = parent.findChild(QLineEdit, __get_mdi_command_control_name(command_number))
36+
return text_box.text().strip()
37+
38+
39+
def cleanup_mdi_commands(parent):
40+
grid_layout: QGridLayout = parent.mdiCommandsListGL
41+
for i in reversed(range(grid_layout.count())):
42+
widget = grid_layout.itemAt(i).widget()
43+
grid_layout.removeWidget(widget)
44+
widget.setParent(None)
45+
for i in range(10):
46+
__add_mdi_command_row(grid_layout, i)
47+
48+
49+
def __get_mdi_command_control_name(command_number):
50+
return f'mdiCmdLE_{command_number}'
51+
52+
53+
def __add_mdi_command_row(grid_layout, row):
54+
label = QLabel(f'MDI Command {row}')
55+
grid_layout.addWidget(label, row, 0)
56+
text_box = QLineEdit()
57+
text_box.setObjectName(__get_mdi_command_control_name(row))
58+
grid_layout.addWidget(text_box, row, 1)

mesact/src/libmesact/openini.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66

77
from libmesact import utilities
88
from libmesact import dialogs
9+
from libmesact import mdi
10+
911

1012
class loadini:
1113
def __init__(self):
@@ -185,13 +187,14 @@ def loadini(self, parent, iniFile):
185187
start = self.sections['[HALUI]'][0]
186188
end = self.sections['[HALUI]'][1]
187189
mdicmd = []
190+
mdi.cleanup_mdi_commands(parent)
188191
for item in self.content[start:end]:
189192
if item != '\n' and item.startswith('MDI_COMMAND'):
190193
item = item.split('=')
191194
item = item[1].strip()
192195
mdicmd.append(item)
193196
for i, item in enumerate(mdicmd):
194-
getattr(parent, f'mdiCmdLE_{i}').setText(item)
197+
mdi.set_mdi_command(parent, i, item)
195198

196199
for section in self.sections.items():
197200
if section[0].startswith('[JOINT'):

mesact/src/libmesact/updateini.py

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33

44
from PyQt5.QtWidgets import QSpinBox
55

6+
from libmesact import mdi
7+
8+
69
class updateini:
710
def __init__(self):
811
super().__init__()
@@ -336,35 +339,20 @@ def update(self, parent, iniFile):
336339
if '[HALUI]' in self.sections:
337340
index = self.sections['[HALUI]']
338341
if len(index) == 2:
339-
ini_mdi = []
340-
for i in range(index[0], index[1]):
342+
start = index[0]
343+
end = index[1]
344+
# remove all existing MDI commands
345+
for i in reversed(range(start, end)):
341346
if self.content[i].startswith('MDI_COMMAND'):
342-
ini_mdi.append(self.content[i].split('=')[1].strip())
347+
del self.content[i]
343348
tool_mdi = []
344-
for i in range(10):
345-
mdi_text = f'{getattr(parent, f"mdiCmdLE_{i}").text()}'
349+
for i in range(mdi.get_mdi_commands_count(parent)):
350+
mdi_text = mdi.get_mdi_command(parent, i)
346351
if mdi_text:
347-
tool_mdi.append(f'{getattr(parent, f"mdiCmdLE_{i}").text()}')
348-
349-
if len(ini_mdi) == len(tool_mdi):
350-
for i, j in enumerate(range(index[0] + 1, index[1])):
351-
if self.content[j].startswith('MDI_COMMAND'):
352-
self.content[j] = f'MDI_COMMAND = {getattr(parent, f"mdiCmdLE_{i}").text()}\n'
353-
elif len(ini_mdi) > len(tool_mdi):
354-
remove = len(ini_mdi) - len(tool_mdi)
355-
for i in reversed(range(index[0] + 1, index[1])):
356-
if self.content[i].startswith('MDI_COMMAND') and remove > 0:
357-
del self.content[i]
358-
remove -= 1
359-
self.get_sections() # update section start/end
360-
elif len(ini_mdi) < len(tool_mdi):
361-
add = len(tool_mdi) - len(ini_mdi)
362-
for i, j in enumerate(range(index[0] + 1, index[1] + add)):
363-
if self.content[j].startswith('MDI_COMMAND'): # replace it
364-
self.content[j] = f'MDI_COMMAND = {getattr(parent, f"mdiCmdLE_{i}").text()}\n'
365-
elif self.content[j].strip() == '': # insert it
366-
self.content.insert(j, f'MDI_COMMAND = {getattr(parent, f"mdiCmdLE_{i}").text()}\n')
367-
self.get_sections() # update section start/end
352+
tool_mdi.append(mdi_text)
353+
for i in reversed(range(len(tool_mdi))):
354+
self.content.insert(start + 1, f'MDI_COMMAND = {tool_mdi[i]}\n')
355+
self.get_sections() # update section start/end
368356

369357
############ Massive rework needed here
370358
# if the section exists and is in the tool update it

mesact/src/mesact

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ from libmesact import settings
4646
from libmesact import spindle
4747
from libmesact import shutdown
4848
from libmesact import updates
49+
from libmesact import mdi
4950

5051
# testing imports
5152
from libmesact import testing
@@ -226,6 +227,10 @@ class MainWindow(QMainWindow):
226227
#self.checkMesaflashCB.clicked.connect(partial(settings.update_value, self))
227228
#self.newUserCB.clicked.connect(partial(settings.update_value, self))
228229

230+
# Options Tab - MDI
231+
mdi.cleanup_mdi_commands(self)
232+
self.addMdiCommandPB.clicked.connect(partial(mdi.add_mdi_command_row, self))
233+
229234
def changed(self):
230235
#if isinstance(self.sender(), QComboBox):
231236
# if self.sender().currentData():

0 commit comments

Comments
 (0)