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