~tomasgroth/openlp/portable-path

« back to all changes in this revision

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

  • Committer: Tomas Groth
  • Date: 2019-04-30 19:02:42 UTC
  • mfrom: (2829.2.32 openlp)
  • Revision ID: tomasgroth@yahoo.dk-20190430190242-6zwjk8724tyux70m
trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
###############################################################################
5
5
# OpenLP - Open Source Lyrics Projection                                      #
6
6
# --------------------------------------------------------------------------- #
7
 
# Copyright (c) 2008-2018 OpenLP Developers                                   #
 
7
# Copyright (c) 2008-2019 OpenLP Developers                                   #
8
8
# --------------------------------------------------------------------------- #
9
9
# This program is free software; you can redistribute it and/or modify it     #
10
10
# under the terms of the GNU General Public License as published by the Free  #
24
24
"""
25
25
from PyQt5 import QtCore, QtGui, QtWidgets
26
26
 
27
 
from openlp.core.common import is_macosx, clean_button_text
 
27
from openlp.core.common import clean_button_text, is_macosx
28
28
from openlp.core.common.i18n import translate
29
 
from openlp.core.common.settings import Settings
30
29
from openlp.core.lib.ui import add_welcome_page
31
30
from openlp.core.ui.icons import UiIcons
32
31
 
 
32
from openlp.core.display.screens import ScreenList
 
33
from openlp.core.widgets.widgets import ScreenSelectionWidget
 
34
 
33
35
 
34
36
class FirstTimePage(object):
35
37
    """
36
38
    An enumeration class with each of the pages of the wizard.
37
39
    """
38
40
    Welcome = 0
39
 
    Download = 1
40
 
    NoInternet = 2
41
 
    Plugins = 3
42
 
    Songs = 4
43
 
    Bibles = 5
44
 
    Themes = 6
45
 
    Defaults = 7
46
 
    Progress = 8
 
41
    Plugins = 1
 
42
    ScreenConfig = 2
 
43
    SampleOption = 3
 
44
    Download = 4
 
45
    NoInternet = 5
 
46
    Songs = 6
 
47
    Bibles = 7
 
48
    Themes = 8
 
49
    Progress = 9
 
50
 
 
51
 
 
52
class ThemeListWidget(QtWidgets.QListWidget):
 
53
    """
 
54
    Subclass a QListWidget so we can make it look better when it resizes.
 
55
    """
 
56
    def __init__(self, *args, **kwargs):
 
57
        super().__init__(*args, **kwargs)
 
58
        self.setEditTriggers(QtWidgets.QAbstractItemView.NoEditTriggers)
 
59
        self.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
 
60
        self.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
 
61
        self.setVerticalScrollMode(QtWidgets.QAbstractItemView.ScrollPerPixel)
 
62
        self.setSelectionMode(QtWidgets.QAbstractItemView.MultiSelection)
 
63
        self.setSelectionBehavior(QtWidgets.QAbstractItemView.SelectRows)
 
64
        self.setIconSize(QtCore.QSize(133, 100))
 
65
        self.setMovement(QtWidgets.QListView.Static)
 
66
        self.setFlow(QtWidgets.QListView.LeftToRight)
 
67
        self.setProperty("isWrapping", True)
 
68
        self.setResizeMode(QtWidgets.QListView.Adjust)
 
69
        self.setViewMode(QtWidgets.QListView.IconMode)
 
70
        self.setUniformItemSizes(True)
 
71
 
 
72
    def resizeEvent(self, event):
 
73
        """
 
74
        Resize the grid so the list looks better when its resized/
 
75
 
 
76
        :param QtGui.QResizeEvent event: Not used
 
77
        :return: None
 
78
        """
 
79
        nominal_width = 141  # Icon width of 133 + 4 each side
 
80
        max_items_per_row = self.viewport().width() // nominal_width or 1  # or 1 to avoid divide by 0 errors
 
81
        col_size = (self.viewport().width() - 1) / max_items_per_row
 
82
        self.setGridSize(QtCore.QSize(col_size, 140))
47
83
 
48
84
 
49
85
class UiFirstTimeWizard(object):
61
97
        first_time_wizard.resize(550, 386)
62
98
        first_time_wizard.setModal(True)
63
99
        first_time_wizard.setOptions(QtWidgets.QWizard.IndependentPages | QtWidgets.QWizard.NoBackButtonOnStartPage |
64
 
                                     QtWidgets.QWizard.NoBackButtonOnLastPage | QtWidgets.QWizard.HaveCustomButton1 |
65
 
                                     QtWidgets.QWizard.HaveCustomButton2)
 
100
                                     QtWidgets.QWizard.NoBackButtonOnLastPage | QtWidgets.QWizard.HaveCustomButton1)
66
101
        if is_macosx():                                                                             # pragma: nocover
67
102
            first_time_wizard.setPixmap(QtWidgets.QWizard.BackgroundPixmap,
68
103
                                        QtGui.QPixmap(':/wizards/openlp-osx-wizard.png'))
69
104
            first_time_wizard.resize(634, 386)
70
105
        else:
71
106
            first_time_wizard.setWizardStyle(QtWidgets.QWizard.ModernStyle)
72
 
        self.finish_button = self.button(QtWidgets.QWizard.FinishButton)
73
 
        self.no_internet_finish_button = self.button(QtWidgets.QWizard.CustomButton1)
74
 
        self.cancel_button = self.button(QtWidgets.QWizard.CancelButton)
75
 
        self.no_internet_cancel_button = self.button(QtWidgets.QWizard.CustomButton2)
76
 
        self.next_button = self.button(QtWidgets.QWizard.NextButton)
77
 
        self.back_button = self.button(QtWidgets.QWizard.BackButton)
78
107
        add_welcome_page(first_time_wizard, ':/wizards/wizard_firsttime.bmp')
 
108
        # The screen config page
 
109
        self.screen_page = QtWidgets.QWizardPage()
 
110
        self.screen_page.setObjectName('defaults_page')
 
111
        self.screen_page_layout = QtWidgets.QFormLayout(self.screen_page)
 
112
        self.screen_selection_widget = ScreenSelectionWidget(self, ScreenList())
 
113
        self.screen_selection_widget.use_simple_view()
 
114
        self.screen_selection_widget.load()
 
115
        self.screen_page_layout.addRow(self.screen_selection_widget)
 
116
        first_time_wizard.setPage(FirstTimePage.ScreenConfig, self.screen_page)
 
117
        # Download Samples page
 
118
        self.resource_page = QtWidgets.QWizardPage()
 
119
        self.resource_page.setObjectName('resource_page')
 
120
        self.resource_page.setFinalPage(True)
 
121
        self.resource_layout = QtWidgets.QVBoxLayout(self.resource_page)
 
122
        self.resource_layout.setContentsMargins(50, 20, 50, 20)
 
123
        self.resource_layout.setObjectName('resource_layout')
 
124
        self.resource_label = QtWidgets.QLabel(self.resource_page)
 
125
        self.resource_label.setObjectName('resource_label')
 
126
        self.resource_label.setWordWrap(True)
 
127
        self.resource_layout.addWidget(self.resource_label)
 
128
        first_time_wizard.setPage(FirstTimePage.SampleOption, self.resource_page)
79
129
        # The download page
80
130
        self.download_page = QtWidgets.QWizardPage()
81
131
        self.download_page.setObjectName('download_page')
89
139
        # The "you don't have an internet connection" page.
90
140
        self.no_internet_page = QtWidgets.QWizardPage()
91
141
        self.no_internet_page.setObjectName('no_internet_page')
 
142
        self.no_internet_page.setFinalPage(True)
92
143
        self.no_internet_layout = QtWidgets.QVBoxLayout(self.no_internet_page)
93
144
        self.no_internet_layout.setContentsMargins(50, 30, 50, 40)
94
145
        self.no_internet_layout.setObjectName('no_internet_layout')
163
214
        self.themes_page = QtWidgets.QWizardPage()
164
215
        self.themes_page.setObjectName('themes_page')
165
216
        self.themes_layout = QtWidgets.QVBoxLayout(self.themes_page)
166
 
        self.themes_layout.setContentsMargins(20, 50, 20, 60)
167
217
        self.themes_layout.setObjectName('themes_layout')
168
 
        self.themes_list_widget = QtWidgets.QListWidget(self.themes_page)
169
 
        self.themes_list_widget.setViewMode(QtWidgets.QListView.IconMode)
170
 
        self.themes_list_widget.setMovement(QtWidgets.QListView.Static)
171
 
        self.themes_list_widget.setFlow(QtWidgets.QListView.LeftToRight)
172
 
        self.themes_list_widget.setSpacing(4)
173
 
        self.themes_list_widget.setUniformItemSizes(True)
174
 
        self.themes_list_widget.setIconSize(QtCore.QSize(133, 100))
175
 
        self.themes_list_widget.setWrapping(False)
176
 
        self.themes_list_widget.setObjectName('themes_list_widget')
 
218
        self.themes_list_widget = ThemeListWidget(self.themes_page)
177
219
        self.themes_layout.addWidget(self.themes_list_widget)
 
220
        self.theme_options_layout = QtWidgets.QHBoxLayout()
 
221
        self.default_theme_layout = QtWidgets.QHBoxLayout()
 
222
        self.theme_label = QtWidgets.QLabel(self.themes_page)
 
223
        self.default_theme_layout.addWidget(self.theme_label)
 
224
        self.theme_combo_box = QtWidgets.QComboBox(self.themes_page)
 
225
        self.theme_combo_box.setEditable(False)
 
226
        self.default_theme_layout.addWidget(self.theme_combo_box, stretch=1)
 
227
        self.theme_options_layout.addLayout(self.default_theme_layout, stretch=1)
 
228
        self.select_buttons_layout = QtWidgets.QHBoxLayout()
 
229
        self.themes_select_all_button = QtWidgets.QToolButton(self.themes_page)
 
230
        self.themes_select_all_button.setIcon(UiIcons().select_all)
 
231
        self.select_buttons_layout.addWidget(self.themes_select_all_button, stretch=1, alignment=QtCore.Qt.AlignRight)
 
232
        self.themes_deselect_all_button = QtWidgets.QToolButton(self.themes_page)
 
233
        self.themes_deselect_all_button.setIcon(UiIcons().select_none)
 
234
        self.select_buttons_layout.addWidget(self.themes_deselect_all_button)
 
235
        self.theme_options_layout.addLayout(self.select_buttons_layout, stretch=1)
 
236
        self.themes_layout.addLayout(self.theme_options_layout)
178
237
        first_time_wizard.setPage(FirstTimePage.Themes, self.themes_page)
179
 
        # the default settings page
180
 
        self.defaults_page = QtWidgets.QWizardPage()
181
 
        self.defaults_page.setObjectName('defaults_page')
182
 
        self.defaults_layout = QtWidgets.QFormLayout(self.defaults_page)
183
 
        self.defaults_layout.setContentsMargins(50, 20, 50, 20)
184
 
        self.defaults_layout.setObjectName('defaults_layout')
185
 
        self.display_label = QtWidgets.QLabel(self.defaults_page)
186
 
        self.display_label.setObjectName('display_label')
187
 
        self.display_combo_box = QtWidgets.QComboBox(self.defaults_page)
188
 
        self.display_combo_box.setEditable(False)
189
 
        self.display_combo_box.setInsertPolicy(QtWidgets.QComboBox.NoInsert)
190
 
        self.display_combo_box.setObjectName('display_combo_box')
191
 
        self.defaults_layout.addRow(self.display_label, self.display_combo_box)
192
 
        self.theme_label = QtWidgets.QLabel(self.defaults_page)
193
 
        self.theme_label.setObjectName('theme_label')
194
 
        self.theme_combo_box = QtWidgets.QComboBox(self.defaults_page)
195
 
        self.theme_combo_box.setEditable(False)
196
 
        self.theme_combo_box.setInsertPolicy(QtWidgets.QComboBox.NoInsert)
197
 
        self.theme_combo_box.setSizeAdjustPolicy(QtWidgets.QComboBox.AdjustToContents)
198
 
        self.theme_combo_box.setObjectName('theme_combo_box')
199
 
        self.defaults_layout.addRow(self.theme_label, self.theme_combo_box)
200
 
        first_time_wizard.setPage(FirstTimePage.Defaults, self.defaults_page)
201
238
        # Progress page
202
239
        self.progress_page = QtWidgets.QWizardPage()
203
240
        self.progress_page.setObjectName('progress_page')
211
248
        self.progress_bar.setObjectName('progress_bar')
212
249
        self.progress_layout.addWidget(self.progress_bar)
213
250
        first_time_wizard.setPage(FirstTimePage.Progress, self.progress_page)
214
 
        self.retranslate_ui(first_time_wizard)
 
251
        self.retranslate_ui()
215
252
 
216
 
    def retranslate_ui(self, first_time_wizard):
 
253
    def retranslate_ui(self):
217
254
        """
218
255
        Translate the UI on the fly
219
256
 
220
257
        :param first_time_wizard: The wizard form
221
258
        """
222
 
        first_time_wizard.setWindowTitle(translate('OpenLP.FirstTimeWizard', 'First Time Wizard'))
 
259
        self.finish_button_text = clean_button_text(self.buttonText(QtWidgets.QWizard.FinishButton))
 
260
        back_button_text = clean_button_text(self.buttonText(QtWidgets.QWizard.BackButton))
 
261
        next_button_text = clean_button_text(self.buttonText(QtWidgets.QWizard.NextButton))
 
262
 
 
263
        self.setWindowTitle(translate('OpenLP.FirstTimeWizard', 'First Time Wizard'))
223
264
        text = translate('OpenLP.FirstTimeWizard', 'Welcome to the First Time Wizard')
224
 
        first_time_wizard.title_label.setText('<span style="font-size:14pt; font-weight:600;">{text}'
225
 
                                              '</span>'.format(text=text))
226
 
        button = clean_button_text(first_time_wizard.buttonText(QtWidgets.QWizard.NextButton))
227
 
        first_time_wizard.information_label.setText(
 
265
        self.title_label.setText('<span style="font-size:14pt; font-weight:600;">{text}</span>'.format(text=text))
 
266
        self.information_label.setText(
228
267
            translate('OpenLP.FirstTimeWizard', 'This wizard will help you to configure OpenLP for initial use. '
229
 
                                                'Click the {button} button below to start.').format(button=button))
 
268
                                                'Click the \'{next_button}\' button below to start.'
 
269
                      ).format(next_button=next_button_text))
 
270
        self.setButtonText(
 
271
            QtWidgets.QWizard.CustomButton1, translate('OpenLP.FirstTimeWizard', 'Internet Settings'))
230
272
        self.download_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Downloading Resource Index'))
231
 
        self.download_page.setSubTitle(translate('OpenLP.FirstTimeWizard', 'Please wait while the resource index is '
232
 
                                                                           'downloaded.'))
233
 
        self.download_label.setText(translate('OpenLP.FirstTimeWizard', 'Please wait while OpenLP downloads the '
234
 
                                                                        'resource index file...'))
 
273
        self.download_page.setSubTitle(translate('OpenLP.FirstTimeWizard',
 
274
                                                 'Please wait while the resource index is downloaded.'))
 
275
        self.download_label.setText(translate('OpenLP.FirstTimeWizard',
 
276
                                              'Please wait while OpenLP downloads the resource index file...'))
235
277
        self.plugin_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Select parts of the program you wish to use'))
236
278
        self.plugin_page.setSubTitle(translate('OpenLP.FirstTimeWizard',
237
279
                                               'You can also change these settings after the Wizard.'))
 
280
        self.screen_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Displays'))
 
281
        self.screen_page.setSubTitle(translate('OpenLP.FirstTimeWizard',
 
282
                                               'Choose the main display screen for OpenLP.'))
238
283
        self.songs_check_box.setText(translate('OpenLP.FirstTimeWizard', 'Songs'))
239
 
        self.custom_check_box.setText(translate('OpenLP.FirstTimeWizard',
240
 
                                                'Custom Slides – Easier to manage than songs and they have their own'
241
 
                                                ' list of slides'))
242
 
        self.bible_check_box.setText(translate('OpenLP.FirstTimeWizard',
243
 
                                               'Bibles – Import and show Bibles'))
 
284
        self.custom_check_box.setText(
 
285
            translate('OpenLP.FirstTimeWizard',
 
286
                      'Custom Slides – Easier to manage than songs and they have their own list of slides'))
 
287
        self.bible_check_box.setText(translate('OpenLP.FirstTimeWizard', 'Bibles – Import and show Bibles'))
244
288
        self.image_check_box.setText(translate('OpenLP.FirstTimeWizard',
245
289
                                               'Images – Show images or replace background with them'))
246
290
        self.presentation_check_box.setText(translate('OpenLP.FirstTimeWizard',
249
293
        self.song_usage_check_box.setText(translate('OpenLP.FirstTimeWizard', 'Song Usage Monitor'))
250
294
        self.alert_check_box.setText(translate('OpenLP.FirstTimeWizard',
251
295
                                               'Alerts – Display informative messages while showing other slides'))
 
296
        self.resource_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Resource Data'))
 
297
        self.resource_page.setSubTitle(translate('OpenLP.FirstTimeWizard', 'Can OpenLP download some resource data?'))
 
298
        self.resource_label.setText(
 
299
            translate('OpenLP.FirstTimeWizard',
 
300
                      'OpenLP has collected some resources that we have permission to distribute.\n\n'
 
301
                      'If you would like to download some of these resources click the \'{next_button}\' button, '
 
302
                      'otherwise click the \'{finish_button}\' button.'
 
303
                      ).format(next_button=next_button_text, finish_button=self.finish_button_text))
252
304
        self.no_internet_page.setTitle(translate('OpenLP.FirstTimeWizard', 'No Internet Connection'))
253
 
        self.no_internet_page.setSubTitle(
254
 
            translate('OpenLP.FirstTimeWizard', 'Unable to detect an Internet connection.'))
255
 
        button = clean_button_text(first_time_wizard.buttonText(QtWidgets.QWizard.FinishButton))
256
 
        self.no_internet_text = translate('OpenLP.FirstTimeWizard',
257
 
                                          'No Internet connection was found. The First Time Wizard needs an Internet '
258
 
                                          'connection in order to be able to download sample songs, Bibles and themes.'
259
 
                                          '  Click the {button} button now to start OpenLP with initial settings and '
260
 
                                          'no sample data.\n\nTo re-run the First Time Wizard and import this sample '
261
 
                                          'data at a later time, check your Internet connection and re-run this '
262
 
                                          'wizard by selecting "Tools/Re-run First Time Wizard" from OpenLP.'
263
 
                                          ).format(button=button)
264
 
        button = clean_button_text(first_time_wizard.buttonText(QtWidgets.QWizard.CancelButton))
265
 
        self.cancel_wizard_text = translate('OpenLP.FirstTimeWizard',
266
 
                                            '\n\nTo cancel the First Time Wizard completely (and not start OpenLP), '
267
 
                                            'click the {button} button now.').format(button=button)
 
305
        self.no_internet_page.setSubTitle(translate('OpenLP.FirstTimeWizard', 'Cannot connect to the internet.'))
 
306
        self.no_internet_label.setText(
 
307
            translate('OpenLP.FirstTimeWizard',
 
308
                      'OpenLP could not connect to the internet to get information about the sample data available.\n\n'
 
309
                      'Please check your internet connection. If your church uses a proxy server click the '
 
310
                      '\'Internet Settings\' button below and enter the server details there.\n\nClick the '
 
311
                      '\'{back_button}\' button to try again.\n\nIf you click the \'{finish_button}\' '
 
312
                      'button you can download the data at a later time by selecting \'Re-run First Time Wizard\' '
 
313
                      'from the \'Tools\' menu in OpenLP.'
 
314
                      ).format(back_button=back_button_text, finish_button=self.finish_button_text))
268
315
        self.songs_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Sample Songs'))
269
316
        self.songs_page.setSubTitle(translate('OpenLP.FirstTimeWizard', 'Select and download public domain songs.'))
270
317
        self.bibles_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Sample Bibles'))
271
318
        self.bibles_page.setSubTitle(translate('OpenLP.FirstTimeWizard', 'Select and download free Bibles.'))
 
319
        # Themes Page
272
320
        self.themes_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Sample Themes'))
273
321
        self.themes_page.setSubTitle(translate('OpenLP.FirstTimeWizard', 'Select and download sample themes.'))
274
 
        self.defaults_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Default Settings'))
275
 
        self.defaults_page.setSubTitle(translate('OpenLP.FirstTimeWizard',
276
 
                                                 'Set up default settings to be used by OpenLP.'))
277
 
        self.display_label.setText(translate('OpenLP.FirstTimeWizard', 'Default output display:'))
278
 
        self.theme_label.setText(translate('OpenLP.FirstTimeWizard', 'Select default theme:'))
 
322
        self.theme_label.setText(translate('OpenLP.FirstTimeWizard', 'Default theme:'))
 
323
        self.themes_select_all_button.setToolTip(translate('OpenLP.FirstTimeWizard', 'Select all'))
 
324
        self.themes_deselect_all_button.setToolTip(translate('OpenLP.FirstTimeWizard', 'Deselect all'))
279
325
        self.progress_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Downloading and Configuring'))
280
 
        self.progress_page.setSubTitle(translate('OpenLP.FirstTimeWizard', 'Please wait while resources are downloaded '
281
 
                                                                           'and OpenLP is configured.'))
282
 
        self.progress_label.setText(translate('OpenLP.FirstTimeWizard', 'Starting configuration process...'))
283
 
        first_time_wizard.setButtonText(QtWidgets.QWizard.CustomButton1,
284
 
                                        clean_button_text(first_time_wizard.buttonText(QtWidgets.QWizard.FinishButton)))
285
 
        first_time_wizard.setButtonText(QtWidgets.QWizard.CustomButton2,
286
 
                                        clean_button_text(first_time_wizard.buttonText(QtWidgets.QWizard.CancelButton)))
287
 
 
288
 
    def on_projectors_check_box_clicked(self):
289
 
        # When clicking projectors_check box, change the visibility setting for Projectors panel.
290
 
        if Settings().value('projector/show after wizard'):
291
 
            Settings().setValue('projector/show after wizard', False)
292
 
        else:
293
 
            Settings().setValue('projector/show after wizard', True)
 
326
        self.progress_page.setSubTitle(
 
327
            translate('OpenLP.FirstTimeWizard', 'Please wait while resources are downloaded and OpenLP is configured.'))