Skip to content

Commit

Permalink
Add reset GUI state feature. Ref #3549
Browse files Browse the repository at this point in the history
  • Loading branch information
grossmj committed Feb 12, 2024
1 parent 3c8cff2 commit 1441e38
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
22 changes: 20 additions & 2 deletions gns3/main_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ def __init__(self, parent=None, open_file=None):
self._appliance_manager = ApplianceManager().instance()

# restore the geometry and state of the main window.
self._save_gui_state_geometry = True
self.restoreGeometry(QtCore.QByteArray().fromBase64(self._settings["geometry"].encode()))
self.restoreState(QtCore.QByteArray().fromBase64(self._settings["state"].encode()))

Expand Down Expand Up @@ -232,6 +233,7 @@ def _connections(self):
self.uiShowGridAction.triggered.connect(self._showGridActionSlot)
self.uiSnapToGridAction.triggered.connect(self._snapToGridActionSlot)
self.uiLockAllAction.triggered.connect(self._lockActionSlot)
self.uiResetGUIStateAction.triggered.connect(self._resetGUIState)
self.uiResetDocksAction.triggered.connect(self._resetDocksSlot)

# tool menu connections
Expand Down Expand Up @@ -366,6 +368,18 @@ def _lockActionSlot(self):
item.updateNode()
item.update()

def _resetGUIState(self):
"""
Reset the GUI state.
"""

self._save_gui_state_geometry = False
self.close()
if hasattr(sys, "frozen"):
QtCore.QProcess.startDetached(os.path.abspath(sys.executable), sys.argv)
else:
QtWidgets.QMessageBox.information(self, "GUI state","The GUI state has been reset, please restart the application")

def _resetDocksSlot(self):
"""
Reset the dock widgets.
Expand Down Expand Up @@ -1149,8 +1163,12 @@ def _finish_application_closing(self, close_windows=True):

log.debug("_finish_application_closing")

self._settings["geometry"] = bytes(self.saveGeometry().toBase64()).decode()
self._settings["state"] = bytes(self.saveState().toBase64()).decode()
if self._save_gui_state_geometry:
self._settings["geometry"] = bytes(self.saveGeometry().toBase64()).decode()
self._settings["state"] = bytes(self.saveState().toBase64()).decode()
else:
self._settings["geometry"] = ""
self._settings["state"] = ""
self.setSettings(self._settings)

Controller.instance().stopListenNotifications()
Expand Down
6 changes: 6 additions & 0 deletions gns3/ui/main_window.ui
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ background-none;
<addaction name="uiShowPortNamesAction"/>
<addaction name="uiLockAllAction"/>
<addaction name="separator"/>
<addaction name="uiResetGUIStateAction"/>
<addaction name="uiResetDocksAction"/>
<addaction name="uiDocksMenu"/>
</widget>
Expand Down Expand Up @@ -1300,6 +1301,11 @@ background-none;
<string>Reset all console connections</string>
</property>
</action>
<action name="uiResetGUIStateAction">
<property name="text">
<string>Reset GUI state</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>
Expand Down
18 changes: 9 additions & 9 deletions gns3/ui/main_window_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

# Form implementation generated from reading ui file '/home/grossmj/PycharmProjects/gns3-gui/gns3/ui/main_window.ui'
#
# Created by: PyQt5 UI code generator 5.14.1
# Created by: PyQt5 UI code generator 5.15.9
#
# WARNING! All changes made in this file will be lost!
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
# run again. Do not edit this file unless you know what you are doing.


from PyQt5 import QtCore, QtGui, QtWidgets
Expand All @@ -14,7 +15,7 @@ class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.setWindowModality(QtCore.Qt.NonModal)
MainWindow.resize(986, 716)
MainWindow.resize(986, 719)
MainWindow.setContextMenuPolicy(QtCore.Qt.PreventContextMenu)
MainWindow.setStyleSheet("#toolBar_Devices QToolButton {\n"
"width: 50px;\n"
Expand Down Expand Up @@ -450,11 +451,10 @@ def setupUi(self, MainWindow):
self.uiNewTemplateAction.setObjectName("uiNewTemplateAction")
self.uiResetDocksAction = QtWidgets.QAction(MainWindow)
self.uiResetDocksAction.setObjectName("uiResetDocksAction")
self.uiEditReadmeAction = QtWidgets.QAction(MainWindow)
self.uiEditReadmeAction.setIcon(icon31)
self.uiEditReadmeAction.setObjectName("uiEditReadmeAction")
self.uiResetConsoleAllAction = QtWidgets.QAction(MainWindow)
self.uiResetConsoleAllAction.setObjectName("uiResetConsoleAllAction")
self.uiResetGUIStateAction = QtWidgets.QAction(MainWindow)
self.uiResetGUIStateAction.setObjectName("uiResetGUIStateAction")
self.uiEditMenu.addAction(self.uiSelectAllAction)
self.uiEditMenu.addAction(self.uiSelectNoneAction)
self.uiEditMenu.addSeparator()
Expand Down Expand Up @@ -495,6 +495,7 @@ def setupUi(self, MainWindow):
self.uiViewMenu.addAction(self.uiShowPortNamesAction)
self.uiViewMenu.addAction(self.uiLockAllAction)
self.uiViewMenu.addSeparator()
self.uiViewMenu.addAction(self.uiResetGUIStateAction)
self.uiViewMenu.addAction(self.uiResetDocksAction)
self.uiViewMenu.addAction(self.uiDocksMenu.menuAction())
self.uiControlMenu.addAction(self.uiStartAllAction)
Expand Down Expand Up @@ -554,7 +555,7 @@ def setupUi(self, MainWindow):
self.uiAnnotationToolBar.addAction(self.uiScreenshotAction)

self.retranslateUi(MainWindow)
self.uiQuitAction.triggered.connect(MainWindow.close)
self.uiQuitAction.triggered.connect(MainWindow.close) # type: ignore
QtCore.QMetaObject.connectSlotsByName(MainWindow)
MainWindow.setTabOrder(self.uiGraphicsView, self.uiNodesView)
MainWindow.setTabOrder(self.uiNodesView, self.uiConsoleTextEdit)
Expand Down Expand Up @@ -721,9 +722,8 @@ def retranslateUi(self, MainWindow):
self.uiWebUIAction.setText(_translate("MainWindow", "Web UI - beta"))
self.uiNewTemplateAction.setText(_translate("MainWindow", "New template"))
self.uiResetDocksAction.setText(_translate("MainWindow", "Reset docks"))
self.uiEditReadmeAction.setText(_translate("MainWindow", "Edit readme"))
self.uiEditReadmeAction.setToolTip(_translate("MainWindow", "Edit readme"))
self.uiResetConsoleAllAction.setText(_translate("MainWindow", "Reset all console connections"))
self.uiResetGUIStateAction.setText(_translate("MainWindow", "Reset GUI state"))
from ..compute_summary_view import ComputeSummaryView
from ..console_view import ConsoleView
from ..graphics_view import GraphicsView
Expand Down

0 comments on commit 1441e38

Please sign in to comment.