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