eric6/Preferences/ConfigurationPages/EditorHighlightingStylesSelectionDialog.py

branch
jsonfiles
changeset 8028
a4f1b68c0737
child 8143
2c730d5fd177
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/eric6/Preferences/ConfigurationPages/EditorHighlightingStylesSelectionDialog.py	Fri Jan 29 19:31:47 2021 +0100
@@ -0,0 +1,117 @@
+# -*- coding: utf-8 -*-
+
+# Copyright (c) 2021 Detlev Offenbach <detlev@die-offenbachs.de>
+#
+
+"""
+Module implementing a dialog to select the styles to be imported/exported.
+"""
+
+from PyQt5.QtCore import pyqtSlot, Qt
+from PyQt5.QtWidgets import (
+    QDialog, QDialogButtonBox, QListWidgetItem, QAbstractButton
+)
+
+from .Ui_EditorHighlightingStylesSelectionDialog import (
+    Ui_EditorHighlightingStylesSelectionDialog
+)
+
+
+class EditorHighlightingStylesSelectionDialog(
+    QDialog, Ui_EditorHighlightingStylesSelectionDialog
+):
+    """
+    Class implementing a dialog to select the styles to be imported/exported.
+    """
+    def __init__(self, lexerNames, forImport, preselect=None, parent=None):
+        """
+        Constructor
+        
+        @param lexerNames list of lexer names to select from
+        @type list of str
+        @param forImport flag indicating a dialog for importing styles
+        @type bool
+        @param preselect list of lexer names to be preselected
+        @type list of str
+        @param parent reference to the parent widget
+        @type QWidget
+        """
+        super(EditorHighlightingStylesSelectionDialog, self).__init__(parent)
+        self.setupUi(self)
+        
+        self.__selectAllButton = self.buttonBox.addButton(
+            self.tr("Select All"), QDialogButtonBox.ActionRole)
+        
+        if forImport:
+            self.setWindowTitle(self.tr("Import Highlighting Styles"))
+            self.infoLabel.setText(self.tr(
+                "Select the highlighting styles to be imported"))
+        else:
+            self.setWindowTitle(self.tr("Export Highlighting Styles"))
+            self.infoLabel.setText(self.tr(
+                "Select the highlighting styles to be exported"))
+        
+        if preselect is None:
+            preselect = []
+        
+        for name in lexerNames:
+            itm = QListWidgetItem(name, self.lexersList)
+            itm.setFlags(Qt.ItemIsUserCheckable | Qt.ItemIsEnabled)
+            if name in preselect:
+                itm.setCheckState(Qt.Checked)
+            else:
+                itm.setCheckState(Qt.Unchecked)
+        
+        self.__updateOkButton()
+    
+    @pyqtSlot()
+    def __updateOkButton(self):
+        """
+        Private slot to update the state of the OK button.
+        """
+        for row in range(self.lexersList.count()):
+            itm = self.lexersList.item(row)
+            if itm.checkState() == Qt.Checked:
+                enable = True
+                break
+        else:
+            enable = False
+        self.buttonBox.button(QDialogButtonBox.Ok).setEnabled(enable)
+    
+    @pyqtSlot(QListWidgetItem)
+    def on_lexersList_itemChanged(self, item):
+        """
+        Private slot to react on changes in check state.
+        
+        @param item reference to the changed item
+        @type QListWidgetItem
+        """
+        self.__updateOkButton()
+    
+    @pyqtSlot(QAbstractButton)
+    def on_buttonBox_clicked(self, button):
+        """
+        Private slot to handle the user pressing a button.
+        
+        @param button reference to the button pressed
+        @type QAbstractButton
+        """
+        if button is self.__selectAllButton:
+            for row in range(self.lexersList.count()):
+                itm = self.lexersList.item(row)
+                itm.setCheckState(Qt.Checked)
+    
+    def getLexerNames(self):
+        """
+        Public method to get the selected lexer names.
+        
+        @return list of selected lexer names
+        @rtype list of str
+        """
+        lexerNames = []
+        for row in range(self.lexersList.count()):
+            itm = self.lexersList.item(row)
+            if itm.checkState() == Qt.Checked:
+                lexerNames.append(itm.text())
+        
+        return lexerNames

eric ide

mercurial