After choosing the tab type, the title of the tab changes

This commit is contained in:
Micah Lee 2019-10-27 14:35:11 -07:00
parent 4b4020c629
commit fd2046b976
No known key found for this signature in database
GPG Key ID: 403C2657CD994F73
2 changed files with 26 additions and 4 deletions

View File

@ -38,11 +38,14 @@ 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=None): change_title = QtCore.pyqtSignal(int, str)
def __init__(self, common, tab_id, 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__")
self.tab_id = tab_id
self.system_tray = system_tray self.system_tray = system_tray
self.status_bar = status_bar self.status_bar = status_bar
self.filenames = filenames self.filenames = filenames
@ -173,6 +176,8 @@ class Tab(QtWidgets.QWidget):
self.share_mode.server_status.hidservauth_copied.connect(self.copy_hidservauth) self.share_mode.server_status.hidservauth_copied.connect(self.copy_hidservauth)
self.share_mode.set_server_active.connect(self.set_server_active) self.share_mode.set_server_active.connect(self.set_server_active)
self.change_title.emit(self.tab_id, strings._("gui_new_tab_share_button"))
self.update_server_status_indicator() self.update_server_status_indicator()
self.timer.start(500) self.timer.start(500)
@ -216,6 +221,8 @@ class Tab(QtWidgets.QWidget):
) )
self.receive_mode.set_server_active.connect(self.set_server_active) self.receive_mode.set_server_active.connect(self.set_server_active)
self.change_title.emit(self.tab_id, strings._("gui_new_tab_receive_button"))
self.update_server_status_indicator() self.update_server_status_indicator()
self.timer.start(500) self.timer.start(500)
@ -258,6 +265,8 @@ class Tab(QtWidgets.QWidget):
) )
self.website_mode.set_server_active.connect(self.set_server_active) self.website_mode.set_server_active.connect(self.set_server_active)
self.change_title.emit(self.tab_id, strings._("gui_new_tab_website_button"))
self.update_server_status_indicator() self.update_server_status_indicator()
self.timer.start(500) self.timer.start(500)

View File

@ -37,7 +37,11 @@ class TabWidget(QtWidgets.QTabWidget):
self.system_tray = system_tray self.system_tray = system_tray
self.status_bar = status_bar self.status_bar = status_bar
# Definte the new tab button # Keep track of tabs in a dictionary
self.tabs = {}
self.tab_id = 0 # each tab has a unique id
# Define the new tab button
self.new_tab_button = QtWidgets.QPushButton("+", parent=self) self.new_tab_button = QtWidgets.QPushButton("+", parent=self)
self.new_tab_button.setFlat(True) self.new_tab_button.setFlat(True)
self.new_tab_button.setAutoFillBackground(True) self.new_tab_button.setAutoFillBackground(True)
@ -83,11 +87,20 @@ class TabWidget(QtWidgets.QTabWidget):
self.move_new_tab_button() self.move_new_tab_button()
def new_tab_clicked(self): def new_tab_clicked(self):
# Add a new tab # Create the tab
tab = Tab(self.common, self.system_tray, self.status_bar) tab = Tab(self.common, self.tab_id, self.system_tray, self.status_bar)
tab.change_title.connect(self.change_title)
self.tabs[self.tab_id] = tab
self.tab_id += 1
# Add it
index = self.addTab(tab, "New Tab") index = self.addTab(tab, "New Tab")
self.setCurrentIndex(index) self.setCurrentIndex(index)
def change_title(self, tab_id, title):
index = self.indexOf(self.tabs[tab_id])
self.setTabText(index, title)
class TabBar(QtWidgets.QTabBar): class TabBar(QtWidgets.QTabBar):
""" """