mirror of
https://github.com/onionshare/onionshare.git
synced 2025-05-10 10:25:03 -04:00
Make new tab button login in the QTabWidget instead of QTabBar
This commit is contained in:
parent
509516c46a
commit
985b2c4719
4 changed files with 109 additions and 25 deletions
|
@ -50,13 +50,8 @@ class GuiCommon:
|
||||||
|
|
||||||
self.css = {
|
self.css = {
|
||||||
# OnionShareGui styles
|
# OnionShareGui styles
|
||||||
"tab_bar_new_tab": """
|
|
||||||
QTabBar::tab:last {
|
|
||||||
border: 0;
|
|
||||||
margin: 3px;
|
|
||||||
}""",
|
|
||||||
"tab_bar_new_tab_button": """
|
"tab_bar_new_tab_button": """
|
||||||
QToolButton {
|
QPushButton {
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
}""",
|
}""",
|
||||||
|
|
|
@ -26,7 +26,7 @@ from .tor_connection_dialog import TorConnectionDialog
|
||||||
from .settings_dialog import SettingsDialog
|
from .settings_dialog import SettingsDialog
|
||||||
from .widgets import Alert
|
from .widgets import Alert
|
||||||
from .update_checker import UpdateThread
|
from .update_checker import UpdateThread
|
||||||
from .tab import Tab
|
from .tab_widget import TabWidget
|
||||||
|
|
||||||
|
|
||||||
class MainWindow(QtWidgets.QMainWindow):
|
class MainWindow(QtWidgets.QMainWindow):
|
||||||
|
@ -96,25 +96,12 @@ class MainWindow(QtWidgets.QMainWindow):
|
||||||
self.status_bar.addPermanentWidget(self.status_bar.server_status_indicator)
|
self.status_bar.addPermanentWidget(self.status_bar.server_status_indicator)
|
||||||
|
|
||||||
# Tabs
|
# Tabs
|
||||||
self.tabs = QtWidgets.QTabWidget()
|
self.tabs = TabWidget(self.common, self.system_tray, self.status_bar)
|
||||||
self.tabs.setStyleSheet(self.common.gui.css["tab_bar_new_tab"])
|
|
||||||
self.tabs.setMovable(True)
|
|
||||||
self.tabs.setTabsClosable(True)
|
|
||||||
self.tabs.setUsesScrollButtons(True)
|
|
||||||
|
|
||||||
# New tab button
|
|
||||||
new_tab_button = QtWidgets.QToolButton()
|
|
||||||
new_tab_button.setStyleSheet(self.common.gui.css["tab_bar_new_tab_button"])
|
|
||||||
new_tab_button.setText("+")
|
|
||||||
new_tab_button.setAutoRaise(True)
|
|
||||||
self.tabs.insertTab(0, QtWidgets.QWidget(), "")
|
|
||||||
self.tabs.tabBar().setTabButton(0, QtWidgets.QTabBar.RightSide, new_tab_button)
|
|
||||||
self.tabs.tabBar().setTabToolTip(0, strings._("gui_new_tab_tooltip"))
|
|
||||||
|
|
||||||
# Start with a tab
|
# Start with a tab
|
||||||
new_tab = Tab(self.common, self.system_tray, self.status_bar, filenames)
|
# new_tab = Tab(self.common, self.system_tray, self.status_bar, filenames)
|
||||||
self.tabs.insertTab(0, new_tab, strings._("gui_new_tab"))
|
# self.tabs.insertTab(0, new_tab, strings._("gui_new_tab"))
|
||||||
self.tabs.setCurrentIndex(0)
|
# self.tabs.setCurrentIndex(0)
|
||||||
|
|
||||||
# Layout
|
# Layout
|
||||||
layout = QtWidgets.QVBoxLayout()
|
layout = QtWidgets.QVBoxLayout()
|
||||||
|
|
|
@ -38,7 +38,7 @@ class Tab(QtWidgets.QWidget):
|
||||||
A GUI tab, you know, sort of like in a web browser
|
A GUI tab, you know, sort of like in a web browser
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, common, system_tray, status_bar, filenames):
|
def __init__(self, common, system_tray, status_bar, filenames=None):
|
||||||
super(Tab, self).__init__()
|
super(Tab, self).__init__()
|
||||||
self.common = common
|
self.common = common
|
||||||
self.common.log("Tab", "__init__")
|
self.common.log("Tab", "__init__")
|
||||||
|
|
102
onionshare_gui/tab_widget.py
Normal file
102
onionshare_gui/tab_widget.py
Normal file
|
@ -0,0 +1,102 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
"""
|
||||||
|
OnionShare | https://onionshare.org/
|
||||||
|
|
||||||
|
Copyright (C) 2014-2018 Micah Lee <micah@micahflee.com>
|
||||||
|
|
||||||
|
This program is free software: you can redistribute it and/or modify
|
||||||
|
it under the terms of the GNU General Public License as published by
|
||||||
|
the Free Software Foundation, either version 3 of the License, or
|
||||||
|
(at your option) any later version.
|
||||||
|
|
||||||
|
This program is distributed in the hope that it will be useful,
|
||||||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
GNU General Public License for more details.
|
||||||
|
|
||||||
|
You should have received a copy of the GNU General Public License
|
||||||
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
"""
|
||||||
|
from PyQt5 import QtCore, QtWidgets, QtGui
|
||||||
|
|
||||||
|
from onionshare import strings
|
||||||
|
|
||||||
|
from .tab import Tab
|
||||||
|
|
||||||
|
|
||||||
|
class TabWidget(QtWidgets.QTabWidget):
|
||||||
|
"""
|
||||||
|
A custom tab widget, that has a "+" button for adding new tabs
|
||||||
|
"""
|
||||||
|
|
||||||
|
def __init__(self, common, system_tray, status_bar):
|
||||||
|
super(TabWidget, self).__init__()
|
||||||
|
self.common = common
|
||||||
|
self.common.log("TabWidget", "__init__")
|
||||||
|
|
||||||
|
self.system_tray = system_tray
|
||||||
|
self.status_bar = status_bar
|
||||||
|
|
||||||
|
# Definte 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.clicked.connect(self.new_tab_clicked)
|
||||||
|
self.new_tab_button.setStyleSheet(self.common.gui.css["tab_bar_new_tab_button"])
|
||||||
|
self.new_tab_button.setToolTip(strings._("gui_new_tab_tooltip"))
|
||||||
|
|
||||||
|
# Use a custom tab bar
|
||||||
|
tab_bar = TabBar()
|
||||||
|
tab_bar.move_new_tab_button.connect(self.move_new_tab_button)
|
||||||
|
self.setTabBar(tab_bar)
|
||||||
|
|
||||||
|
# Set up the tab widget
|
||||||
|
self.setMovable(True)
|
||||||
|
self.setTabsClosable(True)
|
||||||
|
self.setUsesScrollButtons(True)
|
||||||
|
|
||||||
|
self.move_new_tab_button()
|
||||||
|
|
||||||
|
def move_new_tab_button(self):
|
||||||
|
# Find the width of all tabs
|
||||||
|
tabs_width = sum(
|
||||||
|
[self.tabBar().tabRect(i).width() for i in range(self.count())]
|
||||||
|
)
|
||||||
|
|
||||||
|
# The current positoin of the new tab button
|
||||||
|
pos = self.new_tab_button.pos()
|
||||||
|
|
||||||
|
# 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)
|
||||||
|
else:
|
||||||
|
# Otherwise move the button to the right of the tabs
|
||||||
|
pos.setX(self.tabBar().sizeHint().width())
|
||||||
|
|
||||||
|
self.new_tab_button.move(pos)
|
||||||
|
self.new_tab_button.raise_()
|
||||||
|
|
||||||
|
def resizeEvent(self, event):
|
||||||
|
# Make sure to move new tab button on each resize
|
||||||
|
super(TabWidget, self).resizeEvent(event)
|
||||||
|
self.move_new_tab_button()
|
||||||
|
|
||||||
|
def new_tab_clicked(self):
|
||||||
|
# Add a new tab
|
||||||
|
tab = Tab(self.common, self.system_tray, self.status_bar)
|
||||||
|
self.addTab(tab, "New Tab")
|
||||||
|
|
||||||
|
|
||||||
|
class TabBar(QtWidgets.QTabBar):
|
||||||
|
"""
|
||||||
|
A custom tab bar
|
||||||
|
"""
|
||||||
|
|
||||||
|
move_new_tab_button = QtCore.pyqtSignal()
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
super(TabBar, self).__init__()
|
||||||
|
|
||||||
|
def tabLayoutChange(self):
|
||||||
|
self.move_new_tab_button.emit()
|
Loading…
Add table
Add a link
Reference in a new issue