-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdonations-ui.py
372 lines (270 loc) · 18.2 KB
/
donations-ui.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
import donations
import wx
import wx.lib.agw.floatspin as FS
import sys, os
import ConfigParser
from threading import Thread
class MainWindow(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title='Donation Tracker', size=(500, 300), style=wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX)
self.SetBackgroundColour((255, 255, 255))
# events
self.Bind(wx.EVT_CLOSE, self.nativeClose)
# icon
icon = wx.Icon(resourcePath('icon.ico'), wx.BITMAP_TYPE_ICO)
self.SetIcon(icon)
# interface
logo_image = wx.Image(resourcePath('logo.png'), wx.BITMAP_TYPE_ANY).ConvertToBitmap()
logo = wx.StaticBitmap(self, -1, logo_image, (logo_image.GetWidth(), logo_image.GetHeight()))
button_panel = wx.Panel(self, -1) # style=wx.SUNKEN_BORDER
config_button = wx.Button(button_panel, -1, label='Configure', size=(200, -1))
config_button.Bind(wx.EVT_BUTTON, self.openConfigWindowButton)
run_button = wx.Button(button_panel, -1, label='Run', size=(200, -1))
run_button.Bind(wx.EVT_BUTTON, self.runButton)
# layout
window_layout = wx.BoxSizer(wx.VERTICAL)
window_layout.Add(logo , 1)
# button layout
button_layout = wx.BoxSizer(wx.HORIZONTAL)
button_layout.Add(config_button, border=10, flag=wx.ALIGN_LEFT | wx.RIGHT)
button_layout.Add(run_button, border=10, flag=wx.ALIGN_RIGHT | wx.LEFT)
button_panel.SetSizer(button_layout)
# add buttons to window_layout
window_layout.Add(button_panel, border=20, flag=wx.ALIGN_CENTER | wx.BOTTOM)
window_layout.AddStretchSpacer()
self.SetSizer(window_layout)
self.Center()
#config_button.Disable()
run_button.SetFocus()
def openConfigWindowButton(self, event):
config_frame = ConfigWindow(self)
config_frame.Show()
self.Hide()
def runButton(self, event):
run_frame = RunWindow(self)
run_frame.Show()
self.Hide()
def nativeClose(self, event):
# dlg = wx.MessageDialog(self, "Do you really want to close this application?", "Confirm Exit", wx.OK|wx.CANCEL|wx.ICON_QUESTION)
# result = dlg.ShowModal()
# dlg.Destroy()
# if result == wx.ID_OK:
# self.Destroy()
self.Destroy()
os._exit(1)
class ConfigWindow(wx.Frame):
def __init__(self, parent_window):
self.parent_window = parent_window
# window setup
wx.Frame.__init__(self, None, title='Configure', size=(800, 600), style=wx.CAPTION | wx.CLOSE_BOX | wx.MINIMIZE_BOX)
self.SetBackgroundColour((255, 255, 255))
self.Bind(wx.EVT_CLOSE, self.nativeClose)
# icon
self.icon = wx.Icon(resourcePath('icon.ico'), wx.BITMAP_TYPE_ICO)
self.SetIcon(self.icon)
# config
self.config = ConfigParser.ConfigParser(allow_no_value = True, defaults={
'channel': '',
'api-key': '',
'dailydonationlist': 'false',
'dailyrecentdonation': 'false',
'dailytopdonation': 'false',
'soundminimum': '1.00',
'fileminimum': '1.00',
'donationlistamount': '5',
'playwav': 'true',
'donationwav': 'sound.wav',
'topdonationwav': 'sound.wav',
'donationformatting': '{currencySymbol}{amount} - {note} - From: {username}',
'topdonationformatting': '{currencySymbol}{amount} - From: {username}',
'donationlistformatting': '{username}: {currencySymbol}{amount}',
'consoleformatting': '{currencySymbol}{amount} - {note} - From: {username}, using {processor}',
})
self.config.read(resourcePath('settings.ini', user=True))
if not self.config.has_section("Donation Tracker Config"):
self.config.add_section("Donation Tracker Config")
# interface
self.scroll_window = wx.ScrolledWindow(self, -1)
self.main_panel = wx.Panel(self.scroll_window, -1)
self.channel_text_box_label = wx.StaticText(self.main_panel, label="Channel - your channel name on Twitch")
self.channel_text_box = wx.TextCtrl(self.main_panel, 1, size=(200,-1))
self.channel_text_box.SetValue(self.config.get("Donation Tracker Config", 'channel'))
self.api_key_text_box_label = wx.StaticText(self.main_panel, label="API Key - your API key from StreamDonations.net")
self.api_key_text_box = wx.TextCtrl(self.main_panel, 1, size=(300,-1))
self.api_key_text_box.SetValue(self.config.get("Donation Tracker Config", 'api-key'))
self.clear_files_label = wx.StaticText(self.main_panel, label="Clear the donation lists")
self.clear_donation_list_checkbox = wx.CheckBox(self.main_panel, 1, "Daily Donations List - clear the donations list on start")
self.clear_donation_list_checkbox.SetValue(self.config.getboolean("Donation Tracker Config", 'dailydonationlist'))
self.clear_recent_donation_checkbox = wx.CheckBox(self.main_panel, 1, "Most Recent Donation - clear the most recent donation list on start")
self.clear_recent_donation_checkbox.SetValue(self.config.getboolean("Donation Tracker Config", 'dailyrecentdonation'))
self.clear_top_donation_checkbox = wx.CheckBox(self.main_panel, 1, "Daily Top Donation - clear the top donation list on start")
self.clear_top_donation_checkbox.SetValue(self.config.getboolean("Donation Tracker Config", 'dailytopdonation'))
self.sound_min_text_box_label = wx.StaticText(self.main_panel, label="Alarm Minimum - minimum donation amount before triggering alarm")
self.sound_min_text_box = FS.FloatSpin(self.main_panel, 1, size=(100,-1), min_val=0, max_val=1000, increment=1.0, digits=1)
self.sound_min_text_box.SetValue(self.config.getfloat("Donation Tracker Config", 'soundminimum'))
self.file_min_text_box_label = wx.StaticText(self.main_panel, label="File Minimum - minimum donation amount before adding to the list")
self.file_min_text_box = FS.FloatSpin(self.main_panel, 1, size=(100,-1), min_val=0, max_val=1000, increment=1.0, digits=1)
self.file_min_text_box.SetValue(self.config.getfloat("Donation Tracker Config", 'fileminimum'))
self.donation_list_amount_box_label = wx.StaticText(self.main_panel, label="Donation List Amount - number of donations to include in the list")
self.donation_list_amount_box = wx.SpinCtrl(self.main_panel, 1, size=(100,-1), min=0, max=30)
self.donation_list_amount_box.SetValue(self.config.getint("Donation Tracker Config", 'donationlistamount'))
self.play_sound_checkbox = wx.CheckBox(self.main_panel, 1, "Play Sound - Play a sounds for new donations")
self.play_sound_checkbox.SetValue(self.config.getboolean("Donation Tracker Config", 'playwav'))
self.donation_sound_text_box_label = wx.StaticText(self.main_panel, label="New Donation Sound - sound to play with a new donation. Enter the file name. MUST be in WAV format")
self.donation_sound_text_box = wx.TextCtrl(self.main_panel, 1, size=(400,-1))
self.donation_sound_text_box.SetValue(self.config.get("Donation Tracker Config", 'donationwav'))
self.top_donation_sound_text_box_label = wx.StaticText(self.main_panel, label="New Top Donation Sound - sound to play with a new top donation. Enter the file name. MUST be in WAV format")
self.top_donation_sound_text_box = wx.TextCtrl(self.main_panel, 1, size=(400,-1))
self.top_donation_sound_text_box.SetValue(self.config.get("Donation Tracker Config", 'topdonationwav'))
self.donation_formatting_label = wx.StaticText(self.main_panel, label="Donation Formatting - format how the donations will look. For advanced users only")
self.donation_formatting_text_box_label = wx.StaticText(self.main_panel, label="Donation Formatting")
self.donation_formatting_text_box = wx.TextCtrl(self.main_panel, 1, size=(500,-1))
self.donation_formatting_text_box.SetValue(self.config.get("Donation Tracker Config", 'donationformatting'))
self.top_donation_formatting_text_box_label = wx.StaticText(self.main_panel, label="Top Donation Formatting")
self.top_donation_formatting_text_box = wx.TextCtrl(self.main_panel, 1, size=(500,-1))
self.top_donation_formatting_text_box.SetValue(self.config.get("Donation Tracker Config", 'topdonationformatting'))
self.donation_list_formatting_text_box_label = wx.StaticText(self.main_panel, label="Donation List Formatting")
self.donation_list_formatting_text_box = wx.TextCtrl(self.main_panel, 1, size=(500,-1))
self.donation_list_formatting_text_box.SetValue(self.config.get("Donation Tracker Config", 'donationlistformatting'))
self.console_formatting_text_box_label = wx.StaticText(self.main_panel, label="Console Formatting")
self.console_formatting_text_box = wx.TextCtrl(self.main_panel, 1, size=(500,-1))
self.console_formatting_text_box.SetValue(self.config.get("Donation Tracker Config", 'consoleformatting'))
self.formatting_help_label = wx.StaticText(self.main_panel, label="""
{amount} = Amount with currency sign
{note} = Note/memo field
{username} = Twitch Username of contributer
{processor} = Payment Processor
{currencySymbol} = Currency Symbol
""")
# layout
self.panel_sizer = wx.BoxSizer(wx.VERTICAL)
self.panel_sizer.Add(self.channel_text_box_label, border=5, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.channel_text_box, border=20, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.api_key_text_box_label, border=5, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.api_key_text_box, border=50, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.clear_files_label, border=5, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.clear_donation_list_checkbox, border=10, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.clear_recent_donation_checkbox, border=10, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.clear_top_donation_checkbox, border=50, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.sound_min_text_box_label, border=5, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.sound_min_text_box, border=20, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.file_min_text_box_label, border=5, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.file_min_text_box, border=50, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.donation_list_amount_box_label, border=5, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.donation_list_amount_box, border=50, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.play_sound_checkbox, border=10, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.donation_sound_text_box_label, border=5, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.donation_sound_text_box, border=10, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.top_donation_sound_text_box_label, border=5, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.top_donation_sound_text_box, border=50, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.donation_formatting_label, border=20, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.donation_formatting_text_box_label, border=5, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.donation_formatting_text_box, border=20, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.top_donation_formatting_text_box_label, border=5, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.top_donation_formatting_text_box, border=20, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.donation_list_formatting_text_box_label, border=5, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.donation_list_formatting_text_box, border=20, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.console_formatting_text_box_label, border=5, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.console_formatting_text_box, border=20, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.panel_sizer.Add(self.formatting_help_label, border=5, flag= wx.ALIGN_LEFT | wx.BOTTOM)
self.main_panel.SetSizer(self.panel_sizer)
self.scroll_sizer = wx.BoxSizer(wx.VERTICAL)
self.scroll_sizer.Add(self.main_panel, border=60, flag= wx.ALIGN_LEFT | wx.TOP | wx.LEFT | wx.RIGHT)
self.scroll_window.SetSizer(self.scroll_sizer)
self.window_sizer = wx.BoxSizer(wx.VERTICAL)
self.window_sizer.Add(self.scroll_window, 1, wx.ALL|wx.EXPAND, 0)
self.main_panel.SetAutoLayout(True)
self.main_panel.Layout()
self.main_panel.Fit()
self.SetSizer(self.window_sizer)
self.Center()
# scroll settings
self.main_panel_width, self.main_panel_height = self.main_panel.GetSize()
self.unit = 20
self.scroll_window.SetScrollbars( self.unit, self.unit, self.main_panel_width/self.unit, self.main_panel_height/self.unit )
def nativeClose(self, event):
self.write_config()
self.Destroy()
self.parent_window.Show()
def write_config(self):
self.config.set('Donation Tracker Config', 'channel', self.channel_text_box.GetValue())
self.config.set('Donation Tracker Config', 'api-key', self.api_key_text_box.GetValue())
self.config.set('Donation Tracker Config', 'dailydonationlist', self.clear_donation_list_checkbox.GetValue())
self.config.set('Donation Tracker Config', 'dailyrecentdonation', self.clear_recent_donation_checkbox.GetValue())
self.config.set('Donation Tracker Config', 'dailytopdonation', self.clear_top_donation_checkbox.GetValue())
self.config.set('Donation Tracker Config', 'soundminimum', self.sound_min_text_box.GetValue())
self.config.set('Donation Tracker Config', 'fileminimum', self.file_min_text_box.GetValue())
self.config.set('Donation Tracker Config', 'donationlistamount', self.donation_list_amount_box.GetValue())
self.config.set('Donation Tracker Config', 'playwav', self.play_sound_checkbox.GetValue())
self.config.set('Donation Tracker Config', 'donationwav', self.donation_sound_text_box.GetValue())
self.config.set('Donation Tracker Config', 'topdonationwav', self.top_donation_sound_text_box.GetValue())
self.config.set('Donation Tracker Config', 'donationformatting', self.donation_formatting_text_box.GetValue())
self.config.set('Donation Tracker Config', 'topdonationformatting', self.top_donation_formatting_text_box.GetValue())
self.config.set('Donation Tracker Config', 'donationlistformatting', self.donation_list_formatting_text_box.GetValue())
self.config.set('Donation Tracker Config', 'consoleformatting', self.console_formatting_text_box.GetValue())
with open(resourcePath('settings.ini', user=True), 'w') as fp:
self.config.write(fp)
class RedirectText(object):
def __init__(self, aWxTextCtrl):
self.out = aWxTextCtrl
def write(self, string):
#self.out.SetInsertionPoint()
wx.CallAfter(self.out.AppendText, string)
class RunWindow(wx.Frame):
def __init__(self, parent_window):
self.parent_window = parent_window
wx.Frame.__init__(self, None, title='Donation Tracker', size=(800, 450))
# events
self.Bind(wx.EVT_CLOSE, self.nativeClose)
# icon
icon = wx.Icon(resourcePath('icon.ico'), wx.BITMAP_TYPE_ICO)
self.SetIcon(icon)
# interface
#output_panel = wx.Panel(self, -1) # style=wx.SUNKEN_BORDER
#output_panel.SetBackgroundColour((0, 0, 0))
log = wx.TextCtrl(self, -1, size=(600,350), style = wx.TE_RICH | wx.TE_MULTILINE | wx.TE_READONLY)
log.SetBackgroundColour((0, 0, 0))
log_font = wx.Font(11, wx.MODERN, wx.NORMAL, wx.NORMAL, False, u'Consolas')
log.SetFont(log_font)
log.SetForegroundColour((200, 200, 200))
# layout
window_layout = wx.BoxSizer(wx.VERTICAL)
window_layout.Add(log, 1, wx.ALL|wx.EXPAND, 0)
self.SetSizer(window_layout)
self.Center()
self.SetFocus()
# redirect text
redir=RedirectText(log)
sys.stdout=redir
try:
res_dir = sys._MEIPASS
except Exception:
res_dir = os.path.abspath(".")
# start donation tracking in a new thread
donations_thread = Thread(target=donations.start_tracking, args=(res_dir,))
donations_thread.start()
def nativeClose(self, event):
self.Destroy()
#self.parent_window.Show()
os._exit(1)
def resourcePath(relative_path = '', user = False):
base_dir = ''
if getattr(sys, 'frozen', False):
# running in a PyInstaller bundle
if (user == False):
# bundle dir
base_dir = sys._MEIPASS
else:
# user access dir
base_dir = os.path.dirname(sys.executable)
else:
# running in normal Python environment
base_dir = os.path.dirname(__file__)
return os.path.join(base_dir, relative_path)
def main():
app = wx.App()
main_frame = MainWindow()
main_frame.Show()
app.MainLoop()
if __name__ == '__main__':
main()