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
|
||||
|
||||
log = logging.getLogger()
|
||||
|
||||
from openlp.core.lib import Receiver
|
||||
from openlp.core.resources import qInitResources
|
||||
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"""
|
||||
QMainWindow::separator
|
||||
@ -141,7 +141,7 @@ class OpenLP(QtGui.QApplication):
|
||||
# now kill the splashscreen
|
||||
self.splash.finish(self.mainWindow)
|
||||
self.mainWindow.repaint()
|
||||
self.mainWindow.versionThread()
|
||||
VersionThread(self.mainWindow, app_version).start()
|
||||
return self.exec_()
|
||||
|
||||
def main():
|
||||
|
@ -25,8 +25,6 @@
|
||||
###############################################################################
|
||||
|
||||
import logging
|
||||
import time
|
||||
import re
|
||||
|
||||
from PyQt4 import QtCore, QtGui
|
||||
|
||||
@ -34,8 +32,7 @@ from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, \
|
||||
ThemeManager, SlideController, PluginForm, MediaDockManager, DisplayManager
|
||||
from openlp.core.lib import RenderManager, build_icon, OpenLPDockWidget, \
|
||||
SettingsManager, PluginManager, Receiver, translate
|
||||
from openlp.core.utils import check_latest_version, AppLocation, add_actions, \
|
||||
LanguageManager
|
||||
from openlp.core.utils import AppLocation, add_actions, LanguageManager
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
@ -58,49 +55,6 @@ MEDIA_MANAGER_STYLE = """
|
||||
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):
|
||||
def setupUi(self, MainWindow):
|
||||
@ -578,20 +532,15 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
QtCore.SIGNAL(u'triggered()'),
|
||||
self.ThemeManagerContents.onExportTheme)
|
||||
QtCore.QObject.connect(self.ViewMediaManagerItem,
|
||||
QtCore.SIGNAL(u'triggered(bool)'),
|
||||
self.toggleMediaManager)
|
||||
QtCore.SIGNAL(u'triggered(bool)'), self.toggleMediaManager)
|
||||
QtCore.QObject.connect(self.ViewServiceManagerItem,
|
||||
QtCore.SIGNAL(u'triggered(bool)'),
|
||||
self.toggleServiceManager)
|
||||
QtCore.SIGNAL(u'triggered(bool)'), self.toggleServiceManager)
|
||||
QtCore.QObject.connect(self.ViewThemeManagerItem,
|
||||
QtCore.SIGNAL(u'triggered(bool)'),
|
||||
self.toggleThemeManager)
|
||||
QtCore.SIGNAL(u'triggered(bool)'), self.toggleThemeManager)
|
||||
QtCore.QObject.connect(self.ViewPreviewPanel,
|
||||
QtCore.SIGNAL(u'toggled(bool)'),
|
||||
self.setPreviewPanelVisibility)
|
||||
QtCore.SIGNAL(u'toggled(bool)'), self.setPreviewPanelVisibility)
|
||||
QtCore.QObject.connect(self.ViewLivePanel,
|
||||
QtCore.SIGNAL(u'toggled(bool)'),
|
||||
self.setLivePanelVisibility)
|
||||
QtCore.SIGNAL(u'toggled(bool)'), self.setLivePanelVisibility)
|
||||
QtCore.QObject.connect(self.MediaManagerDock,
|
||||
QtCore.SIGNAL(u'visibilityChanged(bool)'),
|
||||
self.ViewMediaManagerItem.setChecked)
|
||||
@ -609,8 +558,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
QtCore.SIGNAL(u'triggered()'), self.onPluginItemClicked)
|
||||
QtCore.QObject.connect(self.SettingsConfigureItem,
|
||||
QtCore.SIGNAL(u'triggered()'), self.onOptionsSettingsItemClicked)
|
||||
QtCore.QObject.connect(self.FileNewItem,
|
||||
QtCore.SIGNAL(u'triggered()'),
|
||||
QtCore.QObject.connect(self.FileNewItem, QtCore.SIGNAL(u'triggered()'),
|
||||
self.ServiceManagerContents.onNewService)
|
||||
QtCore.QObject.connect(self.FileOpenItem,
|
||||
QtCore.SIGNAL(u'triggered()'),
|
||||
@ -623,22 +571,18 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
self.ServiceManagerContents.onSaveService)
|
||||
#i18n set signals for languages
|
||||
QtCore.QObject.connect(self.AutoLanguageItem,
|
||||
QtCore.SIGNAL(u'toggled(bool)'),
|
||||
self.setAutoLanguage)
|
||||
QtCore.SIGNAL(u'toggled(bool)'), self.setAutoLanguage)
|
||||
self.LanguageGroup.triggered.connect(LanguageManager.set_language)
|
||||
QtCore.QObject.connect(self.ModeDefaultItem,
|
||||
QtCore.SIGNAL(u'triggered()'),
|
||||
self.onModeDefaultItemClicked)
|
||||
QtCore.SIGNAL(u'triggered()'), self.setViewMode)
|
||||
QtCore.QObject.connect(self.ModeSetupItem,
|
||||
QtCore.SIGNAL(u'triggered()'),
|
||||
self.onModeSetupItemClicked)
|
||||
QtCore.SIGNAL(u'triggered()'), self.onModeSetupItemClicked)
|
||||
QtCore.QObject.connect(self.ModeLiveItem,
|
||||
QtCore.SIGNAL(u'triggered()'),
|
||||
self.onModeLiveItemClicked)
|
||||
QtCore.SIGNAL(u'triggered()'), self.onModeLiveItemClicked)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
QtCore.SIGNAL(u'theme_update_global'), self.defaultThemeChanged)
|
||||
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.SIGNAL(u'maindisplay_blank_check'), self.blankCheck)
|
||||
QtCore.QObject.connect(Receiver.get_receiver(),
|
||||
@ -699,12 +643,11 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
LanguageManager.AutoLanguage = value
|
||||
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.
|
||||
"""
|
||||
app_version = self.applicationVersion[u'full']
|
||||
version_text = unicode(translate('OpenLP.MainWindow',
|
||||
'Version %s of OpenLP is now available for download (you are '
|
||||
'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>.'))
|
||||
QtGui.QMessageBox.question(self,
|
||||
translate('OpenLP.MainWindow', 'OpenLP Version Updated'),
|
||||
version_text % (version, app_version),
|
||||
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok),
|
||||
QtGui.QMessageBox.Ok)
|
||||
version_text % (version, self.applicationVersion[u'full']))
|
||||
|
||||
def show(self):
|
||||
"""
|
||||
Show the main form, as well as the display form
|
||||
"""
|
||||
QtGui.QWidget.show(self)
|
||||
#screen_number = self.getMonitorNumber()
|
||||
self.displayManager.setup()
|
||||
if self.displayManager.mainDisplay.isVisible():
|
||||
self.displayManager.mainDisplay.setFocus()
|
||||
@ -749,13 +689,6 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
'The Main Display has been blanked out'))
|
||||
settings.endGroup()
|
||||
|
||||
def versionThread(self):
|
||||
"""
|
||||
Start an initial setup thread to delay notifications
|
||||
"""
|
||||
vT = VersionThread(self, self.applicationVersion)
|
||||
vT.start()
|
||||
|
||||
def onHelpWebSiteClicked(self):
|
||||
"""
|
||||
Load the OpenLP website
|
||||
@ -783,35 +716,28 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
|
||||
"""
|
||||
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):
|
||||
"""
|
||||
Put OpenLP into "Setup" view mode.
|
||||
"""
|
||||
self.MediaManagerDock.setVisible(True)
|
||||
self.ServiceManagerDock.setVisible(True)
|
||||
self.ThemeManagerDock.setVisible(False)
|
||||
self.setPreviewPanelVisibility(True)
|
||||
self.setLivePanelVisibility(False)
|
||||
self.setViewMode(True, True, False, True, False)
|
||||
|
||||
def onModeLiveItemClicked(self):
|
||||
"""
|
||||
Put OpenLP into "Live" view mode.
|
||||
"""
|
||||
self.MediaManagerDock.setVisible(False)
|
||||
self.ServiceManagerDock.setVisible(True)
|
||||
self.ThemeManagerDock.setVisible(False)
|
||||
self.setPreviewPanelVisibility(False)
|
||||
self.setLivePanelVisibility(True)
|
||||
self.setViewMode(False, True, False, False, True)
|
||||
|
||||
def setViewMode(self, media=True, service=True, theme=True, preview=True,
|
||||
live=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):
|
||||
"""
|
||||
|
@ -27,20 +27,66 @@
|
||||
The :mod:`utils` module provides the utility libraries for OpenLP
|
||||
"""
|
||||
|
||||
import os
|
||||
import sys
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import time
|
||||
import urllib2
|
||||
from datetime import datetime
|
||||
|
||||
from PyQt4 import QtGui, QtCore
|
||||
|
||||
import openlp
|
||||
from openlp.core.lib import translate
|
||||
from openlp.core.lib import Receiver, translate
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
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):
|
||||
"""
|
||||
The :class:`AppLocation` class is a static class which retrieves a
|
||||
|
Loading…
Reference in New Issue
Block a user