-
Notifications
You must be signed in to change notification settings - Fork 1
/
gui.py
159 lines (129 loc) · 7.01 KB
/
gui.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
import subprocess
import threading
import wx
import wx.adv
import client
import config
from packets_pb2 import GameEvent, PlaySound
from threadripper import threadripper
class TaskbarIcon(wx.adv.TaskBarIcon):
def __init__(self, frame):
super().__init__()
self.frame = frame
self.SetIcon(wx.Icon("icon.ico"))
self.Bind(wx.adv.EVT_TASKBAR_LEFT_DOWN, self.OnLeftClick)
def OnLeftClick(self, evt):
self.frame.Show()
self.frame.Restore()
class MainFrame(wx.Frame):
def __init__(self, *args, **kw):
super().__init__(*args, **kw)
self.panel = wx.Panel(self)
self.SetIcon(wx.Icon("icon.ico"))
# Client needs self.shardCodeIpt
friends_zone = self.make_friends_zone()
# Start threads
self.CreateStatusBar()
self.SetStatusText("Loading sounds...")
self.client = client.Client(self, threadripper)
vbox = wx.BoxSizer(wx.VERTICAL)
vbox.AddStretchSpacer()
vbox.Add(self.make_volume_zone(), border=5, flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALL)
vbox.Add(friends_zone, border=5, flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALL)
vbox.Add(self.make_settings_zone(), border=5, flag=wx.ALIGN_CENTER_HORIZONTAL | wx.ALL)
vbox.AddStretchSpacer()
self.panel.SetSizer(vbox)
self.panel.Layout()
self.UpdateSounds(None)
self.taskbarIcon = TaskbarIcon(self)
self.Bind(wx.EVT_ICONIZE, self.OnMinimize)
self.Bind(wx.EVT_SHOW, self.OnUnMinimize)
self.Bind(wx.EVT_CLOSE, self.OnClose)
self.Centre()
self.Show()
def make_volume_zone(self):
with self.client.sounds.cache_lock:
self.volumeSlider = wx.Slider(self.panel, value=self.client.sounds.volume, size=(272, 25))
self.Bind(wx.EVT_COMMAND_SCROLL_CHANGED, self.OnVolumeSlider, self.volumeSlider)
volumeZone = wx.StaticBoxSizer(wx.VERTICAL, self.panel, label="Volume")
volumeZone.Add(self.volumeSlider)
return volumeZone
def make_friends_zone(self):
shardCodeBtn = wx.Button(self.panel, label="Join room")
self.Bind(wx.EVT_BUTTON, self.UpdateShardCode, shardCodeBtn)
with config.lock:
self.shardCodeIpt = wx.TextCtrl(self.panel, value=config.config['Sounds'].get('Room', ''), size=(164, shardCodeBtn.GetMinSize().GetHeight()))
self.shardCodeIpt.SetFocus()
shardCodeExplanationTxt = wx.StaticText(self.panel, label="In order to hear your teammates' sounds, you\nneed to join the same room.")
friendsZone = wx.StaticBoxSizer(wx.VERTICAL, self.panel, label="Room")
friendsZone.Add(shardCodeExplanationTxt, border=5, flag=wx.LEFT | wx.DOWN)
friendsInputZone = wx.BoxSizer(wx.HORIZONTAL)
friendsInputZone.Add(self.shardCodeIpt, border=5, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
friendsInputZone.Add(shardCodeBtn, border=5, flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
friendsZone.Add(friendsInputZone)
return friendsZone
def make_settings_zone(self):
self.preferHeadshotsChk = wx.CheckBox(self.panel, label="Prefer headshot sounds over killstreak sounds")
self.downloadWhenAliveChk = wx.CheckBox(self.panel, label="Download custom sounds")
self.uploadWhenAliveChk = wx.CheckBox(self.panel, label="Upload custom sounds")
whenAliveTxt = wx.StaticText(self.panel, label="When alive:")
whenAliveWarningTxt = wx.StaticText(self.panel, label="(can impact gameplay on slow connections)")
openSoundDirBtn = wx.Button(self.panel, label="Open sounds directory")
self.updateSoundsBtn = wx.Button(self.panel, label="Update sounds")
self.Bind(wx.EVT_BUTTON, self.OpenSoundsDir, openSoundDirBtn)
self.Bind(wx.EVT_BUTTON, self.UpdateSounds, self.updateSoundsBtn)
soundBtns = wx.BoxSizer(wx.HORIZONTAL)
soundBtns.Add(openSoundDirBtn)
soundBtns.Add(self.updateSoundsBtn)
settingsBox = wx.StaticBoxSizer(wx.VERTICAL, self.panel, label="Settings")
settingsBox.Add(self.preferHeadshotsChk, border=5, flag=wx.ALL)
settingsBox.Add(whenAliveTxt, border=5, flag=wx.ALL)
settingsBox.Add(self.downloadWhenAliveChk, border=15, flag=wx.LEFT)
settingsBox.Add(self.uploadWhenAliveChk, border=15, flag=wx.LEFT)
settingsBox.Add(whenAliveWarningTxt, border=5, flag=wx.ALL)
settingsBox.Add(soundBtns, border=5, flag=wx.ALIGN_CENTER | wx.UP | wx.DOWN)
with config.lock:
preferHeadshots = config.config['Sounds'].getboolean('PreferHeadshots', False)
downloadWhenAlive = config.config['Network'].getboolean('DownloadWhenAlive', False)
uploadWhenAlive = config.config['Network'].getboolean('UploadWhenAlive', False)
self.preferHeadshotsChk.SetValue(preferHeadshots)
self.downloadWhenAliveChk.SetValue(downloadWhenAlive)
self.uploadWhenAliveChk.SetValue(uploadWhenAlive)
self.Bind(wx.EVT_CHECKBOX, lambda e: config.set('Sounds', 'PreferHeadshots', self.preferHeadshotsChk.Value), self.preferHeadshotsChk)
self.Bind(wx.EVT_CHECKBOX, lambda e: config.set('Network', 'DownloadWhenAlive', self.downloadWhenAliveChk.Value), self.downloadWhenAliveChk)
self.Bind(wx.EVT_CHECKBOX, lambda e: config.set('Network', 'UploadWhenAlive', self.uploadWhenAliveChk.Value), self.uploadWhenAliveChk)
return settingsBox
def SetStatusText(self, text):
"""Override default SetStatusText to avoid minimizing CS:GO"""
if self.IsIconized():
return
super().SetStatusText(text)
def OnUnMinimize(self, event):
threading.Thread(target=self.client.update_status, daemon=True).start()
def OnVolumeSlider(self, event):
config.set('Sounds', 'Volume', self.volumeSlider.Value)
with self.client.sounds.cache_lock:
# Volume didn't change
if self.client.sounds.volume == self.volumeSlider.Value:
return
self.client.sounds.volume = self.volumeSlider.Value
playpacket = PlaySound()
playpacket.steamid = 0
playpacket.sound_hash = self.client.sounds.get_random(GameEvent.HEADSHOT, None)
self.client.sounds.play(playpacket)
def OpenSoundsDir(self, event):
# TODO linux
subprocess.Popen('explorer "sounds"')
def UpdateShardCode(self, event):
self.client.shard_code = self.shardCodeIpt.GetValue()
config.set('Sounds', 'Room', self.shardCodeIpt.GetValue())
threading.Thread(target=self.client.client_update, daemon=True).start()
def UpdateSounds(self, event):
self.updateSoundsBtn.Disable()
threading.Thread(target=self.client.reload_sounds, daemon=True).start()
def OnMinimize(self, event):
if self.IsIconized():
self.Hide()
def OnClose(self, event):
self.taskbarIcon.Destroy()
self.Destroy()