~ubuntu-branches/ubuntu/karmic/eric/karmic

« back to all changes in this revision

Viewing changes to eric/Project/FiletypeAssociationDialog.py

  • Committer: Bazaar Package Importer
  • Author(s): Scott Kitterman
  • Date: 2008-01-28 18:02:25 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20080128180225-6nrox6yrworh2c4v
Tags: 4.0.4-1ubuntu1
* Add python-qt3 to build-depends becuase that's where Ubuntu puts 
  pyqtconfig
* Change maintainer to MOTU

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
import sys
11
11
import os
12
12
 
13
 
from qt import *
14
 
from FiletypeAssociationForm import FiletypeAssociationForm
15
 
 
16
 
class FiletypeAssociationDialog(FiletypeAssociationForm):
 
13
from PyQt4.QtCore import *
 
14
from PyQt4.QtGui import *
 
15
 
 
16
from Ui_FiletypeAssociationDialog import Ui_FiletypeAssociationDialog
 
17
 
 
18
class FiletypeAssociationDialog(QDialog, Ui_FiletypeAssociationDialog):
17
19
    """
18
20
    Class implementing a dialog to enter filetype associations for the project.
19
21
    """
24
26
        @param project reference to the project object
25
27
        @param parent reference to the parent widget (QWidget)
26
28
        """
27
 
        FiletypeAssociationForm.__init__(self, parent, None, 1)
 
29
        QDialog.__init__(self, parent)
 
30
        self.setupUi(self)
28
31
 
 
32
        self.filetypeAssociationList.header().setSortIndicator(0, Qt.AscendingOrder)
 
33
        
29
34
        # keep these lists in sync
30
 
        self.filetypes = ["SOURCES", "FORMS", "INTERFACES", "OTHERS"]
 
35
        self.filetypes = ["SOURCES", "FORMS", "RESOURCES", "INTERFACES", "OTHERS"]
31
36
        self.filetypeStrings = [self.trUtf8("Sources"), self.trUtf8("Forms"),
 
37
                                self.trUtf8("Resources"),
32
38
                                self.trUtf8("Interfaces"), self.trUtf8("Others")]
33
39
        self.filetypesList = QStringList()
34
40
        for fts in self.filetypeStrings:
35
41
            self.filetypesList.append(fts)
36
 
        self.filetypeCombo.insertStringList(self.filetypesList)
 
42
        self.filetypeCombo.addItems(self.filetypesList)
37
43
        
38
44
        self.project = project
39
45
        for pattern, filetype in self.project.pdata["FILETYPES"].items():
40
46
            try:
41
47
                index = self.filetypes.index(filetype)
42
 
                itm = QListViewItem(self.filetypeAssociationList, pattern, 
43
 
                    self.filetypeStrings[index])
 
48
                itm = self.__createItem(pattern, self.filetypeStrings[index])
44
49
            except ValueError:
45
50
                pass    # silently discard entries of unknown type
46
51
        
47
 
    def handleAssociationSelected(self, itm):
48
 
        """
49
 
        Private slot to handle the clicked signal of the association list.
50
 
        
51
 
        @param itm reference to the selecte item (QListViewItem)
 
52
        self.__resort()
 
53
        self.__reformat()
 
54
        
 
55
    def __resort(self):
 
56
        """
 
57
        Private method to resort the tree.
 
58
        """
 
59
        self.filetypeAssociationList.sortItems(self.filetypeAssociationList.sortColumn(), 
 
60
            self.filetypeAssociationList.header().sortIndicatorOrder())
 
61
        
 
62
    def __reformat(self):
 
63
        """
 
64
        Private method to reformat the tree.
 
65
        """
 
66
        self.filetypeAssociationList.header().resizeSections(QHeaderView.ResizeToContents)
 
67
        self.filetypeAssociationList.header().setStretchLastSection(True)
 
68
        
 
69
    def __createItem(self, pattern, filetype):
 
70
        """
 
71
        Private slot to create a new entry in the association list.
 
72
        
 
73
        @param pattern pattern of the entry (string or QString)
 
74
        @param filetype file type of the entry (string or QString)
 
75
        @return reference to the newly generated entry (QTreeWidgetItem)
 
76
        """
 
77
        itm = QTreeWidgetItem(self.filetypeAssociationList,
 
78
            QStringList() << pattern << filetype)
 
79
        return itm
 
80
        
 
81
    def on_filetypeAssociationList_currentItemChanged(self, itm, prevItm):
 
82
        """
 
83
        Private slot to handle the currentItemChanged signal of the association list.
 
84
        
 
85
        @param itm reference to the new current item (QTreeWidgetItem)
 
86
        @param prevItm reference to the previous current item (QTreeWidgetItem)
52
87
        """
53
88
        if itm is None:
54
89
            self.filePatternEdit.clear()
55
 
            self.filetypeCombo.setCurrentItem(0)
56
 
            self.deleteAssociationButton.setEnabled(0)
 
90
            self.filetypeCombo.setCurrentIndex(0)
 
91
            self.deleteAssociationButton.setEnabled(False)
57
92
        else:
58
93
            self.filePatternEdit.setText(itm.text(0))
59
 
            self.filetypeCombo.setCurrentText(itm.text(1))
60
 
            self.deleteAssociationButton.setEnabled(1)
 
94
            self.filetypeCombo.setCurrentIndex(self.filetypeCombo.findText(itm.text(1)))
 
95
            self.deleteAssociationButton.setEnabled(True)
61
96
 
62
 
    def handleAssociationAdd(self):
 
97
    @pyqtSignature("")
 
98
    def on_addAssociationButton_clicked(self):
63
99
        """
64
 
        Private slot to add the association displayed to the listbox.
 
100
        Private slot to add the association displayed to the list.
65
101
        """
66
102
        pattern = self.filePatternEdit.text()
67
103
        filetype = self.filetypeCombo.currentText()
68
104
        if not pattern.isEmpty():
69
 
            itm = self.filetypeAssociationList.findItem(pattern, 0)
70
 
            if itm:
71
 
                self.filetypeAssociationList.takeItem(itm)
 
105
            items = self.filetypeAssociationList.findItems(\
 
106
                pattern, Qt.MatchFlags(Qt.MatchExactly), 0)
 
107
            for itm in items:
 
108
                itm = self.filetypeAssociationList.takeTopLevelItem(\
 
109
                    self.filetypeAssociationList.indexOfTopLevelItem(itm))
72
110
                del itm
73
 
            itm = QListViewItem(self.filetypeAssociationList, pattern, filetype)
 
111
            itm = self.__createItem(pattern, filetype)
 
112
            self.__resort()
 
113
            self.__reformat()
74
114
            self.filePatternEdit.clear()
75
 
            self.filetypeCombo.setCurrentItem(0)
76
 
            self.filetypeAssociationList.setSelected(itm, 1)
 
115
            self.filetypeCombo.setCurrentIndex(0)
 
116
            self.filetypeAssociationList.setCurrentItem(itm)
77
117
 
78
 
    def handleAssociationDelete(self):
 
118
    @pyqtSignature("")
 
119
    def on_deleteAssociationButton_clicked(self):
79
120
        """
80
121
        Private slot to delete the currently selected association of the listbox.
81
122
        """
82
 
        itm = self.filetypeAssociationList.selectedItem()
83
 
        if itm is not None:
84
 
            self.filetypeAssociationList.takeItem(itm)
 
123
        for itm in self.filetypeAssociationList.selectedItems():
 
124
            itm = self.filetypeAssociationList.takeTopLevelItem(\
 
125
                self.filetypeAssociationList.indexOfTopLevelItem(itm))
85
126
            del itm
86
127
            
87
128
            self.filetypeAssociationList.clearSelection()
88
129
            self.filePatternEdit.clear()
89
 
            self.filetypeCombo.setCurrentItem(0)
 
130
            self.filetypeCombo.setCurrentIndex(0)
90
131
 
91
 
    def handlePatternTextChanged(self, txt):
 
132
    def on_filePatternEdit_textChanged(self, txt):
92
133
        """
93
134
        Private slot to handle the textChanged signal of the pattern lineedit.
94
135
        
95
136
        @param txt text of the lineedit (QString)
96
137
        """
97
138
        if txt.isEmpty():
98
 
            self.addAssociationButton.setEnabled(0)
99
 
            self.deleteAssociationButton.setEnabled(0)
 
139
            self.addAssociationButton.setEnabled(False)
 
140
            self.deleteAssociationButton.setEnabled(False)
100
141
        else:
101
 
            self.addAssociationButton.setEnabled(1)
102
 
            if self.filetypeAssociationList.selectedItem() is None:
103
 
                self.deleteAssociationButton.setEnabled(0)
 
142
            self.addAssociationButton.setEnabled(True)
 
143
            if len(self.filetypeAssociationList.selectedItems()) == 0:
 
144
                self.deleteAssociationButton.setEnabled(False)
104
145
            else:
105
 
                self.deleteAssociationButton.setEnabled(1)
 
146
                self.deleteAssociationButton.setEnabled(\
 
147
                    self.filetypeAssociationList.selectedItems()[0].text(0) == txt)
106
148
 
107
149
    def transferData(self):
108
150
        """
109
151
        Public slot to transfer the associations into the projects data structure.
110
152
        """
111
153
        self.project.pdata["FILETYPES"] = {}
112
 
        itm = self.filetypeAssociationList.firstChild()
113
 
        while itm is not None:
 
154
        for index in range(self.filetypeAssociationList.topLevelItemCount()):
 
155
            itm = self.filetypeAssociationList.topLevelItem(index)
114
156
            pattern = unicode(itm.text(0))
115
157
            index = self.filetypeStrings.index(itm.text(1))
116
158
            self.project.pdata["FILETYPES"][pattern] = self.filetypes[index]
117
 
            itm = itm.nextSibling()
118