Skip to content

Commit

Permalink
Add custom theming
Browse files Browse the repository at this point in the history
  • Loading branch information
justin025 committed Dec 20, 2024
1 parent d60b543 commit 26ba32e
Show file tree
Hide file tree
Showing 13 changed files with 46 additions and 160 deletions.
6 changes: 6 additions & 0 deletions src/onthespot/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ def main():
if isinstance(config.get("file_hertz"), str):
config.set_("file_hertz", int(config.get("file_hertz")))

# Migration (>v1.0.4)
if config.get('theme') == 'dark':
config.set_('theme', f'background-color: #282828; color: white;')
elif config.get('theme') == 'light':
config.set_('theme', f'background-color: white; color: black;')

# Set Application Version
version = "v1.0.4"
logger.info(f'OnTheSpot Version: {version}')
Expand Down
6 changes: 6 additions & 0 deletions src/onthespot/accounts.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from time import sleep
from PyQt6.QtCore import QThread, pyqtSignal
from .api.apple_music import apple_music_login_user, apple_music_get_token
from .api.bandcamp import bandcamp_login_user
Expand Down Expand Up @@ -40,6 +41,7 @@ def run(self):
else:
if self.gui is True:
self.progress.emit(self.tr('Login failed for \n{0}!').format(account['login']['pltvcid']), True)
sleep(0.5)
continue

elif service == 'bandcamp':
Expand All @@ -61,6 +63,7 @@ def run(self):
except Exception as e:
if self.gui is True:
self.progress.emit(self.tr('Login failed for \n{0}...!').format(account['login']['arl'][:30]), True)
sleep(0.5)
continue

elif service == 'soundcloud':
Expand All @@ -75,6 +78,7 @@ def run(self):
else:
if self.gui is True:
self.progress.emit(self.tr('Login failed for \n{0}!').format(account['login']['client_id']), True)
sleep(0.5)
continue

elif service == 'spotify':
Expand All @@ -92,6 +96,7 @@ def run(self):
except Exception as e:
if self.gui is True:
self.progress.emit(self.tr('Login failed for \n{0}!').format(account['login']['username']), True)
sleep(0.5)
continue

elif service == 'tidal':
Expand All @@ -106,6 +111,7 @@ def run(self):
else:
if self.gui is True:
self.progress.emit(self.tr('Login failed for \n{0}!').format(account['login']['username']), True)
sleep(0.5)
continue

elif service == 'youtube':
Expand Down
9 changes: 3 additions & 6 deletions src/onthespot/api/deezer.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ def genurlkey(songid, md5origin, mediaver=4, fmt=1):
def deezer_login_user(account):
uuid = account['uuid']
arl = account['login']['arl']
if uuid == 'public_deezer':
try:

try:
if uuid == 'public_deezer':
# I have no idea why rentry 403s every scraping trick I've tried
ia_url = f"http://archive.org/wayback/available?url=https://rentry.co/firehawk52"
response = requests.get(ia_url)
Expand All @@ -251,11 +252,7 @@ def deezer_login_user(account):
public_arl = re.search(r'<code>(.*?)</code>', row)
public_arls.append(public_arl.group(1))
arl = random.choice(public_arls)
except Exception as e:
logger.error('Failed to fetch firehawk52 shared deezer accounts.')
return False

try:
headers = {
'Origin': 'https://www.deezer.com',
'Accept-Encoding': 'utf-8',
Expand Down
2 changes: 1 addition & 1 deletion src/onthespot/api/soundcloud.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def soundcloud_login_user(account):
logger.error(f"Unknown Exception: {str(e)}")
account_pool.append({
"uuid": "public_soundcloud",
"username": "N/A",
"username": account['login']['client_id'],
"service": "soundcloud",
"status": "error",
"account_type": "N/A",
Expand Down
60 changes: 19 additions & 41 deletions src/onthespot/gui/mainui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from PyQt6 import uic, QtGui
from PyQt6.QtCore import QThread, QDir, Qt, pyqtSignal, QObject, QTimer
from PyQt6.QtGui import QIcon
from PyQt6.QtWidgets import QApplication, QMainWindow, QHeaderView, QLabel, QPushButton, QProgressBar, QTableWidgetItem, QFileDialog, QRadioButton, QHBoxLayout, QWidget
from PyQt6.QtWidgets import QApplication, QMainWindow, QHeaderView, QLabel, QPushButton, QProgressBar, QTableWidgetItem, QFileDialog, QRadioButton, QHBoxLayout, QWidget, QColorDialog
from ..accounts import get_account_token, FillAccountPool
from ..api.apple_music import apple_music_add_account, apple_music_get_track_metadata
from ..api.bandcamp import bandcamp_add_account, bandcamp_get_track_metadata
Expand Down Expand Up @@ -91,6 +91,7 @@ def __init__(self, _dialog, start_url=''):
QApplication.setStyle("fusion")
uic.loadUi(os.path.join(self.path, "qtui", "main.ui"), self)
self.setWindowIcon(self.get_icon('onthespot'))
self.centralwidget.setStyleSheet(config.get('theme'))

self.start_url = start_url
self.inp_version.setText(config.get("version"))
Expand Down Expand Up @@ -126,23 +127,6 @@ def __init__(self, _dialog, start_url=''):
# Bind button click
self.bind_button_inputs()

# Set application theme
self.toggle_theme_button.clicked.connect(self.toggle_theme)
self.theme = config.get("theme")
self.theme_path = os.path.join(config.app_root,'resources', 'themes', f'{self.theme}.qss')
if self.theme == "dark":
self.toggle_theme_button.setText(self.tr(" Light Theme"))
theme_icon = 'light'
elif self.theme == "light":
self.toggle_theme_button.setText(self.tr(" Dark Theme"))
theme_icon = 'dark'
self.toggle_theme_button.setIcon(self.get_icon(theme_icon))

with open(self.theme_path, 'r') as f:
theme = f.read()
self.setStyleSheet(theme)
logger.info(f"Set theme {self.theme}!")

# Set the table header properties
self.set_table_props()
logger.info("Main window init completed !")
Expand All @@ -155,31 +139,23 @@ def get_icon(self, name):
return self.icon_cache[name]


def load_dark_theme(self):
self.theme = "dark"
self.theme_path = os.path.join(config.app_root,'resources', 'themes', f'{self.theme}.qss')
self.toggle_theme_button.setIcon(self.get_icon('light'))
self.toggle_theme_button.setText(self.tr(" Light Theme"))
with open(self.theme_path, 'r') as f:
dark_theme = f.read()
self.setStyleSheet(dark_theme)


def load_light_theme(self):
self.theme = "light"
self.theme_path = os.path.join(config.app_root,'resources', 'themes', f'{self.theme}.qss')
self.toggle_theme_button.setIcon(self.get_icon('dark'))
self.toggle_theme_button.setText(self.tr(" Dark Theme"))
with open(self.theme_path, 'r') as f:
light_theme = f.read()
self.setStyleSheet(light_theme)
def open_theme_dialog(self):
color = QColorDialog().getColor()

if color.isValid():
r, g, b = color.red(), color.green(), color.blue()
luminance = (0.299 * r + 0.587 * g + 0.114 * b)

def toggle_theme(self):
if self.theme == "light":
self.load_dark_theme()
elif self.theme == "dark":
self.load_light_theme()
if luminance < 128:
# Dark color, set light font
stylesheet = f'background-color: {color.name()}; color: white;'
else:
# Light color, set dark font
stylesheet = f'background-color: {color.name()}; color: black;'
config.set_('theme', stylesheet)
config.update()
self.centralwidget.setStyleSheet(stylesheet)
self.__splash_dialog.update_theme(stylesheet)


def bind_button_inputs(self):
Expand All @@ -191,6 +167,8 @@ def bind_button_inputs(self):
self.btn_save_config.clicked.connect(self.update_config)
self.btn_reset_config.clicked.connect(self.reset_app_config)

self.toggle_theme_button.clicked.connect(self.open_theme_dialog)

self.btn_progress_retry_all.clicked.connect(self.retry_all_failed_downloads)
self.btn_progress_cancel_all.clicked.connect(self.cancel_all_downloads)
self.btn_download_root_browse.clicked.connect(self.__select_dir)
Expand Down
18 changes: 6 additions & 12 deletions src/onthespot/gui/minidialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,15 @@ def __init__(self, parent=None):
uic.loadUi(os.path.join(self.path, 'qtui', 'notice.ui'), self)
self.btn_close.clicked.connect(self.hide)
logger.debug('Dialog item is ready..')

# Set theme
self.theme = config.get("theme")
self.theme_path = os.path.join(config.app_root, 'resources', 'themes', f'{self.theme}.qss')
if self.theme == "dark":
with open(self.theme_path, 'r') as f:
dark_theme = f.read()
self.setStyleSheet(dark_theme)
elif self.theme == "light":
with open(self.theme_path, 'r') as f:
light_theme = f.read()
self.setStyleSheet(light_theme)
self.setStyleSheet(config.get('theme'))

self.lb_main.mousePressEvent = self.on_label_click


def update_theme(self, stylesheet):
self.setStyleSheet(stylesheet)


def on_label_click(self, event):
if event.button() == Qt.MouseButton.LeftButton:
match = re.search(r"href='(https?://[^']+)'", self.lb_main.text())
Expand All @@ -45,6 +38,7 @@ def on_label_click(self, event):
# No url in label
pass


def run(self, content, btn_hidden=False):
if btn_hidden:
self.btn_close.hide()
Expand Down
4 changes: 2 additions & 2 deletions src/onthespot/gui/qtui/main.ui
Original file line number Diff line number Diff line change
Expand Up @@ -656,7 +656,7 @@
<property name="geometry">
<rect>
<x>0</x>
<y>-1543</y>
<y>-213</y>
<width>627</width>
<height>3255</height>
</rect>
Expand Down Expand Up @@ -918,7 +918,7 @@
<item>
<widget class="QPushButton" name="toggle_theme_button">
<property name="text">
<string>Dark/Light Theme</string>
<string>Set Theme</string>
</property>
</widget>
</item>
Expand Down
2 changes: 2 additions & 0 deletions src/onthespot/gui/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ def load_config(self):
self.group_download_items.hide()

# Icons
self.toggle_theme_button.setIcon(self.get_icon('light'))

self.inp_language.insertItem(0, self.get_icon('en_US'), "English")
self.inp_language.insertItem(1, self.get_icon('de_DE'), "Deutsch")
self.inp_language.insertItem(2, self.get_icon('pt_PT'), "Português")
Expand Down
2 changes: 1 addition & 1 deletion src/onthespot/otsconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def __init__(self, cfg_path=None):
"download_open_btn": True, # Add open button to downloads
"download_locate_btn": True, # Add locate button to downloads
"download_delete_btn": False, # Add delete button to downloads
"theme": "dark", # Light\Dark
"theme": "background-color: #282828; color: white;", # Custom stylesheet
"accounts": [
{
"uuid": "public_bandcamp",
Expand Down
Binary file removed src/onthespot/resources/icons/dark.png
Binary file not shown.
Empty file.
48 changes: 0 additions & 48 deletions src/onthespot/resources/themes/dark.qss

This file was deleted.

49 changes: 0 additions & 49 deletions src/onthespot/resources/themes/light.qss

This file was deleted.

0 comments on commit 26ba32e

Please sign in to comment.