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