forked from Moussa/TF2IdleGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainWindow.py
429 lines (373 loc) · 19.4 KB
/
MainWindow.py
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
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
import Config, subprocess, webbrowser, shutil, os, threading
from PyQt4 import QtCore, QtGui
from sets import Set
from AccountDialog import Ui_AccountDialog
from SettingsDialog import Ui_SettingsDialog
from GroupsDialog import Ui_GroupsDialog
def returnResourcePath(resource):
MEIPASS2 = '_MEIPASS2'
if MEIPASS2 in os.environ:
return os.environ[MEIPASS2] + resource
else:
return resource
class Worker(QtCore.QThread):
def __init__(self, parent = None):
QtCore.QThread.__init__(self, parent)
def run(self):
self.settings = Config.settings
self.settings.set_section('Settings')
steam_location = self.settings.get_option('steam_location')
secondary_steamapps_location = self.settings.get_option('secondary_steamapps_location')
gcfs = ['team fortress 2 content.gcf','team fortress 2 materials.gcf','team fortress 2 client content.gcf']
if not os.path.exists(steam_location + os.sep + 'steamapps' + os.sep):
self.returnMessage('Path does not exist', 'The Steam folder path does not exist. Please check settings')
elif not os.path.exists(secondary_steamapps_location):
self.returnMessage('Path does not exist', 'The secondary Steam folder path does not exist. Please check settings')
else:
self.returnMessage('Info', 'Remember to start the backup Steam installation unsandboxed to finish the updating process')
self.emit(QtCore.SIGNAL('StartedCopyingGCFs'))
try:
for file in gcfs:
shutil.copy(steam_location + os.sep + 'steamapps' + os.sep + file, secondary_steamapps_location)
except:
self.returnMessage('File copy error', 'The GCFs could not be copied')
self.emit(QtCore.SIGNAL('FinishedCopyingGCFs'))
def returnMessage(self, title, message):
self.emit(QtCore.SIGNAL('returnMessage'), title, message)
class curry(object):
def __init__(self, func, *args, **kwargs):
self._func = func
self._pending = args[:]
self._kwargs = kwargs
def __call__(self, *args, **kwargs):
if kwargs and self._kwargs:
kw = self._kwargs.copy()
kw.update(kwargs)
else:
kw = kwargs or self._kwargs
return self._func(*(self._pending + args), **kw)
class MainWindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.settings = Config.settings
self.toolBars = []
self.accountButtons = []
self.chosenGroupAccounts = []
# Create MainWindow
self.setObjectName('MainWindow')
self.resize(694, 410)
self.setMinimumSize(QtCore.QSize(self.width(), self.height()))
self.setWindowTitle('TF2Idle')
self.setWindowIcon(QtGui.QIcon(returnResourcePath('images/tf2idle.png')))
self.updateWindow()
def updateWindow(self, disableUpdateGCFs=False):
# Clear toolbars first
for toolbar in self.toolBars:
toolbar.close()
del toolbar
# 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)
# Add vertical toolbar actions
addAccountIcon = QtGui.QIcon()
addAccountIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/add_account.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.addAccountAction = self.vtoolBar.addAction(addAccountIcon, 'Add account')
QtCore.QObject.connect(self.addAccountAction, QtCore.SIGNAL('triggered()'), self.openAccountDialog)
editAccountIcon = QtGui.QIcon()
editAccountIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/edit_account.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.editAccountAction = self.vtoolBar.addAction(editAccountIcon, 'Edit account')
QtCore.QObject.connect(self.editAccountAction, QtCore.SIGNAL('triggered()'), curry(self.openAccountDialog, editAccount=True))
removeAccountIcon = QtGui.QIcon()
removeAccountIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/remove_account.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.deleteAccountsAction = self.vtoolBar.addAction(removeAccountIcon, 'Delete account')
QtCore.QObject.connect(self.deleteAccountsAction, QtCore.SIGNAL('triggered()'), self.deleteAccounts)
selectGroupIcon = QtGui.QIcon()
selectGroupIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/select_group.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.selectGroupsAction = self.vtoolBar.addAction(selectGroupIcon, 'Select Groups')
QtCore.QObject.connect(self.selectGroupsAction, QtCore.SIGNAL('triggered()'), self.selectGroups)
viewBackpackIcon = QtGui.QIcon()
viewBackpackIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/backpack.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.viewBackpackAction = self.vtoolBar.addAction(viewBackpackIcon, 'View backpack')
QtCore.QObject.connect(self.viewBackpackAction, QtCore.SIGNAL('triggered()'), self.openBackpack)
# Add horizontal toolbar actions
startIdleIcon = QtGui.QIcon()
startIdleIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/start_idle.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.startIdleAction = self.htoolBar.addAction(startIdleIcon, 'Start idling')
QtCore.QObject.connect(self.startIdleAction, QtCore.SIGNAL('triggered()'), curry(self.startUpAccounts, action='idle'))
startIdleUnsandboxedIcon = QtGui.QIcon()
startIdleUnsandboxedIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/start_idle_unsandboxed.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.startIdleUnsandboxedAction = self.htoolBar.addAction(startIdleUnsandboxedIcon, 'Start idling (no sandbox)')
QtCore.QObject.connect(self.startIdleUnsandboxedAction, QtCore.SIGNAL('triggered()'), curry(self.startUpAccounts, action='idle_unsandboxed'))
startTF2Icon = QtGui.QIcon()
startTF2Icon.addPixmap(QtGui.QPixmap(returnResourcePath('images/start_tf2.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.startTF2Action = self.htoolBar.addAction(startTF2Icon, 'Start TF2')
QtCore.QObject.connect(self.startTF2Action, QtCore.SIGNAL('triggered()'), curry(self.startUpAccounts, action='start_TF2'))
startSteamIcon = QtGui.QIcon()
startSteamIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/start_steam.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.startSteamAction = self.htoolBar.addAction(startSteamIcon, 'Start Steam')
QtCore.QObject.connect(self.startSteamAction, QtCore.SIGNAL('triggered()'), curry(self.startUpAccounts, action='start_steam'))
self.htoolBar.addSeparator()
updateGCFsIcon = QtGui.QIcon()
if not disableUpdateGCFs:
updateGCFsIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/update_gcfs.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.updateGCFsAction = self.htoolBar.addAction(updateGCFsIcon, 'Update GCFs')
QtCore.QObject.connect(self.updateGCFsAction, QtCore.SIGNAL('triggered()'), self.updateGCFs)
else:
updateGCFsIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/updating_gcfs.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.updateGCFsAction = self.htoolBar.addAction(updateGCFsIcon, 'Updating GCFs')
terminateSandboxIcon = QtGui.QIcon()
terminateSandboxIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/terminate_sandbox.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.terminateSandboxAction = self.htoolBar.addAction(terminateSandboxIcon, 'Terminate sandbox')
QtCore.QObject.connect(self.terminateSandboxAction, QtCore.SIGNAL('triggered()'), curry(self.modifySandboxes, action='/terminate'))
emptySandboxIcon = QtGui.QIcon()
emptySandboxIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/delete_sandbox.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.emptySandboxAction = self.htoolBar.addAction(emptySandboxIcon, 'Empty sandbox')
QtCore.QObject.connect(self.emptySandboxAction, QtCore.SIGNAL('triggered()'), curry(self.modifySandboxes, action='delete_sandbox'))
self.htoolBar.addSeparator()
startLogIcon = QtGui.QIcon()
startLogIcon.addPixmap(QtGui.QPixmap(returnResourcePath('images/start_log.png')), QtGui.QIcon.Normal, QtGui.QIcon.Off)
self.htoolBar.addAction(startLogIcon, 'Start drop log')
# Attach toolbars to MainWindow
self.addToolBar(QtCore.Qt.BottomToolBarArea, self.htoolBar)
self.addToolBar(QtCore.Qt.RightToolBarArea, self.vtoolBar)
self.centralwidget = QtGui.QWidget(self)
self.gridLayout = QtGui.QGridLayout(self.centralwidget)
self.gridLayout.setMargin(0)
self.verticalLayout = QtGui.QVBoxLayout()
self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 1)
self.setCentralWidget(self.centralwidget)
# 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, 'Settings', text='Settings', statustip='Open settings', shortcut='Ctrl+S', action={'trigger':'triggered()', 'action':self.openSettings})
filemenu.addSeparator()
self.addSubMenu(filemenu, 'Exit', text='Exit', statustip='Exit TF2Idle', shortcut='Ctrl+Q', action={'trigger':'triggered()', 'action':self.close})
# Add About menu
aboutmenu = self.addMenu('About')
self.addSubMenu(aboutmenu, 'Credits', text='Credits', statustip='See credits', action={'trigger':'triggered()', 'action':self.showCredits})
QtCore.QMetaObject.connectSlotsByName(self)
self.updateAccountBoxes()
def updateAccountBoxes(self):
checkedbuttons = []
for widget in self.accountButtons:
if widget.isChecked():
checkedbuttons.append(str(widget.text()))
widget.close()
del widget
self.accountButtons = []
row = 0
column = 0
self.settings.set_section('Settings')
numperrow = int(self.settings.get_option('ui_no_of_columns'))
for account in list(Set(self.settings.get_sections()) - Set(['Settings'])):
self.settings.set_section(account)
if self.settings.get_option('account_nickname') != '':
accountname = self.settings.get_option('account_nickname')
else:
accountname = self.settings.get_option('steam_username')
commandLinkButton = QtGui.QCommandLinkButton(self.centralwidget)
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)
commandLinkButton.setIcon(icon)
commandLinkButton.setIconSize(QtCore.QSize(45, 45))
commandLinkButton.setStyleSheet('font: 10pt "TF2 Build";')
commandLinkButton.setCheckable(True)
commandLinkButton.setChecked(accountname in checkedbuttons or self.settings.get_option('steam_username') in self.chosenGroupAccounts)
commandLinkButton.setObjectName(self.settings.get_option('steam_username'))
commandLinkButton.setText(accountname)
self.accountButtons.append(commandLinkButton)
self.gridLayout.addWidget(commandLinkButton, row, column, 1, 1)
column += 1
if column == numperrow:
row += 1
column = 0
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, menuname, shortcut=None, text=None, tooltip=None, statustip=None, action=None):
self.action = QtGui.QAction(self)
if shortcut:
self.action.setShortcut(shortcut)
self.action.setObjectName('action' + menuname)
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 statustip:
self.action.setStatusTip(statustip)
def openAccountDialog(self, editAccount=False):
if editAccount:
checkedbuttons = []
for widget in self.accountButtons:
if widget.isChecked():
checkedbuttons.append('Account-' + str(widget.objectName()))
if len(checkedbuttons) == 0:
QtGui.QMessageBox.information(self, 'No accounts selected', 'Please select at least one account to edit')
else:
dialogWindow = AccountDialogWindow(checkedbuttons)
dialogWindow.setModal(True)
dialogWindow.exec_()
self.updateAccountBoxes()
else:
dialogWindow = AccountDialogWindow()
dialogWindow.setModal(True)
dialogWindow.exec_()
self.updateAccountBoxes()
def deleteAccounts(self):
checkedbuttons = []
for widget in self.accountButtons:
if widget.isChecked():
checkedbuttons.append(str(widget.objectName()))
if len(checkedbuttons) == 0:
QtGui.QMessageBox.information(self, 'No accounts selected', 'Please select at least one account to delete')
else:
reply = QtGui.QMessageBox.warning(self, 'Warning', 'Are you sure to want to delete these accounts?', QtGui.QMessageBox.Yes | QtGui.QMessageBox.No, QtGui.QMessageBox.No)
if reply == QtGui.QMessageBox.Yes:
for account in checkedbuttons:
self.settings.set_section('Account-' + account)
self.settings.remove_section()
self.updateAccountBoxes()
def openSettings(self):
dialogWindow = SettingsDialogWindow()
dialogWindow.setModal(True)
dialogWindow.exec_()
self.updateAccountBoxes()
def selectGroups(self):
dialogWindow = GroupsDialogWindow()
dialogWindow.setModal(True)
dialogWindow.exec_()
self.chosenGroupAccounts = dialogWindow.returnAccounts()
self.updateAccountBoxes()
def showCredits(self):
about = QtGui.QMessageBox(self)
about.setWindowTitle('Credits')
about.setIconPixmap(QtGui.QPixmap(returnResourcePath('images/tf2idle.png')))
about.setTextFormat(QtCore.Qt.RichText)
about.setText("""<b>TF2Idle 1.0</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> 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://wiki.teamfortress.com">official TF2 wiki</a> for the \'borrowed\' icons.
<br/><br/>They are kredit to team.""")
about.exec_()
def startUpAccounts(self, action):
checkedbuttons = []
for widget in self.accountButtons:
if widget.isChecked():
checkedbuttons.append(str(widget.objectName()))
if len(checkedbuttons) == 0:
if action == 'idle':
QtGui.QMessageBox.information(self, 'No accounts selected', 'Please select at least one account to idle')
elif action == 'idle_unsandboxed':
QtGui.QMessageBox.information(self, 'No account selected', 'Please select an account to idle')
elif action == 'start_steam':
QtGui.QMessageBox.information(self, 'No accounts selected', 'Please select at least one account to start Steam with')
elif action == 'start_TF2':
QtGui.QMessageBox.information(self, 'No accounts selected', 'Please select at least one account to start TF2 with')
elif action == 'idle_unsandboxed' and len(checkedbuttons) > 1:
QtGui.QMessageBox.information(self, 'Too many accounts selected', 'Please select one account to idle')
else:
for account in checkedbuttons:
self.settings.set_section('Settings')
steamlocation = self.settings.get_option('steam_location')
sandboxielocation = self.settings.get_option('sandboxie_location')
steamlaunchcommand = self.settings.get_option('launch_options')
self.settings.set_section('Account-' + account)
username = self.settings.get_option('steam_username')
password = self.settings.get_option('steam_password')
sandboxname = self.settings.get_option('sandbox_name')
sandbox_install = self.settings.get_option('sandbox_install')
if action == 'idle':
command = r'"%s/Steam.exe" -login %s %s -applaunch 440 %s' % (sandbox_install, username, password, steamlaunchcommand)
command = r'"%s/Start.exe" /box:%s %s' % (sandboxielocation, sandboxname, command)
if action == 'idle_unsandboxed':
command = r'"%s/Steam.exe" -login %s %s -applaunch 440 %s' % (steamlocation, username, password, steamlaunchcommand)
elif action == 'start_steam':
command = r'"%s/Steam.exe" -login %s %s' % (sandbox_install, username, password)
command = r'"%s/Start.exe" /box:%s %s' % (sandboxielocation, sandboxname, command)
elif action == 'start_TF2':
command = r'"%s/Steam.exe" -login %s %s -applaunch 440' % (sandbox_install, username, password)
command = r'"%s/Start.exe" /box:%s %s' % (sandboxielocation, sandboxname, command)
returnCode = subprocess.call(command)
def openBackpack(self):
checkedbuttons = []
for widget in self.accountButtons:
if widget.isChecked():
checkedbuttons.append(str(widget.objectName()))
if len(checkedbuttons) == 0:
QtGui.QMessageBox.information(self, 'No accounts selected', 'Please select at least one account to view backpack')
else:
self.settings.set_section('Settings')
backpack_viewer = self.settings.get_option('backpack_viewer')
if backpack_viewer == 'OPTF2':
url = 'http://optf2.com/tf2/user/%(ID)s'
elif backpack_viewer == 'Steam':
url = 'http://steamcommunity.com/id/%(ID)s/inventory'
elif backpack_viewer == 'TF2B':
url = 'http://tf2b.com/?id=%(ID)s'
elif backpack_viewer == 'TF2Items':
url = 'http://www.tf2items.com/id/%(ID)s'
for account in checkedbuttons:
self.settings.set_section('Account-' + account)
webbrowser.open(url % {'ID': self.settings.get_option('steam_vanityid')})
def modifySandboxes(self, action):
checkedbuttons = []
for widget in self.accountButtons:
if widget.isChecked():
checkedbuttons.append(str(widget.objectName()))
if len(checkedbuttons) == 0:
if action == '/terminate':
QtGui.QMessageBox.information(self, 'No accounts selected', 'Please select at least one account to terminate its sandbox')
else:
QtGui.QMessageBox.information(self, 'No accounts selected', 'Please select at least one account to delete its sandbox contents')
else:
self.settings.set_section('Settings')
sandboxie_location = self.settings.get_option('sandboxie_location')
for account in checkedbuttons:
self.settings.set_section('Account-' + account)
if self.settings.get_option('sandbox_name') != '':
command = r'"%s/Start.exe" /box:%s %s' % (sandboxie_location, self.settings.get_option('sandbox_name'), action)
returnCode = subprocess.call(command)
def updateGCFs(self):
def Dialog(title, message):
QtGui.QMessageBox.information(self, title, message)
self.thread = Worker()
QtCore.QObject.connect(self.thread, QtCore.SIGNAL('returnMessage'), Dialog)
QtCore.QObject.connect(self.thread, QtCore.SIGNAL('StartedCopyingGCFs'), curry(self.updateWindow, disableUpdateGCFs=True))
QtCore.QObject.connect(self.thread, QtCore.SIGNAL('FinishedCopyingGCFs'), self.updateWindow)
self.thread.start()
class AccountDialogWindow(QtGui.QDialog):
def __init__(self, accounts=[], parent=None):
QtGui.QDialog.__init__(self, parent)
self.ui = Ui_AccountDialog(self, accounts)
class SettingsDialogWindow(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.ui = Ui_SettingsDialog(self)
class GroupsDialogWindow(QtGui.QDialog):
def __init__(self, parent=None):
QtGui.QDialog.__init__(self, parent)
self.ui = Ui_GroupsDialog(self)
def returnAccounts(self):
return self.ui.returnAccounts()