Added user theme preference option in Settings

Added an option to choose theme in settings dialog like auto, light and dark.
Fixed Dark Mode Dark Text.
This commit is contained in:
SIDDHANT DIXIT 2021-07-19 18:27:02 +05:30
parent 76e7880702
commit 3cbe55916b
5 changed files with 45 additions and 4 deletions

View file

@ -110,6 +110,7 @@ class Settings(object):
"tor_bridges_use_custom_bridges": "",
"persistent_tabs": [],
"locale": None, # this gets defined in fill_in_defaults()
"theme": 0
}
self._settings = {}
self.fill_in_defaults()

View file

@ -29,6 +29,7 @@ import getpass
from PySide2 import QtCore, QtWidgets, QtGui
from onionshare_cli.common import Common
from onionshare_cli.settings import Settings
from .gui_common import GuiCommon
from .widgets import Alert
@ -47,7 +48,8 @@ class Application(QtWidgets.QApplication):
QtWidgets.QApplication.__init__(self, sys.argv)
# Check color mode on starting the app
self.color_mode = self.get_color_mode()
# self.color_mode = self.get_color_mode()
self.color_mode = self.get_color_mode(common)
self.installEventFilter(self)
def eventFilter(self, obj, event):
@ -65,9 +67,20 @@ class Application(QtWidgets.QApplication):
return False
return True
def get_color_mode(self):
return "dark" if self.is_dark_mode() else "light"
def get_color_mode(self, common):
# return "dark" if self.is_dark_mode() else "light"
curr_settings = Settings(common)
curr_settings.load()
current_theme = curr_settings.get("theme")
if current_theme == 0:
return "dark" if self.is_dark_mode() else "light"
elif current_theme == 1:
return "light"
elif current_theme == 2:
return "dark"
else:
return "light"
def main():
"""

View file

@ -89,7 +89,7 @@ class GuiCommon:
new_tab_button_text_color = "#4e0d4e"
if color_mode == "dark":
header_color = "#F2F2F2"
title_color = "#F2F2F2"
# title_color = "#F2F2F2"
stop_button_color = "#C32F2F"
new_tab_button_background = "#5F5F5F"
new_tab_button_border = "#878787"

View file

@ -115,6 +115,10 @@
"gui_receive_mode_warning": "Receive mode lets people upload files to your computer.<br><br><b>Some files can potentially take control of your computer if you open them. Only open things from people you trust, or if you know what you are doing.</b>",
"gui_open_folder_error": "Failed to open folder with xdg-open. The file is here: {}",
"gui_settings_language_label": "Preferred language",
"gui_settings_theme_label": "Theme",
"gui_settings_theme_auto": "Auto",
"gui_settings_theme_light": "Light",
"gui_settings_theme_dark": "Dark",
"gui_settings_language_changed_notice": "Restart OnionShare for the new language to be applied.",
"gui_color_mode_changed_notice": "Restart OnionShare for the new color mode to be applied.",
"systray_menu_exit": "Quit",

View file

@ -123,6 +123,20 @@ class SettingsDialog(QtWidgets.QDialog):
language_layout.addWidget(self.language_combobox)
language_layout.addStretch()
#Theme Settings
theme_label = QtWidgets.QLabel(strings._("gui_settings_theme_label"))
self.theme_combobox = QtWidgets.QComboBox()
theme_choices = [
strings._("gui_settings_theme_auto"),
strings._("gui_settings_theme_light"),
strings._("gui_settings_theme_dark")
]
self.theme_combobox.addItems(theme_choices)
theme_layout = QtWidgets.QHBoxLayout()
theme_layout.addWidget(theme_label)
theme_layout.addWidget(self.theme_combobox)
theme_layout.addStretch()
# Connection type: either automatic, control port, or socket file
# Bundled Tor
@ -451,6 +465,8 @@ class SettingsDialog(QtWidgets.QDialog):
layout.addSpacing(20)
layout.addLayout(language_layout)
layout.addSpacing(20)
layout.addLayout(theme_layout)
layout.addSpacing(20)
layout.addStretch()
layout.addLayout(buttons_layout)
@ -477,6 +493,9 @@ class SettingsDialog(QtWidgets.QDialog):
locale_index = self.language_combobox.findData(locale)
self.language_combobox.setCurrentIndex(locale_index)
theme_choice = self.old_settings.get("theme")
self.theme_combobox.setCurrentIndex(theme_choice)
connection_type = self.old_settings.get("connection_type")
if connection_type == "bundled":
if self.connection_type_bundled_radio.isEnabled():
@ -931,6 +950,10 @@ class SettingsDialog(QtWidgets.QDialog):
settings = Settings(self.common)
settings.load() # To get the last update timestamp
# Theme
theme_index = self.theme_combobox.currentIndex()
settings.set("theme",theme_index)
# Language
locale_index = self.language_combobox.currentIndex()
locale = self.language_combobox.itemData(locale_index)