openlp/openlp/core/ui/mainwindow.py

1383 lines
67 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2012-12-29 13:15:42 +00:00
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2012-12-29 20:56:56 +00:00
# Copyright (c) 2008-2013 Raoul Snyman #
# Portions copyright (c) 2008-2013 Tim Bentley, Gerald Britton, Jonathan #
# Corwin, Samuel Findlay, Michael Gorven, Scott Guerrieri, Matthias Hub, #
2012-11-11 21:16:14 +00:00
# Meinert Jordan, Armin Köhler, Erik Lundin, Edwin Lunando, Brian T. Meyer. #
2012-10-21 13:16:22 +00:00
# Joshua Miller, Stevan Pettit, Andreas Preikschat, Mattias Põldaru, #
# Christian Richter, Philip Ridout, Simon Scudder, Jeffrey Smith, #
# Maikel Stuivenberg, Martin Thompson, Jon Tibble, Dave Warnock, #
# Frode Woldsund, Martin Zibricky, Patrick Zimmermann #
# --------------------------------------------------------------------------- #
# This program is free software; you can redistribute it and/or modify it #
# under the terms of the GNU General Public License as published by the Free #
# Software Foundation; version 2 of the License. #
# #
# This program is distributed in the hope that it will be useful, but WITHOUT #
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
# more details. #
# #
# You should have received a copy of the GNU General Public License along #
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
###############################################################################
2013-02-01 20:36:27 +00:00
"""
This is the main window, where all the action happens.
"""
import logging
import os
import sys
import shutil
from distutils import dir_util
from distutils.errors import DistutilsFileError
from tempfile import gettempdir
2012-05-26 17:51:27 +00:00
import time
from datetime import datetime
from PyQt4 import QtCore, QtGui
2013-02-07 08:42:17 +00:00
from openlp.core.lib import Renderer, OpenLPDockWidget, PluginManager, ImageManager, PluginStatus, Registry, \
2013-02-05 08:10:50 +00:00
Settings, ScreenList, build_icon, check_directory_exists, translate
from openlp.core.lib.ui import UiStrings, create_action
2012-12-29 13:15:42 +00:00
from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, ThemeManager, SlideController, PluginForm, \
MediaDockManager, ShortcutListForm, FormattingTagForm
2011-08-29 21:51:03 +00:00
from openlp.core.ui.media import MediaController
2013-02-05 08:05:28 +00:00
from openlp.core.utils import AppLocation, LanguageManager, add_actions, get_application_version, \
2012-12-29 13:15:42 +00:00
get_filesystem_encoding
2011-04-09 16:11:02 +00:00
from openlp.core.utils.actions import ActionList, CategoryOrder
from openlp.core.ui.firsttimeform import FirstTimeForm
2010-02-27 15:31:23 +00:00
log = logging.getLogger(__name__)
2010-07-07 14:44:22 +00:00
MEDIA_MANAGER_STYLE = """
2010-07-22 19:55:09 +00:00
QToolBox {
padding-bottom: 2px;
}
QToolBox::tab {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
2010-07-22 20:01:03 +00:00
stop: 0 palette(button), stop: 0.5 palette(button),
stop: 1.0 palette(mid));
border: 1px groove palette(mid);
border-radius: 5px;
}
QToolBox::tab:selected {
background: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
2010-07-22 20:01:03 +00:00
stop: 0 palette(light), stop: 0.5 palette(midlight),
stop: 1.0 palette(dark));
border: 1px groove palette(dark);
font-weight: bold;
}
"""
2010-02-02 20:05:21 +00:00
2011-06-29 06:12:32 +00:00
PROGRESSBAR_STYLE = """
2011-06-28 16:40:17 +00:00
QProgressBar{
height: 10px;
}
"""
2009-08-09 17:58:37 +00:00
class Ui_MainWindow(object):
2013-02-01 20:36:27 +00:00
"""
This is the UI part of the main window.
"""
def setupUi(self, main_window):
"""
Set up the user interface
"""
main_window.setObjectName(u'MainWindow')
main_window.setWindowIcon(build_icon(u':/icon/openlp-logo-64x64.png'))
main_window.setDockNestingEnabled(True)
2010-12-26 14:44:07 +00:00
# Set up the main container, which contains all the other form widgets.
2013-03-16 11:05:52 +00:00
self.main_content = QtGui.QWidget(main_window)
self.main_content.setObjectName(u'main_content')
self.main_contentLayout = QtGui.QHBoxLayout(self.main_content)
self.main_contentLayout.setSpacing(0)
self.main_contentLayout.setMargin(0)
self.main_contentLayout.setObjectName(u'main_contentLayout')
main_window.setCentralWidget(self.main_content)
self.controlSplitter = QtGui.QSplitter(self.main_content)
2011-02-07 22:07:48 +00:00
self.controlSplitter.setOrientation(QtCore.Qt.Horizontal)
self.controlSplitter.setObjectName(u'controlSplitter')
2013-03-16 11:05:52 +00:00
self.main_contentLayout.addWidget(self.controlSplitter)
# Create slide controllers
2013-02-18 20:41:08 +00:00
self.preview_controller = SlideController(self)
2013-02-18 19:59:35 +00:00
self.live_controller = SlideController(self, True)
2013-03-16 11:05:52 +00:00
preview_visible = Settings().value(u'user interface/preview panel')
self.preview_controller.panel.setVisible(preview_visible)
live_visible = Settings().value(u'user interface/live panel')
panel_locked = Settings().value(u'user interface/lock panel')
self.live_controller.panel.setVisible(live_visible)
# Create menu
self.menuBar = QtGui.QMenuBar(main_window)
2011-05-25 07:59:51 +00:00
self.menuBar.setObjectName(u'menuBar')
2013-03-16 11:05:52 +00:00
self.file_menu = QtGui.QMenu(self.menuBar)
self.file_menu.setObjectName(u'fileMenu')
self.recent_files_menu = QtGui.QMenu(self.file_menu)
self.recent_files_menu.setObjectName(u'recentFilesMenu')
self.file_import_menu = QtGui.QMenu(self.file_menu)
2013-02-18 20:57:14 +00:00
self.file_import_menu.setObjectName(u'file_import_menu')
2013-03-16 11:05:52 +00:00
self.file_export_menu = QtGui.QMenu(self.file_menu)
2013-02-18 20:57:14 +00:00
self.file_export_menu.setObjectName(u'file_export_menu')
2010-07-03 20:39:29 +00:00
# View Menu
2013-03-16 11:05:52 +00:00
self.view_menu = QtGui.QMenu(self.menuBar)
self.view_menu.setObjectName(u'viewMenu')
self.view_modeMenu = QtGui.QMenu(self.view_menu)
self.view_modeMenu.setObjectName(u'viewModeMenu')
2010-07-03 20:39:29 +00:00
# Tools Menu
2013-02-18 20:57:14 +00:00
self.tools_menu = QtGui.QMenu(self.menuBar)
self.tools_menu.setObjectName(u'tools_menu')
2010-07-03 20:39:29 +00:00
# Settings Menu
2013-03-16 11:05:52 +00:00
self.settings_menu = QtGui.QMenu(self.menuBar)
self.settings_menu.setObjectName(u'settingsMenu')
self.settings_language_menu = QtGui.QMenu(self.settings_menu)
self.settings_language_menu.setObjectName(u'settingsLanguageMenu')
2010-07-03 20:39:29 +00:00
# Help Menu
2013-03-16 11:05:52 +00:00
self.help_menu = QtGui.QMenu(self.menuBar)
self.help_menu.setObjectName(u'helpMenu')
main_window.setMenuBar(self.menuBar)
2013-03-16 11:05:52 +00:00
self.status_bar = QtGui.QStatusBar(main_window)
self.status_bar.setObjectName(u'status_bar')
main_window.setStatusBar(self.status_bar)
self.load_progress_bar = QtGui.QProgressBar(self.status_bar)
self.load_progress_bar.setObjectName(u'load_progress_bar')
self.status_bar.addPermanentWidget(self.load_progress_bar)
self.load_progress_bar.hide()
self.load_progress_bar.setValue(0)
self.load_progress_bar.setStyleSheet(PROGRESSBAR_STYLE)
self.default_theme_label = QtGui.QLabel(self.status_bar)
self.default_theme_label.setObjectName(u'default_theme_label')
self.status_bar.addPermanentWidget(self.default_theme_label)
# Create the MediaManager
2013-03-16 11:05:52 +00:00
self.media_manager_dock = OpenLPDockWidget(main_window, u'media_manager_dock',
u':/system/system_mediamanager.png')
self.media_manager_dock.setStyleSheet(MEDIA_MANAGER_STYLE)
# Create the media toolbox
2013-03-16 11:05:52 +00:00
self.media_tool_box = QtGui.QToolBox(self.media_manager_dock)
self.media_tool_box.setObjectName(u'media_tool_box')
self.media_manager_dock.setWidget(self.media_tool_box)
main_window.addDockWidget(QtCore.Qt.LeftDockWidgetArea, self.media_manager_dock)
# Create the service manager
2013-03-16 11:05:52 +00:00
self.service_manager_dock = OpenLPDockWidget(main_window, u'service_manager_dock',
2012-12-29 13:15:42 +00:00
u':/system/system_servicemanager.png')
2013-03-16 11:05:52 +00:00
self.service_manager_contents = ServiceManager(self.service_manager_dock)
self.service_manager_dock.setWidget(self.service_manager_contents)
main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.service_manager_dock)
# Create the theme manager
2013-03-16 11:05:52 +00:00
self.theme_manager_dock = OpenLPDockWidget(main_window, u'theme_manager_dock',
u':/system/system_thememanager.png')
self.theme_manager_contents = ThemeManager(self.theme_manager_dock)
self.theme_manager_contents.setObjectName(u'theme_manager_contents')
self.theme_manager_dock.setWidget(self.theme_manager_contents)
main_window.addDockWidget(QtCore.Qt.RightDockWidgetArea, self.theme_manager_dock)
# Create the menu items
2011-04-09 16:11:02 +00:00
action_list = ActionList.get_instance()
action_list.add_category(UiStrings().File, CategoryOrder.standard_menu)
2013-03-16 11:05:52 +00:00
self.file_new_item = create_action(main_window, u'fileNewItem',
icon=u':/general/general_new.png',
can_shortcuts=True,
category=UiStrings().File,
2013-03-16 11:05:52 +00:00
triggers=self.service_manager_contents.on_new_service_clicked)
self.file_open_item = create_action(main_window, u'fileOpenItem',
icon=u':/general/general_open.png',
can_shortcuts=True,
category=UiStrings().File,
2013-03-16 11:05:52 +00:00
triggers=self.service_manager_contents.on_load_service_clicked)
self.file_save_item = create_action(main_window, u'fileSaveItem',
icon=u':/general/general_save.png',
can_shortcuts=True,
category=UiStrings().File,
2013-03-16 11:05:52 +00:00
triggers=self.service_manager_contents.save_file)
self.file_save_as_item = create_action(main_window, u'fileSaveAsItem',
can_shortcuts=True,
category=UiStrings().File,
2013-03-16 11:05:52 +00:00
triggers=self.service_manager_contents.save_file_as)
self.print_service_order_item = create_action(main_window,
2013-02-19 09:33:07 +00:00
u'printServiceItem', can_shortcuts=True,
category=UiStrings().File,
2013-03-16 11:05:52 +00:00
triggers=self.service_manager_contents.print_service_order)
self.file_exit_item = create_action(main_window, u'fileExitItem',
icon=u':/system/system_exit.png',
can_shortcuts=True,
category=UiStrings().File, triggers=main_window.close)
# Give QT Extra Hint that this is the Exit Menu Item
2013-03-16 11:05:52 +00:00
self.file_exit_item.setMenuRole(QtGui.QAction.QuitRole)
action_list.add_category(UiStrings().Import, CategoryOrder.standard_menu)
2013-03-16 11:05:52 +00:00
self.import_theme_item = create_action(
2013-02-19 13:09:00 +00:00
main_window, u'importThemeItem', category=UiStrings().Import, can_shortcuts=True)
2013-03-16 11:05:52 +00:00
self.import_language_item = create_action(main_window, u'importLanguageItem')
action_list.add_category(UiStrings().Export, CategoryOrder.standard_menu)
2013-03-16 11:05:52 +00:00
self.export_theme_item = create_action(
2013-02-19 13:09:00 +00:00
main_window, u'exportThemeItem', category=UiStrings().Export, can_shortcuts=True)
2013-03-16 11:05:52 +00:00
self.export_language_item = create_action(main_window, u'exportLanguageItem')
action_list.add_category(UiStrings().View, CategoryOrder.standard_menu)
2013-03-16 11:05:52 +00:00
self.view_media_manager_item = create_action(main_window,
u'viewMediaManagerItem',
icon=u':/system/system_mediamanager.png',
2013-03-16 11:05:52 +00:00
checked=self.media_manager_dock.isVisible(),
can_shortcuts=True,
2013-03-16 11:05:52 +00:00
category=UiStrings().View, triggers=self.toggle_media_manager)
self.view_theme_manager_item = create_action(main_window,
2013-02-19 09:33:07 +00:00
u'viewThemeManagerItem', can_shortcuts=True,
icon=u':/system/system_thememanager.png',
2013-03-16 11:05:52 +00:00
checked=self.theme_manager_dock.isVisible(),
category=UiStrings().View, triggers=self.toggle_theme_manager)
self.view_service_manager_item = create_action(main_window,
2013-02-19 09:33:07 +00:00
u'viewServiceManagerItem', can_shortcuts=True,
icon=u':/system/system_servicemanager.png',
2013-03-16 11:05:52 +00:00
checked=self.service_manager_dock.isVisible(),
category=UiStrings().View, triggers=self.toggle_service_manager)
self.view_preview_panel = create_action(main_window, u'viewPreviewPanel',
can_shortcuts=True, checked=preview_visible,
category=UiStrings().View, triggers=self.set_preview_panel_visibility)
self.view_live_panel = create_action(main_window, u'viewLivePanel',
can_shortcuts=True, checked=live_visible,
category=UiStrings().View, triggers=self.set_live_panel_visibility)
self.lockPanel = create_action(main_window, u'lockPanel',
2013-03-16 11:05:52 +00:00
can_shortcuts=True, checked=panel_locked,
category=UiStrings().View,
2013-03-16 11:05:52 +00:00
triggers=self.set_lock_panel)
2013-02-19 13:09:00 +00:00
action_list.add_category(UiStrings().ViewMode, CategoryOrder.standard_menu)
2013-03-16 11:05:52 +00:00
self.mode_default_Item = create_action(
2013-02-19 13:09:00 +00:00
main_window, u'modeDefaultItem', checked=False, category=UiStrings().ViewMode, can_shortcuts=True)
2013-03-16 11:05:52 +00:00
self.mode_setup_item = create_action(
2013-02-19 13:09:00 +00:00
main_window, u'modeSetupItem', checked=False, category=UiStrings().ViewMode, can_shortcuts=True)
2013-03-16 11:05:52 +00:00
self.mode_live_item = create_action(
2013-02-19 13:09:00 +00:00
main_window, u'modeLiveItem', checked=True, category=UiStrings().ViewMode, can_shortcuts=True)
2013-03-17 20:00:39 +00:00
self.mode_group = QtGui.QActionGroup(main_window)
self.mode_group.addAction(self.mode_default_Item)
self.mode_group.addAction(self.mode_setup_item)
self.mode_group.addAction(self.mode_live_item)
2013-03-16 11:05:52 +00:00
self.mode_default_Item.setChecked(True)
action_list.add_category(UiStrings().Tools, CategoryOrder.standard_menu)
2013-03-17 20:00:39 +00:00
self.tools_add_tool_item = create_action(main_window,
2013-02-19 13:09:00 +00:00
u'toolsAddToolItem', icon=u':/tools/tools_add.png', category=UiStrings().Tools, can_shortcuts=True)
2013-03-16 11:05:52 +00:00
self.tools_open_data_folder = create_action(main_window,
2013-02-19 13:09:00 +00:00
u'toolsOpenDataFolder', icon=u':/general/general_open.png', category=UiStrings().Tools, can_shortcuts=True)
2013-03-16 11:05:52 +00:00
self.tools_first_time_wizard = create_action(main_window,
u'toolsFirstTimeWizard', icon=u':/general/general_revert.png',
2013-02-19 13:09:00 +00:00
category=UiStrings().Tools, can_shortcuts=True)
2013-03-16 11:05:52 +00:00
self.update_theme_images = create_action(main_window,
2013-02-19 13:09:00 +00:00
u'updateThemeImages', category=UiStrings().Tools, can_shortcuts=True)
action_list.add_category(UiStrings().Settings, CategoryOrder.standard_menu)
self.settingsPluginListItem = create_action(main_window,
u'settingsPluginListItem',
icon=u':/system/settings_plugin_list.png',
can_shortcuts=True,
2013-03-16 11:05:52 +00:00
category=UiStrings().Settings, triggers=self.on_plugin_item_clicked)
2010-12-26 14:44:07 +00:00
# i18n Language Items
2013-03-16 11:05:52 +00:00
self.auto_language_item = create_action(main_window, u'autoLanguageItem', checked=LanguageManager.auto_language)
self.language_group = QtGui.QActionGroup(main_window)
self.language_group.setExclusive(True)
self.language_group.setObjectName(u'languageGroup')
add_actions(self.language_group, [self.auto_language_item])
qm_list = LanguageManager.get_qm_list()
saved_language = LanguageManager.get_language()
for key in sorted(qm_list.keys()):
language_item = create_action(main_window, key, checked=qm_list[key] == saved_language)
add_actions(self.language_group, [language_item])
self.settings_shortcuts_item = create_action(main_window, u'settingsShortcutsItem',
2013-02-19 13:09:00 +00:00
icon=u':/system/system_configure_shortcuts.png', category=UiStrings().Settings, can_shortcuts=True)
2011-07-30 07:40:34 +00:00
# Formatting Tags were also known as display tags.
2013-03-16 11:05:52 +00:00
self.formatting_tag_item = create_action(main_window, u'displayTagItem',
2013-02-19 13:09:00 +00:00
icon=u':/system/tag_editor.png', category=UiStrings().Settings, can_shortcuts=True)
2013-03-16 11:05:52 +00:00
self.settings_configure_item = create_action(main_window, u'settingsConfigureItem',
icon=u':/system/system_settings.png', can_shortcuts=True, category=UiStrings().Settings)
# Give QT Extra Hint that this is the Preferences Menu Item
2013-03-16 11:05:52 +00:00
self.settings_configure_item.setMenuRole(QtGui.QAction.PreferencesRole)
self.settings_import_item = create_action(
main_window, u'settingsImportItem', category=UiStrings().Import, can_shortcuts=True)
2013-03-16 11:05:52 +00:00
self.settings_export_item = create_action(
main_window, u'settingsExportItem', category=UiStrings().Export, can_shortcuts=True)
action_list.add_category(UiStrings().Help, CategoryOrder.standard_menu)
2013-03-16 11:05:52 +00:00
self.about_item = create_action(main_window, u'aboutItem', icon=u':/system/system_about.png',
2013-02-19 13:09:00 +00:00
can_shortcuts=True, category=UiStrings().Help, triggers=self.onAboutItemClicked)
# Give QT Extra Hint that this is an About Menu Item
2013-03-16 11:05:52 +00:00
self.about_item.setMenuRole(QtGui.QAction.AboutRole)
2011-06-29 17:30:53 +00:00
if os.name == u'nt':
self.localHelpFile = os.path.join(
AppLocation.get_directory(AppLocation.AppDir), 'OpenLP.chm')
self.offlineHelpItem = create_action(main_window, u'offlineHelpItem',
icon=u':/system/system_help_contents.png',
can_shortcuts=True,
category=UiStrings().Help, triggers=self.onOfflineHelpClicked)
2013-03-16 11:05:52 +00:00
self.on_line_help_item = create_action(main_window, u'onlineHelpItem',
icon=u':/system/system_online_help.png',
can_shortcuts=True,
category=UiStrings().Help, triggers=self.onOnlineHelpClicked)
2013-03-16 11:05:52 +00:00
self.web_site_item = create_action(main_window, u'webSiteItem', can_shortcuts=True, category=UiStrings().Help)
add_actions(self.file_import_menu, (self.settings_import_item, None, self.import_theme_item,
self.import_language_item))
add_actions(self.file_export_menu, (self.settings_export_item, None, self.export_theme_item,
self.export_language_item))
add_actions(self.file_menu, (self.file_new_item, self.file_open_item,
self.file_save_item, self.file_save_as_item, self.recent_files_menu.menuAction(), None,
self.file_import_menu.menuAction(), self.file_export_menu.menuAction(), None, self.print_service_order_item,
self.file_exit_item))
add_actions(self.view_modeMenu, (self.mode_default_Item, self.mode_setup_item, self.mode_live_item))
add_actions(self.view_menu, (self.view_modeMenu.menuAction(), None, self.view_media_manager_item,
self.view_service_manager_item, self.view_theme_manager_item, None, self.view_preview_panel,
self.view_live_panel, None, self.lockPanel))
2010-12-26 14:44:07 +00:00
# i18n add Language Actions
2013-03-16 11:05:52 +00:00
add_actions(self.settings_language_menu, (self.auto_language_item, None))
add_actions(self.settings_language_menu, self.language_group.actions())
# Order things differently in OS X so that Preferences menu item in the
# app menu is correct (this gets picked up automatically by Qt).
if sys.platform == u'darwin':
2013-03-16 11:05:52 +00:00
add_actions(self.settings_menu, (self.settingsPluginListItem, self.settings_language_menu.menuAction(),
None, self.settings_configure_item, self.settings_shortcuts_item, self.formatting_tag_item))
else:
2013-03-16 11:05:52 +00:00
add_actions(self.settings_menu, (self.settingsPluginListItem, self.settings_language_menu.menuAction(),
None, self.formatting_tag_item, self.settings_shortcuts_item, self.settings_configure_item))
2013-03-17 20:00:39 +00:00
add_actions(self.tools_menu, (self.tools_add_tool_item, None))
2013-03-16 11:05:52 +00:00
add_actions(self.tools_menu, (self.tools_open_data_folder, None))
add_actions(self.tools_menu, (self.tools_first_time_wizard, None))
add_actions(self.tools_menu, [self.update_theme_images])
2011-06-29 17:30:53 +00:00
if os.name == u'nt':
2013-03-16 11:05:52 +00:00
add_actions(self.help_menu, (self.offlineHelpItem, self.on_line_help_item, None, self.web_site_item,
self.about_item))
else:
2013-03-16 11:05:52 +00:00
add_actions(self.help_menu, (self.on_line_help_item, None, self.web_site_item, self.about_item))
add_actions(self.menuBar, (self.file_menu.menuAction(), self.view_menu.menuAction(),
self.tools_menu.menuAction(), self.settings_menu.menuAction(), self.help_menu.menuAction()))
# Initialise the translation
self.retranslateUi(main_window)
2013-03-16 11:05:52 +00:00
self.media_tool_box.setCurrentIndex(0)
# Connect up some signals and slots
2013-03-16 11:05:52 +00:00
self.file_menu.aboutToShow.connect(self.update_recent_files_menu)
2011-03-15 20:53:36 +00:00
# Hide the entry, as it does not have any functionality yet.
2013-03-17 20:00:39 +00:00
self.tools_add_tool_item.setVisible(False)
2013-03-16 11:05:52 +00:00
self.import_language_item.setVisible(False)
self.export_language_item.setVisible(False)
self.set_lock_panel(panel_locked)
self.settingsImported = False
2011-01-21 19:09:56 +00:00
def retranslateUi(self, mainWindow):
"""
Set up the translation system
"""
2012-12-04 06:09:55 +00:00
mainWindow.mainTitle = UiStrings().OLPV2x
2011-01-21 19:09:56 +00:00
mainWindow.setWindowTitle(mainWindow.mainTitle)
2013-03-16 11:05:52 +00:00
self.file_menu.setTitle(translate('OpenLP.MainWindow', '&File'))
2013-02-18 20:57:14 +00:00
self.file_import_menu.setTitle(translate('OpenLP.MainWindow', '&Import'))
self.file_export_menu.setTitle(translate('OpenLP.MainWindow', '&Export'))
2013-03-16 11:05:52 +00:00
self.recent_files_menu.setTitle(translate('OpenLP.MainWindow', '&Recent Files'))
self.view_menu.setTitle(translate('OpenLP.MainWindow', '&View'))
self.view_modeMenu.setTitle(translate('OpenLP.MainWindow', 'M&ode'))
2013-02-18 20:57:14 +00:00
self.tools_menu.setTitle(translate('OpenLP.MainWindow', '&Tools'))
2013-03-16 11:05:52 +00:00
self.settings_menu.setTitle(translate('OpenLP.MainWindow', '&Settings'))
self.settings_language_menu.setTitle(translate('OpenLP.MainWindow', '&Language'))
self.help_menu.setTitle(translate('OpenLP.MainWindow', '&Help'))
self.media_manager_dock.setWindowTitle(translate('OpenLP.MainWindow', 'Media Manager'))
self.service_manager_dock.setWindowTitle(translate('OpenLP.MainWindow', 'Service Manager'))
self.theme_manager_dock.setWindowTitle(translate('OpenLP.MainWindow', 'Theme Manager'))
self.file_new_item.setText(translate('OpenLP.MainWindow', '&New'))
self.file_new_item.setToolTip(UiStrings().NewService)
self.file_new_item.setStatusTip(UiStrings().CreateService)
self.file_open_item.setText(translate('OpenLP.MainWindow', '&Open'))
self.file_open_item.setToolTip(UiStrings().OpenService)
self.file_open_item.setStatusTip(translate('OpenLP.MainWindow', 'Open an existing service.'))
self.file_save_item.setText(translate('OpenLP.MainWindow', '&Save'))
self.file_save_item.setToolTip(UiStrings().SaveService)
self.file_save_item.setStatusTip(translate('OpenLP.MainWindow', 'Save the current service to disk.'))
self.file_save_as_item.setText(translate('OpenLP.MainWindow', 'Save &As...'))
self.file_save_as_item.setToolTip(translate('OpenLP.MainWindow', 'Save Service As'))
self.file_save_as_item.setStatusTip(translate('OpenLP.MainWindow',
'Save the current service under a new name.'))
self.print_service_order_item.setText(UiStrings().PrintService)
self.print_service_order_item.setStatusTip(translate('OpenLP.MainWindow', 'Print the current service.'))
self.file_exit_item.setText(translate('OpenLP.MainWindow', 'E&xit'))
self.file_exit_item.setStatusTip(translate('OpenLP.MainWindow', 'Quit OpenLP'))
self.import_theme_item.setText(translate('OpenLP.MainWindow', '&Theme'))
self.import_language_item.setText(translate('OpenLP.MainWindow', '&Language'))
self.export_theme_item.setText(translate('OpenLP.MainWindow', '&Theme'))
self.export_language_item.setText(translate('OpenLP.MainWindow', '&Language'))
self.settings_shortcuts_item.setText(translate('OpenLP.MainWindow', 'Configure &Shortcuts...'))
self.formatting_tag_item.setText(translate('OpenLP.MainWindow', 'Configure &Formatting Tags...'))
self.settings_configure_item.setText(translate('OpenLP.MainWindow', '&Configure OpenLP...'))
self.settings_export_item.setStatusTip(translate('OpenLP.MainWindow',
2011-08-29 06:30:31 +00:00
'Export OpenLP settings to a specified *.config file'))
2013-03-16 11:05:52 +00:00
self.settings_export_item.setText(translate('OpenLP.MainWindow', 'Settings'))
self.settings_import_item.setStatusTip(translate('OpenLP.MainWindow',
2012-12-29 13:15:42 +00:00
'Import OpenLP settings from a specified *.config file previously exported on this or another machine'))
2013-03-16 11:05:52 +00:00
self.settings_import_item.setText(translate('OpenLP.MainWindow', 'Settings'))
self.view_media_manager_item.setText(translate('OpenLP.MainWindow', '&Media Manager'))
self.view_media_manager_item.setToolTip(translate('OpenLP.MainWindow', 'Toggle Media Manager'))
self.view_media_manager_item.setStatusTip(translate('OpenLP.MainWindow',
2010-07-03 20:39:29 +00:00
'Toggle the visibility of the media manager.'))
2013-03-16 11:05:52 +00:00
self.view_theme_manager_item.setText(translate('OpenLP.MainWindow', '&Theme Manager'))
self.view_theme_manager_item.setToolTip(translate('OpenLP.MainWindow', 'Toggle Theme Manager'))
self.view_theme_manager_item.setStatusTip(translate('OpenLP.MainWindow',
2010-07-03 20:39:29 +00:00
'Toggle the visibility of the theme manager.'))
2013-03-16 11:05:52 +00:00
self.view_service_manager_item.setText(translate('OpenLP.MainWindow', '&Service Manager'))
self.view_service_manager_item.setToolTip(translate('OpenLP.MainWindow', 'Toggle Service Manager'))
self.view_service_manager_item.setStatusTip(translate('OpenLP.MainWindow',
2010-07-03 20:39:29 +00:00
'Toggle the visibility of the service manager.'))
2013-03-16 11:05:52 +00:00
self.view_preview_panel.setText(translate('OpenLP.MainWindow', '&Preview Panel'))
self.view_preview_panel.setToolTip(translate('OpenLP.MainWindow', 'Toggle Preview Panel'))
self.view_preview_panel.setStatusTip(
2013-02-01 20:36:27 +00:00
translate('OpenLP.MainWindow', 'Toggle the visibility of the preview panel.'))
2013-03-16 11:05:52 +00:00
self.view_live_panel.setText(translate('OpenLP.MainWindow', '&Live Panel'))
self.view_live_panel.setToolTip(translate('OpenLP.MainWindow', 'Toggle Live Panel'))
2012-12-29 13:15:42 +00:00
self.lockPanel.setText(translate('OpenLP.MainWindow', 'L&ock Panels'))
self.lockPanel.setStatusTip(translate('OpenLP.MainWindow', 'Prevent the panels being moved.'))
2013-03-16 11:05:52 +00:00
self.view_live_panel.setStatusTip(translate('OpenLP.MainWindow', 'Toggle the visibility of the live panel.'))
2012-12-29 13:15:42 +00:00
self.settingsPluginListItem.setText(translate('OpenLP.MainWindow', '&Plugin List'))
self.settingsPluginListItem.setStatusTip(translate('OpenLP.MainWindow', 'List the Plugins'))
2013-03-16 11:05:52 +00:00
self.about_item.setText(translate('OpenLP.MainWindow', '&About'))
self.about_item.setStatusTip(translate('OpenLP.MainWindow', 'More information about OpenLP'))
2011-06-29 17:30:53 +00:00
if os.name == u'nt':
2012-12-29 13:15:42 +00:00
self.offlineHelpItem.setText(translate('OpenLP.MainWindow', '&User Guide'))
2013-03-16 11:05:52 +00:00
self.on_line_help_item.setText(translate('OpenLP.MainWindow', '&Online Help'))
self.web_site_item.setText(translate('OpenLP.MainWindow', '&Web Site'))
for item in self.language_group.actions():
2010-05-11 19:00:21 +00:00
item.setText(item.objectName())
2012-12-29 13:15:42 +00:00
item.setStatusTip(translate('OpenLP.MainWindow', 'Set the interface language to %s') % item.objectName())
2013-03-16 11:05:52 +00:00
self.auto_language_item.setText(translate('OpenLP.MainWindow', '&Autodetect'))
self.auto_language_item.setStatusTip(translate('OpenLP.MainWindow', 'Use the system language, if available.'))
2013-03-17 20:00:39 +00:00
self.tools_add_tool_item.setText(translate('OpenLP.MainWindow', 'Add &Tool...'))
self.tools_add_tool_item.setStatusTip(translate('OpenLP.MainWindow',
2013-03-16 11:05:52 +00:00
'Add an application to the list of tools.'))
self.tools_open_data_folder.setText(translate('OpenLP.MainWindow', 'Open &Data Folder...'))
self.tools_open_data_folder.setStatusTip(translate('OpenLP.MainWindow',
2011-02-09 22:53:35 +00:00
'Open the folder where songs, bibles and other data resides.'))
2013-03-16 11:05:52 +00:00
self.tools_first_time_wizard.setText(translate('OpenLP.MainWindow', 'Re-run First Time Wizard'))
self.tools_first_time_wizard.setStatusTip(translate('OpenLP.MainWindow',
2012-12-29 13:15:42 +00:00
'Re-run the First Time Wizard, importing songs, Bibles and themes.'))
2013-03-16 11:05:52 +00:00
self.update_theme_images.setText(translate('OpenLP.MainWindow', 'Update Theme Images'))
self.update_theme_images.setStatusTip(translate('OpenLP.MainWindow',
'Update the preview images for all themes.'))
self.mode_default_Item.setText(translate('OpenLP.MainWindow', '&Default'))
self.mode_default_Item.setStatusTip(translate('OpenLP.MainWindow', 'Set the view mode back to the default.'))
self.mode_setup_item.setText(translate('OpenLP.MainWindow', '&Setup'))
self.mode_setup_item.setStatusTip(translate('OpenLP.MainWindow', 'Set the view mode to Setup.'))
self.mode_live_item.setText(translate('OpenLP.MainWindow', '&Live'))
self.mode_live_item.setStatusTip(translate('OpenLP.MainWindow', 'Set the view mode to Live.'))
2009-08-09 17:58:37 +00:00
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
"""
The main window.
"""
log.info(u'MainWindow loaded')
2013-02-03 19:23:12 +00:00
def __init__(self):
2009-08-09 17:58:37 +00:00
"""
This constructor sets up the interface, the various managers, and the
plugins.
"""
QtGui.QMainWindow.__init__(self)
Registry().register(u'main_window', self)
2012-05-26 17:12:01 +00:00
self.clipboard = self.application.clipboard()
self.arguments = self.application.args
2013-01-16 12:26:17 +00:00
# Set up settings sections for the main application (not for use by plugins).
2013-03-16 11:05:52 +00:00
self.ui_settings_section = u'user interface'
self.general_settings_section = u'general'
self.advanced_settings_section = u'advanced'
self.shortcuts_settings_section = u'shortcuts'
self.service_manager_settings_section = u'servicemanager'
self.songs_settings_section = u'songs'
self.themes_settings_section = u'themes'
self.players_settings_section = u'players'
self.display_tags_section = u'displayTags'
self.header_section = u'SettingsImport'
self.recent_files = []
2013-02-18 20:41:08 +00:00
self.timer_id = 0
self.timer_version_id = 0
self.new_data_path = None
self.copy_data = False
Settings().set_up_default_values()
Settings().remove_obsolete_settings()
2013-03-16 11:05:52 +00:00
self.service_not_saved = False
self.about_form = AboutForm(self)
2013-03-04 16:55:13 +00:00
self.media_controller = MediaController()
2013-03-16 11:05:52 +00:00
self.settings_form = SettingsForm(self)
self.formatting_tag_form = FormattingTagForm(self)
self.shortcut_form = ShortcutListForm(self)
2009-08-09 17:58:37 +00:00
# Set up the path with plugins
2013-02-17 12:57:52 +00:00
self.plugin_manager = PluginManager()
2013-02-18 21:36:36 +00:00
self.image_manager = ImageManager()
2009-08-09 17:58:37 +00:00
# Set up the interface
self.setupUi(self)
2013-02-18 20:41:08 +00:00
# Define the media Dock Manager
2013-03-16 11:05:52 +00:00
self.media_dock_manager = MediaDockManager(self.media_tool_box)
2010-04-28 01:28:37 +00:00
# Load settings after setupUi so default UI sizes are overwritten
2013-03-16 11:05:52 +00:00
self.load_settings()
# Once settings are loaded update the menu with the recent files.
2013-03-16 11:05:52 +00:00
self.update_recent_files_menu()
self.plugin_form = PluginForm(self)
2009-08-09 17:58:37 +00:00
# Set up signals and slots
2013-03-16 11:05:52 +00:00
self.media_manager_dock.visibilityChanged.connect(self.view_media_manager_item.setChecked)
self.service_manager_dock.visibilityChanged.connect(self.view_service_manager_item.setChecked)
self.theme_manager_dock.visibilityChanged.connect(self.view_theme_manager_item.setChecked)
self.import_theme_item.triggered.connect(self.theme_manager_contents.on_import_theme)
self.export_theme_item.triggered.connect(self.theme_manager_contents.on_export_theme)
self.web_site_item.triggered.connect(self.onHelpWebSiteClicked)
self.tools_open_data_folder.triggered.connect(self.onToolsOpenDataFolderClicked)
self.tools_first_time_wizard.triggered.connect(self.onFirstTimeWizardClicked)
self.update_theme_images.triggered.connect(self.onUpdateThemeImages)
self.formatting_tag_item.triggered.connect(self.onFormattingTagItemClicked)
self.settings_configure_item.triggered.connect(self.onSettingsConfigureItemClicked)
self.settings_shortcuts_item.triggered.connect(self.onSettingsShortcutsItemClicked)
self.settings_import_item.triggered.connect(self.onSettingsImportItemClicked)
self.settings_export_item.triggered.connect(self.onSettingsExportItemClicked)
2010-10-30 09:29:59 +00:00
# i18n set signals for languages
2013-03-16 11:05:52 +00:00
self.language_group.triggered.connect(LanguageManager.set_language)
self.mode_default_Item.triggered.connect(self.onModeDefaultItemClicked)
self.mode_setup_item.triggered.connect(self.onModeSetupItemClicked)
self.mode_live_item.triggered.connect(self.onModeLiveItemClicked)
# Media Manager
2013-03-16 11:05:52 +00:00
self.media_tool_box.currentChanged.connect(self.onMediaToolBoxChanged)
2013-02-03 19:23:12 +00:00
self.application.set_busy_cursor()
2011-01-01 10:33:14 +00:00
# Simple message boxes
2013-02-07 08:42:17 +00:00
Registry().register_function(u'theme_update_global', self.default_theme_changed)
Registry().register_function(u'openlp_version_check', self.version_notice)
Registry().register_function(u'config_screen_changed', self.screen_changed)
2013-01-22 21:09:43 +00:00
self.renderer = Renderer()
2009-08-29 07:17:56 +00:00
log.info(u'Load data from Settings')
if Settings().value(u'advanced/save current plugin'):
savedPlugin = Settings().value(u'advanced/current media plugin')
if savedPlugin != -1:
2013-03-16 11:05:52 +00:00
self.media_tool_box.setCurrentIndex(savedPlugin)
# Reset the cursor
2013-02-03 19:23:12 +00:00
self.application.set_normal_cursor()
2009-10-11 05:47:38 +00:00
2010-04-16 22:06:28 +00:00
def setAutoLanguage(self, value):
2013-02-01 20:36:27 +00:00
"""
Set the language to automatic.
"""
2013-03-16 11:05:52 +00:00
self.language_group.setDisabled(value)
LanguageManager.auto_language = value
2013-03-16 11:05:52 +00:00
LanguageManager.set_language(self.language_group.checkedAction())
2010-04-16 22:06:28 +00:00
def onMediaToolBoxChanged(self, index):
2013-02-01 20:36:27 +00:00
"""
Focus a widget when the media toolbox changes.
"""
2013-03-16 11:05:52 +00:00
widget = self.media_tool_box.widget(index)
if widget:
widget.onFocus()
2013-02-07 08:42:17 +00:00
def version_notice(self, version):
"""
2010-07-30 22:48:09 +00:00
Notifies the user that a newer version of OpenLP is available.
2013-02-07 10:16:08 +00:00
Triggered by delay thread and cannot display popup.
"""
2013-02-07 10:16:08 +00:00
log.debug(u'version_notice')
2012-12-29 13:15:42 +00:00
version_text = translate('OpenLP.MainWindow', 'Version %s of OpenLP is now available for download (you are '
'currently running version %s). \n\nYou can download the latest version from http://openlp.org/.')
2013-02-07 10:16:08 +00:00
self.version_text = version_text % (version, get_application_version()[u'full'])
2009-08-09 17:58:37 +00:00
def show(self):
"""
Show the main form, as well as the display form
"""
2010-04-23 21:31:54 +00:00
QtGui.QWidget.show(self)
2013-02-18 19:59:35 +00:00
if self.live_controller.display.isVisible():
self.live_controller.display.setFocus()
self.activateWindow()
if self.arguments:
2011-03-19 10:08:05 +00:00
args = []
for a in self.arguments:
2011-03-19 10:08:05 +00:00
args.extend([a])
2011-12-05 21:40:56 +00:00
filename = args[0]
if not isinstance(filename, unicode):
filename = unicode(filename, sys.getfilesystemencoding())
2013-03-16 11:05:52 +00:00
self.service_manager_contents.load_file(filename)
elif Settings().value(self.general_settings_section + u'/auto open'):
self.service_manager_contents.load_Last_file()
2013-02-07 10:16:08 +00:00
self.timer_version_id = self.startTimer(1000)
2013-03-16 11:05:52 +00:00
view_mode = Settings().value(u'%s/view mode' % self.general_settings_section)
2010-09-18 17:14:27 +00:00
if view_mode == u'default':
2013-03-16 11:05:52 +00:00
self.mode_default_Item.setChecked(True)
2010-09-18 17:14:27 +00:00
elif view_mode == u'setup':
self.setViewMode(True, True, False, True, False)
2013-03-16 11:05:52 +00:00
self.mode_setup_item.setChecked(True)
2010-09-18 17:14:27 +00:00
elif view_mode == u'live':
self.setViewMode(False, True, False, False, True)
2013-03-16 11:05:52 +00:00
self.mode_live_item.setChecked(True)
2010-04-10 10:28:57 +00:00
2013-02-03 15:06:17 +00:00
def app_startup(self):
"""
Give all the plugins a chance to perform some tasks at startup
"""
2013-02-03 19:23:12 +00:00
self.application.process_events()
2013-02-03 15:06:17 +00:00
for plugin in self.plugin_manager.plugins:
if plugin.isActive():
plugin.app_startup()
2013-02-03 19:23:12 +00:00
self.application.process_events()
def first_time(self):
2013-02-01 20:36:27 +00:00
"""
Import themes if first time
"""
2013-02-03 19:23:12 +00:00
self.application.process_events()
2013-02-03 15:06:17 +00:00
for plugin in self.plugin_manager.plugins:
if hasattr(plugin, u'first_time'):
2013-02-03 19:23:12 +00:00
self.application.process_events()
plugin.first_time()
2013-02-03 19:23:12 +00:00
self.application.process_events()
temp_dir = os.path.join(unicode(gettempdir()), u'openlp')
shutil.rmtree(temp_dir, True)
def onFirstTimeWizardClicked(self):
"""
Re-run the first time wizard. Prompts the user for run confirmation
If wizard is run, songs, bibles and themes are imported. The default
theme is changed (if necessary). The plugins in pluginmanager are
set active/in-active to match the selection in the wizard.
"""
answer = QtGui.QMessageBox.warning(self,
translate('OpenLP.MainWindow', 'Re-run First Time Wizard?'),
2012-12-29 13:15:42 +00:00
translate('OpenLP.MainWindow', 'Are you sure you want to re-run the First Time Wizard?\n\n'
'Re-running this wizard may make changes to your current '
'OpenLP configuration and possibly add songs to your '
'existing songs list and change your default theme.'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No),
QtGui.QMessageBox.No)
if answer == QtGui.QMessageBox.No:
return
screens = ScreenList()
first_run_wizard = FirstTimeForm(screens, self)
first_run_wizard.exec_()
if first_run_wizard.was_download_cancelled:
return
2013-02-03 19:23:12 +00:00
self.application.set_busy_cursor()
2013-02-03 15:06:17 +00:00
self.first_time()
for plugin in self.plugin_manager.plugins:
self.activePlugin = plugin
oldStatus = self.activePlugin.status
self.activePlugin.setStatus()
if oldStatus != self.activePlugin.status:
if self.activePlugin.status == PluginStatus.Active:
self.activePlugin.toggleStatus(PluginStatus.Active)
self.activePlugin.app_startup()
else:
self.activePlugin.toggleStatus(PluginStatus.Inactive)
2013-03-12 09:09:42 +00:00
# Set global theme and
2013-03-16 11:05:52 +00:00
Registry().execute(u'theme_update_global', self.theme_manager_contents.global_theme)
self.theme_manager_contents.load_first_time_themes()
2013-03-11 19:11:46 +00:00
# Check if any Bibles downloaded. If there are, they will be processed.
2013-02-07 08:42:17 +00:00
Registry().execute(u'bibles_load_list', True)
2013-02-03 19:23:12 +00:00
self.application.set_normal_cursor()
2013-02-10 16:05:52 +00:00
def is_display_blank(self):
"""
Check and display message if screen blank on setup.
"""
2012-05-17 15:13:09 +00:00
settings = Settings()
2013-02-18 19:59:35 +00:00
self.live_controller.mainDisplaySetBackground()
2013-03-16 11:05:52 +00:00
if settings.value(u'%s/screen blank' % self.general_settings_section):
if settings.value(u'%s/blank warning' % self.general_settings_section):
2012-12-29 13:15:42 +00:00
QtGui.QMessageBox.question(self, translate('OpenLP.MainWindow', 'OpenLP Main Display Blanked'),
translate('OpenLP.MainWindow', 'The Main Display has been blanked out'))
2009-08-09 17:58:37 +00:00
2013-02-05 21:42:15 +00:00
def error_message(self, title, message):
2013-02-01 20:36:27 +00:00
"""
Display an error message
2013-02-05 21:42:15 +00:00
``title``
The title of the warning box.
``message``
The message to be displayed.
2013-02-01 20:36:27 +00:00
"""
2013-02-03 21:46:56 +00:00
self.application.splash.close()
2013-02-05 21:42:15 +00:00
QtGui.QMessageBox.critical(self, title, message)
2011-01-01 10:33:14 +00:00
2013-02-05 21:42:15 +00:00
def warning_message(self, title, message):
2013-02-01 20:36:27 +00:00
"""
Display a warning message
2013-02-05 21:42:15 +00:00
``title``
The title of the warning box.
``message``
The message to be displayed.
2013-02-01 20:36:27 +00:00
"""
2013-02-03 21:46:56 +00:00
self.application.splash.close()
2013-02-05 21:42:15 +00:00
QtGui.QMessageBox.warning(self, title, message)
2011-01-01 10:33:14 +00:00
2013-02-05 21:42:15 +00:00
def information_message(self, title, message):
2013-02-01 20:36:27 +00:00
"""
Display an informational message
2013-02-05 21:42:15 +00:00
``title``
The title of the warning box.
``message``
The message to be displayed.
2013-02-01 20:36:27 +00:00
"""
2013-02-03 21:46:56 +00:00
self.application.splash.close()
2013-02-05 21:42:15 +00:00
QtGui.QMessageBox.information(self, title, message)
2011-01-01 10:33:14 +00:00
def onHelpWebSiteClicked(self):
"""
Load the OpenLP website
"""
import webbrowser
webbrowser.open_new(u'http://openlp.org/')
def onOfflineHelpClicked(self):
"""
Load the local OpenLP help file
"""
os.startfile(self.localHelpFile)
def onOnlineHelpClicked(self):
2011-03-24 21:20:38 +00:00
"""
Load the online OpenLP manual
"""
import webbrowser
webbrowser.open_new(u'http://manual.openlp.org/')
2011-07-10 10:52:30 +00:00
def onAboutItemClicked(self):
2009-08-09 17:58:37 +00:00
"""
Show the About form
"""
2013-03-16 11:05:52 +00:00
self.about_form.exec_()
2009-08-09 17:58:37 +00:00
2013-03-16 11:05:52 +00:00
def on_plugin_item_clicked(self):
"""
Show the Plugin form
"""
2013-03-16 11:05:52 +00:00
self.plugin_form.load()
self.plugin_form.exec_()
2011-02-09 22:53:35 +00:00
def onToolsOpenDataFolderClicked(self):
"""
Open data folder
"""
path = AppLocation.get_data_path()
QtGui.QDesktopServices.openUrl(QtCore.QUrl("file:///" + path))
def onUpdateThemeImages(self):
"""
Updates the new theme preview images.
"""
2013-03-16 11:05:52 +00:00
self.theme_manager_contents.update_preview_images()
def onFormattingTagItemClicked(self):
2011-02-20 15:35:52 +00:00
"""
Show the Settings dialog
"""
2013-03-16 11:05:52 +00:00
self.formatting_tag_form.exec_()
2011-02-20 15:35:52 +00:00
2010-10-07 21:27:26 +00:00
def onSettingsConfigureItemClicked(self):
2009-08-09 17:58:37 +00:00
"""
Show the Settings dialog
"""
2013-03-16 11:05:52 +00:00
self.settings_form.exec_()
2010-04-02 18:12:54 +00:00
def paintEvent(self, event):
"""
We need to make sure, that the SlidePreview's size is correct.
"""
2013-02-18 20:41:08 +00:00
self.preview_controller.previewSizeChanged()
2013-02-18 19:59:35 +00:00
self.live_controller.previewSizeChanged()
2010-10-07 21:27:26 +00:00
def onSettingsShortcutsItemClicked(self):
"""
Show the shortcuts dialog
"""
2013-03-16 11:05:52 +00:00
if self.shortcut_form.exec_():
self.shortcut_form.save()
2010-10-07 21:27:26 +00:00
def onSettingsImportItemClicked(self):
"""
Import settings from an export INI file
"""
2012-12-29 13:15:42 +00:00
answer = QtGui.QMessageBox.critical(self, translate('OpenLP.MainWindow', 'Import settings?'),
translate('OpenLP.MainWindow', 'Are you sure you want to import settings?\n\n'
'Importing settings will make permanent changes to your current OpenLP configuration.\n\n'
'Importing incorrect settings may cause erratic behaviour or OpenLP to terminate abnormally.'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No),
QtGui.QMessageBox.No)
if answer == QtGui.QMessageBox.No:
return
2013-02-01 20:36:27 +00:00
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 = []
# Add main sections.
2013-03-16 11:05:52 +00:00
setting_sections.extend([self.general_settings_section])
setting_sections.extend([self.advanced_settings_section])
setting_sections.extend([self.ui_settings_section])
setting_sections.extend([self.shortcuts_settings_section])
setting_sections.extend([self.service_manager_settings_section])
setting_sections.extend([self.themes_settings_section])
setting_sections.extend([self.players_settings_section])
setting_sections.extend([self.display_tags_section])
setting_sections.extend([self.header_section])
setting_sections.extend([u'crashreport'])
# Add plugin sections.
2013-02-03 15:06:17 +00:00
for plugin in self.plugin_manager.plugins:
setting_sections.extend([plugin.name])
2013-01-30 20:34:54 +00:00
# Copy the settings file to the tmp dir, because we do not want to change the original one.
temp_directory = os.path.join(unicode(gettempdir()), u'openlp')
check_directory_exists(temp_directory)
temp_config = os.path.join(temp_directory, os.path.basename(import_file_name))
shutil.copyfile(import_file_name, temp_config)
2012-05-17 15:13:09 +00:00
settings = Settings()
import_settings = Settings(temp_config, Settings.IniFormat)
# Remove/rename old settings to prepare the import.
import_settings.remove_obsolete_settings()
# Lets do a basic sanity check. If it contains this string we can
# assume it was created by OpenLP and so we'll load what we can
# from it, and just silently ignore anything we don't recognise
if import_settings.value(u'SettingsImport/type') != u'OpenLP_settings_export':
QtGui.QMessageBox.critical(self, translate('OpenLP.MainWindow', 'Import settings'),
translate('OpenLP.MainWindow', 'The file you have selected does not appear to be a valid OpenLP '
'settings file.\n\nProcessing has terminated and no changes have been made.'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
return
import_keys = import_settings.allKeys()
for section_key in import_keys:
# We need to handle the really bad files.
try:
section, key = section_key.split(u'/')
except ValueError:
section = u'unknown'
key = u''
# Switch General back to lowercase.
if section == u'General' or section == u'%General':
section = u'general'
section_key = section + "/" + key
# Make sure it's a valid section for us.
if not section in setting_sections:
continue
# We have a good file, import it.
for section_key in import_keys:
2013-01-18 21:24:25 +00:00
if u'eneral' in section_key:
section_key = section_key.lower()
value = import_settings.value(section_key)
2012-12-27 17:00:40 +00:00
if value is not None:
settings.setValue(u'%s' % (section_key), value)
2011-08-24 16:17:24 +00:00
now = datetime.now()
2013-03-16 11:05:52 +00:00
settings.beginGroup(self.header_section)
2012-05-17 15:13:09 +00:00
settings.setValue(u'file_imported', import_file_name)
2012-05-17 16:53:54 +00:00
settings.setValue(u'file_date_imported', now.strftime("%Y-%m-%d %H:%M"))
2011-08-24 16:17:24 +00:00
settings.endGroup()
settings.sync()
# We must do an immediate restart or current configuration will
# overwrite what was just imported when application terminates
# normally. We need to exit without saving configuration.
2012-12-29 13:15:42 +00:00
QtGui.QMessageBox.information(self, translate('OpenLP.MainWindow', 'Import settings'),
translate('OpenLP.MainWindow', 'OpenLP will now close. Imported settings will '
'be applied the next time you start OpenLP.'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
self.settingsImported = True
2013-01-27 07:36:04 +00:00
self.clean_up()
2011-08-28 13:39:34 +00:00
QtCore.QCoreApplication.exit()
2011-09-05 13:03:30 +00:00
def onSettingsExportItemClicked(self):
"""
2011-09-05 13:03:30 +00:00
Export settings to a .conf file in INI format
"""
2012-05-17 18:57:01 +00:00
export_file_name = QtGui.QFileDialog.getSaveFileName(self,
2011-09-05 13:03:30 +00:00
translate('OpenLP.MainWindow', 'Export Settings File'), '',
2012-12-29 13:15:42 +00:00
translate('OpenLP.MainWindow', 'OpenLP Export Settings File (*.conf)'))
2011-09-05 13:03:30 +00:00
if not export_file_name:
return
# Make sure it's a .conf file.
2011-09-05 13:03:30 +00:00
if not export_file_name.endswith(u'conf'):
2013-02-04 21:26:27 +00:00
export_file_name += u'.conf'
2012-06-22 20:12:43 +00:00
temp_file = os.path.join(unicode(gettempdir(),
get_filesystem_encoding()), u'openlp', u'exportConf.tmp')
self.save_settings()
setting_sections = []
# Add main sections.
2013-03-16 11:05:52 +00:00
setting_sections.extend([self.general_settings_section])
setting_sections.extend([self.advanced_settings_section])
setting_sections.extend([self.ui_settings_section])
setting_sections.extend([self.shortcuts_settings_section])
setting_sections.extend([self.service_manager_settings_section])
setting_sections.extend([self.themes_settings_section])
setting_sections.extend([self.display_tags_section])
# Add plugin sections.
2013-02-03 15:06:17 +00:00
for plugin in self.plugin_manager.plugins:
setting_sections.extend([plugin.name])
2011-08-24 16:17:24 +00:00
# Delete old files if found.
if os.path.exists(temp_file):
os.remove(temp_file)
2011-09-05 13:03:30 +00:00
if os.path.exists(export_file_name):
os.remove(export_file_name)
2012-05-17 15:13:09 +00:00
settings = Settings()
2013-03-16 11:05:52 +00:00
settings.remove(self.header_section)
# Get the settings.
keys = settings.allKeys()
2012-10-03 16:38:06 +00:00
export_settings = Settings(temp_file, Settings.IniFormat)
# Add a header section.
2011-09-05 13:03:30 +00:00
# This is to insure it's our conf file for import.
now = datetime.now()
application_version = get_application_version()
# Write INI format using Qsettings.
# Write our header.
2013-03-16 11:05:52 +00:00
export_settings.beginGroup(self.header_section)
export_settings.setValue(u'Make_Changes', u'At_Own_RISK')
export_settings.setValue(u'type', u'OpenLP_settings_export')
2013-01-11 12:43:18 +00:00
export_settings.setValue(u'file_date_created', now.strftime("%Y-%m-%d %H:%M"))
export_settings.setValue(u'version', application_version[u'full'])
export_settings.endGroup()
# Write all the sections and keys.
for section_key in keys:
2013-01-16 12:26:17 +00:00
# FIXME: We are conflicting with the standard "General" section.
2013-01-30 18:24:41 +00:00
if u'eneral' in section_key:
section_key = section_key.lower()
key_value = settings.value(section_key)
2012-12-27 16:46:27 +00:00
if key_value is not None:
export_settings.setValue(section_key, key_value)
export_settings.sync()
2011-09-05 13:03:30 +00:00
# Temp CONF file has been written. Blanks in keys are now '%20'.
# Read the temp file and output the user's CONF file with blanks to
2011-08-24 16:17:24 +00:00
# make it more readable.
2011-09-05 13:03:30 +00:00
temp_conf = open(temp_file, u'r')
2013-01-11 00:35:00 +00:00
export_conf = open(export_file_name, u'w')
2011-09-05 13:03:30 +00:00
for file_record in temp_conf:
# Get rid of any invalid entries.
if file_record.find(u'@Invalid()') == -1:
2013-01-11 00:35:00 +00:00
file_record = file_record.replace(u'%20', u' ')
2011-09-05 13:03:30 +00:00
export_conf.write(file_record)
temp_conf.close()
export_conf.close()
2011-08-24 16:17:24 +00:00
os.remove(temp_file)
2010-09-18 18:15:54 +00:00
def onModeDefaultItemClicked(self):
2010-09-18 17:14:27 +00:00
"""
Put OpenLP into "Default" view mode.
"""
2011-02-02 05:31:11 +00:00
self.setViewMode(True, True, True, True, True, u'default')
2010-09-18 17:14:27 +00:00
2010-07-06 20:05:48 +00:00
def onModeSetupItemClicked(self):
"""
Put OpenLP into "Setup" view mode.
"""
2011-02-02 05:31:11 +00:00
self.setViewMode(True, True, False, True, False, u'setup')
2010-07-06 20:05:48 +00:00
def onModeLiveItemClicked(self):
"""
Put OpenLP into "Live" view mode.
"""
2011-02-02 05:31:11 +00:00
self.setViewMode(False, True, False, False, True, u'live')
2010-07-30 22:48:09 +00:00
def setViewMode(self, media=True, service=True, theme=True, preview=True,
2011-02-02 05:31:11 +00:00
live=True, mode=u''):
2010-07-30 22:48:09 +00:00
"""
Set OpenLP to a different view mode.
"""
2011-02-02 05:31:11 +00:00
if mode:
2012-05-17 15:13:09 +00:00
settings = Settings()
2013-03-16 11:05:52 +00:00
settings.setValue(u'%s/view mode' % self.general_settings_section, mode)
self.media_manager_dock.setVisible(media)
self.service_manager_dock.setVisible(service)
self.theme_manager_dock.setVisible(theme)
self.set_preview_panel_visibility(preview)
self.set_live_panel_visibility(live)
2010-07-06 20:05:48 +00:00
2013-02-07 08:42:17 +00:00
def screen_changed(self):
"""
The screen has changed so we have to update components such as the
renderer.
"""
2013-02-07 08:42:17 +00:00
log.debug(u'screen_changed')
2013-02-03 19:23:12 +00:00
self.application.set_busy_cursor()
2013-02-17 21:28:45 +00:00
self.image_manager.update_display()
2011-05-05 11:51:47 +00:00
self.renderer.update_display()
2013-02-18 20:41:08 +00:00
self.preview_controller.screenSizeChanged()
2013-02-18 19:59:35 +00:00
self.live_controller.screenSizeChanged()
2011-05-05 15:16:55 +00:00
self.setFocus()
self.activateWindow()
2013-02-03 19:23:12 +00:00
self.application.set_normal_cursor()
2009-08-09 17:58:37 +00:00
2009-10-16 21:29:38 +00:00
def closeEvent(self, event):
2009-08-09 17:58:37 +00:00
"""
Hook to close the main window and display windows on exit
"""
# The MainApplication did not even enter the event loop (this happens
# when OpenLP is not fully loaded). Just ignore the event.
if not self.application.is_event_loop_active:
event.ignore()
return
# If we just did a settings import, close without saving changes.
if self.settingsImported:
2013-01-27 07:36:04 +00:00
self.clean_up(False)
event.accept()
2013-03-16 11:05:52 +00:00
if self.service_manager_contents.is_modified():
ret = self.service_manager_contents.save_modified_service()
2009-08-09 17:58:37 +00:00
if ret == QtGui.QMessageBox.Save:
2013-03-16 11:05:52 +00:00
if self.service_manager_contents.decide_save_method():
2013-01-27 07:36:04 +00:00
self.clean_up()
event.accept()
else:
event.ignore()
2009-08-09 17:58:37 +00:00
elif ret == QtGui.QMessageBox.Discard:
2013-01-27 07:36:04 +00:00
self.clean_up()
2009-08-09 17:58:37 +00:00
event.accept()
else:
event.ignore()
else:
if Settings().value(u'advanced/enable exit confirmation'):
2012-12-29 13:15:42 +00:00
ret = QtGui.QMessageBox.question(self, translate('OpenLP.MainWindow', 'Close OpenLP'),
translate('OpenLP.MainWindow', 'Are you sure you want to close OpenLP?'),
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Yes | QtGui.QMessageBox.No),
2011-01-02 16:42:30 +00:00
QtGui.QMessageBox.Yes)
if ret == QtGui.QMessageBox.Yes:
2013-01-27 07:36:04 +00:00
self.clean_up()
2011-01-02 16:42:30 +00:00
event.accept()
else:
event.ignore()
else:
2013-01-27 07:36:04 +00:00
self.clean_up()
2010-12-29 12:45:16 +00:00
event.accept()
2011-01-02 16:42:30 +00:00
2013-01-27 07:36:04 +00:00
def clean_up(self, save_settings=True):
2009-09-19 23:05:30 +00:00
"""
2012-05-26 17:51:27 +00:00
Runs all the cleanup code before OpenLP shuts down.
``save_settings``
Switch to prevent saving settings. Defaults to **True**.
2009-09-19 23:05:30 +00:00
"""
2013-02-17 21:28:45 +00:00
self.image_manager.stop_manager = True
while self.image_manager.image_thread.isRunning():
2012-05-26 17:51:27 +00:00
time.sleep(0.1)
2009-09-19 23:05:30 +00:00
# Clean temporary files used by services
2013-03-16 11:05:52 +00:00
self.service_manager_contents.clean_up()
2012-05-26 17:51:27 +00:00
if save_settings:
if Settings().value(u'advanced/save current plugin'):
2013-03-16 11:05:52 +00:00
Settings().setValue(u'advanced/current media plugin', self.media_tool_box.currentIndex())
2009-08-09 17:58:37 +00:00
# Call the cleanup method to shutdown plugins.
log.info(u'cleanup plugins')
2013-02-03 15:06:17 +00:00
self.plugin_manager.finalise_plugins()
if save_settings:
2012-05-26 17:51:27 +00:00
# Save settings
self.save_settings()
# Check if we need to change the data directory
2013-02-07 08:42:17 +00:00
if self.new_data_path:
2013-03-16 11:05:52 +00:00
self.change_data_directory()
2010-10-30 11:09:36 +00:00
# Close down the display
2013-02-18 19:59:35 +00:00
if self.live_controller.display:
self.live_controller.display.close()
self.live_controller.display = None
2009-08-09 17:58:37 +00:00
2013-03-16 11:05:52 +00:00
def service_changed(self, reset=False, serviceName=None):
2009-08-09 17:58:37 +00:00
"""
2010-04-19 18:43:20 +00:00
Hook to change the main window title when the service changes
2009-09-19 21:45:50 +00:00
``reset``
Shows if the service has been cleared or saved
``serviceName``
The name of the service (if it has one)
2009-08-09 17:58:37 +00:00
"""
2009-09-19 21:45:50 +00:00
if not serviceName:
2009-08-09 17:58:37 +00:00
service_name = u'(unsaved service)'
else:
2009-09-19 21:45:50 +00:00
service_name = serviceName
2009-11-03 15:13:52 +00:00
if reset:
2013-03-16 11:05:52 +00:00
self.service_not_saved = False
2009-08-09 17:58:37 +00:00
title = u'%s - %s' % (self.mainTitle, service_name)
else:
2013-03-16 11:05:52 +00:00
self.service_not_saved = True
2009-08-09 17:58:37 +00:00
title = u'%s - %s*' % (self.mainTitle, service_name)
self.setWindowTitle(title)
2013-03-16 11:05:52 +00:00
def set_service_modified(self, modified, fileName):
"""
This method is called from the ServiceManager to set the title of the
main window.
``modified``
Whether or not this service has been modified.
``fileName``
The file name of the service file.
"""
if modified:
title = u'%s - %s*' % (self.mainTitle, fileName)
else:
title = u'%s - %s' % (self.mainTitle, fileName)
self.setWindowTitle(title)
2013-02-03 21:46:56 +00:00
def show_status_message(self, message):
2013-02-01 20:36:27 +00:00
"""
Show a message in the status bar
"""
2013-03-16 11:05:52 +00:00
self.status_bar.showMessage(message)
2013-03-11 19:11:46 +00:00
def default_theme_changed(self):
2013-02-01 20:36:27 +00:00
"""
Update the default theme indicator in the status bar
"""
2013-03-16 11:05:52 +00:00
self.default_theme_label.setText(translate('OpenLP.MainWindow', 'Default Theme: %s') %
2013-03-11 19:11:46 +00:00
Settings().value(u'themes/global theme'))
2013-03-16 11:05:52 +00:00
def toggle_media_manager(self):
2013-02-01 20:36:27 +00:00
"""
Toggle the visibility of the media manager
"""
2013-03-16 11:05:52 +00:00
self.media_manager_dock.setVisible(not self.media_manager_dock.isVisible())
2013-03-16 11:05:52 +00:00
def toggle_service_manager(self):
2013-02-01 20:36:27 +00:00
"""
Toggle the visibility of the service manager
"""
2013-03-16 11:05:52 +00:00
self.service_manager_dock.setVisible(not self.service_manager_dock.isVisible())
2013-03-16 11:05:52 +00:00
def toggle_theme_manager(self):
2013-02-01 20:36:27 +00:00
"""
Toggle the visibility of the theme manager
"""
2013-03-16 11:05:52 +00:00
self.theme_manager_dock.setVisible(not self.theme_manager_dock.isVisible())
2013-03-16 11:05:52 +00:00
def set_preview_panel_visibility(self, visible):
2010-07-06 21:18:55 +00:00
"""
Sets the visibility of the preview panel including saving the setting
and updating the menu.
``visible``
A bool giving the state to set the panel to
True - Visible
False - Hidden
"""
2013-02-18 19:59:35 +00:00
self.preview_controller.panel.setVisible(visible)
2012-05-17 15:13:09 +00:00
Settings().setValue(u'user interface/preview panel', visible)
2013-03-16 11:05:52 +00:00
self.view_preview_panel.setChecked(visible)
2010-07-06 20:05:48 +00:00
2013-03-16 11:05:52 +00:00
def set_lock_panel(self, lock):
2011-06-12 14:19:32 +00:00
"""
2011-06-26 06:49:10 +00:00
Sets the ability to stop the toolbars being changed.
2011-06-12 14:19:32 +00:00
"""
if lock:
2013-03-16 11:05:52 +00:00
self.theme_manager_dock.setFeatures(QtGui.QDockWidget.NoDockWidgetFeatures)
self.service_manager_dock.setFeatures(QtGui.QDockWidget.NoDockWidgetFeatures)
self.media_manager_dock.setFeatures(QtGui.QDockWidget.NoDockWidgetFeatures)
self.view_media_manager_item.setEnabled(False)
self.view_service_manager_item.setEnabled(False)
self.view_theme_manager_item.setEnabled(False)
self.view_preview_panel.setEnabled(False)
self.view_live_panel.setEnabled(False)
2011-06-12 14:19:32 +00:00
else:
2013-03-16 11:05:52 +00:00
self.theme_manager_dock.setFeatures(QtGui.QDockWidget.AllDockWidgetFeatures)
self.service_manager_dock.setFeatures(QtGui.QDockWidget.AllDockWidgetFeatures)
self.media_manager_dock.setFeatures(QtGui.QDockWidget.AllDockWidgetFeatures)
self.view_media_manager_item.setEnabled(True)
self.view_service_manager_item.setEnabled(True)
self.view_theme_manager_item.setEnabled(True)
self.view_preview_panel.setEnabled(True)
self.view_live_panel.setEnabled(True)
2012-05-17 15:13:09 +00:00
Settings().setValue(u'user interface/lock panel', lock)
2011-06-12 14:19:32 +00:00
2013-03-16 11:05:52 +00:00
def set_live_panel_visibility(self, visible):
2010-07-06 21:18:55 +00:00
"""
Sets the visibility of the live panel including saving the setting and
updating the menu.
``visible``
A bool giving the state to set the panel to
True - Visible
False - Hidden
"""
2013-02-18 19:59:35 +00:00
self.live_controller.panel.setVisible(visible)
2012-05-17 15:13:09 +00:00
Settings().setValue(u'user interface/live panel', visible)
2013-03-16 11:05:52 +00:00
self.view_live_panel.setChecked(visible)
2010-04-23 18:30:53 +00:00
2013-03-16 11:05:52 +00:00
def load_settings(self):
2010-07-09 21:32:32 +00:00
"""
Load the main window settings.
"""
2010-04-23 18:30:53 +00:00
log.debug(u'Loading QSettings')
2012-05-17 15:13:09 +00:00
settings = Settings()
# Remove obsolete entries.
settings.remove(u'custom slide')
settings.remove(u'service')
2013-03-16 11:05:52 +00:00
settings.beginGroup(self.general_settings_section)
self.recent_files = settings.value(u'recent files')
2010-04-30 01:31:41 +00:00
settings.endGroup()
2013-03-16 11:05:52 +00:00
settings.beginGroup(self.ui_settings_section)
self.move(settings.value(u'main window position'))
self.restoreGeometry(settings.value(u'main window geometry'))
self.restoreState(settings.value(u'main window state'))
2013-02-18 19:59:35 +00:00
self.live_controller.splitter.restoreState(settings.value(u'live splitter geometry'))
self.preview_controller.splitter.restoreState(settings.value(u'preview splitter geometry'))
self.controlSplitter.restoreState(settings.value(u'main window splitter geometry'))
2010-04-28 14:17:42 +00:00
settings.endGroup()
2010-04-23 18:30:53 +00:00
def save_settings(self):
2010-07-09 21:32:32 +00:00
"""
Save the main window settings.
"""
# Exit if we just did a settings import.
if self.settingsImported:
return
2010-04-23 18:30:53 +00:00
log.debug(u'Saving QSettings')
2012-05-17 15:13:09 +00:00
settings = Settings()
2013-03-16 11:05:52 +00:00
settings.beginGroup(self.general_settings_section)
settings.setValue(u'recent files', self.recent_files)
2010-04-30 01:31:41 +00:00
settings.endGroup()
2013-03-16 11:05:52 +00:00
settings.beginGroup(self.ui_settings_section)
2012-05-17 15:13:09 +00:00
settings.setValue(u'main window position', self.pos())
settings.setValue(u'main window state', self.saveState())
settings.setValue(u'main window geometry', self.saveGeometry())
2013-02-18 19:59:35 +00:00
settings.setValue(u'live splitter geometry', self.live_controller.splitter.saveState())
settings.setValue(u'preview splitter geometry', self.preview_controller.splitter.saveState())
settings.setValue(u'main window splitter geometry', self.controlSplitter.saveState())
2010-04-28 14:17:42 +00:00
settings.endGroup()
2010-04-23 18:30:53 +00:00
2013-03-16 11:05:52 +00:00
def update_recent_files_menu(self):
2010-07-09 21:32:32 +00:00
"""
Updates the recent file menu with the latest list of service files
accessed.
2010-07-09 21:32:32 +00:00
"""
2013-03-16 11:05:52 +00:00
recent_file_count = Settings().value(u'advanced/recent file count')
existing_recent_files = [recentFile for recentFile in self.recent_files
2012-02-26 21:09:22 +00:00
if os.path.isfile(unicode(recentFile))]
2013-03-16 11:05:52 +00:00
recent_files_to_display = existing_recent_files[0:recent_file_count]
self.recent_files_menu.clear()
for file_id, filename in enumerate(recent_files_to_display):
log.debug('Recent file name: %s', filename)
action = create_action(self, u'',
2013-03-16 11:05:52 +00:00
text=u'&%d %s' % (file_id + 1, os.path.splitext(os.path.basename(
unicode(filename)))[0]), data=filename,
2013-03-16 11:05:52 +00:00
triggers=self.service_manager_contents.on_recent_service_clicked)
self.recent_files_menu.addAction(action)
clear_recent_files_action = create_action(self, u'',
2012-12-29 13:15:42 +00:00
text=translate('OpenLP.MainWindow', 'Clear List', 'Clear List of recent files'),
statustip=translate('OpenLP.MainWindow', 'Clear the list of recent files.'),
2013-03-16 11:05:52 +00:00
enabled=bool(self.recent_files),
triggers=self.clear_recent_file_menu)
add_actions(self.recent_files_menu, (None, clear_recent_files_action))
clear_recent_files_action.setEnabled(bool(self.recent_files))
2010-04-23 18:30:53 +00:00
2013-03-16 11:05:52 +00:00
def add_recent_file(self, filename):
2010-07-09 21:32:32 +00:00
"""
Adds a service to the list of recently used files.
``filename``
The service filename to add
"""
2013-03-16 11:05:52 +00:00
# The max_recent_files value does not have an interface and so never gets
2010-12-26 14:44:07 +00:00
# actually stored in the settings therefore the default value of 20 will
# always be used.
2013-03-16 11:05:52 +00:00
max_recent_files = Settings().value(u'advanced/max recent files')
2010-06-30 11:59:09 +00:00
if filename:
# Add some cleanup to reduce duplication in the recent file list
filename = os.path.abspath(filename)
# abspath() only capitalises the drive letter if it wasn't provided
# in the given filename which then causes duplication.
if filename[1:3] == ':\\':
filename = filename[0].upper() + filename[1:]
2013-03-16 11:05:52 +00:00
if filename in self.recent_files:
self.recent_files.remove(filename)
self.recent_files.insert(0, filename)
while len(self.recent_files) > max_recent_files:
self.recent_files.pop()
2011-04-28 18:13:19 +00:00
2013-03-16 11:05:52 +00:00
def clear_recent_file_menu(self):
2012-05-17 16:19:06 +00:00
"""
Clears the recent files.
"""
2013-03-16 11:05:52 +00:00
self.recent_files = []
2012-05-17 16:19:06 +00:00
2013-03-16 11:05:52 +00:00
def display_progress_bar(self, size):
2011-04-28 18:13:19 +00:00
"""
Make Progress bar visible and set size
"""
2013-03-16 11:05:52 +00:00
self.load_progress_bar.show()
self.load_progress_bar.setMaximum(size)
self.load_progress_bar.setValue(0)
2013-02-03 19:23:12 +00:00
self.application.process_events()
2011-04-28 18:13:19 +00:00
2013-03-07 11:11:35 +00:00
def increment_progress_bar(self):
2011-04-28 18:13:19 +00:00
"""
2011-04-29 07:40:19 +00:00
Increase the Progress Bar value by 1
2011-04-28 18:13:19 +00:00
"""
2013-03-16 11:05:52 +00:00
self.load_progress_bar.setValue(self.load_progress_bar.value() + 1)
2013-02-03 19:23:12 +00:00
self.application.process_events()
2011-04-28 18:13:19 +00:00
2013-03-16 11:05:52 +00:00
def finished_progress_bar(self):
2011-04-28 18:13:19 +00:00
"""
2011-04-29 07:40:19 +00:00
Trigger it's removal after 2.5 second
2011-04-28 18:13:19 +00:00
"""
2011-04-29 07:40:19 +00:00
self.timer_id = self.startTimer(2500)
2011-04-28 18:13:19 +00:00
2011-04-29 07:40:19 +00:00
def timerEvent(self, event):
2011-04-28 18:13:19 +00:00
"""
Remove the Progress bar from view.
"""
2011-04-29 07:40:19 +00:00
if event.timerId() == self.timer_id:
2011-04-29 08:54:11 +00:00
self.timer_id = 0
2013-03-16 11:05:52 +00:00
self.load_progress_bar.hide()
2013-02-03 19:23:12 +00:00
self.application.process_events()
2013-02-07 10:16:08 +00:00
if event.timerId() == self.timer_version_id:
self.timer_version_id = 0
# Has the thread passed some data to be displayed so display it and stop all waiting
if hasattr(self, u'version_text'):
QtGui.QMessageBox.question(self, translate('OpenLP.MainWindow', 'OpenLP Version Updated'),
self.version_text)
else:
# the thread has not confirmed it is running or it has not yet sent any data so lets keep waiting
2013-02-20 07:02:48 +00:00
if not hasattr(self, u'version_update_running') or self.version_update_running:
2013-02-07 10:16:08 +00:00
self.timer_version_id = self.startTimer(1000)
self.application.process_events()
2013-02-07 08:42:17 +00:00
def set_new_data_path(self, new_data_path):
2013-02-01 20:36:27 +00:00
"""
Set the new data path
"""
2013-02-07 08:42:17 +00:00
self.new_data_path = new_data_path
2012-05-03 18:30:30 +00:00
2013-02-07 08:42:17 +00:00
def set_copy_data(self, copy_data):
2013-02-01 20:36:27 +00:00
"""
Set the flag to copy the data
"""
2013-02-07 08:42:17 +00:00
self.copy_data = copy_data
2012-05-03 18:30:30 +00:00
2013-03-16 11:05:52 +00:00
def change_data_directory(self):
2013-02-01 20:36:27 +00:00
"""
Change the data directory.
"""
2013-02-07 08:42:17 +00:00
log.info(u'Changing data path to %s' % self.new_data_path)
old_data_path = unicode(AppLocation.get_data_path())
# Copy OpenLP data to new location if requested.
2013-02-03 19:23:12 +00:00
self.application.set_busy_cursor()
2013-02-07 08:42:17 +00:00
if self.copy_data:
2012-05-03 18:30:30 +00:00
log.info(u'Copying data to new path')
try:
2012-05-03 18:30:30 +00:00
self.showStatusMessage(
2012-12-29 13:15:42 +00:00
translate('OpenLP.MainWindow', 'Copying OpenLP data to new data directory location - %s '
2013-02-07 08:42:17 +00:00
'- Please wait for copy to finish').replace('%s', self.new_data_path))
dir_util.copy_tree(old_data_path, self.new_data_path)
2012-05-03 18:30:30 +00:00
log.info(u'Copy sucessful')
2013-01-11 00:35:00 +00:00
except (IOError, os.error, DistutilsFileError), why:
2013-02-03 19:23:12 +00:00
self.application.set_normal_cursor()
log.exception(u'Data copy failed %s' % unicode(why))
2012-12-29 13:15:42 +00:00
QtGui.QMessageBox.critical(self, translate('OpenLP.MainWindow', 'New Data Directory Error'),
translate('OpenLP.MainWindow',
2012-12-29 13:15:42 +00:00
'OpenLP Data directory copy failed\n\n%s').replace('%s', unicode(why)),
2013-02-03 09:07:31 +00:00
QtGui.QMessageBox.StandardButtons(QtGui.QMessageBox.Ok))
return False
2012-05-03 18:30:30 +00:00
else:
log.info(u'No data copy requested')
# Change the location of data directory in config file.
2012-05-03 18:30:30 +00:00
settings = QtCore.QSettings()
2013-02-07 08:42:17 +00:00
settings.setValue(u'advanced/data path', self.new_data_path)
# Check if the new data path is our default.
2013-02-07 08:42:17 +00:00
if self.new_data_path == AppLocation.get_directory(AppLocation.DataDir):
settings.remove(u'advanced/data path')
2013-02-03 19:23:12 +00:00
self.application.set_normal_cursor()
2013-01-24 06:00:51 +00:00
2013-02-03 19:23:12 +00:00
def _get_application(self):
2013-02-03 09:07:31 +00:00
"""
Adds the openlp to the class dynamically
"""
2013-02-03 19:23:12 +00:00
if not hasattr(self, u'_application'):
self._application = Registry().get(u'application')
return self._application
2013-02-03 09:07:31 +00:00
2013-02-03 19:23:12 +00:00
application = property(_get_application)