openlp/openlp/core/ui/screen.py

136 lines
5.0 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2010-12-26 11:04:47 +00:00
# Copyright (c) 2008-2011 Raoul Snyman #
# Portions copyright (c) 2008-2011 Tim Bentley, Jonathan Corwin, Michael #
# Gorven, Scott Guerrieri, Meinert Jordan, Armin Köhler, Andreas Preikschat, #
# Christian Richter, Philip Ridout, Maikel Stuivenberg, Martin Thompson, Jon #
# Tibble, Carsten Tinggaard, Frode Woldsund #
# --------------------------------------------------------------------------- #
# 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; version 2 of the License. #
# #
# 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, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
2010-06-10 21:30:50 +00:00
"""
The :mod:`screen` module provides management functionality for a machines'
2011-02-26 21:43:41 +00:00
displays.
2010-06-10 21:30:50 +00:00
"""
import logging
2010-04-24 19:57:29 +00:00
import copy
2010-02-27 15:31:23 +00:00
log = logging.getLogger(__name__)
2010-01-22 18:59:36 +00:00
class ScreenList(object):
"""
Wrapper to handle the parameters of the display screen
"""
log.info(u'Screen loaded')
def __init__(self):
self.preview = None
self.current = None
2010-04-24 19:57:29 +00:00
self.override = None
self.screen_list = []
2010-04-02 18:12:54 +00:00
self.display_count = 0
2010-08-26 05:01:29 +00:00
# actual display number
self.current_display = 0
2010-08-26 05:01:29 +00:00
# save config display number
2010-04-02 18:12:54 +00:00
self.monitor_number = 0
def add_screen(self, screen):
2010-06-10 21:30:50 +00:00
"""
2011-02-26 21:43:41 +00:00
Add a screen to the list of known screens.
``screen``
A dict with the screen properties::
{
u'primary': True,
u'number': 0,
u'size': PyQt4.QtCore.QRect(0, 0, 1024, 768)
}
2010-06-10 21:30:50 +00:00
"""
2011-02-26 21:43:41 +00:00
print u'add screen: %s' % screen
2010-03-09 19:14:23 +00:00
if screen[u'primary']:
self.current = screen
self.screen_list.append(screen)
2010-04-02 18:12:54 +00:00
self.display_count += 1
2011-02-26 21:43:41 +00:00
def remove_screen(self, number):
"""
Remove a screen from the list of known screens.
``number``
The screen number (int).
"""
print u'remove screen %s' % number
for screen in self.screen_list:
if screen[u'number'] == number:
self.screen_list.remove(screen)
self.display_count -= 1
break
def screen_exists(self, number):
2010-06-10 21:30:50 +00:00
"""
2011-02-26 21:43:41 +00:00
Confirms a screen is known.
``number``
The screen number (int).
2010-06-10 21:30:50 +00:00
"""
for screen in self.screen_list:
if screen[u'number'] == number:
2011-02-26 21:43:41 +00:00
print u'screen %s exists' % number
return True
2011-02-26 21:43:41 +00:00
print u'screen %s does not exist' % number
return False
def set_current_display(self, number):
2010-04-02 18:12:54 +00:00
"""
2011-02-26 21:43:41 +00:00
Set up the current screen dimensions.
``number``
The screen number (int).
2010-04-02 18:12:54 +00:00
"""
2011-02-16 03:28:06 +00:00
log.debug(u'set_current_display %s', number)
2010-04-02 18:12:54 +00:00
if number + 1 > self.display_count:
self.current = self.screen_list[0]
self.override = copy.deepcopy(self.current)
self.current_display = 0
else:
self.current = self.screen_list[number]
2010-04-24 19:57:29 +00:00
self.override = copy.deepcopy(self.current)
self.preview = copy.deepcopy(self.current)
self.current_display = number
2010-04-02 18:12:54 +00:00
if self.display_count == 1:
self.preview = self.screen_list[0]
def set_override_display(self):
"""
2011-02-26 21:43:41 +00:00
Replace the current size with the override values, as the user wants to
have their own screen attributes.
"""
2010-04-24 19:57:29 +00:00
log.debug(u'set_override_display')
self.current = copy.deepcopy(self.override)
self.preview = copy.deepcopy(self.current)
2010-04-24 19:57:29 +00:00
def reset_current_display(self):
"""
2011-02-26 21:43:41 +00:00
Replace the current values with the correct values, as the user wants to
use the correct screen attributes.
"""
2010-04-24 19:57:29 +00:00
log.debug(u'reset_current_display')
2011-02-16 03:28:06 +00:00
self.set_current_display(self.current_display)