Merge pull request #1268 from SaptakS/macos-dark

MacOS dark mode implementations
This commit is contained in:
Micah Lee 2021-02-01 20:33:31 -08:00 committed by GitHub
commit acceed9782
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
41 changed files with 96 additions and 33 deletions

View File

@ -27,7 +27,7 @@ import signal
import json
import psutil
import getpass
from PySide2 import QtCore, QtWidgets
from PySide2 import QtCore, QtWidgets, QtGui
from onionshare_cli.common import Common
@ -46,6 +46,9 @@ class Application(QtWidgets.QApplication):
if common.platform == "Linux" or common.platform == "BSD":
self.setAttribute(QtCore.Qt.AA_X11InitThreads, True)
QtWidgets.QApplication.__init__(self, sys.argv)
# Check color mode on starting the app
self.color_mode = self.get_color_mode()
self.installEventFilter(self)
def eventFilter(self, obj, event):
@ -57,6 +60,15 @@ class Application(QtWidgets.QApplication):
self.quit()
return False
def is_dark_mode(self):
baseColor = QtGui.QPalette().color(QtGui.QPalette.Base)
if baseColor.name().lower() == "#ffffff":
return False
return True
def get_color_mode(self):
return "dark" if self.is_dark_mode() else "light"
def main():
"""

View File

@ -78,7 +78,19 @@ class GuiCommon:
os.makedirs(self.events_dir, 0o700, True)
self.events_filename = os.path.join(self.events_dir, "events")
self.css = {
self.css = self.get_css(qtapp.color_mode)
self.color_mode = qtapp.color_mode
def get_css(self, color_mode):
header_color = "#4E064F" # purple in light
title_color = "#333333" # dark gray color in main window
stop_button_color = "#d0011b" # red button color for stopping server
if color_mode == "dark":
header_color = "#F2F2F2"
title_color = "#F2F2F2"
stop_button_color = "#C32F2F"
return {
# OnionShareGui styles
"tab_widget": """
QTabBar::tab { width: 170px; height: 30px; }
@ -96,7 +108,9 @@ class GuiCommon:
}""",
"mode_header_label": """
QLabel {
color: #4E064F;
color: """
+ header_color
+ """;
font-size: 48px;
margin-bottom: 16px;
}""",
@ -143,15 +157,8 @@ class GuiCommon:
""",
"server_status_url_buttons": """
QPushButton {
border: 1px solid #d3d3d3;
border-radius: 4px;
background-color: #ffffff;
padding: 8px 16px;
padding: 4px 8px;
text-align: center;
color: #4e0d4e;
}
QPushButton:pressed {
background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:0, y2:1, stop:0 rgba(255, 255, 255, 255), stop:1 rgba(239, 239, 240, 255))
}
""",
"server_status_button_stopped": """
@ -173,7 +180,9 @@ class GuiCommon:
}""",
"server_status_button_started": """
QPushButton {
background-color: #d0011b;
background-color: """
+ stop_button_color
+ """;
color: #ffffff;
padding: 10px 30px 10px 30px;
border: 0;
@ -218,14 +227,18 @@ class GuiCommon:
}""",
"downloads_uploads_progress_bar": """
QProgressBar {
border: 1px solid #4e064f;
border: 1px solid """
+ header_color
+ """;
background-color: #ffffff !important;
text-align: center;
color: #9b9b9b;
font-size: 14px;
}
QProgressBar::chunk {
background-color: #4e064f;
background-color: """
+ header_color
+ """;
width: 10px;
}""",
"history_individual_file_timestamp_label": """
@ -259,7 +272,9 @@ class GuiCommon:
"new_tab_title_text": """
QLabel {
text-align: center;
color: #333333;
color: """
+ title_color
+ """;
font-size: 25px;
}
""",
@ -271,26 +286,34 @@ class GuiCommon:
""",
"share_zip_progess_bar": """
QProgressBar {
border: 1px solid #4e064f;
border: 1px solid """
+ header_color
+ """;
background-color: #ffffff !important;
text-align: center;
color: #9b9b9b;
}
QProgressBar::chunk {
border: 0px;
background-color: #4e064f;
background-color: """
+ header_color
+ """;
width: 10px;
}""",
"share_filesize_warning": """
QLabel {
padding: 10px 0;
font-weight: bold;
color: #333333;
color: """
+ title_color
+ """;
}
""",
"share_file_selection_drop_here_header_label": """
QLabel {
color: #4E064F;
color: """
+ header_color
+ """;
font-size: 48px;
}""",
"share_file_selection_drop_here_label": """

View File

@ -113,7 +113,11 @@ class MainWindow(QtWidgets.QMainWindow):
self.settings_button.setDefault(False)
self.settings_button.setFixedSize(40, 50)
self.settings_button.setIcon(
QtGui.QIcon(GuiCommon.get_resource_path("images/settings.png"))
QtGui.QIcon(
GuiCommon.get_resource_path(
"images/{}_settings.png".format(self.common.gui.color_mode)
)
)
)
self.settings_button.clicked.connect(self.open_settings)
self.settings_button.setStyleSheet(self.common.gui.css["settings_button"])
@ -285,6 +289,20 @@ class MainWindow(QtWidgets.QMainWindow):
self.system_tray.hide()
e.accept()
def event(self, event):
# Check if color mode switched while onionshare was open, if so, ask user to restart
if event.type() == QtCore.QEvent.Type.ApplicationPaletteChange:
QtCore.QTimer.singleShot(1, self.color_mode_warning)
return True
return QtWidgets.QMainWindow.event(self, event)
def color_mode_warning(self):
"""
Open the color mode warning alert.
"""
notice = strings._("gui_color_mode_changed_notice")
Alert(self.common, notice, QtWidgets.QMessageBox.Information)
def cleanup(self):
self.common.log("MainWindow", "cleanup")
self.tabs.cleanup()

Binary file not shown.

After

Width:  |  Height:  |  Size: 203 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 305 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.0 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 456 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 23 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.4 KiB

View File

Before

Width:  |  Height:  |  Size: 1.1 KiB

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 27 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 5.1 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 6.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.8 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 36 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.3 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 7.9 KiB

View File

@ -111,6 +111,7 @@
"gui_open_folder_error": "Failed to open folder with xdg-open. The file is here: {}",
"gui_settings_language_label": "Preferred language",
"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",
"systray_page_loaded_title": "Page Loaded",
"systray_page_loaded_message": "OnionShare address loaded",

View File

@ -53,7 +53,11 @@ class ChatMode(Mode):
self.image_label = QtWidgets.QLabel()
self.image_label.setPixmap(
QtGui.QPixmap.fromImage(
QtGui.QImage(GuiCommon.get_resource_path("images/mode_chat.png"))
QtGui.QImage(
GuiCommon.get_resource_path(
"images/{}_mode_chat.png".format(self.common.gui.color_mode)
)
)
)
)
self.image_label.setFixedSize(300, 300)

View File

@ -46,7 +46,11 @@ class ReceiveMode(Mode):
self.image_label = QtWidgets.QLabel()
self.image_label.setPixmap(
QtGui.QPixmap.fromImage(
QtGui.QImage(GuiCommon.get_resource_path("images/mode_receive.png"))
QtGui.QImage(
GuiCommon.get_resource_path(
"images/{}_mode_receive.png".format(self.common.gui.color_mode)
)
)
)
)
self.image_label.setFixedSize(250, 250)

View File

@ -69,7 +69,7 @@ class ShareMode(Mode):
# File selection
self.file_selection = FileSelection(
self.common,
"images/mode_share.png",
"images/{}_mode_share.png".format(self.common.gui.color_mode),
strings._("gui_new_tab_share_button"),
self,
)

View File

@ -69,7 +69,7 @@ class WebsiteMode(Mode):
# File selection
self.file_selection = FileSelection(
self.common,
"images/mode_website.png",
"images/{}_mode_website.png".format(self.common.gui.color_mode),
strings._("gui_new_tab_website_button"),
self,
)

View File

@ -93,7 +93,6 @@ class ServerStatus(QtWidgets.QWidget):
)
self.copy_url_button = QtWidgets.QPushButton(strings._("gui_copy_url"))
self.copy_url_button.setFlat(True)
self.copy_url_button.setStyleSheet(
self.common.gui.css["server_status_url_buttons"]
)
@ -108,12 +107,10 @@ class ServerStatus(QtWidgets.QWidget):
self.show_url_qr_code_button.clicked.connect(
self.show_url_qr_code_button_clicked
)
self.show_url_qr_code_button.setFlat(True)
self.show_url_qr_code_button.setStyleSheet(
self.common.gui.css["server_status_url_buttons"]
)
self.copy_hidservauth_button.setFlat(True)
self.copy_hidservauth_button.setStyleSheet(
self.common.gui.css["server_status_url_buttons"]
)

View File

@ -121,10 +121,14 @@ class Tab(QtWidgets.QWidget):
self.image_label = QtWidgets.QLabel()
self.image_label.setPixmap(
QtGui.QPixmap.fromImage(
QtGui.QImage(GuiCommon.get_resource_path("images/logo_text.png"))
QtGui.QImage(
GuiCommon.get_resource_path(
"images/{}_logo_text.png".format(self.common.gui.color_mode)
)
)
)
)
self.image_label.setFixedSize(160, 40)
self.image_label.setFixedSize(180, 40)
image_layout = QtWidgets.QVBoxLayout()
image_layout.addWidget(self.image_label)
image_layout.addStretch()
@ -134,7 +138,7 @@ class Tab(QtWidgets.QWidget):
# New tab buttons
self.share_button = NewTabButton(
self.common,
"images/mode_new_tab_share.png",
"images/{}_mode_new_tab_share.png".format(self.common.gui.color_mode),
strings._("gui_new_tab_share_button"),
strings._("gui_main_page_share_button"),
)
@ -142,7 +146,7 @@ class Tab(QtWidgets.QWidget):
self.receive_button = NewTabButton(
self.common,
"images/mode_new_tab_receive.png",
"images/{}_mode_new_tab_receive.png".format(self.common.gui.color_mode),
strings._("gui_new_tab_receive_button"),
strings._("gui_main_page_receive_button"),
)
@ -150,7 +154,7 @@ class Tab(QtWidgets.QWidget):
self.website_button = NewTabButton(
self.common,
"images/mode_new_tab_website.png",
"images/{}_mode_new_tab_website.png".format(self.common.gui.color_mode),
strings._("gui_new_tab_website_button"),
strings._("gui_main_page_website_button"),
)
@ -158,7 +162,7 @@ class Tab(QtWidgets.QWidget):
self.chat_button = NewTabButton(
self.common,
"images/mode_new_tab_chat.png",
"images/{}_mode_new_tab_chat.png".format(self.common.gui.color_mode),
strings._("gui_new_tab_chat_button"),
strings._("gui_main_page_chat_button"),
)