Project/FiletypeAssociationDialog.py

changeset 2995
63d874899b8b
parent 2302
f29e9405c851
child 3010
befeff46ec0f
equal deleted inserted replaced
2994:5ae1349b8fb4 2995:63d874899b8b
27 super().__init__(parent) 27 super().__init__(parent)
28 self.setupUi(self) 28 self.setupUi(self)
29 29
30 self.filetypeAssociationList.headerItem().setText( 30 self.filetypeAssociationList.headerItem().setText(
31 self.filetypeAssociationList.columnCount(), "") 31 self.filetypeAssociationList.columnCount(), "")
32 self.filetypeAssociationList.header().setSortIndicator(0, Qt.AscendingOrder) 32 self.filetypeAssociationList.header().setSortIndicator(
33 0, Qt.AscendingOrder)
33 34
34 # keep these lists in sync 35 # keep these lists in sync
35 self.filetypes = ["SOURCES", "FORMS", "TRANSLATIONS", "RESOURCES", "INTERFACES", 36 self.filetypes = ["SOURCES", "FORMS", "TRANSLATIONS", "RESOURCES",
36 "OTHERS", "__IGNORE__"] 37 "INTERFACES", "OTHERS", "__IGNORE__"]
37 self.filetypeStrings = [self.trUtf8("Sources"), self.trUtf8("Forms"), 38 self.filetypeStrings = [self.trUtf8("Sources"), self.trUtf8("Forms"),
38 self.trUtf8("Translations"), self.trUtf8("Resources"), 39 self.trUtf8("Translations"),
39 self.trUtf8("Interfaces"), self.trUtf8("Others"), 40 self.trUtf8("Resources"),
41 self.trUtf8("Interfaces"),
42 self.trUtf8("Others"),
40 self.trUtf8("Ignore")] 43 self.trUtf8("Ignore")]
41 self.filetypeCombo.addItems(self.filetypeStrings) 44 self.filetypeCombo.addItems(self.filetypeStrings)
42 45
43 self.project = project 46 self.project = project
44 for pattern, filetype in list(self.project.pdata["FILETYPES"].items()): 47 for pattern, filetype in list(self.project.pdata["FILETYPES"].items()):
53 56
54 def __resort(self): 57 def __resort(self):
55 """ 58 """
56 Private method to resort the tree. 59 Private method to resort the tree.
57 """ 60 """
58 self.filetypeAssociationList.sortItems(self.filetypeAssociationList.sortColumn(), 61 self.filetypeAssociationList.sortItems(
62 self.filetypeAssociationList.sortColumn(),
59 self.filetypeAssociationList.header().sortIndicatorOrder()) 63 self.filetypeAssociationList.header().sortIndicatorOrder())
60 64
61 def __reformat(self): 65 def __reformat(self):
62 """ 66 """
63 Private method to reformat the tree. 67 Private method to reformat the tree.
64 """ 68 """
65 self.filetypeAssociationList.header().resizeSections(QHeaderView.ResizeToContents) 69 self.filetypeAssociationList.header().resizeSections(
70 QHeaderView.ResizeToContents)
66 self.filetypeAssociationList.header().setStretchLastSection(True) 71 self.filetypeAssociationList.header().setStretchLastSection(True)
67 72
68 def __createItem(self, pattern, filetype): 73 def __createItem(self, pattern, filetype):
69 """ 74 """
70 Private slot to create a new entry in the association list. 75 Private slot to create a new entry in the association list.
76 itm = QTreeWidgetItem(self.filetypeAssociationList, [pattern, filetype]) 81 itm = QTreeWidgetItem(self.filetypeAssociationList, [pattern, filetype])
77 return itm 82 return itm
78 83
79 def on_filetypeAssociationList_currentItemChanged(self, itm, prevItm): 84 def on_filetypeAssociationList_currentItemChanged(self, itm, prevItm):
80 """ 85 """
81 Private slot to handle the currentItemChanged signal of the association list. 86 Private slot to handle the currentItemChanged signal of the
87 association list.
82 88
83 @param itm reference to the new current item (QTreeWidgetItem) 89 @param itm reference to the new current item (QTreeWidgetItem)
84 @param prevItm reference to the previous current item (QTreeWidgetItem) 90 @param prevItm reference to the previous current item (QTreeWidgetItem)
85 """ 91 """
86 if itm is None: 92 if itm is None:
87 self.filePatternEdit.clear() 93 self.filePatternEdit.clear()
88 self.filetypeCombo.setCurrentIndex(0) 94 self.filetypeCombo.setCurrentIndex(0)
89 self.deleteAssociationButton.setEnabled(False) 95 self.deleteAssociationButton.setEnabled(False)
90 else: 96 else:
91 self.filePatternEdit.setText(itm.text(0)) 97 self.filePatternEdit.setText(itm.text(0))
92 self.filetypeCombo.setCurrentIndex(self.filetypeCombo.findText(itm.text(1))) 98 self.filetypeCombo.setCurrentIndex(
99 self.filetypeCombo.findText(itm.text(1)))
93 self.deleteAssociationButton.setEnabled(True) 100 self.deleteAssociationButton.setEnabled(True)
94 101
95 @pyqtSlot() 102 @pyqtSlot()
96 def on_addAssociationButton_clicked(self): 103 def on_addAssociationButton_clicked(self):
97 """ 104 """
114 self.filetypeAssociationList.setCurrentItem(itm) 121 self.filetypeAssociationList.setCurrentItem(itm)
115 122
116 @pyqtSlot() 123 @pyqtSlot()
117 def on_deleteAssociationButton_clicked(self): 124 def on_deleteAssociationButton_clicked(self):
118 """ 125 """
119 Private slot to delete the currently selected association of the listbox. 126 Private slot to delete the currently selected association of the
127 listbox.
120 """ 128 """
121 for itm in self.filetypeAssociationList.selectedItems(): 129 for itm in self.filetypeAssociationList.selectedItems():
122 itm = self.filetypeAssociationList.takeTopLevelItem( 130 itm = self.filetypeAssociationList.takeTopLevelItem(
123 self.filetypeAssociationList.indexOfTopLevelItem(itm)) 131 self.filetypeAssociationList.indexOfTopLevelItem(itm))
124 del itm 132 del itm
140 self.addAssociationButton.setEnabled(True) 148 self.addAssociationButton.setEnabled(True)
141 if len(self.filetypeAssociationList.selectedItems()) == 0: 149 if len(self.filetypeAssociationList.selectedItems()) == 0:
142 self.deleteAssociationButton.setEnabled(False) 150 self.deleteAssociationButton.setEnabled(False)
143 else: 151 else:
144 self.deleteAssociationButton.setEnabled( 152 self.deleteAssociationButton.setEnabled(
145 self.filetypeAssociationList.selectedItems()[0].text(0) == txt) 153 self.filetypeAssociationList.selectedItems()[0].text(0) \
154 == txt)
146 155
147 def transferData(self): 156 def transferData(self):
148 """ 157 """
149 Public slot to transfer the associations into the projects data structure. 158 Public slot to transfer the associations into the projects data
159 structure.
150 """ 160 """
151 self.project.pdata["FILETYPES"] = {} 161 self.project.pdata["FILETYPES"] = {}
152 for index in range(self.filetypeAssociationList.topLevelItemCount()): 162 for index in range(self.filetypeAssociationList.topLevelItemCount()):
153 itm = self.filetypeAssociationList.topLevelItem(index) 163 itm = self.filetypeAssociationList.topLevelItem(index)
154 pattern = itm.text(0) 164 pattern = itm.text(0)

eric ide

mercurial