From 970a2577926c651a5fb4c97ba6092496a7d912ef Mon Sep 17 00:00:00 2001 From: Micah Lee Date: Thu, 20 Aug 2020 21:23:05 -0700 Subject: [PATCH] Make macOS tabs left-aligned, and manually add close button --- onionshare_gui/gui_common.py | 3 +++ onionshare_gui/tab/tab.py | 8 ++++---- onionshare_gui/tab_widget.py | 20 +++++++++++++++++--- share/images/close_tab.png | Bin 0 -> 688 bytes share/locale/en.json | 4 ++++ 5 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 share/images/close_tab.png diff --git a/onionshare_gui/gui_common.py b/onionshare_gui/gui_common.py index 59316a6e..f6d3eedf 100644 --- a/onionshare_gui/gui_common.py +++ b/onionshare_gui/gui_common.py @@ -61,6 +61,9 @@ class GuiCommon: self.css = { # OnionShareGui styles + "tab_widget": """ + QTabBar::tab { width: 170px; height: 30px; } + """, "tab_widget_new_tab_button": """ QPushButton { font-weight: bold; diff --git a/onionshare_gui/tab/tab.py b/onionshare_gui/tab/tab.py index 604d1acf..fbc828ff 100644 --- a/onionshare_gui/tab/tab.py +++ b/onionshare_gui/tab/tab.py @@ -228,7 +228,7 @@ class Tab(QtWidgets.QWidget): self.share_mode.server_status.url_copied.connect(self.copy_url) self.share_mode.server_status.hidservauth_copied.connect(self.copy_hidservauth) - self.change_title.emit(self.tab_id, strings._("gui_new_tab_share_button")) + self.change_title.emit(self.tab_id, strings._("gui_tab_name_share")) self.update_server_status_indicator() self.timer.start(500) @@ -265,7 +265,7 @@ class Tab(QtWidgets.QWidget): self.copy_hidservauth ) - self.change_title.emit(self.tab_id, strings._("gui_new_tab_receive_button")) + self.change_title.emit(self.tab_id, strings._("gui_tab_name_receive")) self.update_server_status_indicator() self.timer.start(500) @@ -302,7 +302,7 @@ class Tab(QtWidgets.QWidget): self.copy_hidservauth ) - self.change_title.emit(self.tab_id, strings._("gui_new_tab_website_button")) + self.change_title.emit(self.tab_id, strings._("gui_tab_name_website")) self.update_server_status_indicator() self.timer.start(500) @@ -335,7 +335,7 @@ class Tab(QtWidgets.QWidget): self.chat_mode.server_status.url_copied.connect(self.copy_url) self.chat_mode.server_status.hidservauth_copied.connect(self.copy_hidservauth) - self.change_title.emit(self.tab_id, strings._("gui_new_tab_chat_button")) + self.change_title.emit(self.tab_id, strings._("gui_tab_name_chat")) self.update_server_status_indicator() self.timer.start(500) diff --git a/onionshare_gui/tab_widget.py b/onionshare_gui/tab_widget.py index 1ef82cad..1eee0181 100644 --- a/onionshare_gui/tab_widget.py +++ b/onionshare_gui/tab_widget.py @@ -48,8 +48,7 @@ class TabWidget(QtWidgets.QTabWidget): # Define the new tab button self.new_tab_button = QtWidgets.QPushButton("+", parent=self) self.new_tab_button.setFlat(True) - self.new_tab_button.setAutoFillBackground(True) - self.new_tab_button.setFixedSize(30, 30) + self.new_tab_button.setFixedSize(40, 30) self.new_tab_button.clicked.connect(self.new_tab_clicked) self.new_tab_button.setStyleSheet( self.common.gui.css["tab_widget_new_tab_button"] @@ -66,6 +65,8 @@ class TabWidget(QtWidgets.QTabWidget): self.setMovable(True) self.setTabsClosable(True) self.setUsesScrollButtons(True) + self.setDocumentMode(True) + self.setStyleSheet(self.common.gui.css["tab_widget"]) self.tabCloseRequested.connect(self.close_tab) @@ -99,7 +100,7 @@ class TabWidget(QtWidgets.QTabWidget): # If there are so many tabs it scrolls, move the button to the left of the scroll buttons if tabs_width > self.width(): - pos.setX(self.width() - 61) + pos.setX(self.width() - 65) else: # Otherwise move the button to the right of the tabs pos.setX(self.tabBar().sizeHint().width()) @@ -152,6 +153,19 @@ class TabWidget(QtWidgets.QTabWidget): index = self.addTab(tab, strings._("gui_new_tab")) self.setCurrentIndex(index) + # Create a close button + def close_tab(): + self.tabBar().tabCloseRequested.emit(self.indexOf(tab)) + + close_button = QtWidgets.QPushButton() + close_button.setFlat(True) + close_button.setFixedWidth(40) + close_button.setIcon( + QtGui.QIcon(self.common.get_resource_path("images/close_tab.png")) + ) + close_button.clicked.connect(close_tab) + self.tabBar().setTabButton(index, QtWidgets.QTabBar.RightSide, close_button) + tab.init(mode_settings) # If it's persistent, set the persistent image in the tab self.change_persistent(tab.tab_id, tab.settings.get("persistent", "enabled")) diff --git a/share/images/close_tab.png b/share/images/close_tab.png new file mode 100644 index 0000000000000000000000000000000000000000..a7984a6d5f62671a8622df4802e2aa0efdb2f860 GIT binary patch literal 688 zcmV;h0#E&kP)EX>4Tx04R}tkv&MmKpe$iTct%R4ptCx$WWauh)U_GRVYG*P%E_RU~=gfG-*gu zTpR`0f`cE6RRL(Ac45VOnpui)9@T$_we!cF2=LG&;2?2m4e9tpFljzbi*RvAdYWZ zI_G`j2rEkp@j3B?K^G)`x1k-{RDAVPqQIx48bLX1|86cZWRPkQ)A9KT2|nOqex zax9<*6_Voz|AXJ%n#JiUHz}M1dS7h&V+;uH0jVfq16NwdUuy!1PtqG5 zEqVkDYy%h99ZlW?E_Z<8CtWfmM+(sN7mL9A8GTb87`z4g*4*CO`#607veZ@j1~@nb z#!HmF?(yzWcW?imY4`U7%&&6GnQcfO00006VoOIv0QUg*0Q;GgYt zE+K~?5h;=B!}h`cg@8zC!&T&vQjqve4l&4l!JKwSPrEZ3$I<*NOWL+=djJ@QVJ+z! zSOI7O0%Y4wM4W6NuMqQ)fok3>NjuvtJb)aw-+}YOtV+msQ%%$KQ`hycq*oxgSGL{s zeg72z5n-O|0-%)ATN%8(D(NF0K