Refactored ScreenList into a true Pythonic singleton.

bzr-revno: 1974
This commit is contained in:
Raoul Snyman 2012-05-23 18:25:20 +02:00 committed by Andreas Preikschat
commit 3a6f59a35e
9 changed files with 32 additions and 28 deletions

View File

@ -109,7 +109,7 @@ class OpenLP(QtGui.QApplication):
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)
# Decide how many screens we have and their size # Decide how many screens we have and their size
screens = ScreenList(self.desktop()) screens = ScreenList.create(self.desktop())
# First time checks in settings # First time checks in settings
has_run_wizard = QtCore.QSettings().value( has_run_wizard = QtCore.QSettings().value(
u'general/has run wizard', QtCore.QVariant(False)).toBool() u'general/has run wizard', QtCore.QVariant(False)).toBool()

View File

@ -52,7 +52,7 @@ class OpenLPDockWidget(QtGui.QDockWidget):
if icon: if icon:
self.setWindowIcon(build_icon(icon)) self.setWindowIcon(build_icon(icon))
# Sort out the minimum width. # Sort out the minimum width.
screens = ScreenList.get_instance() screens = ScreenList()
mainwindow_docbars = screens.current[u'size'].width() / 5 mainwindow_docbars = screens.current[u'size'].width() / 5
if mainwindow_docbars > 300: if mainwindow_docbars > 300:
self.setMinimumWidth(300) self.setMinimumWidth(300)

View File

@ -163,7 +163,7 @@ class ImageManager(QtCore.QObject):
def __init__(self): def __init__(self):
QtCore.QObject.__init__(self) QtCore.QObject.__init__(self)
current_screen = ScreenList.get_instance().current current_screen = ScreenList().current
self.width = current_screen[u'size'].width() self.width = current_screen[u'size'].width()
self.height = current_screen[u'size'].height() self.height = current_screen[u'size'].height()
self._cache = {} self._cache = {}
@ -177,7 +177,7 @@ class ImageManager(QtCore.QObject):
Screen has changed size so rebuild the cache to new size. Screen has changed size so rebuild the cache to new size.
""" """
log.debug(u'update_display') log.debug(u'update_display')
current_screen = ScreenList.get_instance().current current_screen = ScreenList().current
self.width = current_screen[u'size'].width() self.width = current_screen[u'size'].width()
self.height = current_screen[u'size'].height() self.height = current_screen[u'size'].height()
# Mark the images as dirty for a rebuild by setting the image and byte # Mark the images as dirty for a rebuild by setting the image and byte

View File

@ -69,7 +69,7 @@ class Renderer(object):
log.debug(u'Initialisation started') log.debug(u'Initialisation started')
self.themeManager = themeManager self.themeManager = themeManager
self.imageManager = imageManager self.imageManager = imageManager
self.screens = ScreenList.get_instance() self.screens = ScreenList()
self.service_theme = u'' self.service_theme = u''
self.theme_level = u'' self.theme_level = u''
self.override_background = None self.override_background = None

View File

@ -42,7 +42,7 @@ class GeneralTab(SettingsTab):
""" """
Initialise the general settings tab Initialise the general settings tab
""" """
self.screens = ScreenList.get_instance() self.screens = ScreenList()
self.iconPath = u':/icon/openlp-logo-16x16.png' self.iconPath = u':/icon/openlp-logo-16x16.png'
generalTranslated = translate('OpenLP.GeneralTab', 'General') generalTranslated = translate('OpenLP.GeneralTab', 'General')
SettingsTab.__init__(self, parent, u'General', generalTranslated) SettingsTab.__init__(self, parent, u'General', generalTranslated)

View File

@ -119,7 +119,7 @@ class MainDisplay(Display):
def __init__(self, parent, imageManager, live, controller): def __init__(self, parent, imageManager, live, controller):
Display.__init__(self, parent, live, controller) Display.__init__(self, parent, live, controller)
self.imageManager = imageManager self.imageManager = imageManager
self.screens = ScreenList.get_instance() self.screens = ScreenList()
self.plugins = PluginManager.get_instance().plugins self.plugins = PluginManager.get_instance().plugins
self.rebuildCSS = False self.rebuildCSS = False
self.hideMode = None self.hideMode = None

View File

@ -795,7 +795,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
if answer == QtGui.QMessageBox.No: if answer == QtGui.QMessageBox.No:
return return
Receiver.send_message(u'cursor_busy') Receiver.send_message(u'cursor_busy')
screens = ScreenList.get_instance() screens = ScreenList()
FirstTimeForm(screens, self).exec_() FirstTimeForm(screens, self).exec_()
self.firstTime() self.firstTime()
for plugin in self.pluginManager.plugins: for plugin in self.pluginManager.plugins:

View File

@ -41,36 +41,40 @@ class ScreenList(object):
""" """
Wrapper to handle the parameters of the display screen. Wrapper to handle the parameters of the display screen.
To get access to the screen list call ``ScreenList.get_instance()``. To get access to the screen list call ``ScreenList()``.
""" """
log.info(u'Screen loaded') log.info(u'Screen loaded')
instance = None __instance__ = None
@staticmethod def __new__(cls):
def get_instance(): if not cls.__instance__:
return ScreenList.instance cls.__instance__ = object.__new__(cls)
return cls.__instance__
def __init__(self, desktop): @classmethod
def create(cls, desktop):
""" """
Initialise the screen list. Initialise the screen list.
``desktop`` ``desktop``
A ``QDesktopWidget`` object. A ``QDesktopWidget`` object.
""" """
ScreenList.instance = self screen_list = cls()
self.desktop = desktop screen_list.desktop = desktop
self.preview = None screen_list.preview = None
self.current = None screen_list.current = None
self.override = None screen_list.override = None
self.screen_list = [] screen_list.screen_list = []
self.display_count = 0 screen_list.display_count = 0
self.screen_count_changed() screen_list.screen_count_changed()
self._load_screen_settings() screen_list._load_screen_settings()
QtCore.QObject.connect(desktop, QtCore.QObject.connect(desktop,
QtCore.SIGNAL(u'resized(int)'), self.screen_resolution_changed) QtCore.SIGNAL(u'resized(int)'),
screen_list.screen_resolution_changed)
QtCore.QObject.connect(desktop, QtCore.QObject.connect(desktop,
QtCore.SIGNAL(u'screenCountChanged(int)'), QtCore.SIGNAL(u'screenCountChanged(int)'),
self.screen_count_changed) screen_list.screen_count_changed)
return screen_list
def screen_resolution_changed(self, number): def screen_resolution_changed(self, number):
""" """
@ -233,8 +237,8 @@ class ScreenList(object):
y = window.y() + (window.height() / 2) y = window.y() + (window.height() / 2)
for screen in self.screen_list: for screen in self.screen_list:
size = screen[u'size'] size = screen[u'size']
if x >= size.x() and x <= (size.x() + size.width()) \ if x >= size.x() and x <= (size.x() + size.width()) and \
and y >= size.y() and y <= (size.y() + size.height()): y >= size.y() and y <= (size.y() + size.height()):
return screen[u'number'] return screen[u'number']
def _load_screen_settings(self): def _load_screen_settings(self):

View File

@ -83,7 +83,7 @@ class SlideController(Controller):
Set up the Slide Controller. Set up the Slide Controller.
""" """
Controller.__init__(self, parent, isLive) Controller.__init__(self, parent, isLive)
self.screens = ScreenList.get_instance() self.screens = ScreenList()
try: try:
self.ratio = float(self.screens.current[u'size'].width()) / \ self.ratio = float(self.screens.current[u'size'].width()) / \
float(self.screens.current[u'size'].height()) float(self.screens.current[u'size'].height())