Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix screen sizes #1237

Merged
merged 3 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions pyface/i_system_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@
""" 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):
""" The interface to system metrics (screen width and height etc). """

# '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?
Expand Down
7 changes: 7 additions & 0 deletions pyface/tests/test_system_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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])
Expand Down
47 changes: 26 additions & 21 deletions pyface/ui/qt/system_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -29,37 +25,46 @@ 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)

# ------------------------------------------------------------------------
# Private interface.
# ------------------------------------------------------------------------

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 = (
Expand Down
15 changes: 11 additions & 4 deletions pyface/ui/wx/system_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)

# ------------------------------------------------------------------------
Expand All @@ -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.
Expand Down