diff options
Diffstat (limited to 'desktop/onionshare/gui_common.py')
-rw-r--r-- | desktop/onionshare/gui_common.py | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/desktop/onionshare/gui_common.py b/desktop/onionshare/gui_common.py index cda40c1e..c717fd22 100644 --- a/desktop/onionshare/gui_common.py +++ b/desktop/onionshare/gui_common.py @@ -21,6 +21,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. import os import shutil from pkg_resources import resource_filename +from PySide2 import QtCore, QtWidgets, QtGui from . import strings from onionshare_cli.onion import ( @@ -39,6 +40,7 @@ from onionshare_cli.onion import ( TorTooOldStealth, PortNotAvailable, ) +from onionshare_cli.meek import Meek class GuiCommon: @@ -77,6 +79,9 @@ class GuiCommon: os.makedirs(self.events_dir, 0o700, True) self.events_filename = os.path.join(self.events_dir, "events") + # Instantiate Meek, which is used to bypass censorship + self.meek = Meek(self.common, get_tor_paths=self.get_tor_paths) + self.css = self.get_css(qtapp.color_mode) self.color_mode = qtapp.color_mode @@ -116,6 +121,15 @@ class GuiCommon: font-weight: bold; font-size: 20px; }""", + "settings_subtab_bar": """ + QTabBar::tab { + background: transparent; + } + QTabBar::tab:selected { + border-bottom: 3px solid; + border-color: #4E064F; + padding: 3px + }""", "mode_new_tab_button": """ QPushButton { font-weight: bold; @@ -149,6 +163,52 @@ class GuiCommon: QStatusBar::item { border: 0px; }""", + "autoconnect_start_button": """ + QPushButton { + background-color: #5fa416; + color: #ffffff; + padding: 10px; + border: 0; + border-radius: 5px; + }""", + "autoconnect_configure_button": """ + QPushButton { + padding: 9px 29px; + color: #3f7fcf; + text-align: left; + }""", + "enable_autoconnect": """ + QCheckBox { + margin-top: 30px; + background: #FCFCFC; + color: #000000; + border: 1px solid #DDDBDA; + border-radius: 8px; + padding: 24px 16px; + } + QCheckBox::indicator { + width: 0; + height: 0; + }""", + "autoconnect_countries_combobox": """ + QComboBox { + padding: 10px; + font-size: 16px; + } + QComboBox:disabled { + color: #666666; + } + """, + "autoconnect_task_label": """ + QLabel { + font-weight: bold; + } + """, + "autoconnect_failed_to_connect_label": """ + QLabel { + font-size: 18px; + font-weight: bold; + }""", # Common styles between modes and their child widgets "mode_settings_toggle_advanced": """ QPushButton { @@ -508,3 +568,50 @@ class GuiCommon: elif type(e) is PortNotAvailable: return strings._("error_port_not_available") return None + + +class ToggleCheckbox(QtWidgets.QCheckBox): + def __init__(self, text): + super(ToggleCheckbox, self).__init__(text) + # Set default parameters + self.setCursor(QtCore.Qt.PointingHandCursor) + self.w = 50 + self.h = 24 + self.bg_color = "#D4D4D4" + self.circle_color = "#BDBDBD" + self.active_color = "#4E0D4E" + self.inactive_color = "" + + def hitButton(self, pos): + return self.toggleRect.contains(pos) + + def paintEvent(self, e): + painter = QtGui.QPainter(self) + painter.setRenderHint(QtGui.QPainter.Antialiasing) + painter.setPen(QtCore.Qt.NoPen) + opt = QtWidgets.QStyleOptionButton() + opt.init(self) + self.initStyleOption(opt) + s = self.style() + s.drawControl(QtWidgets.QStyle.CE_CheckBox, opt, painter, self) + + rect = QtCore.QRect( + s.subElementRect(QtWidgets.QStyle.SE_CheckBoxContents, opt, self) + ) + x = ( + rect.width() - rect.x() - self.w + 20 + ) # 20 is the padding between text and toggle + y = self.height() / 2 - self.h / 2 + 16 # 16 is the padding top for the checkbox + self.toggleRect = QtCore.QRect(x, y, self.w, self.h) + painter.setBrush(QtGui.QColor(self.bg_color)) + painter.drawRoundedRect(x, y, self.w, self.h, self.h / 2, self.h / 2) + if not self.isChecked(): + painter.setBrush(QtGui.QColor(self.circle_color)) + painter.drawEllipse(x, y - 3, self.h + 6, self.h + 6) + else: + painter.setBrush(QtGui.QColor(self.active_color)) + painter.drawEllipse( + x + self.w - (self.h + 6), y - 3, self.h + 6, self.h + 6 + ) + + painter.end() |