-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsettings.py
More file actions
571 lines (443 loc) · 22.5 KB
/
settings.py
File metadata and controls
571 lines (443 loc) · 22.5 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
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
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
import os
from sys import platform
import wx
import wx.adv
from pubsub import pub
from urllib.parse import urlparse
import webbrowser
from enums import ID
import tooltips
class Settings(wx.Dialog):
def __init__(self, parent, appData: list):
super().__init__(parent)
self.SetTitle('Settings')
self.parent = parent
self.appData = appData
self.domains_dict = {}
self.isDomainModified = False
self.file_twitch_auth = ''
self.InitUI()
self.LoadData()
self.CenterOnParent()
self.Bind(wx.EVT_CLOSE, self.OnClose)
def InitUI(self) -> None:
sizer = wx.BoxSizer(wx.VERTICAL)
self.notebook = wx.Notebook(self, -1)
sizer.Add(self.notebook, flag=wx.ALL | wx.EXPAND, border=5)
streamers = self.GetStreamersPanel()
preferences = self.GetPreferencesPanel()
self.notebook.AddPage(streamers, 'Streamers')
self.notebook.AddPage(preferences, 'Preferences')
self.SetSizerAndFit(sizer)
def LoadData(self) -> None:
''' Load the data for the streamers and the controls. '''
streamers = self.appData['streamers_data']
if streamers:
for streamer in streamers:
self.listBox.Append(streamer['name'])
self.listBox.SetSelection(0)
self.OnListBox(None)
self.domains_dict = self.appData['domains']
self.UpdateDomainComboBox()
self.startCheckBox.SetValue(self.appData['start_on_scheduler'])
self.trayMinimizeCheckBox.SetValue(self.appData['tray_on_minimized'])
self.trayCloseCheckBox.SetValue(self.appData['tray_on_closed'])
self.notificationCheckBox.SetValue(self.appData['send_notifications'])
self.dirCtrl.SetValue(self.appData['download_dir'])
self.twitchAuthCtrl.SetValue(self.appData['twitch_auth'])
self.file_twitch_auth = self.appData['twitch_auth']
def GetStreamersPanel(self) -> wx.Panel:
''' Gets the streamer panel. '''
panel = wx.Panel(self.notebook)
masterSizer = wx.BoxSizer(wx.HORIZONTAL)
listSizer = wx.BoxSizer(wx.VERTICAL)
detailsSizer = wx.BoxSizer(wx.VERTICAL)
masterSizer.Add(listSizer, flag=wx.ALL, border=10)
masterSizer.Add(detailsSizer, flag=wx.ALL, border=10)
if platform != 'win32':
spinSize = (110, 32)
comboSize = (150, 32)
textSize = (75, 23)
textCtrlSize = (300, 32)
spacing = 6
else:
spinSize = (60, 23)
comboSize = (100, 23)
textSize = (75, 23)
textCtrlSize = (250, 23)
spacing = 3
removeBtn = wx.Button(panel, -1, 'Remove')
createBtn = wx.Button(panel, -1, 'Create')
editBtn = wx.Button(panel, -1, 'Edit')
clearBtn = wx.Button(panel, -1, 'Clear')
clearBtn.Bind(wx.EVT_BUTTON, self.OnClear)
removeBtn.Bind(wx.EVT_BUTTON, self.OnRemove)
createBtn.Bind(wx.EVT_BUTTON, self.OnCreate)
editBtn.Bind(wx.EVT_BUTTON, self.OnEdit)
self.listBox = wx.ListBox(panel, -1, size=(200, 200))
self.listBox.Bind(wx.EVT_LISTBOX, self.OnListBox)
urlSizer = wx.BoxSizer(wx.HORIZONTAL)
self.urlCtrl = wx.TextCtrl(panel, -1, size=textCtrlSize)
url_text = wx.StaticText(panel, -1, 'URL :', size=textSize, style=wx.ALIGN_RIGHT)
url_tooltip = wx.ToolTip(tooltips.URL_TOOLTIP)
url_tooltip.SetAutoPop(30_000)
url_text.SetToolTip(url_tooltip)
urlSizer.Add(url_text, flag=wx.TOP, border=spacing)
urlSizer.Add(self.urlCtrl, flag=wx.LEFT, border=15)
nameSizer = wx.BoxSizer(wx.HORIZONTAL)
self.nameCtrl = wx.TextCtrl(panel, -1, size=textCtrlSize)
name_text = wx.StaticText(panel, -1, 'Name :', size=textSize, style=wx.ALIGN_RIGHT)
name_tooltip = wx.ToolTip(tooltips.NAME_TOOLTIP)
name_tooltip.SetAutoPop(30_000)
name_text.SetToolTip(url_tooltip)
nameSizer.Add(name_text, flag=wx.TOP, border=spacing)
nameSizer.Add(self.nameCtrl, flag=wx.LEFT, border=15)
prioritySizer = wx.BoxSizer(wx.HORIZONTAL)
self.priorityCtrl = wx.SpinCtrl(panel, -1, size=spinSize, min=1, max=5)
priority_text = wx.StaticText(panel, -1, 'Priority :', size=textSize, style=wx.ALIGN_RIGHT)
priority_tooltip = wx.ToolTip(tooltips.PRIORITY_TOOLTIP)
priority_tooltip.SetAutoPop(30_000)
priority_text.SetToolTip(priority_tooltip)
prioritySizer.Add(priority_text, flag=wx.TOP, border=spacing)
prioritySizer.Add(self.priorityCtrl, flag=wx.LEFT, border=15)
qualitySizer = wx.BoxSizer(wx.HORIZONTAL)
choices = ['best', 'high', 'medium', 'low', 'worst', 'audio only']
self.qualityCombo = wx.ComboBox(panel, -1, choices[0], choices=choices, size=comboSize, style=wx.CB_READONLY)
quality_text = wx.StaticText(panel, -1, 'Quality :', size=textSize, style=wx.ALIGN_RIGHT)
quality_tooltip = wx.ToolTip(tooltips.QUALITY_TOOLTIP)
quality_tooltip.SetAutoPop(30_000)
quality_text.SetToolTip(quality_tooltip)
qualitySizer.Add(quality_text, flag=wx.TOP, border=spacing)
qualitySizer.Add(self.qualityCombo, flag=wx.LEFT, border=15)
detailsSizer.Add(urlSizer)
detailsSizer.Add(nameSizer, flag=wx.TOP, border=10)
detailsSizer.Add(prioritySizer, flag=wx.TOP, border=10)
detailsSizer.Add(qualitySizer, flag=wx.TOP, border=10)
BtnSizer = wx.BoxSizer(wx.HORIZONTAL)
BtnSizer.Add(clearBtn, flag=wx.ALIGN_CENTER)
BtnSizer.Add(editBtn, flag=wx.LEFT | wx.ALIGN_CENTER, border=25)
BtnSizer.Add(createBtn, flag=wx.LEFT | wx.ALIGN_CENTER, border=25)
detailsSizer.Add(BtnSizer, flag=wx.TOP | wx.ALIGN_CENTER, border=25)
buttonsSizer = wx.BoxSizer(wx.HORIZONTAL)
buttonsSizer.Add(removeBtn, flag=wx.ALIGN_CENTER)
listSizer.Add(buttonsSizer, proportion=1, flag=wx.BOTTOM, border=10)
listSizer.Add(self.listBox, proportion=5, flag=wx.EXPAND)
panel.SetSizer(masterSizer)
return panel
def GetPreferencesPanel(self) -> wx.Panel:
''' Gets the preferences panel. '''
panel = wx.Panel(self.notebook)
sizer = wx.BoxSizer(wx.VERTICAL)
if platform != 'win32':
spinSize = (110, 32)
textSize = (120, 32)
longTextSize = (350, 32)
comboSize = (250, 32)
spacing = 6
else:
spinSize = (60, 23)
textSize = (100, 23)
longTextSize = (285, 23)
comboSize = (180, 23)
spacing = 3
waitSizer = wx.BoxSizer(wx.HORIZONTAL)
self.waitCtrl = wx.SpinCtrl(panel, -1, size=spinSize, min=5, max=120, initial=30)
self.waitCtrl.Bind(wx.EVT_SPINCTRL, self.OnWaitCtrl)
self.domainCombo = wx.ComboBox(panel, -1, '', size=comboSize, style=wx.CB_READONLY)
self.domainCombo.Bind(wx.EVT_COMBOBOX, self.OnDomainCombo)
wait_text = wx.StaticText(panel, -1, 'Wait time (s) :', size=textSize)
wait_tooltip = wx.ToolTip(tooltips.WAIT_TOOLTIP)
wait_tooltip.SetAutoPop(30_000)
wait_text.SetToolTip(wait_tooltip)
waitSizer.Add(wait_text, flag=wx.TOP, border=spacing)
waitSizer.Add(self.waitCtrl, flag=wx.RIGHT, border=15)
waitSizer.Add(wx.StaticText(panel, -1, 'for'), flag=wx.TOP, border=spacing)
waitSizer.Add(self.domainCombo, flag=wx.LEFT, border=15)
startSizer = wx.BoxSizer(wx.HORIZONTAL)
self.startCheckBox = wx.CheckBox(panel, -1)
startSizer.Add(self.startCheckBox, flag=wx.RIGHT, border=10)
startSizer.Add(wx.StaticText(panel, -1, 'Starts the scheduler when the app is opened', size=longTextSize))
self.Bind(wx.EVT_CHECKBOX, self.OnStartCheckBox, self.startCheckBox)
trayMinimizeSizer = wx.BoxSizer(wx.HORIZONTAL)
self.trayMinimizeCheckBox = wx.CheckBox(panel, -1)
trayMinimizeSizer.Add(self.trayMinimizeCheckBox, flag=wx.RIGHT, border=10)
trayMinimizeSizer.Add(wx.StaticText(panel, -1, 'Go to system tray when minimized.', size=longTextSize))
self.Bind(wx.EVT_CHECKBOX, self.OnMinimizeTrayCheckBox, self.trayMinimizeCheckBox)
trayCloseSizer = wx.BoxSizer(wx.HORIZONTAL)
self.trayCloseCheckBox = wx.CheckBox(panel, -1)
trayCloseSizer.Add(self.trayCloseCheckBox, flag=wx.RIGHT, border=10)
trayCloseSizer.Add(wx.StaticText(panel, -1, 'Go to system tray when closed.', size=longTextSize))
self.Bind(wx.EVT_CHECKBOX, self.OnCloseTrayCheckBox, self.trayCloseCheckBox)
notificationSizer = wx.BoxSizer(wx.HORIZONTAL)
self.notificationCheckBox = wx.CheckBox(panel, -1)
notificationSizer.Add(self.notificationCheckBox, flag=wx.RIGHT, border=10)
notificationSizer.Add(wx.StaticText(panel, -1, 'Send notifications about streamers going online', size=longTextSize))
self.Bind(wx.EVT_CHECKBOX, self.OnNotificationCheckBox, self.notificationCheckBox)
if platform != 'win32': ctrlSizer = (400, 32)
else: ctrlSizer = (300, 23)
dirSizer = wx.BoxSizer(wx.HORIZONTAL)
self.dirCtrl = wx.TextCtrl(panel, -1, '', size=ctrlSizer)
dirBtn = wx.Button(panel, -1, 'Choose')
dirBtn.Bind(wx.EVT_BUTTON, self.OnChooseDir)
if platform != 'win32': spacing = 6
else: spacing = 3
dirSizer.Add(wx.StaticText(panel, -1, 'Download folder :', size=textSize, style=wx.ALIGN_RIGHT), flag=wx.TOP, border=spacing)
dirSizer.Add(self.dirCtrl, flag=wx.LEFT, border=15)
dirSizer.Add(dirBtn, flag=wx.LEFT, border=15)
authSizer = wx.BoxSizer(wx.HORIZONTAL)
self.twitchAuthCtrl = wx.TextCtrl(panel, -1, '', size=ctrlSizer)
authInfoBtn = wx.Button(panel, -1, 'Info')
authSizer.Add(wx.StaticText(panel, -1, 'Twitch Auth :', size=textSize, style=wx.ALIGN_RIGHT), flag=wx.TOP, border=spacing)
authSizer.Add(self.twitchAuthCtrl, flag=wx.LEFT, border=15)
authSizer.Add(authInfoBtn, flag=wx.LEFT, border=15)
authInfoBtn.Bind(wx.EVT_BUTTON, self.OnAuthInfo)
sizer.Add(waitSizer, flag=wx.TOP | wx.LEFT, border=10)
sizer.Add(startSizer, flag=wx.TOP | wx.LEFT, border=10)
sizer.Add(trayMinimizeSizer, flag=wx.TOP | wx.LEFT, border=10)
sizer.Add(trayCloseSizer, flag=wx.TOP | wx.LEFT, border=10)
sizer.Add(notificationSizer, flag=wx.TOP | wx.LEFT, border=10)
if platform != 'win32':
sizer.Add(dirSizer, flag=wx.ALL, border=10)
sizer.Add(authSizer, flag=wx.ALL, border=10)
else:
sizer.Add(dirSizer, flag=wx.TOP, border=10)
sizer.Add(authSizer, flag=wx.TOP, border=10)
panel.SetSizer(sizer)
return panel
def GetFieldsData(self) -> dict:
''' Returns the data on the fields through a dictionary. '''
data = {}
url = self.urlCtrl.GetValue().strip()
name = self.nameCtrl.GetValue().strip()
priority = self.priorityCtrl.GetValue()
quality = self.qualityCombo.GetValue()
data['url'] = url
data['name'] = name
data['quality'] = quality
data['priority'] = priority
return data
def OnListBox(self, event) -> None:
''' Call every time the users clicks on something in the wx.ListBox. '''
if not event:
index = 0
else:
index = event.GetEventObject().GetSelection()
if self.appData['streamers_data']:
data = self.appData['streamers_data'][index]
self.urlCtrl.SetValue(data['url'])
self.nameCtrl.SetValue(data['name'])
self.priorityCtrl.SetValue(data['priority'])
self.qualityCombo.SetValue(data['quality'])
else:
self.OnClear(None)
def OnClear(self, event):
''' Reset the field to their default values. '''
self.urlCtrl.Clear()
self.nameCtrl.Clear()
self.priorityCtrl.SetValue(1)
self.qualityCombo.SetValue('best')
self.listBox.SetSelection(wx.NOT_FOUND)
def OnRemove(self, event):
''' Removes a streamer from the file. '''
index = self.listBox.GetSelection()
if index == wx.NOT_FOUND:
dlg = wx.MessageDialog(self, f"Please, select a streamer to remove.", 'No streamer selected', wx.ICON_ERROR)
return
name = self.appData['streamers_data'][index]['name']
url = self.appData['streamers_data'][index]['url']
dlg = wx.MessageDialog(self, f"Are you sure you want to remove {name}? If there is a livestream from it being downloaded, it will be canceled.",
'Removing streamer', wx.ICON_WARNING | wx.YES_NO)
res = dlg.ShowModal()
if res == wx.ID_YES:
self.listBox.Delete(index)
self.DeleteDomainsDict(url)
del self.appData['streamers_data'][index]
self.UpdateDomainComboBox()
pub.sendMessage('save-file')
pub.sendMessage('remove-from-thread', name=name)
pub.sendMessage('remove-from-queue', name=name)
wx.CallAfter(pub.sendMessage, topicName='remove-from-tree', name=name, parent_id=ID.TREE_ALL)
self.OnListBox(None)
def OnCreate(self, event):
if self.urlCtrl.IsEmpty() or self.nameCtrl.IsEmpty():
wx.MessageBox('Please, fill all the information in the text fields.', 'Empty Fields', wx.ICON_ERROR)
return
data = self.GetFieldsData()
for streamer in self.appData['streamers_data']:
if streamer['name'] == data['name']:
wx.MessageBox('A streamer with this name already exists. Please, choose another one.',
'Streamer already exists', wx.ICON_ERROR)
return
data['wait_until'] = ''
self.appData['streamers_data'].append(data)
domain = urlparse(data['url']).netloc
wx.CallAfter(pub.sendMessage, topicName='add-to-tree', name=data['name'], parent_id=ID.TREE_QUEUE)
self.AddToDomainsDict(data)
self.UpdateDomainComboBox()
pub.sendMessage('save-file')
pub.sendMessage('add-to-queue', streamer=data, queue_domain=domain)
self.listBox.Append(data['name'])
wx.MessageBox('Streamer successfully saved.', 'Success', wx.ICON_INFORMATION)
def OnEdit(self, event):
if self.urlCtrl.IsEmpty() or self.nameCtrl.IsEmpty():
wx.MessageBox('Please, fill all the information in the text fields.', 'Empty Fields', wx.ICON_ERROR)
return
index = self.listBox.GetSelection()
data = self.GetFieldsData()
if index == wx.NOT_FOUND:
wx.MessageBox('Please, select a streamer to edit.', 'No streamer selected', wx.ICON_ERROR)
return
oldName = self.listBox.GetString(index)
# If the user is editing without changing the name, we need a exception for cheking
# that. Hence, i != index.
found = -1
for i in range (0, len(self.appData['streamers_data'])):
if self.appData['streamers_data'][i]['name'] == data['name']:
found = i
if i != index:
wx.MessageBox('A streamer with this name already exists. Please, choose another one.',
'Streamer already exists', wx.ICON_ERROR)
return
data['wait_until'] = self.appData['streamers_data'][found]['wait_until']
oldUrl = self.appData['streamers_data'][found]['url']
newUrl = data['url']
self.EditDomainsDict(oldUrl, newUrl)
self.EditStreamerOnFile(index, oldName, data)
self.UpdateDomainComboBox()
self.listBox.SetString(index, data['name'])
pub.sendMessage('edit-in-tree', oldName=oldName, newName=data['name'])
pub.sendMessage('scheduler-edit', oldName=oldName, inData=data)
wx.MessageBox(f"{data['name']} was successfully saved.", 'Success', wx.ICON_INFORMATION)
def EditStreamerOnFile(self, index: int, oldName: str, inData: dict):
''' Edit the stream in the given index with inData. '''
self.appData['streamers_data'][index]['url'] = inData['url']
self.appData['streamers_data'][index]['name'] = inData['name']
self.appData['streamers_data'][index]['quality'] = inData['quality']
self.appData['streamers_data'][index]['priority'] = inData['priority']
self.appData['streamers_data'][index]['wait_until'] = inData['wait_until']
pub.sendMessage('save-file')
pub.sendMessage('scheduler-edit', oldName=oldName, inData=inData)
def OnChooseDir(self, event):
""" Called when the user clicks the Choose Dir button. """
path = os.path.expanduser('~')
dialog = wx.DirDialog(self, 'Choose the download folder', f"{path}/Videos")
if dialog.ShowModal() == wx.ID_OK:
user_path = dialog.GetPath()
self.dirCtrl.SetValue(user_path)
self.appData['download_dir'] = user_path
pub.sendMessage('save-file')
def OnAuthInfo(self, event):
''' Called when the user clicks info the info button about the authentication. '''
webbrowser.open_new('https://streamlink.github.io/latest/cli/plugins/twitch.html#authentication')
def OnCloseTrayCheckBox(self, event):
""" Called when user clicks on close to system tray checkbox. """
obj = event.GetEventObject()
value = obj.GetValue()
self.appData['tray_on_closed'] = value
pub.sendMessage('save-file')
def OnMinimizeTrayCheckBox(self, event):
""" Called when user clicks on minimize to system tray checkbox. """
obj = event.GetEventObject()
value = obj.GetValue()
self.appData['tray_on_minimized'] = value
pub.sendMessage('save-file')
def OnStartCheckBox(self, event):
""" Called when user clicks on start the scheduler when the app is opened checkbox. """
obj = event.GetEventObject()
value = obj.GetValue()
self.appData['start_on_scheduler'] = value
pub.sendMessage('save-file')
def OnNotificationCheckBox(self, event):
""" Called when user clicks on the notification checkbox. """
obj = event.GetEventObject()
value = obj.GetValue()
self.appData['send_notifications'] = value
pub.sendMessage('save-file')
def UpdateDomainComboBox(self):
""" Updates the domain wx.ComboBox using `self.domains_dict`. """
self.domainCombo.Clear()
if len(self.domains_dict) == 0:
return
for key in self.domains_dict.keys():
self.domainCombo.Append(key)
first_key = list(self.domains_dict.keys())[0]
self.domainCombo.SetValue(first_key)
self.OnDomainCombo(None)
def OnWaitCtrl(self, event):
""" Called every time the user changes a value in the wx.SpinCtrl. """
if self.domainCombo.GetValue() != '':
self.isDomainModified = True
domain = self.domainCombo.GetValue()
value = int(self.waitCtrl.GetValue())
self.domains_dict[domain] = value
def OnDomainCombo(self, event):
""" Called every time the user changes a value in the self.domainCombo. """
domain = self.domainCombo.GetValue()
if domain != '':
value = self.domains_dict[domain]
self.waitCtrl.SetValue(str(value))
def AddToDomainsDict(self, streamer: dict) -> str | None:
""" Adds the streamer url domain on the `self.domains_dict`. Should be called only in the
creation of a new entry. If the domain is a unique entry in the dictionary,
it's value is returned. A default wait time of 30 is given. """
domain = urlparse(streamer['url']).netloc
if domain not in self.domains_dict:
self.domains_dict[domain] = 30
self.appData['domains'] = self.domains_dict
return domain
def EditDomainsDict(self, oldUrl: str, newUrl: str):
""" Recievies a old url and a new url that might have been edited.
Changes the `self.domains_dict` as needed. """
# If they are the same, no need to do anything.
if oldUrl == newUrl:
return
oldDomain = urlparse(oldUrl).netloc
newDomain = urlparse(newUrl).netloc
if newDomain == oldDomain:
return
# Ok, they are different.
# Dealing with the old domain.
oldCount = 0
for streamer in self.appData['streamers_data']:
if streamer['url'] == oldUrl:
count += 1
# If there are one of this domain in the file, there's no need to keep it.
if oldCount == 1:
del self.domains_dict[oldDomain]
# Dealing with the new domain.
if newDomain not in self.domains_dict.keys():
self.AddToDomainsDict({'url': newUrl})
def DeleteDomainsDict(self, url: str):
""" Decides if a deletion of a streamer should also delete their domain from the file. """
domain = urlparse(url).netloc
count = 0
for streamer in self.appData['streamers_data']:
url = streamer['url']
dom = urlparse(url).netloc
if domain == dom:
count += 1
# If the count is one, that means that the streamer that was just deleted
# was the only one with that domain. So, we need to remove it.
if count == 1:
del self.domains_dict[domain]
def OnClose(self, event):
""" Called when the user tries to close the window. """
if self.isDomainModified and len(self.domains_dict) > 0:
self.appData['domains'] = self.domains_dict
pub.sendMessage('update-domain-wait-time')
pub.sendMessage('save-file')
auth = self.twitchAuthCtrl.GetValue().strip()
isThereInvalidCh = False
if auth != self.file_twitch_auth:
for char in auth:
if char == '-' or char == '=':
wx.MessageBox('Please, paste only the twitch alphanumeric code extracted from the browser.', 'Error', wx.ICON_ERROR)
isThereInvalidCh = True
break
if isThereInvalidCh is False:
wx.MessageBox('Twitch authentication sucessfully added. You need to restart the application for changes to take effect.', 'Sucess', wx.ICON_INFORMATION)
self.appData['twitch_auth'] = auth
pub.sendMessage('save-file')
self.Unbind(wx.EVT_CLOSE)
event.Skip()
self.Close()