~suutari-olli/openlp/click-slide-to-go-live-from-blank

« back to all changes in this revision

Viewing changes to openlp/core/ui/mainwindow.py

  • Committer: Simon Hanna
  • Date: 2016-05-17 08:48:19 UTC
  • mfrom: (2625.1.36 openlp)
  • mto: (2625.1.37 openlp)
  • mto: This revision was merged to the branch mainline in revision 2649.
  • Revision ID: simon.hanna@serve-me.info-20160517084819-lgup78nzyzjympuu
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
"""
25
25
import logging
26
26
import os
 
27
import shutil
27
28
import sys
28
 
import shutil
 
29
import time
 
30
from datetime import datetime
29
31
from distutils import dir_util
30
32
from distutils.errors import DistutilsFileError
31
33
from tempfile import gettempdir
32
 
import time
33
 
from datetime import datetime
34
34
 
35
35
from PyQt5 import QtCore, QtGui, QtWidgets
36
36
 
37
 
from openlp.core.common import Registry, RegistryProperties, AppLocation, Settings, check_directory_exists, translate, \
38
 
    is_win, is_macosx
39
 
from openlp.core.lib import Renderer, OpenLPDockWidget, PluginManager, ImageManager, PluginStatus, ScreenList, \
40
 
    build_icon
 
37
from openlp.core.common import Registry, RegistryProperties, AppLocation, LanguageManager, Settings, \
 
38
    check_directory_exists, translate, is_win, is_macosx, add_actions
 
39
from openlp.core.common.actions import ActionList, CategoryOrder
 
40
from openlp.core.common.versionchecker import get_application_version
 
41
from openlp.core.lib import Renderer, PluginManager, ImageManager, PluginStatus, ScreenList, build_icon
41
42
from openlp.core.lib.ui import UiStrings, create_action
42
43
from openlp.core.ui import AboutForm, SettingsForm, ServiceManager, ThemeManager, LiveController, PluginForm, \
43
 
    MediaDockManager, ShortcutListForm, FormattingTagForm, PreviewController
44
 
 
 
44
    ShortcutListForm, FormattingTagForm, PreviewController
 
45
from openlp.core.ui.firsttimeform import FirstTimeForm
45
46
from openlp.core.ui.media import MediaController
46
 
from openlp.core.utils import LanguageManager, add_actions, get_application_version
47
 
from openlp.core.utils.actions import ActionList, CategoryOrder
48
 
from openlp.core.ui.firsttimeform import FirstTimeForm
 
47
from openlp.core.ui.printserviceform import PrintServiceForm
49
48
from openlp.core.ui.projector.manager import ProjectorManager
50
 
from openlp.core.ui.printserviceform import PrintServiceForm
 
49
from openlp.core.ui.lib.toolbar import OpenLPToolbar
 
50
from openlp.core.ui.lib.dockwidget import OpenLPDockWidget
 
51
from openlp.core.ui.lib.mediadockmanager import MediaDockManager
51
52
 
52
53
log = logging.getLogger(__name__)
53
54
 
621
622
        :param version: The Version to be displayed.
622
623
        """
623
624
        log.debug('version_notice')
624
 
        version_text = translate('OpenLP.MainWindow', 'Version %s of OpenLP is now available for download (you are '
625
 
                                 'currently running version %s). \n\nYou can download the latest version from '
626
 
                                 'http://openlp.org/.')
627
 
        QtWidgets.QMessageBox.question(self, translate('OpenLP.MainWindow', 'OpenLP Version Updated'),
628
 
                                       version_text % (version, get_application_version()[u'full']))
 
625
        version_text = translate('OpenLP.MainWindow', 'Version {new} of OpenLP is now available for download (you are '
 
626
                                 'currently running version {current}). \n\nYou can download the latest version from '
 
627
                                 'http://openlp.org/.').format(new=version, current=get_application_version()[u'full'])
 
628
        QtWidgets.QMessageBox.question(self, translate('OpenLP.MainWindow', 'OpenLP Version Updated'), version_text)
629
629
 
630
630
    def show(self):
631
631
        """
639
639
            self.open_cmd_line_files(self.arguments)
640
640
        elif Settings().value(self.general_settings_section + '/auto open'):
641
641
            self.service_manager_contents.load_last_file()
642
 
        view_mode = Settings().value('%s/view mode' % self.general_settings_section)
643
 
        if view_mode == 'default':
 
642
        # This will store currently used layout preset so it remains enabled on next startup.
 
643
        # If any panel is enabled/disabled after preset is set, this setting is not saved.
 
644
        view_mode = Settings().value('{section}/view mode'.format(section=self.general_settings_section))
 
645
        if view_mode == 'default' and Settings().value('user interface/is preset layout'):
644
646
            self.mode_default_item.setChecked(True)
645
 
        elif view_mode == 'setup':
 
647
        elif view_mode == 'setup' and Settings().value('user interface/is preset layout'):
646
648
            self.set_view_mode(True, True, False, True, False, True)
647
649
            self.mode_setup_item.setChecked(True)
648
 
        elif view_mode == 'live':
 
650
        elif view_mode == 'live' and Settings().value('user interface/is preset layout'):
649
651
            self.set_view_mode(False, True, False, False, True, True)
650
652
            self.mode_live_item.setChecked(True)
651
653
 
697
699
            return
698
700
        self.application.set_busy_cursor()
699
701
        self.first_time()
 
702
        # Check if Projectors panel should be visible or not after wizard.
 
703
        if Settings().value('projector/show after wizard'):
 
704
            self.projector_manager_dock.setVisible(True)
 
705
        else:
 
706
            self.projector_manager_dock.setVisible(False)
700
707
        for plugin in self.plugin_manager.plugins:
701
708
            self.active_plugin = plugin
702
709
            old_status = self.active_plugin.status
723
730
        """
724
731
        settings = Settings()
725
732
        self.live_controller.main_display_set_background()
726
 
        if settings.value('%s/screen blank' % self.general_settings_section):
727
 
            if settings.value('%s/blank warning' % self.general_settings_section):
 
733
        if settings.value('{section}/screen blank'.format(section=self.general_settings_section)):
 
734
            if settings.value('{section}/blank warning'.format(section=self.general_settings_section)):
728
735
                QtWidgets.QMessageBox.question(self, translate('OpenLP.MainWindow', 'OpenLP Main Display Blanked'),
729
736
                                               translate('OpenLP.MainWindow', 'The Main Display has been blanked out'))
730
737
 
916
923
            try:
917
924
                value = import_settings.value(section_key)
918
925
            except KeyError:
919
 
                log.warning('The key "%s" does not exist (anymore), so it will be skipped.' % section_key)
 
926
                log.warning('The key "{key}" does not exist (anymore), so it will be skipped.'.format(key=section_key))
920
927
            if value is not None:
921
 
                settings.setValue('%s' % (section_key), value)
 
928
                settings.setValue('{key}'.format(key=section_key), value)
922
929
        now = datetime.now()
923
930
        settings.beginGroup(self.header_section)
924
931
        settings.setValue('file_imported', import_file_name)
995
1002
                key_value = settings.value(section_key)
996
1003
            except KeyError:
997
1004
                QtWidgets.QMessageBox.critical(self, translate('OpenLP.MainWindow', 'Export setting error'),
998
 
                                               translate('OpenLP.MainWindow', 'The key "%s" does not have a default '
 
1005
                                               translate('OpenLP.MainWindow', 'The key "{key}" does not have a default '
999
1006
                                                                              'value so it will be skipped in this '
1000
 
                                                                              'export.') % section_key,
 
1007
                                                                              'export.').format(key=section_key),
1001
1008
                                               QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Ok))
1002
1009
                key_value = None
1003
1010
            if key_value is not None:
1019
1026
            os.remove(temp_file)
1020
1027
        except OSError as ose:
1021
1028
                QtWidgets.QMessageBox.critical(self, translate('OpenLP.MainWindow', 'Export setting error'),
1022
 
                                               translate('OpenLP.MainWindow', 'An error occurred while exporting the '
1023
 
                                                                              'settings: %s') % ose.strerror,
 
1029
                                               translate('OpenLP.MainWindow',
 
1030
                                                         'An error occurred while exporting the '
 
1031
                                                         'settings: {err}').format(err=ose.strerror),
1024
1032
                                               QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Ok))
1025
1033
 
1026
1034
    def on_mode_default_item_clicked(self):
1028
1036
        Put OpenLP into "Default" view mode.
1029
1037
        """
1030
1038
        self.set_view_mode(True, True, True, True, True, True, 'default')
 
1039
        Settings().setValue('user interface/is preset layout', True)
 
1040
        Settings().setValue('projector/show after wizard', True)
1031
1041
 
1032
1042
    def on_mode_setup_item_clicked(self):
1033
1043
        """
1034
1044
        Put OpenLP into "Setup" view mode.
1035
1045
        """
1036
1046
        self.set_view_mode(True, True, False, True, False, True, 'setup')
 
1047
        Settings().setValue('user interface/is preset layout', True)
 
1048
        Settings().setValue('projector/show after wizard', True)
1037
1049
 
1038
1050
    def on_mode_live_item_clicked(self):
1039
1051
        """
1040
1052
        Put OpenLP into "Live" view mode.
1041
1053
        """
1042
1054
        self.set_view_mode(False, True, False, False, True, True, 'live')
 
1055
        Settings().setValue('user interface/is preset layout', True)
 
1056
        Settings().setValue('projector/show after wizard', True)
1043
1057
 
1044
1058
    def set_view_mode(self, media=True, service=True, theme=True, preview=True, live=True, projector=True, mode=''):
1045
1059
        """
1047
1061
        """
1048
1062
        if mode:
1049
1063
            settings = Settings()
1050
 
            settings.setValue('%s/view mode' % self.general_settings_section, mode)
 
1064
            settings.setValue('{section}/view mode'.format(section=self.general_settings_section), mode)
1051
1065
        self.media_manager_dock.setVisible(media)
1052
1066
        self.service_manager_dock.setVisible(service)
1053
1067
        self.theme_manager_dock.setVisible(theme)
1154
1168
        :param file_name: The file name of the service file.
1155
1169
        """
1156
1170
        if modified:
1157
 
            title = '%s - %s*' % (UiStrings().OLPV2x, file_name)
 
1171
            title = '{title} - {name}*'.format(title=UiStrings().OLPV2x, name=file_name)
1158
1172
        else:
1159
 
            title = '%s - %s' % (UiStrings().OLPV2x, file_name)
 
1173
            title = '{title} - {name}'.format(title=UiStrings().OLPV2x, name=file_name)
1160
1174
        self.setWindowTitle(title)
1161
1175
 
1162
1176
    def show_status_message(self, message):
1169
1183
        """
1170
1184
        Update the default theme indicator in the status bar
1171
1185
        """
1172
 
        self.default_theme_label.setText(translate('OpenLP.MainWindow', 'Default Theme: %s') %
1173
 
                                         Settings().value('themes/global theme'))
 
1186
        theme_name = Settings().value('themes/global theme')
 
1187
        self.default_theme_label.setText(translate('OpenLP.MainWindow',
 
1188
                                                   'Default Theme: {theme}').format(theme=theme_name))
1174
1189
 
1175
1190
    def toggle_media_manager(self):
1176
1191
        """
1177
1192
        Toggle the visibility of the media manager
1178
1193
        """
1179
1194
        self.media_manager_dock.setVisible(not self.media_manager_dock.isVisible())
 
1195
        Settings().setValue('user interface/is preset layout', False)
1180
1196
 
1181
1197
    def toggle_projector_manager(self):
1182
1198
        """
1183
1199
        Toggle visibility of the projector manager
1184
1200
        """
1185
1201
        self.projector_manager_dock.setVisible(not self.projector_manager_dock.isVisible())
 
1202
        Settings().setValue('user interface/is preset layout', False)
 
1203
        # Check/uncheck checkbox on First time wizard based on visibility of this panel.
 
1204
        if not Settings().value('projector/show after wizard'):
 
1205
            Settings().setValue('projector/show after wizard', True)
 
1206
        else:
 
1207
            Settings().setValue('projector/show after wizard', False)
1186
1208
 
1187
1209
    def toggle_service_manager(self):
1188
1210
        """
1189
1211
        Toggle the visibility of the service manager
1190
1212
        """
1191
1213
        self.service_manager_dock.setVisible(not self.service_manager_dock.isVisible())
 
1214
        Settings().setValue('user interface/is preset layout', False)
1192
1215
 
1193
1216
    def toggle_theme_manager(self):
1194
1217
        """
1195
1218
        Toggle the visibility of the theme manager
1196
1219
        """
1197
1220
        self.theme_manager_dock.setVisible(not self.theme_manager_dock.isVisible())
 
1221
        Settings().setValue('user interface/is preset layout', False)
1198
1222
 
1199
1223
    def set_preview_panel_visibility(self, visible):
1200
1224
        """
1208
1232
        self.preview_controller.panel.setVisible(visible)
1209
1233
        Settings().setValue('user interface/preview panel', visible)
1210
1234
        self.view_preview_panel.setChecked(visible)
 
1235
        Settings().setValue('user interface/is preset layout', False)
1211
1236
 
1212
1237
    def set_lock_panel(self, lock):
1213
1238
        """
1218
1243
            self.service_manager_dock.setFeatures(QtWidgets.QDockWidget.NoDockWidgetFeatures)
1219
1244
            self.media_manager_dock.setFeatures(QtWidgets.QDockWidget.NoDockWidgetFeatures)
1220
1245
            self.projector_manager_dock.setFeatures(QtWidgets.QDockWidget.NoDockWidgetFeatures)
 
1246
            self.view_mode_menu.setEnabled(False)
1221
1247
            self.view_media_manager_item.setEnabled(False)
1222
1248
            self.view_service_manager_item.setEnabled(False)
1223
1249
            self.view_theme_manager_item.setEnabled(False)
1229
1255
            self.service_manager_dock.setFeatures(QtWidgets.QDockWidget.AllDockWidgetFeatures)
1230
1256
            self.media_manager_dock.setFeatures(QtWidgets.QDockWidget.AllDockWidgetFeatures)
1231
1257
            self.projector_manager_dock.setFeatures(QtWidgets.QDockWidget.AllDockWidgetFeatures)
 
1258
            self.view_mode_menu.setEnabled(True)
1232
1259
            self.view_media_manager_item.setEnabled(True)
1233
1260
            self.view_service_manager_item.setEnabled(True)
1234
1261
            self.view_theme_manager_item.setEnabled(True)
1249
1276
        self.live_controller.panel.setVisible(visible)
1250
1277
        Settings().setValue('user interface/live panel', visible)
1251
1278
        self.view_live_panel.setChecked(visible)
 
1279
        Settings().setValue('user interface/is preset layout', False)
1252
1280
 
1253
1281
    def load_settings(self):
1254
1282
        """
1304
1332
        recent_files_to_display = existing_recent_files[0:recent_file_count]
1305
1333
        self.recent_files_menu.clear()
1306
1334
        for file_id, filename in enumerate(recent_files_to_display):
1307
 
            log.debug('Recent file name: %s', filename)
 
1335
            log.debug('Recent file name: {name}'.format(name=filename))
 
1336
            # TODO: Verify ''.format() before committing
1308
1337
            action = create_action(self, '', text='&%d %s' % (file_id + 1,
1309
1338
                                   os.path.splitext(os.path.basename(str(filename)))[0]), data=filename,
1310
1339
                                   triggers=self.service_manager_contents.on_recent_service_clicked)
1397
1426
        """
1398
1427
        Change the data directory.
1399
1428
        """
1400
 
        log.info('Changing data path to %s' % self.new_data_path)
 
1429
        log.info('Changing data path to {newpath}'.format(newpath=self.new_data_path))
1401
1430
        old_data_path = str(AppLocation.get_data_path())
1402
1431
        # Copy OpenLP data to new location if requested.
1403
1432
        self.application.set_busy_cursor()
1405
1434
            log.info('Copying data to new path')
1406
1435
            try:
1407
1436
                self.show_status_message(
1408
 
                    translate('OpenLP.MainWindow', 'Copying OpenLP data to new data directory location - %s '
1409
 
                              '- Please wait for copy to finish').replace('%s', self.new_data_path))
 
1437
                    translate('OpenLP.MainWindow', 'Copying OpenLP data to new data directory location - {path} '
 
1438
                              '- Please wait for copy to finish').format(path=self.new_data_path))
1410
1439
                dir_util.copy_tree(old_data_path, self.new_data_path)
1411
1440
                log.info('Copy successful')
1412
1441
            except (IOError, os.error, DistutilsFileError) as why:
1413
1442
                self.application.set_normal_cursor()
1414
 
                log.exception('Data copy failed %s' % str(why))
 
1443
                log.exception('Data copy failed {err}'.format(err=str(why)))
 
1444
                err_text = translate('OpenLP.MainWindow',
 
1445
                                     'OpenLP Data directory copy failed\n\n{err}').format(err=str(why)),
1415
1446
                QtWidgets.QMessageBox.critical(self, translate('OpenLP.MainWindow', 'New Data Directory Error'),
1416
 
                                               translate('OpenLP.MainWindow',
1417
 
                                                         'OpenLP Data directory copy failed\n\n%s').
1418
 
                                               replace('%s', str(why)),
 
1447
                                               err_text,
1419
1448
                                               QtWidgets.QMessageBox.StandardButtons(QtWidgets.QMessageBox.Ok))
1420
1449
                return False
1421
1450
        else: