mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-23 05:01:24 -05:00
Fix mixup with tab_ids and their indicies, so tabs open and close smoothly
This commit is contained in:
parent
3b9cc80160
commit
556aedf08d
@ -37,7 +37,7 @@ class SettingsTab(QtWidgets.QWidget):
|
||||
Settings dialog.
|
||||
"""
|
||||
|
||||
settings_saved = QtCore.Signal()
|
||||
close_this_tab = QtCore.Signal()
|
||||
|
||||
def __init__(self, common, tab_id):
|
||||
super(SettingsTab, self).__init__()
|
||||
@ -94,6 +94,7 @@ class SettingsTab(QtWidgets.QWidget):
|
||||
locale = language_names_to_locales[language_name]
|
||||
self.language_combobox.addItem(language_name, locale)
|
||||
language_layout = QtWidgets.QHBoxLayout()
|
||||
language_layout.addStretch()
|
||||
language_layout.addWidget(language_label)
|
||||
language_layout.addWidget(self.language_combobox)
|
||||
language_layout.addStretch()
|
||||
@ -108,6 +109,7 @@ class SettingsTab(QtWidgets.QWidget):
|
||||
]
|
||||
self.theme_combobox.addItems(theme_choices)
|
||||
theme_layout = QtWidgets.QHBoxLayout()
|
||||
theme_layout.addStretch()
|
||||
theme_layout.addWidget(theme_label)
|
||||
theme_layout.addWidget(self.theme_combobox)
|
||||
theme_layout.addStretch()
|
||||
@ -116,7 +118,9 @@ class SettingsTab(QtWidgets.QWidget):
|
||||
version_label = QtWidgets.QLabel(
|
||||
strings._("gui_settings_version_label").format(self.common.version)
|
||||
)
|
||||
version_label.setAlignment(QtCore.Qt.AlignHCenter)
|
||||
help_label = QtWidgets.QLabel(strings._("gui_settings_help_label"))
|
||||
help_label.setAlignment(QtCore.Qt.AlignHCenter)
|
||||
help_label.setTextInteractionFlags(QtCore.Qt.TextBrowserInteraction)
|
||||
help_label.setOpenExternalLinks(True)
|
||||
|
||||
@ -126,6 +130,7 @@ class SettingsTab(QtWidgets.QWidget):
|
||||
buttons_layout = QtWidgets.QHBoxLayout()
|
||||
buttons_layout.addStretch()
|
||||
buttons_layout.addWidget(self.save_button)
|
||||
buttons_layout.addStretch()
|
||||
|
||||
# Layout
|
||||
layout = QtWidgets.QVBoxLayout()
|
||||
@ -270,8 +275,7 @@ class SettingsTab(QtWidgets.QWidget):
|
||||
|
||||
# Save the new settings
|
||||
settings.save()
|
||||
self.settings_saved.emit()
|
||||
self.close()
|
||||
self.close_this_tab.emit()
|
||||
|
||||
def help_clicked(self):
|
||||
"""
|
||||
|
@ -186,12 +186,13 @@ class TabWidget(QtWidgets.QTabWidget):
|
||||
self.common.log("TabWidget", "open_settings_tab")
|
||||
|
||||
# See if a settings tab is already open, and if so switch to it
|
||||
for index in range(self.count()):
|
||||
if type(self.tabs[index]) is SettingsTab:
|
||||
self.setCurrentIndex(index)
|
||||
for tab_id in self.tabs:
|
||||
if type(self.tabs[tab_id]) is SettingsTab:
|
||||
self.setCurrentIndex(self.indexOf(self.tabs[tab_id]))
|
||||
return
|
||||
|
||||
settings_tab = SettingsTab(self.common, self.current_tab_id)
|
||||
settings_tab.close_this_tab.connect(self.close_settings_tab)
|
||||
self.tabs[self.current_tab_id] = settings_tab
|
||||
self.current_tab_id += 1
|
||||
index = self.addTab(settings_tab, strings._("gui_settings_window_title"))
|
||||
@ -205,12 +206,13 @@ class TabWidget(QtWidgets.QTabWidget):
|
||||
self.common.log("TabWidget", "open_tor_settings_tab")
|
||||
|
||||
# See if a settings tab is already open, and if so switch to it
|
||||
for index in range(self.count()):
|
||||
if type(self.tabs[index]) is TorSettingsTab:
|
||||
self.setCurrentIndex(index)
|
||||
for tab_id in self.tabs:
|
||||
if type(self.tabs[tab_id]) is TorSettingsTab:
|
||||
self.setCurrentIndex(self.indexOf(self.tabs[tab_id]))
|
||||
return
|
||||
|
||||
tor_settings_tab = TorSettingsTab(self.common, self.current_tab_id)
|
||||
tor_settings_tab.close_this_tab.connect(self.close_tor_settings_tab)
|
||||
self.tabs[self.current_tab_id] = tor_settings_tab
|
||||
self.current_tab_id += 1
|
||||
index = self.addTab(
|
||||
@ -297,6 +299,22 @@ class TabWidget(QtWidgets.QTabWidget):
|
||||
if self.count() == 0:
|
||||
self.new_tab_clicked()
|
||||
|
||||
def close_settings_tab(self):
|
||||
self.common.log("TabWidget", "close_settings_tab")
|
||||
for tab_id in self.tabs:
|
||||
if type(self.tabs[tab_id]) is SettingsTab:
|
||||
index = self.indexOf(self.tabs[tab_id])
|
||||
self.close_tab(index)
|
||||
return
|
||||
|
||||
def close_tor_settings_tab(self):
|
||||
self.common.log("TabWidget", "close_tor_settings_tab")
|
||||
for tab_id in self.tabs:
|
||||
if type(self.tabs[tab_id]) is TorSettingsTab:
|
||||
index = self.indexOf(self.tabs[tab_id])
|
||||
self.close_tab(index)
|
||||
return
|
||||
|
||||
def are_tabs_active(self):
|
||||
"""
|
||||
See if there are active servers in any open tabs
|
||||
|
@ -39,7 +39,7 @@ class TorSettingsTab(QtWidgets.QWidget):
|
||||
Settings dialog.
|
||||
"""
|
||||
|
||||
settings_saved = QtCore.Signal()
|
||||
close_this_tab = QtCore.Signal()
|
||||
|
||||
def __init__(self, common, tab_id):
|
||||
super(TorSettingsTab, self).__init__()
|
||||
@ -339,7 +339,6 @@ class TorSettingsTab(QtWidgets.QWidget):
|
||||
|
||||
# Layout
|
||||
layout = QtWidgets.QVBoxLayout()
|
||||
layout.addStretch()
|
||||
layout.addLayout(columns_layout)
|
||||
layout.addWidget(self.tor_con)
|
||||
layout.addStretch()
|
||||
@ -582,6 +581,7 @@ class TorSettingsTab(QtWidgets.QWidget):
|
||||
return
|
||||
|
||||
self.test_tor_button.hide()
|
||||
self.save_button.hide()
|
||||
|
||||
onion = Onion(
|
||||
self.common,
|
||||
@ -616,6 +616,7 @@ class TorSettingsTab(QtWidgets.QWidget):
|
||||
"""
|
||||
self.tor_con.hide()
|
||||
self.test_tor_button.show()
|
||||
self.save_button.show()
|
||||
|
||||
def save_clicked(self):
|
||||
"""
|
||||
@ -696,15 +697,12 @@ class TorSettingsTab(QtWidgets.QWidget):
|
||||
self.common.gui.onion.is_authenticated()
|
||||
and not tor_con.wasCanceled()
|
||||
):
|
||||
self.settings_saved.emit()
|
||||
self.close()
|
||||
self.close_this_tab.emit()
|
||||
|
||||
else:
|
||||
self.settings_saved.emit()
|
||||
self.close()
|
||||
self.close_this_tab.emit()
|
||||
else:
|
||||
self.settings_saved.emit()
|
||||
self.close()
|
||||
self.close_this_tab.emit()
|
||||
|
||||
def close_tab(self):
|
||||
"""
|
||||
|
Loading…
Reference in New Issue
Block a user