Repository: spyder-ide/spyder

Issue:
Popup "A monitor scale change was detected" every few minutes
## Problem Description

<img width="419" alt="2020-03-18 2 09 05" src="https://user-images.githubusercontent.com/5638823/76931614-090ff000-6924-11ea-9fc2-1fe1c18634c8.png">

After upgrading Spyder to 4.1.0 through conda, Spyder will show a popup stating that a monitor scale change was detected every few minutes. 

In the popup, there is a recommendation "**Enable auto high DPI scaling**" in Spyder preference will be helpful.

However, even if I enable that, and restart my Spyder, the popup still appears every few minutes.

~~**Actually, I have a workaround to this issue, which is **disabling** the _Automatic Graphics Switching_ in  _System Preference_ -> _Energy Saver_ .**~~
I thought it helps, but still the popup keeps appearing.




## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->


* Spyder version: 4.1.0
* Python version: 3.7.6 64-bit
* Qt version: 5.9.6
* PyQt version: 5.9.2
* Operating System name/version: Darwin 19.3.0

I am using MacBook Pro 2018 with Catalina, and with no external display.


Discussion:
I have such a problem too. Moreover, the windows appears is I make a click anywhere outside spyder, on the other desktop or another monitor. 
Darwin 16.7.0 

Are you changing monitors constantly? Or moving Spyder among monitors?
> Are you changing monitors constantly? Or moving Spyder among monitors?

No, I don’t have external display.
I will try with external monitor to see if issue persist.
@dalthviz, I don't understand why this happens but I think we have two options here:

1. See if there's a better way to detect a screen resolution change using Qt.
2. If not, we need to offer the possibility of not showing this message during the entire session.
Hi, same problem here.
I don't have a second monitor but it happend when I'm in full screen with spyder and I switch space on my mac for working on another app.
@fixablecar, @SergeiDBykov, @Colin-Gnt, are all of you using macOS?
I am.
I can reproduce it by having a spyder in fullscreen mode 
> @fixablecar, @SergeiDBykov, @Colin-Gnt, are all of you using macOS?

Yes, MacOS 10.12
> @fixablecar, @SergeiDBykov, @Colin-Gnt, are all of you using macOS?

yes, as stated, Macbook Pro 2018 with macOS Catalina.
Same problem for me. It occurs in fullscreen mode, when we switch the desktops.

<img src=https://user-images.githubusercontent.com/483114/77090949-2e762a00-6a08-11ea-8741-0c04236bb67a.png width="33%" />

I was obliged to downgrade to 4.0.1:
```
The following packages will be DOWNGRADED:

  spyder                                       4.1.0-py37_0 --> 4.0.1-py37_0
  spyder-kernels                               1.9.0-py37_0 --> 1.8.1-py37_0


Proceed ([y]/n)? 

Preparing transaction: done
Verifying transaction: done
Executing transaction: done
```

I encountered the same problem. Tried everything and it seems for me that the only cure is to downgrade Spyder.
ya, it is very annoying. 

solution: quit fullscreen mode, then no more popups. 

Resolving patch:
diff --git a/spyder/app/mainwindow.py b/spyder/app/mainwindow.py
--- a/spyder/app/mainwindow.py
+++ b/spyder/app/mainwindow.py
@@ -75,7 +75,7 @@
 from qtpy.QtGui import QColor, QDesktopServices, QIcon, QKeySequence, QPixmap
 from qtpy.QtWidgets import (QAction, QApplication, QDesktopWidget, QDockWidget,
                             QMainWindow, QMenu, QMessageBox, QShortcut,
-                            QSplashScreen, QStyleFactory, QWidget)
+                            QSplashScreen, QStyleFactory, QWidget, QCheckBox)
 
 # Avoid a "Cannot mix incompatible Qt library" error on Windows platforms
 from qtpy import QtSvg  # analysis:ignore
@@ -490,6 +490,9 @@ def signal_handler(signum, frame=None):
         self.last_focused_widget = None
         self.previous_focused_widget = None
 
+        # Keep track of dpi message
+        self.show_dpi_message = True
+
         # Server to open external files on a single instance
         # This is needed in order to handle socket creation problems.
         # See spyder-ide/spyder#4132.
@@ -1378,11 +1381,16 @@ def post_visible_setup(self):
         self.is_setting_up = False
 
         # Handle DPI scale and window changes to show a restart message
-        window = self.window().windowHandle()
-        window.screenChanged.connect(self.handle_new_screen)
-        self.screen = self.window().windowHandle().screen()
-        self.screen.logicalDotsPerInchChanged.connect(
-            self.show_dpi_change_message)
+        # Handle DPI scale and window changes to show a restart message.
+        # Don't activate this functionality on macOS because it's being
+        # triggered in the wrong situations.
+        # See spyder-ide/spyder#11846
+        if not sys.platform == 'darwin':
+            window = self.window().windowHandle()
+            window.screenChanged.connect(self.handle_new_screen)
+            self.screen = self.window().windowHandle().screen()
+            self.screen.logicalDotsPerInchChanged.connect(
+                self.show_dpi_change_message)
 
         # Notify that the setup of the mainwindow was finished
         self.sig_setup_finished.emit()
@@ -1399,18 +1407,40 @@ def show_dpi_change_message(self):
         """Show message to restart Spyder since the DPI scale changed."""
         self.screen.logicalDotsPerInchChanged.disconnect(
             self.show_dpi_change_message)
-        answer = QMessageBox.warning(
-            self, _("Warning"),
+
+        if not self.show_dpi_message:
+            return
+
+        # Check the window state to not show the message if the window
+        # is in fullscreen mode.
+        window = self.window().windowHandle()
+        if (window.windowState() == Qt.WindowFullScreen and
+                sys.platform == 'darwin'):
+            return
+
+        dismiss_box = QCheckBox(
+            _("Hide this message during the current session")
+        )
+
+        msgbox = QMessageBox(self)
+        msgbox.setIcon(QMessageBox.Warning)
+        msgbox.setText(
             _("A monitor scale change was detected. <br><br>"
               "We recommend restarting Spyder to ensure that it's properly "
               "displayed. If you don't want to do that, please be sure to "
               "activate the option<br><br><tt>Enable auto high DPI scaling"
               "</tt><br><br>in <tt>Preferences > General > Interface</tt>, "
               "in case Spyder is not displayed correctly.<br><br>"
-              "Do you want to restart Spyder?"),
-            QMessageBox.Yes | QMessageBox.No)
+              "Do you want to restart Spyder?"))
+        yes_button = msgbox.addButton(QMessageBox.Yes)
+        msgbox.addButton(QMessageBox.No)
+        msgbox.setCheckBox(dismiss_box)
+        msgbox.exec_()
 
-        if answer == QMessageBox.Yes:
+        if dismiss_box.isChecked():
+            self.show_dpi_message = False
+
+        if msgbox.clickedButton() == yes_button:
             # Activate HDPI auto-scaling option since is needed for a proper
             # display when using OS scaling
             CONF.set('main', 'normal_screen_resolution', False)


Test patch: