forked from e1miran/Now-Playing-Serato
-
Notifications
You must be signed in to change notification settings - Fork 11
/
test_settingsui.py
executable file
·143 lines (114 loc) · 5.08 KB
/
test_settingsui.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
#!/usr/bin/env python3
''' test code '''
# This Python file uses the following encoding: utf-8
import sys
import pathlib
import socket
# pylint: disable=no-name-in-module
from PySide6.QtWidgets import QApplication, QListWidgetItem, QWidget
from PySide6.QtCore import QFile, Qt, Slot
from PySide6.QtUiTools import QUiLoader
GENERAL = [
'about', 'general', 'filter', 'obsws', 'quirks', 'settings', 'source', 'twitchbot', 'webserver'
]
INPUTS = ['inputs_m3u', 'inputs_mpris2', 'inputs_serato']
ARTISTEXTRAS = ['artistextras_discogs', 'artistextras_fanarttv', 'artistextras_theaudiodb']
RECOG = ['recognition_acoustidmb']
class SettingsUI(QWidget): # pylint: disable=too-few-public-methods
''' test class '''
def __init__(self):
super().__init__()
self.qtui = None
self.widgets = {}
self.uipath = pathlib.Path(__file__)
self.uipath = self.uipath.parent.joinpath('nowplaying', 'resources')
self.load_qtui()
def load_qtui(self):
''' load the base UI and wire it up '''
def _load_ui(uipath, name):
''' load a UI file into a widget '''
loader = QUiLoader()
ui_file = QFile(uipath.joinpath(f'{name}_ui.ui'))
ui_file.open(QFile.ReadOnly)
qwidget = loader.load(ui_file)
ui_file.close()
return qwidget
self.qtui = _load_ui(self.uipath, 'settings')
for basic in GENERAL + ARTISTEXTRAS + INPUTS + RECOG:
self.widgets[basic] = _load_ui(self.uipath, f'{basic}')
try:
qobject_connector = getattr(self, f'_connect_{basic}_widget')
qobject_connector(self.widgets[basic])
except AttributeError:
pass
self.qtui.settings_stack.addWidget(self.widgets[basic])
self._load_list_item(f'{basic}', self.widgets[basic])
self.qtui.settings_list.currentRowChanged.connect(self._set_stacked_display)
def _connect_recognition_acoustidmb_widget(self, qobject):
qobject.acoustid_checkbox.clicked.connect(self._acoustidmb_checkbox_hook)
@Slot()
def _acoustidmb_checkbox_hook(self):
if self.widgets['recognition_acoustidmb'].acoustid_checkbox.isChecked():
self.widgets['recognition_acoustidmb'].musicbrainz_checkbox.setChecked(True)
@staticmethod
def _connect_webserver_widget(qobject):
try:
hostname = socket.gethostname()
hostip = socket.gethostbyname(hostname)
except Exception: # pylint: disable=broad-except
pass
if hostname:
qobject.hostname_label.setText(hostname)
if hostip:
qobject.hostip_label.setText(hostip)
def _connect_source_widget(self, qobject):
''' populate the input group box '''
for text in ['Serato', 'M3U', 'MPRIS2']:
qobject.sourcelist.addItem(text)
qobject.currentRowChanged.connect(self._set_source_description)
def _connect_filter_widget(self, qobject):
''' connect regex filter to template picker'''
qobject.add_recommended_button.clicked.connect(self.on_filter_add_recommended_button)
qobject.add_button.clicked.connect(self.on_filter_regex_add_button)
qobject.del_button.clicked.connect(self.on_filter_regex_del_button)
def _set_source_description(self, index):
print('here')
self.widgets['source'].description.setText(f'You hit {index}.')
def _load_list_item(self, name, qobject):
displayname = qobject.property('displayName') or name.capitalize()
self.qtui.settings_list.addItem(displayname)
def _set_stacked_display(self, index):
self.qtui.settings_stack.setCurrentIndex(index)
def _filter_regex_load(self, regex=None):
''' setup the filter table '''
regexitem = QListWidgetItem()
if regex:
regexitem.setText(regex)
regexitem.setFlags(Qt.ItemIsEditable
| Qt.ItemIsEnabled | Qt.ItemIsDragEnabled
| Qt.ItemIsSelectable | Qt.ItemIsUserCheckable)
self.widgets['filter'].regex_list.addItem(regexitem)
@Slot()
def on_filter_regex_add_button(self):
''' filter add button clicked action '''
self._filter_regex_load('new')
@Slot()
def on_filter_regex_del_button(self):
''' filter del button clicked action '''
if items := self.widgets['filter'].regex_list.selectedItems():
for item in items:
self.widgets['filter'].regex_list.takeItem(
self.widgets['filter'].regex_list.row(item))
@Slot()
def on_filter_add_recommended_button(self):
''' load some recommended settings '''
stripworldlist = ['clean', 'dirty', 'explicit', 'official music video']
joinlist = '|'.join(stripworldlist)
self._filter_regex_load(f' \\((?i:{joinlist})\\)')
self._filter_regex_load(f' - (?i:{joinlist}$)')
self._filter_regex_load(f' \\[(?i:{joinlist})\\]')
if __name__ == "__main__":
app = QApplication([])
widget = SettingsUI()
widget.qtui.show()
sys.exit(app.exec())