← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~googol-hush/openlp/tweaks into lp:openlp

 

Andreas Preikschat has proposed merging lp:~googol-hush/openlp/tweaks into lp:openlp.

Requested reviews:
  Jon Tibble (meths)

For more details, see:
https://code.launchpad.net/~googol-hush/openlp/tweaks/+merge/52107

Hello!

- added new code, to be able to detect (un)plugged screens after having OpenLP started
- added the ability to detect screen resolution changes

Note, this does not sets the new screen to the default display location, it just updates the list of available screens.
-- 
https://code.launchpad.net/~googol-hush/openlp/tweaks/+merge/52107
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp.pyw'
--- openlp.pyw	2011-02-14 21:55:38 +0000
+++ openlp.pyw	2011-03-03 18:12:59 +0000
@@ -24,7 +24,6 @@
 # with this program; if not, write to the Free Software Foundation, Inc., 59  #
 # Temple Place, Suite 330, Boston, MA 02111-1307 USA                          #
 ###############################################################################
-
 import os
 import sys
 import logging
@@ -179,14 +178,8 @@
             self.splash.show()
         # make sure Qt really display the splash screen
         self.processEvents()
-        screens = ScreenList()
         # Decide how many screens we have and their size
-        for screen in xrange(0, self.desktop().numScreens()):
-            size = self.desktop().screenGeometry(screen)
-            screens.add_screen({u'number': screen,
-                u'size': size,
-                u'primary': (self.desktop().primaryScreen() == screen)})
-            log.info(u'Screen %d found with resolution %s', screen, size)
+        screens = ScreenList(self.desktop())
         # start the main app window
         self.appClipboard = self.clipboard()
         self.mainWindow = MainWindow(screens, app_version, self.appClipboard)

=== modified file 'openlp/core/ui/generaltab.py'
--- openlp/core/ui/generaltab.py	2011-02-25 17:05:01 +0000
+++ openlp/core/ui/generaltab.py	2011-03-03 18:12:59 +0000
@@ -234,6 +234,9 @@
         QtCore.QObject.connect(self.customXValueEdit,
             QtCore.SIGNAL(u'textEdited(const QString&)'),
             self.onDisplayPositionChanged)
+        # Reload the tab, as the screen resolution/count may has changed.
+        QtCore.QObject.connect(Receiver.get_receiver(),
+            QtCore.SIGNAL(u'config_screen_changed'), self.load)
 
     def retranslateUi(self):
         """
@@ -300,13 +303,9 @@
         """
         settings = QtCore.QSettings()
         settings.beginGroup(self.settingsSection)
-        for screen in self.screens.screen_list:
-            screen_name = u'%s %d' % (translate('OpenLP.GeneralTab', 'Screen'),
-                screen[u'number'] + 1)
-            if screen[u'primary']:
-                screen_name = u'%s (%s)' % (screen_name,
-                    translate('OpenLP.GeneralTab', 'primary'))
-            self.monitorComboBox.addItem(screen_name)
+        self.monitorComboBox.clear()
+        for screen in self.screens.get_screen_list():
+            self.monitorComboBox.addItem(screen)
         self.numberEdit.setText(unicode(settings.value(
             u'ccli number', QtCore.QVariant(u'')).toString()))
         self.usernameEdit.setText(unicode(settings.value(

=== modified file 'openlp/core/ui/screen.py'
--- openlp/core/ui/screen.py	2011-02-24 05:47:38 +0000
+++ openlp/core/ui/screen.py	2011-03-03 18:12:59 +0000
@@ -25,11 +25,15 @@
 ###############################################################################
 """
 The :mod:`screen` module provides management functionality for a machines'
-displays
+displays.
 """
 import logging
 import copy
 
+from PyQt4 import QtCore
+
+from openlp.core.lib import Receiver, translate
+
 log = logging.getLogger(__name__)
 
 class ScreenList(object):
@@ -38,7 +42,14 @@
     """
     log.info(u'Screen loaded')
 
-    def __init__(self):
+    def __init__(self, desktop):
+        """
+        Initialise the screen list.
+
+        ``desktop``
+            A ``QDesktopWidget`` object.
+        """
+        self.desktop = desktop
         self.preview = None
         self.current = None
         self.override = None
@@ -48,19 +59,120 @@
         self.current_display = 0
         # save config display number
         self.monitor_number = 0
+        self.screen_count_changed()
+        QtCore.QObject.connect(desktop,
+            QtCore.SIGNAL(u'resized(int)'), self.screen_resolution_changed)
+        QtCore.QObject.connect(desktop,
+            QtCore.SIGNAL(u'screenCountChanged(int)'),
+            self.screen_count_changed)
+
+    def screen_resolution_changed(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()
+                Receiver.send_message(u'config_screen_changed')
+                break
+
+    def screen_count_changed(self, changed_screen=-1):
+        """
+        Called when a screen has been added or removed.
+
+        ``changed_screen``
+            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)
+                })
+        # We do not want to send this message, when the method is called the
+        # first time.
+        if changed_screen != -1:
+            # Reload setting tabs to apply possible changes.
+            Receiver.send_message(u'config_screen_changed')
+
+    def get_screen_list(self):
+        """
+        Returns a list with the screens. This should only be used to display
+        available screens to the user::
+
+            [u'Screen 1 (primary)', u'Screen 2']
+        """
+        screen_list= []
+        for screen in self.screen_list:
+            screen_name = u'%s %d' % (translate('OpenLP.ScreenList', 'Screen'),
+                screen[u'number'] + 1)
+            if screen[u'primary']:
+                screen_name = u'%s (%s)' % (screen_name,
+                    translate('OpenLP.ScreenList', 'primary'))
+            screen_list.append(screen_name)
+        return screen_list
 
     def add_screen(self, screen):
         """
-        Add a screen to the list of known screens
+        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)
+                }
         """
+        log.info(u'Screen %d found with resolution %s',
+            screen[u'number'], screen[u'size'])
         if screen[u'primary']:
             self.current = screen
         self.screen_list.append(screen)
         self.display_count += 1
 
+    def remove_screen(self, number):
+        """
+        Remove a screen from the list of known screens.
+
+        ``number``
+            The screen number (int).
+        """
+        log.info(u'remove_screen %d' % 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):
         """
-        Confirms a screen is known
+        Confirms a screen is known.
+
+        ``number``
+            The screen number (int).
         """
         for screen in self.screen_list:
             if screen[u'number'] == number:
@@ -69,7 +181,10 @@
 
     def set_current_display(self, number):
         """
-        Set up the current screen dimensions
+        Set up the current screen dimensions.
+
+        ``number``
+            The screen number (int).
         """
         log.debug(u'set_current_display %s', number)
         if number + 1 > self.display_count:
@@ -86,8 +201,8 @@
 
     def set_override_display(self):
         """
-        replace the current size with the override values
-        user wants to have their own screen attributes
+        Replace the current size with the override values, as the user wants to
+        have their own screen attributes.
         """
         log.debug(u'set_override_display')
         self.current = copy.deepcopy(self.override)
@@ -95,8 +210,8 @@
 
     def reset_current_display(self):
         """
-        replace the current values with the correct values
-        user wants to use the correct screen attributes
+        Replace the current values with the correct values, as the user wants to
+        use the correct screen attributes.
         """
         log.debug(u'reset_current_display')
         self.set_current_display(self.current_display)


Follow ups