diff --git a/pyface/i_system_metrics.py b/pyface/i_system_metrics.py index c86c28245..42382cbdc 100644 --- a/pyface/i_system_metrics.py +++ b/pyface/i_system_metrics.py @@ -11,7 +11,7 @@ """ The interface to system metrics (screen width and height etc). """ -from traits.api import HasTraits, Int, Interface, Tuple +from traits.api import HasTraits, Int, Interface, List, Tuple class ISystemMetrics(Interface): @@ -19,12 +19,15 @@ class ISystemMetrics(Interface): # 'ISystemMetrics' interface ------------------------------------------- - #: The width of the screen in pixels. + #: The width of the main screen in pixels. screen_width = Int() - #: The height of the screen in pixels. + #: The height of the main screen in pixels. screen_height = Int() + #: The height and width of each screen in pixels + screen_sizes = List(Tuple(Int, Int)) + #: Background color of a standard dialog window as a tuple of RGB values #: between 0.0 and 1.0. # FIXME v3: Why isn't this a traits colour? diff --git a/pyface/tests/test_system_metrics.py b/pyface/tests/test_system_metrics.py index fd95d7a9a..2cdc93be0 100644 --- a/pyface/tests/test_system_metrics.py +++ b/pyface/tests/test_system_metrics.py @@ -26,6 +26,13 @@ def test_height(self): height = self.metrics.screen_height self.assertGreaterEqual(height, 0) + def test_screen_sizes(self): + screens = self.metrics.screen_sizes + self.assertTrue(all( + (isinstance(screen, tuple) and len(screen) == 2) + for screen in screens + )) + def test_background_color(self): color = self.metrics.dialog_background_color self.assertIn(len(color), [3, 4]) diff --git a/pyface/ui/qt/system_metrics.py b/pyface/ui/qt/system_metrics.py index 4f230453a..06ade0135 100644 --- a/pyface/ui/qt/system_metrics.py +++ b/pyface/ui/qt/system_metrics.py @@ -11,14 +11,10 @@ # This software is provided without warranty under the terms of the BSD license. # However, when used with the GPL version of PyQt the additional terms described in the PyQt GPL exception also apply - -from pyface.qt import QtGui, is_qt4 - - -from traits.api import HasTraits, Int, Property, provides, Tuple - +from traits.api import HasTraits, Int, List, Property, provides, Tuple from pyface.i_system_metrics import ISystemMetrics, MSystemMetrics +from pyface.qt import QtGui @provides(ISystemMetrics) @@ -29,10 +25,17 @@ class SystemMetrics(MSystemMetrics, HasTraits): # 'ISystemMetrics' interface ------------------------------------------- + #: The width of the main screen in pixels. screen_width = Property(Int) + #: The height of the main screen in pixels. screen_height = Property(Int) + #: The height and width of each screen in pixels + screen_sizes = Property(List(Tuple(Int, Int))) + + #: Background color of a standard dialog window as a tuple of RGB values + #: between 0.0 and 1.0. dialog_background_color = Property(Tuple) # ------------------------------------------------------------------------ @@ -40,26 +43,28 @@ class SystemMetrics(MSystemMetrics, HasTraits): # ------------------------------------------------------------------------ def _get_screen_width(self): - # QDesktopWidget.screenGeometry() is deprecated and Qt docs - # suggest using screens() instead, but screens in not available in qt - # see issue: enthought/pyface#721 - if not is_qt4: - return QtGui.QApplication.instance().screens()[0].availableGeometry().width() + screens = self.screen_sizes + if len(screens) == 0: + return 0 else: - return QtGui.QApplication.instance().desktop().availableGeometry().width() + return screens[0][0] def _get_screen_height(self): - # QDesktopWidget.screenGeometry(int screen) is deprecated and Qt docs - # suggest using screens() instead, but screens in not available in qt - # see issue: enthought/pyface#721 - if not is_qt4: - return ( - QtGui.QApplication.instance().screens()[0].availableGeometry().height() - ) + screens = self.screen_sizes + if len(screens) == 0: + return 0 else: - return ( - QtGui.QApplication.instance().desktop().availableGeometry().height() + return screens[0][1] + + def _get_screen_sizes(self): + screens = QtGui.QApplication.instance().screens() + return [ + ( + screen.availableGeometry().width(), + screen.availableGeometry().height(), ) + for screen in screens + ] def _get_dialog_background_color(self): color = ( diff --git a/pyface/ui/wx/system_metrics.py b/pyface/ui/wx/system_metrics.py index 16c308f16..78730b445 100644 --- a/pyface/ui/wx/system_metrics.py +++ b/pyface/ui/wx/system_metrics.py @@ -15,12 +15,9 @@ import sys - import wx - -from traits.api import HasTraits, Int, Property, provides, Tuple - +from traits.api import HasTraits, Int, List, Property, provides, Tuple from pyface.i_system_metrics import ISystemMetrics, MSystemMetrics @@ -33,10 +30,17 @@ class SystemMetrics(MSystemMetrics, HasTraits): # 'ISystemMetrics' interface ------------------------------------------- + #: The width of the main screen in pixels. screen_width = Property(Int) + #: The height of the main screen in pixels. screen_height = Property(Int) + #: The height and width of each screen in pixels + screen_sizes = Property(List(Tuple(Int, Int))) + + #: Background color of a standard dialog window as a tuple of RGB values + #: between 0.0 and 1.0. dialog_background_color = Property(Tuple) # ------------------------------------------------------------------------ @@ -49,6 +53,9 @@ def _get_screen_width(self): def _get_screen_height(self): return wx.SystemSettings.GetMetric(wx.SYS_SCREEN_Y) + def _get_screen_sizes(self): + return [(self.screen_width, self.screen_height)] + def _get_dialog_background_color(self): if sys.platform == "darwin": # wx lies.