forked from openlp/openlp
moved code to ScreenList class
This commit is contained in:
parent
c7644bf8d9
commit
89c988b728
46
openlp.pyw
46
openlp.pyw
@ -24,7 +24,6 @@
|
|||||||
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
import copy
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
@ -166,10 +165,6 @@ class OpenLP(QtGui.QApplication):
|
|||||||
QtCore.SIGNAL(u'cursor_busy'), self.setBusyCursor)
|
QtCore.SIGNAL(u'cursor_busy'), self.setBusyCursor)
|
||||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||||
QtCore.SIGNAL(u'cursor_normal'), self.setNormalCursor)
|
QtCore.SIGNAL(u'cursor_normal'), self.setNormalCursor)
|
||||||
QtCore.QObject.connect(self.desktop(),
|
|
||||||
QtCore.SIGNAL(u'screenCountChanged(int)'), self.updateScreenList)
|
|
||||||
QtCore.QObject.connect(self.desktop(),
|
|
||||||
QtCore.SIGNAL(u'resized(int)'), self.updateScreenList)
|
|
||||||
self.setOrganizationName(u'OpenLP')
|
self.setOrganizationName(u'OpenLP')
|
||||||
self.setOrganizationDomain(u'openlp.org')
|
self.setOrganizationDomain(u'openlp.org')
|
||||||
self.setApplicationName(u'OpenLP')
|
self.setApplicationName(u'OpenLP')
|
||||||
@ -183,13 +178,11 @@ class OpenLP(QtGui.QApplication):
|
|||||||
self.splash.show()
|
self.splash.show()
|
||||||
# make sure Qt really display the splash screen
|
# make sure Qt really display the splash screen
|
||||||
self.processEvents()
|
self.processEvents()
|
||||||
self.screens = ScreenList()
|
|
||||||
# Decide how many screens we have and their size
|
# Decide how many screens we have and their size
|
||||||
self.updateScreenList()
|
screens = ScreenList(self, self.desktop())
|
||||||
# start the main app window
|
# start the main app window
|
||||||
self.appClipboard = self.clipboard()
|
self.appClipboard = self.clipboard()
|
||||||
self.mainWindow = MainWindow(
|
self.mainWindow = MainWindow(screens, app_version, self.appClipboard)
|
||||||
self.screens, app_version, self.appClipboard)
|
|
||||||
self.mainWindow.show()
|
self.mainWindow.show()
|
||||||
if show_splash:
|
if show_splash:
|
||||||
# now kill the splashscreen
|
# now kill the splashscreen
|
||||||
@ -225,41 +218,6 @@ class OpenLP(QtGui.QApplication):
|
|||||||
"""
|
"""
|
||||||
self.restoreOverrideCursor()
|
self.restoreOverrideCursor()
|
||||||
|
|
||||||
def updateScreenList(self, count=-1):
|
|
||||||
"""
|
|
||||||
Called when the list of screens has to be updated.
|
|
||||||
|
|
||||||
``count``
|
|
||||||
The screen's number which has been (un)plugged
|
|
||||||
"""
|
|
||||||
for screen in copy.deepcopy(self.screens.screen_list):
|
|
||||||
# Remove unplugged screens.
|
|
||||||
if screen[u'number'] == self.desktop().numScreens():
|
|
||||||
self.screens.remove_screen(screen[u'number'])
|
|
||||||
else:
|
|
||||||
# Check if the screen has changed.
|
|
||||||
temp_screen = {
|
|
||||||
u'number': screen[u'number'],
|
|
||||||
u'size': self.desktop().screenGeometry(screen[u'number']),
|
|
||||||
u'primary':
|
|
||||||
(self.desktop().primaryScreen() == screen[u'number'])
|
|
||||||
}
|
|
||||||
if temp_screen != screen:
|
|
||||||
self.screens.update_screen(temp_screen)
|
|
||||||
# Add new screens.
|
|
||||||
for number in xrange(0, self.desktop().numScreens()):
|
|
||||||
if not self.screens.screen_exists(number):
|
|
||||||
self.screens.add_screen({
|
|
||||||
u'number': number,
|
|
||||||
u'size': self.desktop().screenGeometry(number),
|
|
||||||
u'primary': (self.desktop().primaryScreen() == number)
|
|
||||||
})
|
|
||||||
if count != -1:
|
|
||||||
# Reload setting tabs to apply possible changes.
|
|
||||||
self.mainWindow.settingsForm.reload()
|
|
||||||
Receiver.send_message(u'config_screen_changed')
|
|
||||||
# TODO: Make the new (second) monitor the live display.
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""
|
"""
|
||||||
The main function which parses command line options and then runs
|
The main function which parses command line options and then runs
|
||||||
|
@ -30,6 +30,10 @@ displays.
|
|||||||
import logging
|
import logging
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
|
from PyQt4 import QtCore
|
||||||
|
|
||||||
|
from openlp.core.lib import Receiver
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
class ScreenList(object):
|
class ScreenList(object):
|
||||||
@ -38,7 +42,11 @@ class ScreenList(object):
|
|||||||
"""
|
"""
|
||||||
log.info(u'Screen loaded')
|
log.info(u'Screen loaded')
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, parent, desktop):
|
||||||
|
"""
|
||||||
|
"""
|
||||||
|
self.parent = parent
|
||||||
|
self.desktop = desktop
|
||||||
# The screen used for the rendermanager.
|
# The screen used for the rendermanager.
|
||||||
# (Why does the rendermanager needs his own?)
|
# (Why does the rendermanager needs his own?)
|
||||||
self.preview = None
|
self.preview = None
|
||||||
@ -50,6 +58,62 @@ class ScreenList(object):
|
|||||||
self.current_display = 0
|
self.current_display = 0
|
||||||
# save config display number
|
# save config display number
|
||||||
self.monitor_number = 0
|
self.monitor_number = 0
|
||||||
|
self.screenCountChanged()
|
||||||
|
QtCore.QObject.connect(desktop,
|
||||||
|
QtCore.SIGNAL(u'resized(int)'), self.screenResolutionChanged)
|
||||||
|
QtCore.QObject.connect(desktop,
|
||||||
|
QtCore.SIGNAL(u'screenCountChanged(int)'), self.screenCountChanged)
|
||||||
|
|
||||||
|
def screenResolutionChanged(self, number):
|
||||||
|
"""
|
||||||
|
Called when the resolution of a screen has changed.
|
||||||
|
|
||||||
|
``number``
|
||||||
|
The number of the screen, which size has changed.
|
||||||
|
"""
|
||||||
|
log.info(u'screenResolutionChanged %d' % number)
|
||||||
|
for screen in self.screen_list:
|
||||||
|
if number == screen[u'number']:
|
||||||
|
newScreen = {
|
||||||
|
u'number': number,
|
||||||
|
u'size': self.desktop.screenGeometry(number),
|
||||||
|
u'primary': (self.desktop.primaryScreen() == number)
|
||||||
|
}
|
||||||
|
self.remove_screen(number)
|
||||||
|
self.add_screen(newScreen)
|
||||||
|
# The screen's default size is used, that is why we have to
|
||||||
|
# update the override screen.
|
||||||
|
if screen == self.override:
|
||||||
|
self.override = copy.deepcopy(newScreen)
|
||||||
|
self.set_override_display()
|
||||||
|
self.parent.mainWindow.settingsForm.reload()
|
||||||
|
Receiver.send_message(u'config_screen_changed')
|
||||||
|
break
|
||||||
|
|
||||||
|
def screenCountChanged(self, count=-1):
|
||||||
|
"""
|
||||||
|
Called when a screen has been added or removed.
|
||||||
|
|
||||||
|
``count``
|
||||||
|
The screen's number which has been (un)plugged.
|
||||||
|
"""
|
||||||
|
# Remove unplugged screens.
|
||||||
|
for screen in copy.deepcopy(self.screen_list):
|
||||||
|
if screen[u'number'] == self.desktop.numScreens():
|
||||||
|
self.remove_screen(screen[u'number'])
|
||||||
|
# Add new screens.
|
||||||
|
for number in xrange(0, self.desktop.numScreens()):
|
||||||
|
if not self.screen_exists(number):
|
||||||
|
self.add_screen({
|
||||||
|
u'number': number,
|
||||||
|
u'size': self.desktop.screenGeometry(number),
|
||||||
|
u'primary': (self.desktop.primaryScreen() == number)
|
||||||
|
})
|
||||||
|
if count != -1:
|
||||||
|
# Reload setting tabs to apply possible changes.
|
||||||
|
self.parent.mainWindow.settingsForm.reload()
|
||||||
|
Receiver.send_message(u'config_screen_changed')
|
||||||
|
# TODO: Make the new (second) monitor the live display.
|
||||||
|
|
||||||
def add_screen(self, screen):
|
def add_screen(self, screen):
|
||||||
"""
|
"""
|
||||||
@ -58,11 +122,11 @@ class ScreenList(object):
|
|||||||
``screen``
|
``screen``
|
||||||
A dict with the screen properties::
|
A dict with the screen properties::
|
||||||
|
|
||||||
{
|
{
|
||||||
u'primary': True,
|
u'primary': True,
|
||||||
u'number': 0,
|
u'number': 0,
|
||||||
u'size': PyQt4.QtCore.QRect(0, 0, 1024, 768)
|
u'size': PyQt4.QtCore.QRect(0, 0, 1024, 768)
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
log.info(u'Screen %d found with resolution %s',
|
log.info(u'Screen %d found with resolution %s',
|
||||||
screen[u'number'], screen[u'size'])
|
screen[u'number'], screen[u'size'])
|
||||||
@ -71,32 +135,6 @@ class ScreenList(object):
|
|||||||
self.screen_list.append(screen)
|
self.screen_list.append(screen)
|
||||||
self.display_count += 1
|
self.display_count += 1
|
||||||
|
|
||||||
def update_screen(self, newScreen):
|
|
||||||
"""
|
|
||||||
Adjusts the screen's properties in the ``screen_list`` to the properties
|
|
||||||
of the given screen.
|
|
||||||
|
|
||||||
``newScreen``
|
|
||||||
A dict with the new properties of the screen::
|
|
||||||
|
|
||||||
{
|
|
||||||
u'primary': True,
|
|
||||||
u'number': 0,
|
|
||||||
u'size': PyQt4.QtCore.QRect(0, 0, 1024, 768)
|
|
||||||
}
|
|
||||||
"""
|
|
||||||
log.info(u'update_screen %d' % newScreen[u'number'])
|
|
||||||
for oldScreen in self.screen_list:
|
|
||||||
if newScreen[u'number'] == oldScreen[u'number']:
|
|
||||||
self.remove_screen(oldScreen[u'number'])
|
|
||||||
self.add_screen(newScreen)
|
|
||||||
# The screen's default size is used, that is why we have to
|
|
||||||
# update the override screen.
|
|
||||||
if oldScreen == self.override:
|
|
||||||
self.override = copy.deepcopy(newScreen)
|
|
||||||
self.set_override_display()
|
|
||||||
break
|
|
||||||
|
|
||||||
def remove_screen(self, number):
|
def remove_screen(self, number):
|
||||||
"""
|
"""
|
||||||
Remove a screen from the list of known screens.
|
Remove a screen from the list of known screens.
|
||||||
|
Loading…
Reference in New Issue
Block a user