From 4ea2578cffead6da86187a6c99a53435fc3cff51 Mon Sep 17 00:00:00 2001 From: Philip Ridout Date: Wed, 6 Feb 2019 20:07:01 +0000 Subject: [PATCH] Rework FTW to use ScreeenSelectionWizard --- openlp/core/ui/firsttimeform.py | 75 ++++++++++++++++--------------- openlp/core/ui/firsttimewizard.py | 59 ++++++++++++------------ openlp/core/widgets/widgets.py | 22 +++++++-- 3 files changed, 85 insertions(+), 71 deletions(-) diff --git a/openlp/core/ui/firsttimeform.py b/openlp/core/ui/firsttimeform.py index 8d9092dc0..99af2decc 100644 --- a/openlp/core/ui/firsttimeform.py +++ b/openlp/core/ui/firsttimeform.py @@ -115,13 +115,13 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): """ Returns the id of the next FirstTimePage to go to based on enabled plugins """ - if FirstTimePage.Welcome < self.currentId() < FirstTimePage.Songs and self.songs_check_box.isChecked(): + if FirstTimePage.ScreenConfig < self.currentId() < FirstTimePage.Songs and self.songs_check_box.isChecked(): # If the songs plugin is enabled then go to the songs page return FirstTimePage.Songs - elif FirstTimePage.Welcome < self.currentId() < FirstTimePage.Bibles and self.bible_check_box.isChecked(): + elif FirstTimePage.ScreenConfig < self.currentId() < FirstTimePage.Bibles and self.bible_check_box.isChecked(): # Otherwise, if the Bibles plugin is enabled then go to the Bibles page return FirstTimePage.Bibles - elif FirstTimePage.Welcome < self.currentId() < FirstTimePage.Themes: + elif FirstTimePage.ScreenConfig < self.currentId() < FirstTimePage.Themes: # Otherwise, if the current page is somewhere between the Welcome and the Themes pages, go to the themes return FirstTimePage.Themes else: @@ -153,7 +153,7 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): self._build_theme_screenshots() self.application.set_normal_cursor() self.theme_screenshot_threads = [] - return FirstTimePage.Defaults + return self.get_next_page_id() else: return self.get_next_page_id() @@ -175,6 +175,8 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): self.theme_screenshot_threads = [] self.has_run_wizard = False + self.themes_list_widget.itemChanged.connect(self.on_theme_selected) + def _download_index(self): """ Download the configuration file and kick off the theme screenshot download threads @@ -204,7 +206,6 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): except (NoSectionError, NoOptionError, MissingSectionHeaderError): log.debug('A problem occurred while parsing the downloaded config file') trace_error_handler(log) - self.update_screen_list_combo() self.application.process_events() self.downloading = translate('OpenLP.FirstTimeWizard', 'Downloading {name}...') if self.has_run_wizard: @@ -273,21 +274,21 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): self.no_internet_finish_button.clicked.connect(self.on_no_internet_finish_button_clicked) self.no_internet_cancel_button.clicked.connect(self.on_no_internet_cancel_button_clicked) self.currentIdChanged.connect(self.on_current_id_changed) - Registry().register_function('config_screen_changed', self.update_screen_list_combo) + Registry().register_function('config_screen_changed', self.screen_selection_widget.load) self.no_internet_finish_button.setVisible(False) self.no_internet_cancel_button.setVisible(False) # Check if this is a re-run of the wizard. self.has_run_wizard = Settings().value('core/has run wizard') create_paths(Path(gettempdir(), 'openlp')) - - def update_screen_list_combo(self): - """ - The user changed screen resolution or enabled/disabled more screens, so - we need to update the combo box. - """ - self.display_combo_box.clear() - self.display_combo_box.addItems(self.screens.get_display_screen_list()) - self.display_combo_box.setCurrentIndex(self.display_combo_box.count() - 1) + self.theme_combo_box.clear() + if self.has_run_wizard: + # Add any existing themes to list. + for theme in self.theme_manager.get_themes(): + self.theme_combo_box.addItem(theme) + default_theme = Settings().value('themes/global theme') + # Pre-select the current default theme. + index = self.theme_combo_box.findText(default_theme) + self.theme_combo_box.setCurrentIndex(index) def on_current_id_changed(self, page_id): """ @@ -311,22 +312,6 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): self.back_button.setVisible(False) self.next_button.setVisible(True) self.next() - elif page_id == FirstTimePage.Defaults: - self.theme_combo_box.clear() - for index in range(self.themes_list_widget.count()): - item = self.themes_list_widget.item(index) - if item.checkState() == QtCore.Qt.Checked: - self.theme_combo_box.addItem(item.text()) - if self.has_run_wizard: - # Add any existing themes to list. - for theme in self.theme_manager.get_themes(): - index = self.theme_combo_box.findText(theme) - if index == -1: - self.theme_combo_box.addItem(theme) - default_theme = Settings().value('themes/global theme') - # Pre-select the current default theme. - index = self.theme_combo_box.findText(default_theme) - self.theme_combo_box.setCurrentIndex(index) elif page_id == FirstTimePage.NoInternet: self.back_button.setVisible(False) self.next_button.setVisible(False) @@ -368,10 +353,31 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): :param title: The title of the theme :param filename: The filename of the theme """ + self.themes_list_widget.blockSignals(True) item = QtWidgets.QListWidgetItem(title, self.themes_list_widget) item.setData(QtCore.Qt.UserRole, (filename, sha256)) item.setCheckState(QtCore.Qt.Unchecked) item.setFlags(item.flags() | QtCore.Qt.ItemIsUserCheckable) + self.themes_list_widget.blockSignals(False) + + def on_theme_selected(self, item): + """ + Add or remove a de/selected sample theme from the theme_combo_box + + :param QtWidgets.QListWidgetItem item: The item that has been de/selected + :rtype: None + """ + theme_name = item.text() + if self.theme_manager and theme_name in self.theme_manager.get_themes(): + return True + if item.checkState() == QtCore.Qt.Checked: + self.theme_combo_box.addItem(theme_name) + return True + else: + index = self.theme_combo_box.findText(theme_name) + if index != -1: + self.theme_combo_box.removeItem(index) + return True def on_no_internet_finish_button_clicked(self): """ @@ -536,12 +542,7 @@ class FirstTimeForm(QtWidgets.QWizard, UiFirstTimeWizard, RegistryProperties): translate('OpenLP.FirstTimeWizard', 'There was a connection problem while ' 'downloading, so further downloads will be skipped. Try to re-run ' 'the First Time Wizard later.')) - # Set Default Display - if self.display_combo_box.currentIndex() != -1: - # No longer need to set this setting directly, the ScreenList object will do it - # Settings().setValue('core/monitor', self.display_combo_box.currentIndex()) - self.screens.set_display_screen(self.display_combo_box.currentIndex(), can_save=True) - # Set Global Theme + self.screen_selection_widget.save() if self.theme_combo_box.currentIndex() != -1: Settings().setValue('themes/global theme', self.theme_combo_box.currentText()) diff --git a/openlp/core/ui/firsttimewizard.py b/openlp/core/ui/firsttimewizard.py index b8e939787..4730daa65 100644 --- a/openlp/core/ui/firsttimewizard.py +++ b/openlp/core/ui/firsttimewizard.py @@ -30,19 +30,21 @@ from openlp.core.common.settings import Settings from openlp.core.lib.ui import add_welcome_page from openlp.core.ui.icons import UiIcons +from openlp.core.display.screens import ScreenList +from openlp.core.widgets.widgets import ScreenSelectionWidget class FirstTimePage(object): """ An enumeration class with each of the pages of the wizard. """ Welcome = 0 - Download = 1 - NoInternet = 2 - Plugins = 3 - Songs = 4 - Bibles = 5 - Themes = 6 - Defaults = 7 + ScreenConfig = 1 + Download = 2 + NoInternet = 3 + Plugins = 4 + Songs = 5 + Bibles = 6 + Themes = 7 Progress = 8 @@ -76,6 +78,15 @@ class UiFirstTimeWizard(object): self.next_button = self.button(QtWidgets.QWizard.NextButton) self.back_button = self.button(QtWidgets.QWizard.BackButton) add_welcome_page(first_time_wizard, ':/wizards/wizard_firsttime.bmp') + # The screen config page + self.screen_page = QtWidgets.QWizardPage() + self.screen_page.setObjectName('defaults_page') + self.screen_page_layout = QtWidgets.QFormLayout(self.screen_page) + self.screen_selection_widget = ScreenSelectionWidget(self, ScreenList()) + self.screen_selection_widget.use_simple_view() + self.screen_selection_widget.load() + self.screen_page_layout.addRow(self.screen_selection_widget) + first_time_wizard.setPage(FirstTimePage.ScreenConfig, self.screen_page) # The download page self.download_page = QtWidgets.QWizardPage() self.download_page.setObjectName('download_page') @@ -175,29 +186,16 @@ class UiFirstTimeWizard(object): self.themes_list_widget.setWrapping(False) self.themes_list_widget.setObjectName('themes_list_widget') self.themes_layout.addWidget(self.themes_list_widget) - first_time_wizard.setPage(FirstTimePage.Themes, self.themes_page) - # the default settings page - self.defaults_page = QtWidgets.QWizardPage() - self.defaults_page.setObjectName('defaults_page') - self.defaults_layout = QtWidgets.QFormLayout(self.defaults_page) - self.defaults_layout.setContentsMargins(50, 20, 50, 20) - self.defaults_layout.setObjectName('defaults_layout') - self.display_label = QtWidgets.QLabel(self.defaults_page) - self.display_label.setObjectName('display_label') - self.display_combo_box = QtWidgets.QComboBox(self.defaults_page) - self.display_combo_box.setEditable(False) - self.display_combo_box.setInsertPolicy(QtWidgets.QComboBox.NoInsert) - self.display_combo_box.setObjectName('display_combo_box') - self.defaults_layout.addRow(self.display_label, self.display_combo_box) - self.theme_label = QtWidgets.QLabel(self.defaults_page) - self.theme_label.setObjectName('theme_label') - self.theme_combo_box = QtWidgets.QComboBox(self.defaults_page) + self.default_theme_layout = QtWidgets.QHBoxLayout() + self.theme_label = QtWidgets.QLabel(self.themes_page) + self.default_theme_layout.addWidget(self.theme_label) + self.theme_combo_box = QtWidgets.QComboBox(self.themes_page) self.theme_combo_box.setEditable(False) self.theme_combo_box.setInsertPolicy(QtWidgets.QComboBox.NoInsert) self.theme_combo_box.setSizeAdjustPolicy(QtWidgets.QComboBox.AdjustToContents) - self.theme_combo_box.setObjectName('theme_combo_box') - self.defaults_layout.addRow(self.theme_label, self.theme_combo_box) - first_time_wizard.setPage(FirstTimePage.Defaults, self.defaults_page) + self.default_theme_layout.addWidget(self.theme_combo_box) + self.themes_layout.addLayout(self.default_theme_layout) + first_time_wizard.setPage(FirstTimePage.Themes, self.themes_page) # Progress page self.progress_page = QtWidgets.QWizardPage() self.progress_page.setObjectName('progress_page') @@ -235,6 +233,9 @@ class UiFirstTimeWizard(object): self.plugin_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Select parts of the program you wish to use')) self.plugin_page.setSubTitle(translate('OpenLP.FirstTimeWizard', 'You can also change these settings after the Wizard.')) + self.screen_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Displays')) + self.screen_page.setSubTitle(translate('OpenLP.FirstTimeWizard', + 'Choose the main display screen for OpenLP.')) self.songs_check_box.setText(translate('OpenLP.FirstTimeWizard', 'Songs')) self.custom_check_box.setText(translate('OpenLP.FirstTimeWizard', 'Custom Slides – Easier to manage than songs and they have their own' @@ -271,10 +272,6 @@ class UiFirstTimeWizard(object): self.bibles_page.setSubTitle(translate('OpenLP.FirstTimeWizard', 'Select and download free Bibles.')) self.themes_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Sample Themes')) self.themes_page.setSubTitle(translate('OpenLP.FirstTimeWizard', 'Select and download sample themes.')) - self.defaults_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Default Settings')) - self.defaults_page.setSubTitle(translate('OpenLP.FirstTimeWizard', - 'Set up default settings to be used by OpenLP.')) - self.display_label.setText(translate('OpenLP.FirstTimeWizard', 'Default output display:')) self.theme_label.setText(translate('OpenLP.FirstTimeWizard', 'Select default theme:')) self.progress_page.setTitle(translate('OpenLP.FirstTimeWizard', 'Downloading and Configuring')) self.progress_page.setSubTitle(translate('OpenLP.FirstTimeWizard', 'Please wait while resources are downloaded ' diff --git a/openlp/core/widgets/widgets.py b/openlp/core/widgets/widgets.py index a8e725daf..1694ecf0a 100644 --- a/openlp/core/widgets/widgets.py +++ b/openlp/core/widgets/widgets.py @@ -189,12 +189,15 @@ class ScreenSelectionWidget(QtWidgets.QWidget): self.screen_frame_layout.setSpacing(8) self.screen_frame_layout.setObjectName('screen_frame_layout') self.layout.addWidget(self.screen_frame) - self.identify_layout = QtWidgets.QHBoxLayout(self) - self.screen_details_layout = QtWidgets.QVBoxLayout(self) + self.identify_layout = QtWidgets.QHBoxLayout() + self.screen_details_layout = QtWidgets.QVBoxLayout() self.screen_details_layout.setObjectName('screen_details_layout') self.screen_number_label = QtWidgets.QLabel(self) self.screen_number_label.setObjectName('screen_number_label') self.screen_details_layout.addWidget(self.screen_number_label) + self.use_screen_check_box = QtWidgets.QCheckBox(self) + self.use_screen_check_box.setVisible(False) + self.screen_details_layout.addWidget(self.use_screen_check_box) self.display_group_box = QtWidgets.QGroupBox(self) self.display_group_box.setObjectName('display_group_box') self.display_group_box.setCheckable(True) @@ -250,6 +253,7 @@ class ScreenSelectionWidget(QtWidgets.QWidget): self.layout.addStretch() # Signals and slots + self.use_screen_check_box.toggled.connect(self.display_group_box.setChecked) self.custom_geometry_button.toggled.connect(self.height_spin_box.setEnabled) self.custom_geometry_button.toggled.connect(self.left_spin_box.setEnabled) self.custom_geometry_button.toggled.connect(self.top_spin_box.setEnabled) @@ -265,7 +269,9 @@ class ScreenSelectionWidget(QtWidgets.QWidget): def retranslate_ui(self): self.full_screen_radio_button.setText(translate('OpenLP.ScreensTab', 'F&ull screen')) self.width_label.setText(translate('OpenLP.ScreensTab', 'Width:')) - self.display_group_box.setTitle(translate('OpenLP.ScreensTab', 'Use this screen as a display')) + use_screen_str = translate('OpenLP.ScreensTab', 'Use this screen as a display') + self.use_screen_check_box.setText(use_screen_str) + self.display_group_box.setTitle(use_screen_str) self.left_label.setText(translate('OpenLP.ScreensTab', 'Left:')) self.custom_geometry_button.setText(translate('OpenLP.ScreensTab', 'Custom &geometry')) self.top_label.setText(translate('OpenLP.ScreensTab', 'Top:')) @@ -336,6 +342,15 @@ class ScreenSelectionWidget(QtWidgets.QWidget): settings.setValue('core/screens', screen_settings) # On save update the screens as well + def use_simple_view(self): + """ + Hide advanced options. Added for use in the FTW + + :rtype: None + """ + self.use_screen_check_box.setVisible(True) + self.display_group_box.setVisible(False) + @QtCore.pyqtSlot() def _on_identify_timer_shot(self): for label in self.identify_labels: @@ -369,6 +384,7 @@ class ScreenSelectionWidget(QtWidgets.QWidget): if self.current_screen is not screen: self._save_screen(self.current_screen) self.screen_number_label.setText(str(screen)) + self.use_screen_check_box.setChecked(screen.is_display) self.display_group_box.setChecked(screen.is_display) self.full_screen_radio_button.setChecked(screen.custom_geometry is None) self.custom_geometry_button.setChecked(screen.custom_geometry is not None)