|
3 | 3 |
|
4 | 4 | from PyQt5.QtWidgets import QSpinBox
|
5 | 5 |
|
| 6 | +from libmesact import mdi |
| 7 | + |
| 8 | + |
6 | 9 | class updateini:
|
7 | 10 | generated_hal_items = [
|
8 | 11 | 'main.hal',
|
@@ -316,35 +319,20 @@ def update(self, parent, iniFile):
|
316 | 319 | if '[HALUI]' in self.sections:
|
317 | 320 | index = self.sections['[HALUI]']
|
318 | 321 | if len(index) == 2:
|
319 |
| - ini_mdi = [] |
320 |
| - for i in range(index[0], index[1]): |
| 322 | + start = index[0] |
| 323 | + end = index[1] |
| 324 | + # remove all existing MDI commands |
| 325 | + for i in reversed(range(start, end)): |
321 | 326 | if self.content[i].startswith('MDI_COMMAND'):
|
322 |
| - ini_mdi.append(self.content[i].split('=')[1].strip()) |
| 327 | + del self.content[i] |
323 | 328 | tool_mdi = []
|
324 |
| - for i in range(10): |
325 |
| - mdi_text = f'{getattr(parent, f"mdiCmdLE_{i}").text()}' |
| 329 | + for i in range(mdi.get_mdi_commands_count(parent)): |
| 330 | + mdi_text = mdi.get_mdi_command(parent, i) |
326 | 331 | if mdi_text:
|
327 |
| - tool_mdi.append(f'{getattr(parent, f"mdiCmdLE_{i}").text()}') |
328 |
| - |
329 |
| - if len(ini_mdi) == len(tool_mdi): |
330 |
| - for i, j in enumerate(range(index[0] + 1, index[1])): |
331 |
| - if self.content[j].startswith('MDI_COMMAND'): |
332 |
| - self.content[j] = f'MDI_COMMAND = {getattr(parent, f"mdiCmdLE_{i}").text()}\n' |
333 |
| - elif len(ini_mdi) > len(tool_mdi): |
334 |
| - remove = len(ini_mdi) - len(tool_mdi) |
335 |
| - for i in reversed(range(index[0] + 1, index[1])): |
336 |
| - if self.content[i].startswith('MDI_COMMAND') and remove > 0: |
337 |
| - del self.content[i] |
338 |
| - remove -= 1 |
339 |
| - self.get_sections() # update section start/end |
340 |
| - elif len(ini_mdi) < len(tool_mdi): |
341 |
| - add = len(tool_mdi) - len(ini_mdi) |
342 |
| - for i, j in enumerate(range(index[0] + 1, index[1] + add)): |
343 |
| - if self.content[j].startswith('MDI_COMMAND'): # replace it |
344 |
| - self.content[j] = f'MDI_COMMAND = {getattr(parent, f"mdiCmdLE_{i}").text()}\n' |
345 |
| - elif self.content[j].strip() == '': # insert it |
346 |
| - self.content.insert(j, f'MDI_COMMAND = {getattr(parent, f"mdiCmdLE_{i}").text()}\n') |
347 |
| - self.get_sections() # update section start/end |
| 332 | + tool_mdi.append(mdi_text) |
| 333 | + for i in reversed(range(len(tool_mdi))): |
| 334 | + self.content.insert(start + 1, f'MDI_COMMAND = {tool_mdi[i]}\n') |
| 335 | + self.get_sections() # update section start/end |
348 | 336 |
|
349 | 337 | ############ Massive rework needed here
|
350 | 338 | # if the section exists and is in the tool update it
|
|
0 commit comments