Refactor the screen handling code to try and set the screen sizes correctly.

This commit is contained in:
Tim Bentley 2010-01-16 07:22:50 +00:00
parent 85bada91ba
commit 9dc38cf289
11 changed files with 104 additions and 49 deletions

View File

@ -34,7 +34,7 @@ from PyQt4 import QtCore, QtGui
from openlp.core.lib import Receiver, str_to_bool
from openlp.core.resources import qInitResources
from openlp.core.ui import MainWindow, SplashScreen
from openlp.core.ui import MainWindow, SplashScreen, Screen
from openlp.core.utils import ConfigHelper
log = logging.getLogger()
@ -117,10 +117,10 @@ class OpenLP(QtGui.QApplication):
self.splash.show()
# make sure Qt really display the splash screen
self.processEvents()
screens = []
screens = Screen()
# Decide how many screens we have and their size
for screen in xrange(0, self.desktop().numScreens()):
screens.append({u'number': screen,
screens.add_screen({u'number': screen,
u'size': self.desktop().availableGeometry(screen),
u'primary': (self.desktop().primaryScreen() == screen)})
log.info(u'Screen %d found with resolution %s',

View File

@ -39,8 +39,8 @@ class RenderManager(object):
``theme_manager``
The ThemeManager instance, used to get the current theme details.
``screen_list``
The list of screens available.
``screens``
Contains information about the Screens.
``screen_number``
Defaults to *0*. The index of the output/display screen.
@ -49,20 +49,16 @@ class RenderManager(object):
log = logging.getLogger(u'RenderManager')
log.info(u'RenderManager Loaded')
def __init__(self, theme_manager, screen_list, screen_number=0):
def __init__(self, theme_manager, screens, screen_number=0):
"""
Initialise the render manager.
"""
log.debug(u'Initilisation started')
self.screen_list = screen_list
self.screens = screens
self.theme_manager = theme_manager
self.displays = len(screen_list)
if (screen_number + 1) > len(screen_list):
self.current_display = 0
else:
self.current_display = screen_number
self.renderer = Renderer()
self.calculate_default(self.screen_list[self.current_display][u'size'])
self.screens.set_current_display(screen_number)
self.calculate_default(self.screens.current[u'size'])
self.theme = u''
self.service_theme = u''
self.theme_level = u''
@ -79,10 +75,7 @@ class RenderManager(object):
The updated index of the output/display screen.
"""
log.debug(u'Update Display')
if self.current_display != screen_number:
self.current_display = screen_number
self.calculate_default(
self.screen_list[self.current_display][u'size'])
self.calculate_default(self.screens.current[u'size'])
self.renderer.bg_frame = None
def set_global_theme(self, global_theme, theme_level=ThemeLevel.Global):
@ -138,8 +131,7 @@ class RenderManager(object):
if self.theme != self.renderer.theme_name or self.themedata is None:
log.debug(u'theme is now %s', self.theme)
self.themedata = self.theme_manager.getThemeData(self.theme)
self.calculate_default(
self.screen_list[self.current_display][u'size'])
self.calculate_default(self.screens.current[u'size'])
self.renderer.set_theme(self.themedata)
self.build_text_rectangle(self.themedata)
#Replace the background image from renderer with one from image
@ -195,12 +187,12 @@ class RenderManager(object):
"""
log.debug(u'generate preview')
#set the default image size for previews
self.calculate_default(QtCore.QSize(1024, 768))
self.calculate_default(self.screens.preview[u'size'])
self.renderer.set_theme(themedata)
self.build_text_rectangle(themedata)
self.renderer.set_frame_dest(self.width, self.height, True)
#Reset the real screen size for subsequent render requests
self.calculate_default(self.screen_list[self.current_display][u'size'])
self.calculate_default(self.screens.current[u'size'])
verse = u'Amazing Grace!\n'\
'How sweet the sound\n'\
'To save a wretch like me;\n'\

View File

@ -33,7 +33,7 @@ class SettingsManager(object):
individual components.
"""
def __init__(self, screen):
self.screen = screen[0]
self.screen = screen.current
self.width = self.screen[u'size'].width()
self.height = self.screen[u'size'].height()
self.mainwindow_height = self.height * 0.8

View File

@ -23,7 +23,7 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
#from slidecontroller import MasterToolbar
from screen import Screen
from maindisplay import MainDisplay
from amendthemeform import AmendThemeForm
from slidecontroller import SlideController

View File

@ -183,7 +183,7 @@ class GeneralTab(SettingsTab):
self.Password = self.PasswordEdit.displayText()
def load(self):
for screen in self.screen_list:
for screen in self.screen_list.screen_list:
screen_name = u'%s %d' % (self.trUtf8('Screen'), screen[u'number'] + 1)
if screen[u'primary']:
screen_name = u'%s (%s)' % (screen_name, self.trUtf8('primary'))

View File

@ -135,15 +135,7 @@ class MainDisplay(DisplayWidget):
log.debug(u'Setup %s for %s ' %(self.screens, screenNumber))
print "all the screen ", self.screens
self.setVisible(False)
self.screen = self.screens[screenNumber]
if self.screen[u'number'] != screenNumber:
# We will most probably never actually hit this bit, but just in
# case the index in the list doesn't match the screen number, we
# search for it.
for scrn in self.screens:
if scrn[u'number'] == screenNumber:
self.screen = scrn
break
self.screen = self.screens.current
#Sort out screen locations and sizes
print "--------- Set screen geom ------------"
print "display ", self.screen[u'size']

View File

@ -425,7 +425,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
plugins.
"""
QtGui.QMainWindow.__init__(self)
self.screenList = screens
self.screens = screens
self.applicationVersion = applicationVersion
self.serviceNotSaved = False
self.settingsmanager = SettingsManager(screens)
@ -433,7 +433,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.mainDisplay = MainDisplay(self, screens)
self.alertForm = AlertForm(self)
self.aboutForm = AboutForm(self, applicationVersion)
self.settingsForm = SettingsForm(self.screenList, self, self)
self.settingsForm = SettingsForm(self.screens, self, self)
# Set up the path with plugins
pluginpath = os.path.split(os.path.abspath(__file__))[0]
pluginpath = os.path.abspath(
@ -500,7 +500,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
#RenderManager needs to call ThemeManager and
#ThemeManager needs to call RenderManager
self.RenderManager = RenderManager(self.ThemeManagerContents,
self.screenList, self.getMonitorNumber())
self.screens, self.getMonitorNumber())
#Define the media Dock Manager
self.mediaDockManager = MediaDockManager(self.MediaToolBox)
log.info(u'Load Plugins')
@ -558,11 +558,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
monitor number does not exist.
"""
screen_number = int(self.generalConfig.get_config(u'monitor', 0))
monitor_exists = False
for screen in self.screenList:
if screen[u'number'] == screen_number:
monitor_exists = True
if not monitor_exists:
if not self.screens.screen_exists(screen_number):
screen_number = 0
return screen_number
@ -613,8 +609,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
"""
self.settingsForm.exec_()
updated_display = self.getMonitorNumber()
if updated_display != self.RenderManager.current_display:
if updated_display != self.screens.current_display:
print "main display screen changed to ", updated_display
self.screens.set_current_display(updated_display)
self.RenderManager.update_display(updated_display)
self.mainDisplay.setup(updated_display)
self.activateWindow()

74
openlp/core/ui/screen.py Normal file
View File

@ -0,0 +1,74 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=80 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2010 Raoul Snyman #
# Portions copyright (c) 2008-2010 Tim Bentley, Jonathan Corwin, Michael #
# Gorven, Scott Guerrieri, Maikel Stuivenberg, Martin Thompson, Jon Tibble, #
# Carsten Tinggaard #
# --------------------------------------------------------------------------- #
# 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 #
###############################################################################
import logging
class Screen(object):
"""
Wrapper to handle the parameters of the display screen
"""
global log
log = logging.getLogger(u'Screen')
log.info(u'Screen loaded')
def __init__(self):
self.preview = None
self.current = None
self.screen_list = []
self.count = 0
self.current_display = 0
def add_screen(self, screen):
if screen[u'primary'] == True:
self.current = screen
self.screen_list.append(screen)
self.count += 1
print self.screen_list
def screen_exists(self, number):
for screen in self.screen_list:
if screen[u'number'] == number:
return True
return False
def set_current_display(self, number):
if number + 1 > self.count:
self.current = self.screen_list[0]
self.current_display = 0
else:
self.current = self.screen_list[number]
self.preview = self.current
self.current_display = number
if self.count == 1:
self.preview = self.screen_list[0]
# if self.screen[u'number'] != screenNumber:
# # We will most probably never actually hit this bit, but just in
# # case the index in the list doesn't match the screen number, we
# # search for it.
# for scrn in self.screens:
# if scrn[u'number'] == screenNumber:
# self.screen = scrn
# break

View File

@ -538,7 +538,7 @@ class SlideController(QtGui.QWidget):
def updatePreview(self):
rm = self.parent.RenderManager
if not rm.screen_list[rm.current_display][u'primary']:
if not rm.screens.current[u'primary']:
# Grab now, but try again in a couple of seconds if slide change is slow
QtCore.QTimer.singleShot(0.5, self.grabMainDisplay)
QtCore.QTimer.singleShot(2.5, self.grabMainDisplay)

View File

@ -145,7 +145,7 @@ class ImpressController(PresentationController):
log.exception(u'Failed to load presentation')
return
self.presentation = self.document.getPresentation()
self.presentation.Display = self.plugin.render_manager.current_display + 1
self.presentation.Display = self.plugin.render_manager.screens.current_display + 1
self.controller = None
self.create_thumbnails()

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 KiB