Evolife
Evolife has been developed to study Genetic algorithms, Natural evolution and behavioural ecology.
Screen.py
Go to the documentation of this file.
1#!/usr/bin/env python3
2""" @brief Physical display (Screen and monitors). """
3
4#============================================================================#
5# EVOLIFE http://evolife.telecom-paris.fr Jean-Louis Dessalles #
6# Telecom Paris 2022-04-11 www.dessalles.fr #
7# -------------------------------------------------------------------------- #
8# License: Creative Commons BY-NC-SA #
9#============================================================================#
10# Documentation: https://evolife.telecom-paris.fr/Classes #
11#============================================================================#
12
13
15
16try: from PyQt5 import QtWidgets
17except ImportError: # compatibility with PyQt4
18 from PyQt4 import QtGui as QtWidgets
19
20class Screen_:
21 """ Stores characteristics of physical display
22 """
23
24 def __init__(self, MainApp):
25 """ Stores available physical screens
26 """
27 self.width = 1920 # will be changed
28 self.height = 1080 # will be changed
29 self.ratio = 1 # comparison with default screen
30 screen_rect = MainApp.desktop().screenGeometry()
31 self.ratio = screen_rect.width() / self.width
32 self.width, self.height = screen_rect.width(), screen_rect.height()
33 self.displays = []
34 for Disp in range(0,8):
35 D = QtWidgets.QDesktopWidget().screenGeometry(Disp)
36 if D: self.displays.append(D)
37 else: break
39 # print(self.displays)
40
41 def resize(self, *Coord):
42 """ applies screen's display ratio to coordinates
43 """
44 return list(map(lambda x: int(x * self.ratio), Coord))
45
46 def locate(self, *Coord):
47 """ calls 'resize' (for high definition screen and optional screen change)
48 """
49 return self.changeScreen(list(self.resize(*Coord)))
50
51 def switchScreen(self):
52 """ Chave the value of 'currentScreen'
53 """
54 self.currentScreen = len(self.displays) - self.currentScreen - 1
55
56 def changeScreen(self, Coord):
57 """ translates coordinates to display on current screen
58 """
59 # print('Change coordinates:', Coord, end=' ')
60 Coord = [Coord[0] + self.displays[self.currentScreen].left(),
61 Coord[1] + self.displays[self.currentScreen].top()] \
62 + Coord[2:]
63 # print('to ', Coord)
64 return Coord
65
66__author__ = 'Dessalles'
Stores characteristics of physical display.
Definition: Screen.py:20
def switchScreen(self)
Chave the value of 'currentScreen'.
Definition: Screen.py:51
def changeScreen(self, Coord)
translates coordinates to display on current screen
Definition: Screen.py:56
def resize(self, *Coord)
applies screen's display ratio to coordinates
Definition: Screen.py:41
def __init__(self, MainApp)
Stores available physical screens.
Definition: Screen.py:24
def locate(self, *Coord)
calls 'resize' (for high definition screen and optional screen change)
Definition: Screen.py:46