6 """ |
6 """ |
7 Module implementing a dialog to select a list of guards. |
7 Module implementing a dialog to select a list of guards. |
8 """ |
8 """ |
9 |
9 |
10 from PyQt6.QtWidgets import ( |
10 from PyQt6.QtWidgets import ( |
11 QDialog, QDialogButtonBox, QListWidgetItem, QAbstractItemView |
11 QDialog, |
|
12 QDialogButtonBox, |
|
13 QListWidgetItem, |
|
14 QAbstractItemView, |
12 ) |
15 ) |
13 |
16 |
14 from .Ui_HgQueuesGuardsSelectionDialog import Ui_HgQueuesGuardsSelectionDialog |
17 from .Ui_HgQueuesGuardsSelectionDialog import Ui_HgQueuesGuardsSelectionDialog |
15 |
18 |
16 |
19 |
17 class HgQueuesGuardsSelectionDialog(QDialog, Ui_HgQueuesGuardsSelectionDialog): |
20 class HgQueuesGuardsSelectionDialog(QDialog, Ui_HgQueuesGuardsSelectionDialog): |
18 """ |
21 """ |
19 Class implementing a dialog to select a list of guards. |
22 Class implementing a dialog to select a list of guards. |
20 """ |
23 """ |
|
24 |
21 def __init__(self, guards, activeGuards=None, listOnly=False, parent=None): |
25 def __init__(self, guards, activeGuards=None, listOnly=False, parent=None): |
22 """ |
26 """ |
23 Constructor |
27 Constructor |
24 |
28 |
25 @param guards list of guards to select from (list of strings) |
29 @param guards list of guards to select from (list of strings) |
26 @param activeGuards list of active guards (list of strings) |
30 @param activeGuards list of active guards (list of strings) |
27 @param listOnly flag indicating to only list the guards (boolean) |
31 @param listOnly flag indicating to only list the guards (boolean) |
28 @param parent reference to the parent widget (QWidget) |
32 @param parent reference to the parent widget (QWidget) |
29 """ |
33 """ |
30 super().__init__(parent) |
34 super().__init__(parent) |
31 self.setupUi(self) |
35 self.setupUi(self) |
32 |
36 |
33 for guard in guards: |
37 for guard in guards: |
34 itm = QListWidgetItem(guard, self.guardsList) |
38 itm = QListWidgetItem(guard, self.guardsList) |
35 if activeGuards is not None and guard in activeGuards: |
39 if activeGuards is not None and guard in activeGuards: |
36 font = itm.font() |
40 font = itm.font() |
37 font.setBold(True) |
41 font.setBold(True) |
38 itm.setFont(font) |
42 itm.setFont(font) |
39 self.guardsList.sortItems() |
43 self.guardsList.sortItems() |
40 |
44 |
41 if listOnly: |
45 if listOnly: |
42 self.buttonBox.button( |
46 self.buttonBox.button(QDialogButtonBox.StandardButton.Cancel).hide() |
43 QDialogButtonBox.StandardButton.Cancel).hide() |
|
44 self.guardsList.setSelectionMode( |
47 self.guardsList.setSelectionMode( |
45 QAbstractItemView.SelectionMode.NoSelection) |
48 QAbstractItemView.SelectionMode.NoSelection |
|
49 ) |
46 self.setWindowTitle(self.tr("Active Guards")) |
50 self.setWindowTitle(self.tr("Active Guards")) |
47 |
51 |
48 def getData(self): |
52 def getData(self): |
49 """ |
53 """ |
50 Public method to retrieve the data. |
54 Public method to retrieve the data. |
51 |
55 |
52 @return list of selected guards (list of strings) |
56 @return list of selected guards (list of strings) |
53 """ |
57 """ |
54 guardsList = [] |
58 guardsList = [] |
55 |
59 |
56 for itm in self.guardsList.selectedItems(): |
60 for itm in self.guardsList.selectedItems(): |
57 guardsList.append(itm.text()) |
61 guardsList.append(itm.text()) |
58 |
62 |
59 return guardsList |
63 return guardsList |