Images refresh when added via settings, Fixes:#2423

This commit is contained in:
ziajka
2018-02-27 16:07:06 +01:00
parent 5ebb3011d3
commit a559bd4ae4
2 changed files with 63 additions and 0 deletions

View File

@@ -54,6 +54,7 @@ from .dialogs.new_appliance_dialog import NewApplianceDialog
from .dialogs.notif_dialog import NotifDialog, NotifDialogHandler
from .status_bar import StatusBarHandler
from .registry.appliance import ApplianceError
from .appliance_manager import ApplianceManager
log = logging.getLogger(__name__)
@@ -69,6 +70,9 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
# signal to tell the view if the user is adding a link or not
adding_link_signal = QtCore.pyqtSignal(bool)
# Signal of settings updates
settings_updated_signal = QtCore.Signal()
def __init__(self, parent=None, open_file=None):
"""
:param open_file: Open this file instead of asking for a new project
@@ -110,6 +114,7 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self._local_config_timer.timeout.connect(local_config.checkConfigChanged)
self._local_config_timer.start(1000) # milliseconds
self._analytics_client = AnalyticsClient()
self._appliance_manager = ApplianceManager()
# restore the geometry and state of the main window.
self.restoreGeometry(QtCore.QByteArray().fromBase64(self._settings["geometry"].encode()))
@@ -190,6 +195,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
# load initial stuff once the event loop isn't busy
self.run_later(0, self.startupLoading)
self.settings_updated_signal.connect(self.settingsChangedSlot)
def _connections(self):
"""
Connect widgets to slots
@@ -303,6 +310,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self._settings.update(new_settings)
# save the settings
LocalConfig.instance().saveSectionSettings(self.__class__.__name__, self._settings)
print("called")
self.settings_updated_signal.emit()
def _openWebInterfaceActionSlot(self):
if Controller.instance().connected():
@@ -491,6 +500,17 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow):
self._project_dialog = None
self._refreshVisibleWidgets()
@qslot
def settingsChangedSlot(self, *args):
"""
Called when settings are updated
"""
# It covers case when project is not set
# and we need to refresh appliance manager
project = Topology.instance().project()
if project is None:
self._appliance_manager.instance().refresh()
def _refreshVisibleWidgets(self):
"""
Refresh widgets that should be visible or not

43
tests/test_main_window.py Normal file
View File

@@ -0,0 +1,43 @@
# -*- coding: utf-8 -*-
#
# Copyright (C) 2018 GNS3 Technologies Inc.
#
# 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/>.
import pytest
from unittest.mock import MagicMock
@pytest.fixture
def real_main_window():
from gns3.main_window import MainWindow
return MainWindow()
def test_main_window_settings_changed_signal(real_main_window):
settings = real_main_window.settings()
signal = MagicMock()
real_main_window.settings_updated_signal = signal
real_main_window.setSettings(settings)
assert signal.emit.called
def test_main_window_settings_changed_slot(real_main_window):
instance = MagicMock()
manager = MagicMock()
manager.instance.return_value = instance
real_main_window._appliance_manager = manager
real_main_window.settingsChangedSlot()
assert instance.refresh.called