-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathGroupsDialog.py
More file actions
129 lines (109 loc) · 4.28 KB
/
GroupsDialog.py
File metadata and controls
129 lines (109 loc) · 4.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
import Config
from PyQt4 import QtCore, QtGui
from sets import Set
from Common import returnResourcePath
def compare_keys(x, y):
try:
x = int(x)
except ValueError:
xint = False
else:
xint = True
try:
y = int(y)
except ValueError:
if xint:
return -1
return cmp(x, y)
else:
if xint:
return cmp(x, y)
return 1
class GroupsDialogWindow(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.settings = Config.settings
# Create dialog
self.setWindowModality(QtCore.Qt.NonModal)
self.resize(250, 450)
self.setMinimumSize(QtCore.QSize(self.width(), self.height()))
self.setWindowTitle('Select groups')
self.setWindowIcon(QtGui.QIcon(returnResourcePath('images/select_group.png')))
self.gridLayout = QtGui.QVBoxLayout(self)
self.scrollArea = QtGui.QScrollArea(self)
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setFrameShape(QtGui.QFrame.NoFrame)
self.gridLayout.addWidget(self.scrollArea)
self.scrollAreaWidgetContents = QtGui.QWidget()
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.widgetVerticalLayout = QtGui.QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayout = QtGui.QVBoxLayout()
self.widgetVerticalLayout.addLayout(self.verticalLayout)
# Generate groups dict
self.groupsDict = {}
for account in list(Set(self.settings.get_sections()) - Set(['Settings'])):
groups = self.settings.get_option(account, 'groups')
groups = groups.split(',')
for group in groups:
if group == '':
pass
else:
if group in self.groupsDict:
self.groupsDict[group].append(self.settings.get_option(account, 'steam_username'))
else:
self.groupsDict[group] = []
self.groupsDict[group].append(self.settings.get_option(account, 'steam_username'))
# Add group checkboxes
self.groupButtons = []
if len(self.groupsDict) == 0:
self.Label = QtGui.QLabel()
self.Label.setText('You have no groups set up. Try adding an account to a group first.')
self.Label.setAlignment(QtCore.Qt.AlignHCenter|QtCore.Qt.AlignVCenter)
self.Label.setWordWrap(True)
self.verticalLayout.addWidget(self.Label)
else:
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap(returnResourcePath('images/unselected_button.png')), QtGui.QIcon.Selected, QtGui.QIcon.Off)
icon.addPixmap(QtGui.QPixmap(returnResourcePath('images/selected_button.png')), QtGui.QIcon.Selected, QtGui.QIcon.On)
for group in sorted(self.groupsDict, cmp = compare_keys):
self.commandLinkButton = QtGui.QCommandLinkButton()
self.commandLinkButton.setText(group)
self.commandLinkButton.setIcon(icon)
# Display members of group
membersString = ''
for member in sorted(self.groupsDict[group]):
membersString += member + '\n'
self.commandLinkButton.setDescription(membersString)
self.commandLinkButton.setCheckable(True)
self.verticalLayout.addWidget(self.commandLinkButton)
self.groupButtons.append(self.commandLinkButton)
# Add buttons
self.buttonBox = QtGui.QDialogButtonBox()
self.buttonBox.setOrientation(QtCore.Qt.Horizontal)
self.buttonBox.setCenterButtons(True)
selectbutton = QtGui.QPushButton('Select', self)
deselectbutton = QtGui.QPushButton('Deselect', self)
cancelbutton = QtGui.QPushButton('Cancel', self)
self.buttonBox.addButton(selectbutton, QtGui.QDialogButtonBox.ActionRole)
self.buttonBox.addButton(deselectbutton, QtGui.QDialogButtonBox.ActionRole)
self.buttonBox.addButton(cancelbutton, QtGui.QDialogButtonBox.RejectRole)
self.gridLayout.addWidget(self.buttonBox)
# Signal connections
self.connect(selectbutton, QtCore.SIGNAL('clicked()'), self.select)
self.connect(deselectbutton, QtCore.SIGNAL('clicked()'), self.deselect)
self.connect(cancelbutton, QtCore.SIGNAL('clicked()'), self.reject)
QtCore.QMetaObject.connectSlotsByName(self)
self.accountsSelectList = []
self.accountsDeselectList = []
def select(self):
for button in self.groupButtons:
if button.isChecked():
self.accountsSelectList += self.groupsDict[str(button.text())]
self.close()
def deselect(self):
for button in self.groupButtons:
if button.isChecked():
self.accountsDeselectList += self.groupsDict[str(button.text())]
self.close()
def returnAccounts(self):
return self.accountsSelectList, self.accountsDeselectList