def bootstrap_post_set_up(self): """ Run any post-setup code for the tabs on the form """ # General tab self.general_tab = GeneralTab(self) # Themes tab self.themes_tab = ThemesTab(self) # Projector Tab self.projector_tab = ProjectorTab(self) # Advanced tab self.advanced_tab = AdvancedTab(self) # Advanced tab self.player_tab = PlayerTab(self) self.general_tab.post_set_up() self.themes_tab.post_set_up() self.advanced_tab.post_set_up() self.player_tab.post_set_up() for plugin in self.plugin_manager.plugins: if plugin.settings_tab: plugin.settings_tab.post_set_up()
def __init__(self, parent=None): """ Initialise the settings form """ Registry().register(u'settings_form', self) QtGui.QDialog.__init__(self, parent) self.setupUi(self) # General tab self.generalTab = GeneralTab(self) # Themes tab self.themesTab = ThemesTab(self) # Advanced tab self.advancedTab = AdvancedTab(self) # Advanced tab self.playerTab = PlayerTab(self)
def post_set_up(self): """ Run any post-setup code for the tabs on the form """ # General tab self.general_tab = GeneralTab(self) # Themes tab self.themes_tab = ThemesTab(self) # Advanced tab self.advanced_tab = AdvancedTab(self) # Advanced tab self.player_tab = PlayerTab(self) self.general_tab.post_set_up() self.themes_tab.post_set_up() self.advanced_tab.post_set_up() self.player_tab.post_set_up() for plugin in self.plugin_manager.plugins: if plugin.settings_tab: plugin.settings_tab.post_set_up()
class SettingsForm(QtWidgets.QDialog, Ui_SettingsDialog, RegistryProperties): """ Provide the form to manipulate the settings for OpenLP """ def __init__(self, parent=None): """ Initialise the settings form """ Registry().register('settings_form', self) Registry().register_function('bootstrap_post_set_up', self.bootstrap_post_set_up) super(SettingsForm, self).__init__(parent, QtCore.Qt.WindowSystemMenuHint | QtCore.Qt.WindowTitleHint) self.processes = [] self.setupUi(self) self.setting_list_widget.currentRowChanged.connect(self.list_item_changed) self.general_tab = None self.themes_tab = None self.projector_tab = None self.advanced_tab = None self.player_tab = None def exec(self): """ Execute the form """ # load all the self.setting_list_widget.blockSignals(True) self.setting_list_widget.clear() while self.stacked_layout.count(): # take at 0 and the rest shuffle up. self.stacked_layout.takeAt(0) self.insert_tab(self.general_tab) self.insert_tab(self.themes_tab) self.insert_tab(self.advanced_tab) self.insert_tab(self.player_tab) self.insert_tab(self.projector_tab) for plugin in self.plugin_manager.plugins: if plugin.settings_tab: self.insert_tab(plugin.settings_tab, plugin.is_active()) self.setting_list_widget.setCurrentRow(0) self.setting_list_widget.blockSignals(False) return QtWidgets.QDialog.exec(self) def insert_tab(self, tab_widget, is_visible=True): """ Add a tab to the form at a specific location :param tab_widget: The widget to add :param is_visible: If this tab should be visible """ log.debug('Inserting {text} tab'.format(text=tab_widget.tab_title)) # add the tab to get it to display in the correct part of the screen self.stacked_layout.addWidget(tab_widget) if is_visible: list_item = QtWidgets.QListWidgetItem(build_icon(tab_widget.icon_path), tab_widget.tab_title_visible) list_item.setData(QtCore.Qt.UserRole, tab_widget.tab_title) self.setting_list_widget.addItem(list_item) def accept(self): """ Process the form saving the settings """ log.debug('Processing settings exit') # We add all the forms into the stacked layout, even if the plugin is inactive, # but we don't add the item to the list on the side if the plugin is inactive, # so loop through the list items, and then find the tab for that item. for item_index in range(self.setting_list_widget.count()): # Get the list item list_item = self.setting_list_widget.item(item_index) if not list_item: continue # Now figure out if there's a tab for it, and save the tab. plugin_name = list_item.data(QtCore.Qt.UserRole) for tab_index in range(self.stacked_layout.count()): tab_widget = self.stacked_layout.widget(tab_index) if tab_widget.tab_title == plugin_name: tab_widget.save() # if the image background has been changed we need to regenerate the image cache if 'images_config_updated' in self.processes or 'config_screen_changed' in self.processes: self.register_post_process('images_regenerate') # Now lets process all the post save handlers while self.processes: Registry().execute(self.processes.pop(0)) return QtWidgets.QDialog.accept(self) def reject(self): """ Process the form saving the settings """ self.processes = [] # Same as accept(), we need to loop over the visible tabs, and skip the inactive ones for item_index in range(self.setting_list_widget.count()): # Get the list item list_item = self.setting_list_widget.item(item_index) if not list_item: continue # Now figure out if there's a tab for it, and save the tab. plugin_name = list_item.data(QtCore.Qt.UserRole) for tab_index in range(self.stacked_layout.count()): tab_widget = self.stacked_layout.widget(tab_index) if tab_widget.tab_title == plugin_name: tab_widget.cancel() return QtWidgets.QDialog.reject(self) def bootstrap_post_set_up(self): """ Run any post-setup code for the tabs on the form """ # General tab self.general_tab = GeneralTab(self) # Themes tab self.themes_tab = ThemesTab(self) # Projector Tab self.projector_tab = ProjectorTab(self) # Advanced tab self.advanced_tab = AdvancedTab(self) # Advanced tab self.player_tab = PlayerTab(self) self.general_tab.post_set_up() self.themes_tab.post_set_up() self.advanced_tab.post_set_up() self.player_tab.post_set_up() for plugin in self.plugin_manager.plugins: if plugin.settings_tab: plugin.settings_tab.post_set_up() def list_item_changed(self, item_index): """ A different settings tab is selected :param item_index: The index of the item that was selected """ # Get the item we clicked on list_item = self.setting_list_widget.item(item_index) # Quick exit to the left if the item doesn't exist (maybe -1?) if not list_item: return # Loop through the list of tabs in the stacked layout for tab_index in range(self.stacked_layout.count()): # Get the widget tab_widget = self.stacked_layout.itemAt(tab_index).widget() # Check that the title of the tab (i.e. plugin name) is the same as the data in the list item if tab_widget.tab_title == list_item.data(QtCore.Qt.UserRole): # Make the matching tab visible tab_widget.tab_visited = True self.stacked_layout.setCurrentIndex(tab_index) self.stacked_layout.currentWidget().tab_visible() def register_post_process(self, function): """ Register for updates to be done on save removing duplicate functions :param function: The function to be called """ if function not in self.processes: self.processes.append(function)
class SettingsForm(QtGui.QDialog, Ui_SettingsDialog, RegistryProperties): """ Provide the form to manipulate the settings for OpenLP """ def __init__(self, parent=None): """ Initialise the settings form """ Registry().register('settings_form', self) Registry().register_function('bootstrap_post_set_up', self.bootstrap_post_set_up) super(SettingsForm, self).__init__(parent) self.processes = [] self.setupUi(self) self.setting_list_widget.currentRowChanged.connect( self.list_item_changed) self.general_tab = None self.themes_tab = None self.projector_tab = None self.advanced_tab = None self.player_tab = None def exec_(self): """ Execute the form """ # load all the settings self.setting_list_widget.clear() while self.stacked_layout.count(): # take at 0 and the rest shuffle up. self.stacked_layout.takeAt(0) self.insert_tab(self.general_tab) self.insert_tab(self.themes_tab) self.insert_tab(self.advanced_tab) self.insert_tab(self.player_tab) self.insert_tab(self.projector_tab) for plugin in self.plugin_manager.plugins: if plugin.settings_tab: self.insert_tab(plugin.settings_tab, plugin.is_active()) self.setting_list_widget.setCurrentRow(0) return QtGui.QDialog.exec_(self) def insert_tab(self, tab_widget, is_visible=True): """ Add a tab to the form at a specific location :param tab_widget: The widget to add :param is_visible: If this tab should be visible """ log.debug('Inserting %s tab' % tab_widget.tab_title) # add the tab to get it to display in the correct part of the screen self.stacked_layout.addWidget(tab_widget) if is_visible: list_item = QtGui.QListWidgetItem(build_icon(tab_widget.icon_path), tab_widget.tab_title_visible) list_item.setData(QtCore.Qt.UserRole, tab_widget.tab_title) self.setting_list_widget.addItem(list_item) def accept(self): """ Process the form saving the settings """ log.debug('Processing settings exit') # We add all the forms into the stacked layout, even if the plugin is inactive, # but we don't add the item to the list on the side if the plugin is inactive, # so loop through the list items, and then find the tab for that item. for item_index in range(self.setting_list_widget.count()): # Get the list item list_item = self.setting_list_widget.item(item_index) if not list_item: continue # Now figure out if there's a tab for it, and save the tab. plugin_name = list_item.data(QtCore.Qt.UserRole) for tab_index in range(self.stacked_layout.count()): tab_widget = self.stacked_layout.widget(tab_index) if tab_widget.tab_title == plugin_name: tab_widget.save() # if the image background has been changed we need to regenerate the image cache if 'images_config_updated' in self.processes or 'config_screen_changed' in self.processes: self.register_post_process('images_regenerate') # Now lets process all the post save handlers while self.processes: Registry().execute(self.processes.pop(0)) return QtGui.QDialog.accept(self) def reject(self): """ Process the form saving the settings """ self.processes = [] # Same as accept(), we need to loop over the visible tabs, and skip the inactive ones for item_index in range(self.setting_list_widget.count()): # Get the list item list_item = self.setting_list_widget.item(item_index) if not list_item: continue # Now figure out if there's a tab for it, and save the tab. plugin_name = list_item.data(QtCore.Qt.UserRole) for tab_index in range(self.stacked_layout.count()): tab_widget = self.stacked_layout.widget(tab_index) if tab_widget.tab_title == plugin_name: tab_widget.cancel() return QtGui.QDialog.reject(self) def bootstrap_post_set_up(self): """ Run any post-setup code for the tabs on the form """ # General tab self.general_tab = GeneralTab(self) # Themes tab self.themes_tab = ThemesTab(self) # Projector Tab self.projector_tab = ProjectorTab(self) # Advanced tab self.advanced_tab = AdvancedTab(self) # Advanced tab self.player_tab = PlayerTab(self) self.general_tab.post_set_up() self.themes_tab.post_set_up() self.advanced_tab.post_set_up() self.player_tab.post_set_up() for plugin in self.plugin_manager.plugins: if plugin.settings_tab: plugin.settings_tab.post_set_up() def list_item_changed(self, item_index): """ A different settings tab is selected :param item_index: The index of the item that was selected """ # Get the item we clicked on list_item = self.setting_list_widget.item(item_index) # Quick exit to the left if the item doesn't exist (maybe -1?) if not list_item: return # Loop through the list of tabs in the stacked layout for tab_index in range(self.stacked_layout.count()): # Get the widget tab_widget = self.stacked_layout.itemAt(tab_index).widget() # Check that the title of the tab (i.e. plugin name) is the same as the data in the list item if tab_widget.tab_title == list_item.data(QtCore.Qt.UserRole): # Make the matching tab visible self.stacked_layout.setCurrentIndex(tab_index) self.stacked_layout.currentWidget().tab_visible() def register_post_process(self, function): """ Register for updates to be done on save removing duplicate functions :param function: The function to be called """ if function not in self.processes: self.processes.append(function)
class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): """ Provide the form to manipulate the settings for OpenLP """ def __init__(self, parent=None): """ Initialise the settings form """ Registry().register('settings_form', self) Registry().register_function('bootstrap_post_set_up', self.post_set_up) super(SettingsForm, self).__init__(parent) self.processes = [] self.setupUi(self) def exec_(self): """ Execute the form """ # load all the settings self.setting_list_widget.clear() while self.stacked_layout.count(): # take at 0 and the rest shuffle up. self.stacked_layout.takeAt(0) self.insert_tab(self.general_tab, 0, PluginStatus.Active) self.insert_tab(self.themes_tab, 1, PluginStatus.Active) self.insert_tab(self.advanced_tab, 2, PluginStatus.Active) self.insert_tab(self.player_tab, 3, PluginStatus.Active) count = 4 for plugin in self.plugin_manager.plugins: if plugin.settings_tab: self.insert_tab(plugin.settings_tab, count, plugin.status) count += 1 self.setting_list_widget.setCurrentRow(0) return QtGui.QDialog.exec_(self) def insert_tab(self, tab, location, is_active): """ Add a tab to the form at a specific location """ log.debug('Inserting %s tab' % tab.tab_title) # add the tab to get it to display in the correct part of the screen pos = self.stacked_layout.addWidget(tab) if is_active: item_name = QtGui.QListWidgetItem(tab.tab_title_visible) icon = build_icon(tab.icon_path) item_name.setIcon(icon) self.setting_list_widget.insertItem(location, item_name) else: # then remove tab to stop the UI displaying it even if it is not required. self.stacked_layout.takeAt(pos) def accept(self): """ Process the form saving the settings """ log.debug('Processing settings exit') for tabIndex in range(self.stacked_layout.count()): self.stacked_layout.widget(tabIndex).save() # if the display of image background are changing we need to regenerate the image cache if 'images_config_updated' in self.processes or 'config_screen_changed' in self.processes: self.register_post_process('images_regenerate') # Now lets process all the post save handlers while self.processes: Registry().execute(self.processes.pop(0)) return QtGui.QDialog.accept(self) def reject(self): """ Process the form saving the settings """ self.processes = [] for tabIndex in range(self.stacked_layout.count()): self.stacked_layout.widget(tabIndex).cancel() return QtGui.QDialog.reject(self) def post_set_up(self): """ Run any post-setup code for the tabs on the form """ # General tab self.general_tab = GeneralTab(self) # Themes tab self.themes_tab = ThemesTab(self) # Advanced tab self.advanced_tab = AdvancedTab(self) # Advanced tab self.player_tab = PlayerTab(self) self.general_tab.post_set_up() self.themes_tab.post_set_up() self.advanced_tab.post_set_up() self.player_tab.post_set_up() for plugin in self.plugin_manager.plugins: if plugin.settings_tab: plugin.settings_tab.post_set_up() def tab_changed(self, tabIndex): """ A different settings tab is selected """ self.stacked_layout.setCurrentIndex(tabIndex) self.stacked_layout.currentWidget().tab_visible() def register_post_process(self, function): """ Register for updates to be done on save removing duplicate functions ``function`` The function to be called """ if not function in self.processes: self.processes.append(function) def _get_main_window(self): """ Adds the main window to the class dynamically """ if not hasattr(self, '_main_window'): self._main_window = Registry().get('main_window') return self._main_window main_window = property(_get_main_window) def _get_service_manager(self): """ Adds the plugin manager to the class dynamically """ if not hasattr(self, '_service_manager'): self._service_manager = Registry().get('service_manager') return self._service_manager service_manager = property(_get_service_manager) def _get_plugin_manager(self): """ Adds the plugin manager to the class dynamically """ if not hasattr(self, '_plugin_manager'): self._plugin_manager = Registry().get('plugin_manager') return self._plugin_manager plugin_manager = property(_get_plugin_manager)
class SettingsForm(QtGui.QDialog, Ui_SettingsDialog): """ Provide the form to manipulate the settings for OpenLP """ def __init__(self, parent=None): """ Initialise the settings form """ Registry().register(u'settings_form', self) QtGui.QDialog.__init__(self, parent) self.setupUi(self) # General tab self.generalTab = GeneralTab(self) # Themes tab self.themesTab = ThemesTab(self) # Advanced tab self.advancedTab = AdvancedTab(self) # Advanced tab self.playerTab = PlayerTab(self) def exec_(self): """ Execute the form """ # load all the settings self.settingListWidget.clear() while self.stackedLayout.count(): # take at 0 and the rest shuffle up. self.stackedLayout.takeAt(0) self.insertTab(self.generalTab, 0, PluginStatus.Active) self.insertTab(self.themesTab, 1, PluginStatus.Active) self.insertTab(self.advancedTab, 2, PluginStatus.Active) self.insertTab(self.playerTab, 3, PluginStatus.Active) count = 4 for plugin in self.plugins: if plugin.settingsTab: self.insertTab(plugin.settingsTab, count, plugin.status) count += 1 self.settingListWidget.setCurrentRow(0) return QtGui.QDialog.exec_(self) def insertTab(self, tab, location, is_active): """ Add a tab to the form at a specific location """ log.debug(u'Inserting %s tab' % tab.tabTitle) # add the tab to get it to display in the correct part of the screen pos = self.stackedLayout.addWidget(tab) if is_active: item_name = QtGui.QListWidgetItem(tab.tabTitleVisible) icon = build_icon(tab.iconPath) item_name.setIcon(icon) self.settingListWidget.insertItem(location, item_name) else: # then remove tab to stop the UI displaying it even if # it is not required. self.stackedLayout.takeAt(pos) def accept(self): """ Process the form saving the settings """ self.resetSuffixes = True for tabIndex in range(self.stackedLayout.count()): self.stackedLayout.widget(tabIndex).save() # Must go after all settings are save Receiver.send_message(u'config_updated') return QtGui.QDialog.accept(self) def reject(self): """ Process the form saving the settings """ for tabIndex in range(self.stackedLayout.count()): self.stackedLayout.widget(tabIndex).cancel() return QtGui.QDialog.reject(self) def postSetUp(self): """ Run any post-setup code for the tabs on the form """ self.generalTab.postSetUp() self.themesTab.postSetUp() self.advancedTab.postSetUp() self.playerTab.postSetUp() for plugin in self.plugins: if plugin.settingsTab: plugin.settingsTab.postSetUp() def tabChanged(self, tabIndex): """ A different settings tab is selected """ self.stackedLayout.setCurrentIndex(tabIndex) self.stackedLayout.currentWidget().tabVisible() def resetSupportedSuffixes(self): """ Control the resetting of the serviceManager suffix list as can be called by a number of settings tab and only needs to be called once per save. """ if self.resetSuffixes: self.service_manager.reset_supported_suffixes() self.resetSuffixes = False def _get_main_window(self): """ Adds the main window to the class dynamically """ if not hasattr(self, u'_main_window'): self._main_window = Registry().get(u'main_window') return self._main_window main_window = property(_get_main_window) def _get_service_manager(self): """ Adds the plugin manager to the class dynamically """ if not hasattr(self, u'_service_manager'): self._service_manager = Registry().get(u'service_manager') return self._service_manager service_manager = property(_get_service_manager)