Project/LexerAssociationDialog.py

changeset 2995
63d874899b8b
parent 2408
dc3a7c9d8f6e
child 3010
befeff46ec0f
equal deleted inserted replaced
2994:5ae1349b8fb4 2995:63d874899b8b
27 @param parent reference to the parent widget (QWidget) 27 @param parent reference to the parent widget (QWidget)
28 """ 28 """
29 super().__init__(parent) 29 super().__init__(parent)
30 self.setupUi(self) 30 self.setupUi(self)
31 31
32 self.editorLexerList.headerItem().setText(self.editorLexerList.columnCount(), "") 32 self.editorLexerList.headerItem().setText(
33 self.editorLexerList.columnCount(), "")
33 header = self.editorLexerList.header() 34 header = self.editorLexerList.header()
34 if qVersion() >= "5.0.0": 35 if qVersion() >= "5.0.0":
35 header.setSectionResizeMode(QHeaderView.ResizeToContents) 36 header.setSectionResizeMode(QHeaderView.ResizeToContents)
36 else: 37 else:
37 header.setResizeMode(QHeaderView.ResizeToContents) 38 header.setResizeMode(QHeaderView.ResizeToContents)
43 self.extsep = "." 44 self.extsep = "."
44 45
45 self.extras = ["-----------", self.trUtf8("Alternative")] 46 self.extras = ["-----------", self.trUtf8("Alternative")]
46 47
47 import QScintilla.Lexers 48 import QScintilla.Lexers
48 languages = \ 49 languages = [''] + \
49 [''] + sorted(QScintilla.Lexers.getSupportedLanguages().keys()) + self.extras 50 sorted(QScintilla.Lexers.getSupportedLanguages().keys()) + \
51 self.extras
50 self.editorLexerCombo.addItems(languages) 52 self.editorLexerCombo.addItems(languages)
51 53
52 from pygments.lexers import get_all_lexers 54 from pygments.lexers import get_all_lexers
53 pygmentsLexers = [''] + sorted([l[0] for l in get_all_lexers()]) 55 pygmentsLexers = [''] + sorted([l[0] for l in get_all_lexers()])
54 self.pygmentsLexerCombo.addItems(pygmentsLexers) 56 self.pygmentsLexerCombo.addItems(pygmentsLexers)
89 self.editorLexerList.header().sortIndicatorOrder()) 91 self.editorLexerList.header().sortIndicatorOrder())
90 92
91 @pyqtSlot() 93 @pyqtSlot()
92 def on_deleteLexerButton_clicked(self): 94 def on_deleteLexerButton_clicked(self):
93 """ 95 """
94 Private slot to delete the currently selected lexer association of the list. 96 Private slot to delete the currently selected lexer association of the
97 list.
95 """ 98 """
96 itmList = self.editorLexerList.selectedItems() 99 itmList = self.editorLexerList.selectedItems()
97 if itmList: 100 if itmList:
98 index = self.editorLexerList.indexOfTopLevelItem(itmList[0]) 101 index = self.editorLexerList.indexOfTopLevelItem(itmList[0])
99 itm = self.editorLexerList.takeTopLevelItem(index) 102 itm = self.editorLexerList.takeTopLevelItem(index)
106 def on_editorLexerList_itemClicked(self, itm, column): 109 def on_editorLexerList_itemClicked(self, itm, column):
107 """ 110 """
108 Private slot to handle the clicked signal of the lexer association list. 111 Private slot to handle the clicked signal of the lexer association list.
109 112
110 @param itm reference to the selecte item (QTreeWidgetItem) 113 @param itm reference to the selecte item (QTreeWidgetItem)
111 @param column column the item was clicked or activated (integer) (ignored) 114 @param column column the item was clicked or activated (integer)
115 (ignored)
112 """ 116 """
113 if itm is None: 117 if itm is None:
114 self.editorFileExtEdit.clear() 118 self.editorFileExtEdit.clear()
115 self.editorLexerCombo.setCurrentIndex(0) 119 self.editorLexerCombo.setCurrentIndex(0)
116 self.pygmentsLexerCombo.setCurrentIndex(0) 120 self.pygmentsLexerCombo.setCurrentIndex(0)
127 self.editorLexerCombo.setCurrentIndex(index) 131 self.editorLexerCombo.setCurrentIndex(index)
128 self.pygmentsLexerCombo.setCurrentIndex(pygmentsIndex) 132 self.pygmentsLexerCombo.setCurrentIndex(pygmentsIndex)
129 133
130 def on_editorLexerList_itemActivated(self, itm, column): 134 def on_editorLexerList_itemActivated(self, itm, column):
131 """ 135 """
132 Private slot to handle the activated signal of the lexer association list. 136 Private slot to handle the activated signal of the lexer association
137 list.
133 138
134 @param itm reference to the selecte item (QTreeWidgetItem) 139 @param itm reference to the selecte item (QTreeWidgetItem)
135 @param column column the item was clicked or activated (integer) (ignored) 140 @param column column the item was clicked or activated (integer)
141 (ignored)
136 """ 142 """
137 self.on_editorLexerList_itemClicked(itm, column) 143 self.on_editorLexerList_itemClicked(itm, column)
138 144
139 @pyqtSlot(str) 145 @pyqtSlot(str)
140 def on_editorLexerCombo_currentIndexChanged(self, text): 146 def on_editorLexerCombo_currentIndexChanged(self, text):
150 self.pygmentsLexerCombo.setEnabled(False) 156 self.pygmentsLexerCombo.setEnabled(False)
151 self.pygmentsLabel.setEnabled(False) 157 self.pygmentsLabel.setEnabled(False)
152 158
153 def transferData(self): 159 def transferData(self):
154 """ 160 """
155 Public slot to transfer the associations into the projects data structure. 161 Public slot to transfer the associations into the projects data
162 structure.
156 """ 163 """
157 self.project.pdata["LEXERASSOCS"] = {} 164 self.project.pdata["LEXERASSOCS"] = {}
158 for index in range(self.editorLexerList.topLevelItemCount()): 165 for index in range(self.editorLexerList.topLevelItemCount()):
159 itm = self.editorLexerList.topLevelItem(index) 166 itm = self.editorLexerList.topLevelItem(index)
160 pattern = itm.text(0) 167 pattern = itm.text(0)

eric ide

mercurial