More cleanups

This commit is contained in:
Raoul Snyman 2013-02-01 22:36:27 +02:00
parent 18034a2f6a
commit 439fc9b8f0
10 changed files with 192 additions and 38 deletions

View File

@ -26,6 +26,9 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
The file rename dialog.
"""
from PyQt4 import QtGui
@ -33,11 +36,15 @@ from filerenamedialog import Ui_FileRenameDialog
from openlp.core.lib import translate
class FileRenameForm(QtGui.QDialog, Ui_FileRenameDialog):
"""
The exception dialog
The file rename dialog
"""
def __init__(self, parent):
"""
Constructor
"""
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)

View File

@ -26,7 +26,9 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
This module contains the first time wizard.
"""
import io
import logging
import os
@ -45,14 +47,15 @@ from firsttimewizard import Ui_FirstTimeWizard, FirstTimePage
log = logging.getLogger(__name__)
class ThemeScreenshotThread(QtCore.QThread):
"""
This thread downloads the theme screenshots.
"""
def __init__(self, parent):
QtCore.QThread.__init__(self, parent)
def run(self):
"""
Overridden method to run the thread.
"""
themes = self.parent().config.get(u'themes', u'files')
themes = themes.split(u',')
config = self.parent().config
@ -79,7 +82,10 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
log.info(u'ThemeWizardForm loaded')
def __init__(self, screens, parent=None):
QtGui.QWizard.__init__(self, parent)
"""
Create and set up the first time wizard.
"""
super(FirstTimeForm, self).__init__(parent)
self.setupUi(self)
self.screens = screens
# check to see if we have web access
@ -297,11 +303,20 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
screenshot)))
def _getFileSize(self, url):
"""
Get the size of a file.
``url``
The URL of the file we want to download.
"""
site = urllib.urlopen(url)
meta = site.info()
return int(meta.getheaders("Content-Length")[0])
def _downloadProgress(self, count, block_size):
"""
Calculate and display the download progress.
"""
increment = (count * block_size) - self.previous_size
self._incrementProgressBar(None, increment)
self.previous_size = count * block_size
@ -459,5 +474,8 @@ class FirstTimeForm(QtGui.QWizard, Ui_FirstTimeWizard):
Settings().setValue(u'themes/global theme', self.themeComboBox.currentText())
def _setPluginStatus(self, field, tag):
"""
Set the status of a plugin.
"""
status = PluginStatus.Active if field.checkState() == QtCore.Qt.Checked else PluginStatus.Inactive
Settings().setValue(tag, status)

View File

@ -26,14 +26,23 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
The UI widgets of the language selection dialog.
"""
from PyQt4 import QtGui
from openlp.core.lib import translate
from openlp.core.lib.ui import create_button_box
class Ui_FirstTimeLanguageDialog(object):
"""
The UI widgets of the language selection dialog.
"""
def setupUi(self, languageDialog):
"""
Set up the UI.
"""
languageDialog.setObjectName(u'languageDialog')
languageDialog.resize(300, 50)
self.dialogLayout = QtGui.QVBoxLayout(languageDialog)
@ -59,6 +68,9 @@ class Ui_FirstTimeLanguageDialog(object):
self.setMaximumHeight(self.sizeHint().height())
def retranslateUi(self, languageDialog):
"""
Translate the UI on the fly.
"""
self.setWindowTitle(translate('OpenLP.FirstTimeLanguageForm', 'Select Translation'))
self.infoLabel.setText(
translate('OpenLP.FirstTimeLanguageForm', 'Choose the translation you\'d like to use in OpenLP.'))

View File

@ -26,18 +26,24 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
The language selection dialog.
"""
from PyQt4 import QtGui
from openlp.core.lib.ui import create_action
from openlp.core.utils import LanguageManager
from firsttimelanguagedialog import Ui_FirstTimeLanguageDialog
class FirstTimeLanguageForm(QtGui.QDialog, Ui_FirstTimeLanguageDialog):
"""
The exception dialog
The language selection dialog.
"""
def __init__(self, parent=None):
"""
Constructor
"""
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
self.qmList = LanguageManager.get_qm_list()
@ -52,6 +58,9 @@ class FirstTimeLanguageForm(QtGui.QDialog, Ui_FirstTimeLanguageDialog):
return QtGui.QDialog.exec_(self)
def accept(self):
"""
Run when the dialog is OKed.
"""
# It's the first row so must be Automatic
if self.languageComboBox.currentIndex() == 0:
LanguageManager.auto_language = True
@ -63,6 +72,9 @@ class FirstTimeLanguageForm(QtGui.QDialog, Ui_FirstTimeLanguageDialog):
return QtGui.QDialog.accept(self)
def reject(self):
"""
Run when the dialog is canceled.
"""
LanguageManager.auto_language = True
LanguageManager.set_language(False, False)
return QtGui.QDialog.reject(self)

View File

@ -26,7 +26,9 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
The UI widgets for the first time wizard.
"""
from PyQt4 import QtCore, QtGui
import sys
@ -34,7 +36,11 @@ import sys
from openlp.core.lib import translate
from openlp.core.lib.ui import add_welcome_page
class FirstTimePage(object):
"""
An enumeration class with each of the pages of the wizard.
"""
Welcome = 0
Plugins = 1
NoInternet = 2
@ -46,13 +52,19 @@ class FirstTimePage(object):
class Ui_FirstTimeWizard(object):
"""
The UI widgets for the first time wizard.
"""
def setupUi(self, FirstTimeWizard):
"""
Set up the UI.
"""
FirstTimeWizard.setObjectName(u'FirstTimeWizard')
FirstTimeWizard.resize(550, 386)
FirstTimeWizard.setModal(True)
FirstTimeWizard.setWizardStyle(QtGui.QWizard.ModernStyle)
FirstTimeWizard.setOptions(QtGui.QWizard.IndependentPages | QtGui.QWizard.NoBackButtonOnStartPage |
QtGui.QWizard.NoBackButtonOnLastPage |QtGui.QWizard.HaveCustomButton1)
QtGui.QWizard.NoBackButtonOnLastPage | QtGui.QWizard.HaveCustomButton1)
self.finishButton = self.button(QtGui.QWizard.FinishButton)
self.noInternetFinishButton = self.button(QtGui.QWizard.CustomButton1)
self.cancelButton = self.button(QtGui.QWizard.CancelButton)
@ -193,17 +205,20 @@ class Ui_FirstTimeWizard(object):
self.retranslateUi(FirstTimeWizard)
def retranslateUi(self, FirstTimeWizard):
"""
Translate the UI on the fly
"""
FirstTimeWizard.setWindowTitle(translate(
'OpenLP.FirstTimeWizard', 'First Time Wizard'))
self.titleLabel.setText(u'<span style="font-size:14pt; font-weight:600;">%s</span>' % \
self.titleLabel.setText(u'<span style="font-size:14pt; font-weight:600;">%s</span>' %
translate('OpenLP.FirstTimeWizard', 'Welcome to the First Time Wizard'))
self.informationLabel.setText(translate('OpenLP.FirstTimeWizard',
'This wizard will help you to configure OpenLP for initial use.'
' Click the next button below to start.'))
self.pluginPage.setTitle(translate('OpenLP.FirstTimeWizard', 'Activate required Plugins'))
self.pluginPage.setSubTitle(translate('OpenLP.FirstTimeWizard','Select the Plugins you wish to use. '))
self.pluginPage.setSubTitle(translate('OpenLP.FirstTimeWizard', 'Select the Plugins you wish to use. '))
self.songsCheckBox.setText(translate('OpenLP.FirstTimeWizard', 'Songs'))
self.customCheckBox.setText(translate('OpenLP.FirstTimeWizard','Custom Slides'))
self.customCheckBox.setText(translate('OpenLP.FirstTimeWizard', 'Custom Slides'))
self.bibleCheckBox.setText(translate('OpenLP.FirstTimeWizard', 'Bible'))
self.imageCheckBox.setText(translate('OpenLP.FirstTimeWizard', 'Images'))
# TODO Presentation plugin is not yet working on Mac OS X.

View File

@ -26,7 +26,9 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
The UI widgets for the formatting tags window.
"""
from PyQt4 import QtCore, QtGui
from openlp.core.lib import translate, UiStrings
@ -34,8 +36,13 @@ from openlp.core.lib.ui import create_button_box
class Ui_FormattingTagDialog(object):
"""
The UI widgets for the formatting tags window.
"""
def setupUi(self, formattingTagDialog):
"""
Set up the UI
"""
formattingTagDialog.setObjectName(u'formattingTagDialog')
formattingTagDialog.resize(725, 548)
self.listdataGridLayout = QtGui.QGridLayout(formattingTagDialog)
@ -116,6 +123,9 @@ class Ui_FormattingTagDialog(object):
self.retranslateUi(formattingTagDialog)
def retranslateUi(self, formattingTagDialog):
"""
Translate the UI on the fly
"""
formattingTagDialog.setWindowTitle(translate('OpenLP.FormattingTagDialog', 'Configure Formatting Tags'))
self.editGroupBox.setTitle(translate('OpenLP.FormattingTagDialog', 'Edit Selection'))
self.savePushButton.setText(translate('OpenLP.FormattingTagDialog', 'Save'))

View File

@ -27,10 +27,9 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
The :mod:`formattingtagform` provides an Tag Edit facility. The Base set are
protected and included each time loaded. Custom tags can be defined and saved.
The Custom Tag arrays are saved in a pickle so QSettings works on them. Base
Tags cannot be changed.
The :mod:`formattingtagform` provides an Tag Edit facility. The Base set are protected and included each time loaded.
Custom tags can be defined and saved. The Custom Tag arrays are saved in a pickle so QSettings works on them. Base Tags
cannot be changed.
"""
from PyQt4 import QtCore, QtGui
@ -49,7 +48,7 @@ class FormattingTagForm(QtGui.QDialog, Ui_FormattingTagDialog):
"""
QtGui.QDialog.__init__(self, parent)
self.setupUi(self)
QtCore.QObject.connect(self.tagTableWidget, QtCore.SIGNAL(u'itemSelectionChanged()'),self.onRowSelected)
QtCore.QObject.connect(self.tagTableWidget, QtCore.SIGNAL(u'itemSelectionChanged()'), self.onRowSelected)
QtCore.QObject.connect(self.newPushButton, QtCore.SIGNAL(u'clicked()'), self.onNewClicked)
QtCore.QObject.connect(self.savePushButton, QtCore.SIGNAL(u'clicked()'), self.onSavedClicked)
QtCore.QObject.connect(self.deletePushButton, QtCore.SIGNAL(u'clicked()'), self.onDeleteClicked)

View File

@ -26,6 +26,9 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
The general tab of the configuration dialog.
"""
import logging
from PyQt4 import QtCore, QtGui
@ -34,6 +37,7 @@ from openlp.core.lib import Receiver, Settings, SettingsTab, translate, ScreenLi
log = logging.getLogger(__name__)
class GeneralTab(SettingsTab):
"""
GeneralTab is the general settings tab in the settings dialog.

View File

@ -27,12 +27,16 @@
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
The :mod:`maindisplay` module provides the functionality to display screens
and play multimedia within OpenLP.
The :mod:`maindisplay` module provides the functionality to display screens and play multimedia within OpenLP.
Some of the code for this form is based on the examples at:
* `http://www.steveheffernan.com/html5-video-player/demo-video-player.html`_
* `http://html5demos.com/two-videos`_
"""
import cgi
import logging
import os
import sys
from PyQt4 import QtCore, QtGui, QtWebKit, QtOpenGL
@ -47,8 +51,6 @@ from openlp.core.ui import HideMode, AlertLocation
log = logging.getLogger(__name__)
#http://www.steveheffernan.com/html5-video-player/demo-video-player.html
#http://html5demos.com/two-videos
class Display(QtGui.QGraphicsView):
"""
@ -57,6 +59,9 @@ class Display(QtGui.QGraphicsView):
Preview display.
"""
def __init__(self, parent, live, controller):
"""
Constructor
"""
if live:
QtGui.QGraphicsView.__init__(self)
# Overwrite the parent() method.
@ -101,6 +106,9 @@ class Display(QtGui.QGraphicsView):
QtCore.Qt.ScrollBarAlwaysOff)
def resizeEvent(self, event):
"""
React to resizing of this display
"""
self.webView.setGeometry(0, 0, self.width(), self.height())
def isWebLoaded(self):
@ -116,6 +124,9 @@ class MainDisplay(Display):
This is the display screen as a specialized class from the Display class
"""
def __init__(self, parent, live, controller):
"""
Constructor
"""
Display.__init__(self, parent, live, controller)
self.screens = ScreenList()
self.rebuildCSS = False
@ -153,6 +164,9 @@ class MainDisplay(Display):
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_updated'), self.configChanged)
def setTransparency(self, enabled):
"""
Set the transparency of the window
"""
if enabled:
self.setAutoFillBackground(False)
else:
@ -386,7 +400,9 @@ class MainDisplay(Display):
BackgroundType.to_string(BackgroundType.Transparent))
if self.serviceItem.themedata.background_filename:
self.serviceItem.bg_image_bytes = self.image_manager.getImageBytes(
self.serviceItem.themedata.background_filename,ImageSource.Theme)
self.serviceItem.themedata.background_filename,
ImageSource.Theme
)
if image_path:
image_bytes = self.image_manager.getImageBytes(image_path, ImageSource.ImagePlugin)
else:
@ -532,6 +548,9 @@ class AudioPlayer(QtCore.QObject):
self.mediaObject.enqueue(self.playlist[self.currentIndex])
def onFinished(self):
"""
When the audio track finishes.
"""
if self.repeat:
log.debug(u'Repeat is enabled... here we go again!')
self.mediaObject.clearQueue()
@ -540,6 +559,9 @@ class AudioPlayer(QtCore.QObject):
self.play()
def connectVolumeSlider(self, slider):
"""
Connect the volume slider to the output channel.
"""
slider.setAudioOutput(self.audioObject)
def reset(self):
@ -586,6 +608,9 @@ class AudioPlayer(QtCore.QObject):
self.playlist.extend(map(Phonon.MediaSource, filenames))
def next(self):
"""
Skip forward to the next track in the list
"""
if not self.repeat and self.currentIndex + 1 >= len(self.playlist):
return
isPlaying = self.mediaObject.state() == Phonon.PlayingState
@ -599,6 +624,9 @@ class AudioPlayer(QtCore.QObject):
self.mediaObject.play()
def goTo(self, index):
"""
Go to a particular track in the list
"""
isPlaying = self.mediaObject.state() == Phonon.PlayingState
self.mediaObject.clearQueue()
self.mediaObject.clear()
@ -609,5 +637,7 @@ class AudioPlayer(QtCore.QObject):
#@todo is this used?
def connectSlot(self, signal, slot):
"""
Connect a slot to a signal on the media object
"""
QtCore.QObject.connect(self.mediaObject, signal, slot)

View File

@ -26,7 +26,9 @@
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
"""
This is the main window, where all the action happens.
"""
import logging
import os
import sys
@ -80,6 +82,9 @@ PROGRESSBAR_STYLE = """
class Ui_MainWindow(object):
"""
This is the UI part of the main window.
"""
def setupUi(self, mainWindow):
"""
Set up the user interface
@ -148,7 +153,7 @@ class Ui_MainWindow(object):
self.defaultThemeLabel.setObjectName(u'defaultThemeLabel')
self.statusBar.addPermanentWidget(self.defaultThemeLabel)
# Create the MediaManager
self.mediaManagerDock = OpenLPDockWidget(mainWindow,u'mediaManagerDock', u':/system/system_mediamanager.png')
self.mediaManagerDock = OpenLPDockWidget(mainWindow, u'mediaManagerDock', u':/system/system_mediamanager.png')
self.mediaManagerDock.setStyleSheet(MEDIA_MANAGER_STYLE)
# Create the media toolbox
self.mediaToolBox = QtGui.QToolBox(self.mediaManagerDock)
@ -406,7 +411,8 @@ class Ui_MainWindow(object):
'Toggle the visibility of the service manager.'))
self.viewPreviewPanel.setText(translate('OpenLP.MainWindow', '&Preview Panel'))
self.viewPreviewPanel.setToolTip(translate('OpenLP.MainWindow', 'Toggle Preview Panel'))
self.viewPreviewPanel.setStatusTip(translate('OpenLP.MainWindow', 'Toggle the visibility of the preview panel.'))
self.viewPreviewPanel.setStatusTip(
translate('OpenLP.MainWindow', 'Toggle the visibility of the preview panel.'))
self.viewLivePanel.setText(translate('OpenLP.MainWindow', '&Live Panel'))
self.viewLivePanel.setToolTip(translate('OpenLP.MainWindow', 'Toggle Live Panel'))
self.lockPanel.setText(translate('OpenLP.MainWindow', 'L&ock Panels'))
@ -517,7 +523,7 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.onSettingsShortcutsItemClicked)
QtCore.QObject.connect(self.settingsImportItem, QtCore.SIGNAL(u'triggered()'),
self.onSettingsImportItemClicked)
QtCore.QObject.connect(self.settingsExportItem,QtCore.SIGNAL(u'triggered()'), self.onSettingsExportItemClicked)
QtCore.QObject.connect(self.settingsExportItem, QtCore.SIGNAL(u'triggered()'), self.onSettingsExportItemClicked)
# i18n set signals for languages
self.languageGroup.triggered.connect(LanguageManager.set_language)
QtCore.QObject.connect(self.modeDefaultItem, QtCore.SIGNAL(u'triggered()'), self.onModeDefaultItemClicked)
@ -527,7 +533,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'openlp_version_check'), self.versionNotice)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'live_display_blank_check'), self.blankCheck)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'config_screen_changed'), self.screenChanged)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'mainwindow_status_text'), self.showStatusMessage)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'mainwindow_status_text'),
self.showStatusMessage)
QtCore.QObject.connect(Receiver.get_receiver(), QtCore.SIGNAL(u'cleanup'), self.clean_up)
# Media Manager
QtCore.QObject.connect(self.mediaToolBox, QtCore.SIGNAL(u'currentChanged(int)'), self.onMediaToolBoxChanged)
@ -583,11 +590,17 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
Receiver.send_message(u'cursor_normal')
def setAutoLanguage(self, value):
"""
Set the language to automatic.
"""
self.languageGroup.setDisabled(value)
LanguageManager.auto_language = value
LanguageManager.set_language(self.languageGroup.checkedAction())
def onMediaToolBoxChanged(self, index):
"""
Focus a widget when the media toolbox changes.
"""
widget = self.mediaToolBox.widget(index)
if widget:
widget.onFocus()
@ -642,7 +655,9 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
Receiver.send_message(u'openlp_process_events')
def firstTime(self):
# Import themes if first time
"""
Import themes if first time
"""
Receiver.send_message(u'openlp_process_events')
for plugin in self.pluginManager.plugins:
if hasattr(plugin, u'firstTime'):
@ -705,14 +720,23 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
translate('OpenLP.MainWindow', 'The Main Display has been blanked out'))
def onErrorMessage(self, data):
"""
Display an error message
"""
Receiver.send_message(u'close_splash')
QtGui.QMessageBox.critical(self, data[u'title'], data[u'message'])
def onWarningMessage(self, data):
"""
Display a warning message
"""
Receiver.send_message(u'close_splash')
QtGui.QMessageBox.warning(self, data[u'title'], data[u'message'])
def onInformationMessage(self, data):
"""
Display an informational message
"""
Receiver.send_message(u'close_splash')
QtGui.QMessageBox.information(self, data[u'title'], data[u'message'])
@ -800,8 +824,8 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
QtGui.QMessageBox.No)
if answer == QtGui.QMessageBox.No:
return
import_file_name = QtGui.QFileDialog.getOpenFileName(self,translate('OpenLP.MainWindow', 'Open File'), '',
translate('OpenLP.MainWindow', 'OpenLP Export Settings Files (*.conf)'))
import_file_name = QtGui.QFileDialog.getOpenFileName(self, translate('OpenLP.MainWindow', 'Open File'), '',
translate('OpenLP.MainWindow', 'OpenLP Export Settings Files (*.conf)'))
if not import_file_name:
return
setting_sections = []
@ -1100,18 +1124,33 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
self.setWindowTitle(title)
def showStatusMessage(self, message):
"""
Show a message in the status bar
"""
self.statusBar.showMessage(message)
def defaultThemeChanged(self, theme):
"""
Update the default theme indicator in the status bar
"""
self.defaultThemeLabel.setText(translate('OpenLP.MainWindow', 'Default Theme: %s') % theme)
def toggleMediaManager(self):
"""
Toggle the visibility of the media manager
"""
self.mediaManagerDock.setVisible(not self.mediaManagerDock.isVisible())
def toggleServiceManager(self):
"""
Toggle the visibility of the service manager
"""
self.serviceManagerDock.setVisible(not self.serviceManagerDock.isVisible())
def toggleThemeManager(self):
"""
Toggle the visibility of the theme manager
"""
self.themeManagerDock.setVisible(not self.themeManagerDock.isVisible())
def setPreviewPanelVisibility(self, visible):
@ -1295,13 +1334,22 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
Receiver.send_message(u'openlp_process_events')
def setNewDataPath(self, new_data_path):
"""
Set the new data path
"""
self.newDataPath = new_data_path
def setCopyData(self, copy_data):
"""
Set the flag to copy the data
"""
self.copyData = copy_data
def changeDataDirectory(self):
log.info(u'Changing data path to %s' % self.newDataPath )
"""
Change the data directory.
"""
log.info(u'Changing data path to %s' % self.newDataPath)
old_data_path = unicode(AppLocation.get_data_path())
# Copy OpenLP data to new location if requested.
if self.copyData:
@ -1330,4 +1378,3 @@ class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
# Check if the new data path is our default.
if self.newDataPath == AppLocation.get_directory(AppLocation.DataDir):
settings.remove(u'advanced/data path')