-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathMainWindow.py
More file actions
363 lines (304 loc) · 15.6 KB
/
MainWindow.py
File metadata and controls
363 lines (304 loc) · 15.6 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
import Config, urllib2, webbrowser
from PyQt4 import QtCore, QtGui
from sets import Set
import Sandboxie
import Version
from SettingsDialog import SettingsDialog
from DropLogView import DropLogView
from AccountsView import AccountsView
from Common import returnResourcePath
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.settings = Config.settings
self.toolBars = []
self.sandboxieINIIsModified = False
self.view = 'accounts'
self.setWindowTitle('TF2Idle')
windowXSize, windowYSize = eval(self.settings.get_option('Settings', 'ui_window_size'))
if (windowXSize, windowYSize) == (0, 0):
self.setWindowState(QtCore.Qt.WindowMaximized)
else:
self.resize(windowXSize, windowYSize)
self.setWindowIcon(QtGui.QIcon(returnResourcePath('images/tf2idle.png')))
self.createSystemTray()
self.drawToolBars()
# Add menu bar
self.menuBar = QtGui.QMenuBar(self)
self.menuBar.setObjectName('menubar')
self.setMenuBar(self.menuBar)
# Add File menu
fileMenu = self.addMenu('File')
self.addSubMenu(fileMenu, text='Settings', shortcut='Ctrl+S', action={'trigger':'triggered()', 'action':self.openSettings}, iconimage=returnResourcePath('images/settings_logo.png'))
fileMenu.addSeparator()
self.addSubMenu(fileMenu, text='Exit', shortcut='Ctrl+Q', action={'trigger':'triggered()', 'action':self.close}, iconimage=returnResourcePath('images/exit_logo.png'))
# Add About menu
helpMenu = self.addMenu('Help')
self.addSubMenu(helpMenu, text='Readme / Source', action={'trigger':'triggered()', 'action':self.openGithub}, iconimage=returnResourcePath('images/readme_logo.png'))
self.addSubMenu(helpMenu, text='Facepunch thread', action={'trigger':'triggered()', 'action':self.openFacepunch}, iconimage=returnResourcePath('images/facepunch_logo.png'))
self.addSubMenu(helpMenu, text='Steam group', action={'trigger':'triggered()', 'action':self.openSteamGroup}, iconimage=returnResourcePath('images/steam_group_logo.png'))
self.addSubMenu(helpMenu, text='Check for update', action={'trigger':'triggered()', 'action':self.checkForUpdate}, iconimage=returnResourcePath('images/update_logo.png'))
self.addSubMenu(helpMenu, text='Bugs/Features/Feedback', action={'trigger':'triggered()', 'action':self.openFeedback}, iconimage=returnResourcePath('images/uservoice.png'))
self.addSubMenu(helpMenu, text='About', action={'trigger':'triggered()', 'action':self.showAbout}, iconimage=returnResourcePath('images/tf2idle.png'))
# Add Steam menu
steamMenu = self.addMenu('Powered by Steam')
self.addSubMenu(steamMenu, text='Steam website', action={'trigger':'triggered()', 'action':self.openSteamSite}, iconimage=returnResourcePath('images/steam_logo.png'))
# Set starting view as accounts page
self.accountsView = AccountsView(self)
self.dropLogView = DropLogView(self, self.tray)
self.stackedWidget = QtGui.QStackedWidget(self)
self.stackedWidget.addWidget(self.accountsView)
self.stackedWidget.addWidget(self.dropLogView)
self.setCentralWidget(self.stackedWidget)
# Connect signals used for passing account information between views
QtCore.QObject.connect(self.accountsView, QtCore.SIGNAL('returnedSelectedAccounts(PyQt_PyObject)'), self.dropLogView.setSelectedAccounts)
QtCore.QObject.connect(self.dropLogView, QtCore.SIGNAL('retrieveSelectedAccounts'), self.accountsView.returnSelectedAccounts)
QtCore.QObject.connect(self.accountsView, QtCore.SIGNAL('startDropLog(PyQt_PyObject)'), self.dropLogView.addAccount)
QtCore.QObject.connect(self.accountsView, QtCore.SIGNAL('stopDropLog(PyQt_PyObject)'), self.dropLogView.removeAccount)
self.changeView()
self.dropLogView.toggleItemValues()
# Override right click context menu to display nothing
def createPopupMenu(self):
pass
def closeEvent(self, event):
# Check if close button is clicked
if self.sender() is None:
if self.settings.get_option('Settings', 'close_to_tray') == 'True':
self.hide()
event.ignore()
else:
reply = QtGui.QMessageBox.question(self, 'Quit', 'Are you sure you want to quit?', QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
self.saveWindowState()
# If sandboxie.ini has been modified restore from backup copy
if self.sandboxieINIIsModified:
Sandboxie.restoreSandboxieINI()
else:
event.ignore()
else:
# Close and save window size
self.saveWindowState()
def saveWindowState(self):
# Save main window size on exit
if self.isMaximized():
self.settings.set_option('Settings', 'ui_window_size', '(0, 0)')
else:
self.settings.set_option('Settings', 'ui_window_size', '(%s, %s)' % (self.width(), self.height()))
def createSystemTray(self):
self.tray = QtGui.QSystemTrayIcon(QtGui.QIcon(returnResourcePath('images/tf2idle.png')), self)
QtCore.QObject.connect(self.tray, QtCore.SIGNAL("activated(QSystemTrayIcon::ActivationReason)"), self.sysTrayIconActivated)
self.iconMenu = QtGui.QMenu(self)
openAction = self.iconMenu.addAction('Open')
QtCore.QObject.connect(openAction, QtCore.SIGNAL('triggered()'), self.show)
exitAction = self.iconMenu.addAction('Exit')
QtCore.QObject.connect(exitAction, QtCore.SIGNAL('triggered()'), self.close)
self.tray.setContextMenu(self.iconMenu)
self.tray.show()
def sysTrayIconActivated(self, reason):
if reason == QtGui.QSystemTrayIcon.DoubleClick:
self.show()
def redrawWindowStates(self):
if self.view == 'log':
self.drawToolBars()
self.accountsView.updateWindow()
elif self.view == 'accounts':
self.drawToolBars(hideRightToolbar=True)
self.dropLogView.updateWindow()
def drawToolBars(self, hideRightToolbar=False):
for toolbar in self.toolBars:
toolbar.close()
del toolbar
self.toolBars = []
if not hideRightToolbar:
# Create vertical toolbar
self.vtoolBar = QtGui.QToolBar(self)
self.vtoolBar.setObjectName('vtoolBar')
self.vtoolBar.setIconSize(QtCore.QSize(40, 40))
self.vtoolBar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
self.vtoolBar.setMovable(False)
# Create horizontal toolbar
self.htoolBar = QtGui.QToolBar(self)
self.htoolBar.setObjectName('htoolBar')
self.htoolBar.setIconSize(QtCore.QSize(40, 40))
self.htoolBar.setToolButtonStyle(QtCore.Qt.ToolButtonTextUnderIcon)
self.htoolBar.setMovable(False)
# Add toolbars to toolbar list so can be deleted when MainWindow is refreshed
self.toolBars.append(self.vtoolBar)
self.toolBars.append(self.htoolBar)
# Attach toolbars to MainWindow
if not hideRightToolbar:
self.addToolBar(QtCore.Qt.RightToolBarArea, self.vtoolBar)
self.toolBars.append(self.vtoolBar)
self.addToolBar(QtCore.Qt.BottomToolBarArea, self.htoolBar)
self.toolBars.append(self.htoolBar)
def changeView(self):
if self.view == 'accounts':
self.drawToolBars()
self.accountsView.updateWindow()
self.stackedWidget.setCurrentIndex(0)
self.view = 'log'
elif self.view == 'log':
self.drawToolBars(hideRightToolbar=True)
self.dropLogView.updateWindow()
self.stackedWidget.setCurrentIndex(1)
self.view = 'accounts'
def sandboxieINIHasBeenModified(self):
self.sandboxieINIIsModified = True
def addMenu(self, menuname):
self.menu = QtGui.QMenu(self.menuBar)
self.menu.setObjectName('menu' + menuname)
self.menu.setTitle(menuname)
self.menuBar.addAction(self.menu.menuAction())
return self.menu
def addSubMenu(self, menu, shortcut=None, text=None, tooltip=None, action=None, iconimage=None):
self.action = QtGui.QAction(self)
if shortcut:
self.action.setShortcut(shortcut)
menu.addAction(self.action)
if action:
QtCore.QObject.connect(self.action, QtCore.SIGNAL(action['trigger']), action['action'])
if text:
self.action.setText(text)
if tooltip:
self.action.setToolTip(tooltip)
if iconimage:
icon = QtGui.QIcon(iconimage)
self.action.setIcon(icon)
def openSettings(self):
dialogWindow = SettingsDialog()
QtCore.QObject.connect(dialogWindow, QtCore.SIGNAL('web_view_status'), self.dropLogView.changeWebServerStatus)
QtCore.QObject.connect(dialogWindow, QtCore.SIGNAL('toggle_sys_tray_notification'), self.dropLogView.toggleSysTrayNotifications)
QtCore.QObject.connect(dialogWindow, QtCore.SIGNAL('toggle_item_values_display'), self.dropLogView.toggleItemValues)
dialogWindow.setModal(True)
dialogWindow.exec_()
self.accountsView.updateAccountBoxes()
self.dropLogView.updateLogDisplay()
def openGithub(self):
webbrowser.open('http://github.com/Moussekateer/TF2IdleGUI')
def openFacepunch(self):
webbrowser.open('http://www.facepunch.com/threads/1250564')
def openSteamGroup(self):
webbrowser.open('http://steamcommunity.com/groups/tf2idletool')
def openSteamSite(self):
webbrowser.open('http://steampowered.com')
def openFeedback(self):
webbrowser.open('https://tf2idle.uservoice.com')
def checkForUpdate(self):
self.updateCheckThread = UpdateCheckThread()
QtCore.QObject.connect(self.updateCheckThread, QtCore.SIGNAL('recievedVersion'), self.updateDialog)
self.updateCheckThread.start()
def updateDialog(self, currentversion):
if currentversion is None:
QtGui.QMessageBox.warning(self, 'Error', 'Could not retrieve the current version number, check your connection.')
else:
currentversionlist = currentversion.split('.')
version = Version.version.split('.')
update = False
index = 0
for n in currentversionlist:
if int(n) > int(version[index]):
update = True
break
elif int(n) < int(version[index]):
break
index += 1
updateMessageDialog = QtGui.QDialog(self)
vBoxLayout = QtGui.QVBoxLayout(updateMessageDialog)
textLabel = QtGui.QLabel(updateMessageDialog)
textLabel.setTextFormat(QtCore.Qt.RichText)
textLabel.setOpenExternalLinks(True)
textLabel.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
vBoxLayout.addWidget(textLabel)
buttonBox = QtGui.QDialogButtonBox(updateMessageDialog)
buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok)
buttonBox.setCenterButtons(True)
QtCore.QObject.connect(buttonBox, QtCore.SIGNAL('accepted()'), updateMessageDialog.accept)
vBoxLayout.addWidget(buttonBox)
if update:
updateMessageDialog.setWindowTitle('New update')
textLabel.setText("""<b>New update available!</b>
<br/><br/>Your version: <b>v%s</b>
<br/><br/>Current version: <b>v%s</b>
<br/><br/><a href="http://github.com/Moussekateer/TF2IdleGUI">Read the latest changes</a>.
<br/><br/><a href="http://code.google.com/p/tf2idle/downloads/list">Download the newest version</a>.<br/><br/>"""
% (Version.version, currentversion))
else:
updateMessageDialog.setWindowTitle('No update')
textLabel.setText("""You have the latest version.
<br/><br/>Your version: <b>v%s</b>
<br/><br/>Current version: <b>v%s</b><br/><br/>"""
% (Version.version, currentversion))
updateMessageDialog.show()
def showAbout(self):
about = AboutDialog(self)
about.exec_()
class AboutDialog(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.setWindowTitle('About')
self.gridLayout = QtGui.QGridLayout(self)
self.imageLabel = ClickableLabel(self)
self.imageLabel.setPixmap(QtGui.QPixmap(returnResourcePath('images/tf2idle.png')))
self.gridLayout.addWidget(self.imageLabel, 0, 0, 1, 1)
self.textLabel = QtGui.QLabel(self)
self.textLabel.setTextFormat(QtCore.Qt.RichText)
self.textLabel.setText("""<b>TF2Idle v%s</b><br/><br/>Developed by <a href="http://steamcommunity.com/id/Moussekateer">Moussekateer</a>.
<br/><br/>Thanks to <a href="http://steamcommunity.com/id/WindPower">WindPower</a> (aka the witch) for his limitless Python knowledge.
<br/><br/>Thanks to <a href="http://steamcommunity.com/id/rjackson">RJackson</a> for contributing code to TF2Idle.
<br/><br/>Thanks to <a href="http://steamcommunity.com/id/stragglerastic">Lagg</a> for his <a href="http://git.optf2.com/steamodd/">Steamodd Python module</a>.
<br/><br/>Thanks to <a href="http://steamcommunity.com/id/bradpitt77">Brad Pitt</a> for the <a href="http://backpack.tf/api">backpack.tf pricelist API</a>.
<br/><br/>Some images used were extracted from TF2 and are the property of <a href="http://www.valvesoftware.com">Valve</a>.
<br/><br/>Some images used were created by <a href="http://fabrydesign.com">Wade 'Nineaxis' Fabry</a>.
<br/><br/>They are kredit to team.""" % Version.version)
self.textLabel.setOpenExternalLinks(True)
self.gridLayout.addWidget(self.textLabel, 0, 1, 1, 1)
self.licenseImage = QtGui.QLabel()
self.licenseImage.setPixmap(QtGui.QPixmap(returnResourcePath('images/creative_commons.png')))
self.gridLayout.addWidget(self.licenseImage, 1, 0, 1, 1)
self.licenseLabel = QtGui.QLabel(self)
self.licenseLabel.setTextFormat(QtCore.Qt.RichText)
self.licenseLabel.setText("""<span xmlns:dct="http://purl.org/dc/terms/" property="dct:title">TF2Idle</span> by <a xmlns:cc="http://creativecommons.org/ns#" href="http://steamcommunity.com/id/moussekateer" property="cc:attributionName" rel="cc:attributionURL">Moussekateer</a> is licensed under a<br/><a rel="license" href="http://creativecommons.org/licenses/by-nc-sa/3.0/">Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License</a>.""")
self.licenseLabel.setOpenExternalLinks(True)
self.gridLayout.addWidget(self.licenseLabel, 1, 1, 1, 1)
self.buttonBox = QtGui.QDialogButtonBox(self)
self.buttonBox.setStandardButtons(QtGui.QDialogButtonBox.Ok)
self.buttonBox.setCenterButtons(False)
self.gridLayout.addWidget(self.buttonBox, 2, 1, 1, 1)
QtCore.QObject.connect(self.buttonBox, QtCore.SIGNAL('accepted()'), self.accept)
class UpdateCheckThread(QtCore.QThread):
def __init__(self, parent=None):
QtCore.QThread.__init__(self, parent)
self.URL = r'http://tf2notifications.appspot.com/TF2Idleversion'
def run(self):
try:
current_version = urllib2.urlopen(self.URL, timeout=5).read()
self.emit(QtCore.SIGNAL('recievedVersion'), current_version)
except:
self.emit(QtCore.SIGNAL('recievedVersion'), None)
class ClickableLabel(QtGui.QLabel):
def __init__(self, parent=None):
QtGui.QLabel.__init__(self, parent)
def mouseDoubleClickEvent(self, event):
stoat = Stoat(self)
stoat.exec_()
class Stoat(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.setWindowTitle('Secret Stoat')
self.vBoxLayout = QtGui.QVBoxLayout(self)
self.imageLabel = QtGui.QLabel(self)
self.imageLabel.setPixmap(QtGui.QPixmap(returnResourcePath('images/secret_stoat.png')))
self.vBoxLayout.addWidget(self.imageLabel)
self.textLabel = QtGui.QLabel(self)
self.textLabel.setText("""Praise the <b>Secret Stoat</b> and all it stands for: <b>WIN</b>.<br/>
Definitions of <b>WIN</b> on the Web:<br/><br/>
- be the winner in a contest or competition; be victorious; "He won the Gold Medal in skating"; "Our home team won"; "Win the game"<br/>
- acquire: win something through one\'s efforts; "I acquired a passing knowledge of Chinese"; "Gain an understanding of international finance"<br/>
- gain: obtain advantages, such as points, etc.; "The home team was gaining ground"<br/>
- a victory (as in a race or other competition); "he was happy to get the win"<br/>
- winnings: something won (especially money)<br/>
- succeed: attain success or reach a desired goal; "The enterprise succeeded"; "We succeeded in getting tickets to the show"; "she struggled to overcome her handicap and won"
""")
self.textLabel.setWordWrap(True)
self.textLabel.setAlignment(QtCore.Qt.AlignHCenter | QtCore.Qt.AlignVCenter)
self.vBoxLayout.addWidget(self.textLabel)