forked from openlp/openlp
Code sorting, refactoring and cleaning
This commit is contained in:
parent
02912ed7ea
commit
ee80308997
@ -32,12 +32,12 @@ from optparse import OptionParser
|
|||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
log = logging.getLogger()
|
|
||||||
|
|
||||||
from openlp.core.lib import Receiver
|
from openlp.core.lib import Receiver
|
||||||
from openlp.core.resources import qInitResources
|
from openlp.core.resources import qInitResources
|
||||||
from openlp.core.ui import MainWindow, SplashScreen, ScreenList
|
from openlp.core.ui import MainWindow, SplashScreen, ScreenList
|
||||||
from openlp.core.utils import AppLocation, LanguageManager
|
from openlp.core.utils import AppLocation, LanguageManager, VersionThread
|
||||||
|
|
||||||
|
log = logging.getLogger()
|
||||||
|
|
||||||
application_stylesheet = u"""
|
application_stylesheet = u"""
|
||||||
QMainWindow::separator
|
QMainWindow::separator
|
||||||
@ -141,7 +141,7 @@ class OpenLP(QtGui.QApplication):
|
|||||||
# now kill the splashscreen
|
# now kill the splashscreen
|
||||||
self.splash.finish(self.mainWindow)
|
self.splash.finish(self.mainWindow)
|
||||||
self.mainWindow.repaint()
|
self.mainWindow.repaint()
|
||||||
self.mainWindow.versionThread()
|
VersionThread(self.mainWindow, app_version).start()
|
||||||
return self.exec_()
|
return self.exec_()
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -25,8 +25,6 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
import time
|
|
||||||
import re
|
|
||||||
|
|
||||||
from PyQt4 import QtCore, QtGui
|
from PyQt4 import QtCore, QtGui
|
||||||
|
|
||||||
@ -34,8 +32,7 @@ from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, \
|
|||||||
ThemeManager, SlideController, PluginForm, MediaDockManager, DisplayManager
|
ThemeManager, SlideController, PluginForm, MediaDockManager, DisplayManager
|
||||||
from openlp.core.lib import RenderManager, build_icon, OpenLPDockWidget, \
|
from openlp.core.lib import RenderManager, build_icon, OpenLPDockWidget, \
|
||||||
SettingsManager, PluginManager, Receiver, translate
|
SettingsManager, PluginManager, Receiver, translate
|
||||||
from openlp.core.utils import check_latest_version, AppLocation, add_actions, \
|
from openlp.core.utils import AppLocation, add_actions, LanguageManager
|
||||||
LanguageManager
|
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
@ -58,49 +55,6 @@ MEDIA_MANAGER_STYLE = """
|
|||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
class VersionThread(QtCore.QThread):
|
|
||||||
"""
|
|
||||||
A special Qt thread class to fetch the version of OpenLP from the website.
|
|
||||||
This is threaded so that it doesn't affect the loading time of OpenLP.
|
|
||||||
"""
|
|
||||||
def __init__(self, parent, app_version):
|
|
||||||
QtCore.QThread.__init__(self, parent)
|
|
||||||
self.parent = parent
|
|
||||||
self.app_version = app_version
|
|
||||||
self.version_splitter = re.compile(
|
|
||||||
r'([0-9]+).([0-9]+).([0-9]+)(?:-bzr([0-9]+))?')
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
"""
|
|
||||||
Run the thread.
|
|
||||||
"""
|
|
||||||
time.sleep(1)
|
|
||||||
Receiver.send_message(u'maindisplay_blank_check')
|
|
||||||
version = check_latest_version(self.app_version)
|
|
||||||
remote_version = {}
|
|
||||||
local_version = {}
|
|
||||||
match = self.version_splitter.match(version)
|
|
||||||
if match:
|
|
||||||
remote_version[u'major'] = int(match.group(1))
|
|
||||||
remote_version[u'minor'] = int(match.group(2))
|
|
||||||
remote_version[u'release'] = int(match.group(3))
|
|
||||||
if len(match.groups()) > 3 and match.group(4):
|
|
||||||
remote_version[u'revision'] = int(match.group(4))
|
|
||||||
match = self.version_splitter.match(self.app_version[u'full'])
|
|
||||||
if match:
|
|
||||||
local_version[u'major'] = int(match.group(1))
|
|
||||||
local_version[u'minor'] = int(match.group(2))
|
|
||||||
local_version[u'release'] = int(match.group(3))
|
|
||||||
if len(match.groups()) > 3 and match.group(4):
|
|
||||||
local_version[u'revision'] = int(match.group(4))
|
|
||||||
if remote_version[u'major'] > local_version[u'major'] or \
|
|
||||||
remote_version[u'minor'] > local_version[u'minor'] or \
|
|
||||||
remote_version[u'release'] > local_version[u'release']:
|
|
||||||
Receiver.send_message(u'openlp_version_check', u'%s' % version)
|
|
||||||
elif remote_version.get(u'revision') and \
|
|
||||||
local_version.get(u'revision') and \
|
|
||||||
remote_version[u'revision'] > local_version[u'revision']:
|
|
||||||
Receiver.send_message(u'openlp_version_check', u'%s' % version)
|
|
||||||
|
|
||||||
class Ui_MainWindow(object):
|
class Ui_MainWindow(object):
|
||||||
def setupUi(self, MainWindow):
|
def setupUi(self, MainWindow):
|
||||||
@ -578,20 +532,15 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
QtCore.SIGNAL(u'triggered()'),
|
QtCore.SIGNAL(u'triggered()'),
|
||||||
self.ThemeManagerContents.onExportTheme)
|
self.ThemeManagerContents.onExportTheme)
|
||||||
QtCore.QObject.connect(self.ViewMediaManagerItem,
|
QtCore.QObject.connect(self.ViewMediaManagerItem,
|
||||||
QtCore.SIGNAL(u'triggered(bool)'),
|
QtCore.SIGNAL(u'triggered(bool)'), self.toggleMediaManager)
|
||||||
self.toggleMediaManager)
|
|
||||||
QtCore.QObject.connect(self.ViewServiceManagerItem,
|
QtCore.QObject.connect(self.ViewServiceManagerItem,
|
||||||
QtCore.SIGNAL(u'triggered(bool)'),
|
QtCore.SIGNAL(u'triggered(bool)'), self.toggleServiceManager)
|
||||||
self.toggleServiceManager)
|
|
||||||
QtCore.QObject.connect(self.ViewThemeManagerItem,
|
QtCore.QObject.connect(self.ViewThemeManagerItem,
|
||||||
QtCore.SIGNAL(u'triggered(bool)'),
|
QtCore.SIGNAL(u'triggered(bool)'), self.toggleThemeManager)
|
||||||
self.toggleThemeManager)
|
|
||||||
QtCore.QObject.connect(self.ViewPreviewPanel,
|
QtCore.QObject.connect(self.ViewPreviewPanel,
|
||||||
QtCore.SIGNAL(u'toggled(bool)'),
|
QtCore.SIGNAL(u'toggled(bool)'), self.setPreviewPanelVisibility)
|
||||||
self.setPreviewPanelVisibility)
|
|
||||||
QtCore.QObject.connect(self.ViewLivePanel,
|
QtCore.QObject.connect(self.ViewLivePanel,
|
||||||
QtCore.SIGNAL(u'toggled(bool)'),
|
QtCore.SIGNAL(u'toggled(bool)'), self.setLivePanelVisibility)
|
||||||
self.setLivePanelVisibility)
|
|
||||||
QtCore.QObject.connect(self.MediaManagerDock,
|
QtCore.QObject.connect(self.MediaManagerDock,
|
||||||
QtCore.SIGNAL(u'visibilityChanged(bool)'),
|
QtCore.SIGNAL(u'visibilityChanged(bool)'),
|
||||||
self.ViewMediaManagerItem.setChecked)
|
self.ViewMediaManagerItem.setChecked)
|
||||||
@ -609,8 +558,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
QtCore.SIGNAL(u'triggered()'), self.onPluginItemClicked)
|
QtCore.SIGNAL(u'triggered()'), self.onPluginItemClicked)
|
||||||
QtCore.QObject.connect(self.SettingsConfigureItem,
|
QtCore.QObject.connect(self.SettingsConfigureItem,
|
||||||
QtCore.SIGNAL(u'triggered()'), self.onOptionsSettingsItemClicked)
|
QtCore.SIGNAL(u'triggered()'), self.onOptionsSettingsItemClicked)
|
||||||
QtCore.QObject.connect(self.FileNewItem,
|
QtCore.QObject.connect(self.FileNewItem, QtCore.SIGNAL(u'triggered()'),
|
||||||
QtCore.SIGNAL(u'triggered()'),
|
|
||||||
self.ServiceManagerContents.onNewService)
|
self.ServiceManagerContents.onNewService)
|
||||||
QtCore.QObject.connect(self.FileOpenItem,
|
QtCore.QObject.connect(self.FileOpenItem,
|
||||||
QtCore.SIGNAL(u'triggered()'),
|
QtCore.SIGNAL(u'triggered()'),
|
||||||
@ -623,22 +571,18 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
self.ServiceManagerContents.onSaveService)
|
self.ServiceManagerContents.onSaveService)
|
||||||
#i18n set signals for languages
|
#i18n set signals for languages
|
||||||
QtCore.QObject.connect(self.AutoLanguageItem,
|
QtCore.QObject.connect(self.AutoLanguageItem,
|
||||||
QtCore.SIGNAL(u'toggled(bool)'),
|
QtCore.SIGNAL(u'toggled(bool)'), self.setAutoLanguage)
|
||||||
self.setAutoLanguage)
|
|
||||||
self.LanguageGroup.triggered.connect(LanguageManager.set_language)
|
self.LanguageGroup.triggered.connect(LanguageManager.set_language)
|
||||||
QtCore.QObject.connect(self.ModeDefaultItem,
|
QtCore.QObject.connect(self.ModeDefaultItem,
|
||||||
QtCore.SIGNAL(u'triggered()'),
|
QtCore.SIGNAL(u'triggered()'), self.setViewMode)
|
||||||
self.onModeDefaultItemClicked)
|
|
||||||
QtCore.QObject.connect(self.ModeSetupItem,
|
QtCore.QObject.connect(self.ModeSetupItem,
|
||||||
QtCore.SIGNAL(u'triggered()'),
|
QtCore.SIGNAL(u'triggered()'), self.onModeSetupItemClicked)
|
||||||
self.onModeSetupItemClicked)
|
|
||||||
QtCore.QObject.connect(self.ModeLiveItem,
|
QtCore.QObject.connect(self.ModeLiveItem,
|
||||||
QtCore.SIGNAL(u'triggered()'),
|
QtCore.SIGNAL(u'triggered()'), self.onModeLiveItemClicked)
|
||||||
self.onModeLiveItemClicked)
|
|
||||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||||
QtCore.SIGNAL(u'theme_update_global'), self.defaultThemeChanged)
|
QtCore.SIGNAL(u'theme_update_global'), self.defaultThemeChanged)
|
||||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||||
QtCore.SIGNAL(u'openlp_version_check'), self.versionCheck)
|
QtCore.SIGNAL(u'openlp_version_check'), self.versionNotice)
|
||||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||||
QtCore.SIGNAL(u'maindisplay_blank_check'), self.blankCheck)
|
QtCore.SIGNAL(u'maindisplay_blank_check'), self.blankCheck)
|
||||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||||
@ -699,12 +643,11 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
LanguageManager.AutoLanguage = value
|
LanguageManager.AutoLanguage = value
|
||||||
LanguageManager.set_language(self.LanguageGroup.checkedAction())
|
LanguageManager.set_language(self.LanguageGroup.checkedAction())
|
||||||
|
|
||||||
def versionCheck(self, version):
|
def versionNotice(self, version):
|
||||||
"""
|
"""
|
||||||
Checks the version of the Application called from openlp.pyw
|
Notifies the user that a newer version of OpenLP is available.
|
||||||
Triggered by delay thread.
|
Triggered by delay thread.
|
||||||
"""
|
"""
|
||||||
app_version = self.applicationVersion[u'full']
|
|
||||||
version_text = unicode(translate('OpenLP.MainWindow',
|
version_text = unicode(translate('OpenLP.MainWindow',
|
||||||
'Version %s of OpenLP is now available for download (you are '
|
'Version %s of OpenLP is now available for download (you are '
|
||||||
'currently running version %s). \n\nYou can download the latest '
|
'currently running version %s). \n\nYou can download the latest '
|
||||||
@ -712,16 +655,13 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
'<a href="http://openlp.org/">http://openlp.org/</a>.'))
|
'<a href="http://openlp.org/">http://openlp.org/</a>.'))
|
||||||
QtGui.QMessageBox.question(self,
|
QtGui.QMessageBox.question(self,
|
||||||
translate('OpenLP.MainWindow', 'OpenLP Version Updated'),
|
translate('OpenLP.MainWindow', 'OpenLP Version Updated'),
|
||||||
version_text % (version, app_version),
|
version_text % (version, self.applicationVersion[u'full']))
|
||||||
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok),
|
|
||||||
QtGui.QMessageBox.Ok)
|
|
||||||
|
|
||||||
def show(self):
|
def show(self):
|
||||||
"""
|
"""
|
||||||
Show the main form, as well as the display form
|
Show the main form, as well as the display form
|
||||||
"""
|
"""
|
||||||
QtGui.QWidget.show(self)
|
QtGui.QWidget.show(self)
|
||||||
#screen_number = self.getMonitorNumber()
|
|
||||||
self.displayManager.setup()
|
self.displayManager.setup()
|
||||||
if self.displayManager.mainDisplay.isVisible():
|
if self.displayManager.mainDisplay.isVisible():
|
||||||
self.displayManager.mainDisplay.setFocus()
|
self.displayManager.mainDisplay.setFocus()
|
||||||
@ -749,13 +689,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
'The Main Display has been blanked out'))
|
'The Main Display has been blanked out'))
|
||||||
settings.endGroup()
|
settings.endGroup()
|
||||||
|
|
||||||
def versionThread(self):
|
|
||||||
"""
|
|
||||||
Start an initial setup thread to delay notifications
|
|
||||||
"""
|
|
||||||
vT = VersionThread(self, self.applicationVersion)
|
|
||||||
vT.start()
|
|
||||||
|
|
||||||
def onHelpWebSiteClicked(self):
|
def onHelpWebSiteClicked(self):
|
||||||
"""
|
"""
|
||||||
Load the OpenLP website
|
Load the OpenLP website
|
||||||
@ -783,35 +716,28 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
|||||||
"""
|
"""
|
||||||
self.settingsForm.exec_()
|
self.settingsForm.exec_()
|
||||||
|
|
||||||
def onModeDefaultItemClicked(self):
|
|
||||||
"""
|
|
||||||
Put OpenLP into "Default" view mode.
|
|
||||||
"""
|
|
||||||
self.MediaManagerDock.setVisible(True)
|
|
||||||
self.ServiceManagerDock.setVisible(True)
|
|
||||||
self.ThemeManagerDock.setVisible(True)
|
|
||||||
self.setPreviewPanelVisibility(True)
|
|
||||||
self.setLivePanelVisibility(True)
|
|
||||||
|
|
||||||
def onModeSetupItemClicked(self):
|
def onModeSetupItemClicked(self):
|
||||||
"""
|
"""
|
||||||
Put OpenLP into "Setup" view mode.
|
Put OpenLP into "Setup" view mode.
|
||||||
"""
|
"""
|
||||||
self.MediaManagerDock.setVisible(True)
|
self.setViewMode(True, True, False, True, False)
|
||||||
self.ServiceManagerDock.setVisible(True)
|
|
||||||
self.ThemeManagerDock.setVisible(False)
|
|
||||||
self.setPreviewPanelVisibility(True)
|
|
||||||
self.setLivePanelVisibility(False)
|
|
||||||
|
|
||||||
def onModeLiveItemClicked(self):
|
def onModeLiveItemClicked(self):
|
||||||
"""
|
"""
|
||||||
Put OpenLP into "Live" view mode.
|
Put OpenLP into "Live" view mode.
|
||||||
"""
|
"""
|
||||||
self.MediaManagerDock.setVisible(False)
|
self.setViewMode(False, True, False, False, True)
|
||||||
self.ServiceManagerDock.setVisible(True)
|
|
||||||
self.ThemeManagerDock.setVisible(False)
|
def setViewMode(self, media=True, service=True, theme=True, preview=True,
|
||||||
self.setPreviewPanelVisibility(False)
|
live=True):
|
||||||
self.setLivePanelVisibility(True)
|
"""
|
||||||
|
Set OpenLP to a different view mode.
|
||||||
|
"""
|
||||||
|
self.MediaManagerDock.setVisible(media)
|
||||||
|
self.ServiceManagerDock.setVisible(service)
|
||||||
|
self.ThemeManagerDock.setVisible(theme)
|
||||||
|
self.setPreviewPanelVisibility(preview)
|
||||||
|
self.setLivePanelVisibility(live)
|
||||||
|
|
||||||
def screenChanged(self):
|
def screenChanged(self):
|
||||||
"""
|
"""
|
||||||
|
@ -27,20 +27,66 @@
|
|||||||
The :mod:`utils` module provides the utility libraries for OpenLP
|
The :mod:`utils` module provides the utility libraries for OpenLP
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
|
||||||
import sys
|
|
||||||
import logging
|
import logging
|
||||||
|
import os
|
||||||
|
import re
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
import urllib2
|
import urllib2
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
from PyQt4 import QtGui, QtCore
|
from PyQt4 import QtGui, QtCore
|
||||||
|
|
||||||
import openlp
|
import openlp
|
||||||
from openlp.core.lib import translate
|
from openlp.core.lib import Receiver, translate
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
images_filter = None
|
images_filter = None
|
||||||
|
|
||||||
|
class VersionThread(QtCore.QThread):
|
||||||
|
"""
|
||||||
|
A special Qt thread class to fetch the version of OpenLP from the website.
|
||||||
|
This is threaded so that it doesn't affect the loading time of OpenLP.
|
||||||
|
"""
|
||||||
|
def __init__(self, parent, app_version):
|
||||||
|
QtCore.QThread.__init__(self, parent)
|
||||||
|
self.app_version = app_version
|
||||||
|
self.version_splitter = re.compile(
|
||||||
|
r'([0-9]+).([0-9]+).([0-9]+)(?:-bzr([0-9]+))?')
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
"""
|
||||||
|
Run the thread.
|
||||||
|
"""
|
||||||
|
time.sleep(1)
|
||||||
|
Receiver.send_message(u'maindisplay_blank_check')
|
||||||
|
version = check_latest_version(self.app_version)
|
||||||
|
remote_version = {}
|
||||||
|
local_version = {}
|
||||||
|
match = self.version_splitter.match(version)
|
||||||
|
if match:
|
||||||
|
remote_version[u'major'] = int(match.group(1))
|
||||||
|
remote_version[u'minor'] = int(match.group(2))
|
||||||
|
remote_version[u'release'] = int(match.group(3))
|
||||||
|
if len(match.groups()) > 3 and match.group(4):
|
||||||
|
remote_version[u'revision'] = int(match.group(4))
|
||||||
|
match = self.version_splitter.match(self.app_version[u'full'])
|
||||||
|
if match:
|
||||||
|
local_version[u'major'] = int(match.group(1))
|
||||||
|
local_version[u'minor'] = int(match.group(2))
|
||||||
|
local_version[u'release'] = int(match.group(3))
|
||||||
|
if len(match.groups()) > 3 and match.group(4):
|
||||||
|
local_version[u'revision'] = int(match.group(4))
|
||||||
|
if remote_version[u'major'] > local_version[u'major'] or \
|
||||||
|
remote_version[u'minor'] > local_version[u'minor'] or \
|
||||||
|
remote_version[u'release'] > local_version[u'release']:
|
||||||
|
Receiver.send_message(u'openlp_version_check', u'%s' % version)
|
||||||
|
elif remote_version.get(u'revision') and \
|
||||||
|
local_version.get(u'revision') and \
|
||||||
|
remote_version[u'revision'] > local_version[u'revision']:
|
||||||
|
Receiver.send_message(u'openlp_version_check', u'%s' % version)
|
||||||
|
|
||||||
|
|
||||||
class AppLocation(object):
|
class AppLocation(object):
|
||||||
"""
|
"""
|
||||||
The :class:`AppLocation` class is a static class which retrieves a
|
The :class:`AppLocation` class is a static class which retrieves a
|
||||||
|
Loading…
Reference in New Issue
Block a user