Tue, 07 Dec 2010 20:10:13 +0100
Continued implementing user defined file filters.
Preferences/ConfigurationPages/EditorFilePage.py | file | annotate | diff | comparison | revisions | |
Preferences/ConfigurationPages/EditorFilePage.ui | file | annotate | diff | comparison | revisions |
--- a/Preferences/ConfigurationPages/EditorFilePage.py Tue Dec 07 19:00:48 2010 +0100 +++ b/Preferences/ConfigurationPages/EditorFilePage.py Tue Dec 07 20:10:13 2010 +0100 @@ -7,8 +7,12 @@ Module implementing the Editor General configuration page. """ +from PyQt4.QtCore import pyqtSlot +from PyQt4.QtGui import QListWidgetItem, QInputDialog, QLineEdit from PyQt4.Qsci import QsciScintilla +from E5Gui import E5MessageBox + import QScintilla.Lexers from .ConfigurationPageBase import ConfigurationPageBase @@ -29,10 +33,12 @@ self.setupUi(self) self.setObjectName("EditorFilePage") - self.openFilesFilterComboBox.addItems( - QScintilla.Lexers.getOpenFileFiltersList(True)) - self.saveFilesFilterComboBox.addItems( - QScintilla.Lexers.getSaveFileFiltersList(True)) + self.__showsOpenFilters = True + self.openFileFilters = Preferences.getEditor("AdditionalOpenFilters")[:] + self.saveFileFilters = Preferences.getEditor("AdditionalSaveFilters")[:] + self.fileFiltersList.addItems(self.openFileFilters) + + self.__setDefaultFiltersLists() self.defaultEncodingComboBox.addItems(sorted(supportedCodecs)) @@ -110,6 +116,129 @@ Preferences.setEditor("EOLMode", QsciScintilla.EolMac) elif self.lfRadioButton.isChecked(): Preferences.setEditor("EOLMode", QsciScintilla.EolUnix) + + self.__extractFileFilters() + Preferences.setEditor("AdditionalOpenFilters", self.openFileFilters) + Preferences.setEditor("AdditionalSaveFilters", self.saveFileFilters) + + def __setDefaultFiltersLists(self, keepSelection = False): + """ + Private slot to set the default file filter combo boxes. + """ + if keepSelection: + selectedOpenFilter = self.openFilesFilterComboBox.currentText() + selectedSaveFilter = self.saveFilesFilterComboBox.currentText() + + openFileFiltersList = \ + QScintilla.Lexers.getOpenFileFiltersList(False, withAdditional = False) + \ + self.openFileFilters + openFileFiltersList.sort() + self.openFilesFilterComboBox.addItems(openFileFiltersList) + saveFileFiltersList = \ + QScintilla.Lexers.getSaveFileFiltersList(False, withAdditional = False) + \ + self.saveFileFilters + saveFileFiltersList.sort() + self.saveFilesFilterComboBox.addItems(saveFileFiltersList) + + if keepSelection: + self.openFilesFilterComboBox.setCurrentIndex( + self.openFilesFilterComboBox.findText(selectedOpenFilter)) + self.saveFilesFilterComboBox.setCurrentIndex( + self.saveFilesFilterComboBox.findText(selectedSaveFilter)) + + def __extractFileFilters(self): + """ + Private method to extract the file filters. + """ + filters = [] + for row in range(self.fileFiltersList.count()): + filters.append(self.fileFiltersList.item(row).text()) + if self.__showsOpenFilters: + self.openFileFilters = filters + else: + self.saveFileFilters = filters + + def __checkFileFilter(self, filter): + """ + Private method to check a file filter for validity. + + @param filter file filter pattern to check (string) + @return flag indicating validity (boolean) + """ + if not self.__showsOpenFilters and \ + filter.count("*") != 1: + E5MessageBox.critical(self, + self.trUtf8("Add File Filter"), + self.trUtf8("""A Save File Filter must contain exactly one""" + """ wildcard pattern. Yours contains {0}.""")\ + .format(filter.count("*"))) + return False + + if filter.count("*") == 0: + E5MessageBox.critical(self, + self.trUtf8("Add File Filter"), + self.trUtf8("""A File Filter must contain at least one""" + """ wildcard pattern.""")\ + .format(filter.count("*"))) + return False + + return True + + @pyqtSlot() + def on_addFileFilterButton_clicked(self): + """ + Private slot to add a file filter to the list. + """ + filter, ok = QInputDialog.getText( + self, + self.trUtf8("Add File Filter"), + self.trUtf8("Enter the file filter entry:"), + QLineEdit.Normal) + if ok and filter: + if self.__checkFileFilter(filter): + self.fileFiltersList.addItem(filter) + self.__extractFileFilters() + self.__setDefaultFiltersLists(keepSelection = True) + + @pyqtSlot() + def on_editFileFilterButton_clicked(self): + """ + Slot documentation goes here. + """ + # TODO: not implemented yet + raise NotImplementedError + + @pyqtSlot() + def on_deleteFileFilterButton_clicked(self): + """ + Slot documentation goes here. + """ + # TODO: not implemented yet + raise NotImplementedError + + @pyqtSlot(bool) + def on_openFiltersButton_toggled(self, checked): + """ + Private slot to switch the list of file filters. + """ + self.__extractFileFilters() + self.__showsOpenFilters = checked + self.fileFiltersList.clear() + if checked: + self.fileFiltersList.addItems(self.openFileFilters) + else: + self.fileFiltersList.addItems(self.saveFileFilters) + + @pyqtSlot(QListWidgetItem, QListWidgetItem) + def on_fileFiltersList_currentItemChanged(self, current, previous): + """ + Private slot to set the state of the edit and delete buttons. + + @param current new current item (QListWidgetItem) + @param previous previous current item (QListWidgetItem) + """ + self.editFileFilterButton.setEnabled(current is not None) + self.deleteFileFilterButton.setEnabled(current is not None) def create(dlg): """ @@ -118,4 +247,4 @@ @param dlg reference to the configuration dialog """ page = EditorFilePage() - return page \ No newline at end of file + return page
--- a/Preferences/ConfigurationPages/EditorFilePage.ui Tue Dec 07 19:00:48 2010 +0100 +++ b/Preferences/ConfigurationPages/EditorFilePage.ui Tue Dec 07 20:10:13 2010 +0100 @@ -1,59 +1,60 @@ -<ui version="4.0" > +<?xml version="1.0" encoding="UTF-8"?> +<ui version="4.0"> <class>EditorFilePage</class> - <widget class="QWidget" name="EditorFilePage" > - <property name="geometry" > + <widget class="QWidget" name="EditorFilePage"> + <property name="geometry"> <rect> <x>0</x> <y>0</y> - <width>547</width> - <height>755</height> + <width>600</width> + <height>904</height> </rect> </property> - <layout class="QVBoxLayout" name="verticalLayout_2" > + <layout class="QVBoxLayout" name="verticalLayout_2"> <item> - <widget class="QLabel" name="headerLabel" > - <property name="text" > - <string><b>Configure file handling settings</b></string> + <widget class="QLabel" name="headerLabel"> + <property name="text"> + <string><b>Configure file handling settings</b></string> </property> </widget> </item> <item> - <widget class="Line" name="line2" > - <property name="frameShape" > + <widget class="Line" name="line2"> + <property name="frameShape"> <enum>QFrame::HLine</enum> </property> - <property name="frameShadow" > + <property name="frameShadow"> <enum>QFrame::Sunken</enum> </property> - <property name="orientation" > + <property name="orientation"> <enum>Qt::Horizontal</enum> </property> </widget> </item> <item> - <widget class="QGroupBox" name="groupBox_3" > - <property name="title" > + <widget class="QGroupBox" name="groupBox_3"> + <property name="title"> <string>Open && Close</string> </property> - <layout class="QVBoxLayout" > + <layout class="QVBoxLayout"> <item> - <layout class="QHBoxLayout" > + <layout class="QHBoxLayout"> <item> - <widget class="QCheckBox" name="clearBreakpointsCheckBox" > - <property name="toolTip" > + <widget class="QCheckBox" name="clearBreakpointsCheckBox"> + <property name="toolTip"> <string>Select, whether breakpoint belonging to an editor should be cleared, when the editor is closed</string> </property> - <property name="text" > + <property name="text"> <string>Clear Breakpoints upon closing</string> </property> </widget> </item> <item> - <widget class="QCheckBox" name="automaticReopenCheckBox" > - <property name="toolTip" > + <widget class="QCheckBox" name="automaticReopenCheckBox"> + <property name="toolTip"> <string>Select to reread the file automatically, if it was changed externally</string> </property> - <property name="text" > + <property name="text"> <string>Reopen automatically</string> </property> </widget> @@ -61,42 +62,42 @@ </layout> </item> <item> - <layout class="QHBoxLayout" > + <layout class="QHBoxLayout"> <item> - <widget class="QLabel" name="label" > - <property name="text" > + <widget class="QLabel" name="label"> + <property name="text"> <string>Warn, if file is greater than</string> </property> </widget> </item> <item> - <widget class="QSpinBox" name="warnFilesizeSpinBox" > - <property name="toolTip" > + <widget class="QSpinBox" name="warnFilesizeSpinBox"> + <property name="toolTip"> <string>Enter the filesize, a warning dialog should be shown.</string> </property> - <property name="suffix" > + <property name="suffix"> <string> KB</string> </property> - <property name="minimum" > + <property name="minimum"> <number>1</number> </property> - <property name="maximum" > + <property name="maximum"> <number>16384</number> </property> - <property name="singleStep" > + <property name="singleStep"> <number>16</number> </property> - <property name="value" > + <property name="value"> <number>1024</number> </property> </widget> </item> <item> <spacer> - <property name="orientation" > + <property name="orientation"> <enum>Qt::Horizontal</enum> </property> - <property name="sizeHint" stdset="0" > + <property name="sizeHint" stdset="0"> <size> <width>40</width> <height>20</height> @@ -110,43 +111,43 @@ </widget> </item> <item> - <widget class="QGroupBox" name="groupBox_5" > - <property name="title" > + <widget class="QGroupBox" name="groupBox_5"> + <property name="title"> <string>End of Line</string> </property> - <layout class="QVBoxLayout" name="verticalLayout" > + <layout class="QVBoxLayout" name="verticalLayout"> <item> - <widget class="QGroupBox" name="groupBox_8" > - <property name="title" > + <widget class="QGroupBox" name="groupBox_8"> + <property name="title"> <string>End of Line Characters</string> </property> - <layout class="QHBoxLayout" name="_12" > + <layout class="QHBoxLayout" name="_12"> <item> - <widget class="QRadioButton" name="lfRadioButton" > - <property name="toolTip" > + <widget class="QRadioButton" name="lfRadioButton"> + <property name="toolTip"> <string>Select Unix type end of line</string> </property> - <property name="text" > + <property name="text"> <string>Unix</string> </property> </widget> </item> <item> - <widget class="QRadioButton" name="crRadioButton" > - <property name="toolTip" > + <widget class="QRadioButton" name="crRadioButton"> + <property name="toolTip"> <string>Select Macintosh type end of line</string> </property> - <property name="text" > + <property name="text"> <string>Macintosh</string> </property> </widget> </item> <item> - <widget class="QRadioButton" name="crlfRadioButton" > - <property name="toolTip" > + <widget class="QRadioButton" name="crlfRadioButton"> + <property name="toolTip"> <string>Select Windows type end of line</string> </property> - <property name="text" > + <property name="text"> <string>Windows/DOS</string> </property> </widget> @@ -155,11 +156,11 @@ </widget> </item> <item> - <widget class="QCheckBox" name="automaticEolConversionCheckBox" > - <property name="toolTip" > + <widget class="QCheckBox" name="automaticEolConversionCheckBox"> + <property name="toolTip"> <string>Select whether the eol type should be converted upon opening the file.</string> </property> - <property name="text" > + <property name="text"> <string>Automatic End of Line Conversion</string> </property> </widget> @@ -168,39 +169,39 @@ </widget> </item> <item> - <widget class="QGroupBox" name="groupBox_4" > - <property name="title" > + <widget class="QGroupBox" name="groupBox_4"> + <property name="title"> <string>Save</string> </property> - <layout class="QVBoxLayout" > + <layout class="QVBoxLayout"> <item> - <layout class="QGridLayout" > - <item row="0" column="0" > - <widget class="QCheckBox" name="automaticSyntaxCheckCheckBox" > - <property name="toolTip" > + <layout class="QGridLayout"> + <item row="0" column="0"> + <widget class="QCheckBox" name="automaticSyntaxCheckCheckBox"> + <property name="toolTip"> <string>Select, whether Python files should be checked automatically for syntax errors</string> </property> - <property name="text" > + <property name="text"> <string>Automatic Syntax Check</string> </property> </widget> </item> - <item row="0" column="1" > - <widget class="QCheckBox" name="stripWhitespaceCheckBox" > - <property name="toolTip" > + <item row="0" column="1"> + <widget class="QCheckBox" name="stripWhitespaceCheckBox"> + <property name="toolTip"> <string>Select, whether trailing whitespace should be removed upon save</string> </property> - <property name="text" > + <property name="text"> <string>Strip trailing whitespace upon save</string> </property> </widget> </item> - <item row="1" column="0" > - <widget class="QCheckBox" name="createBackupFileCheckBox" > - <property name="toolTip" > + <item row="1" column="0"> + <widget class="QCheckBox" name="createBackupFileCheckBox"> + <property name="toolTip"> <string>Select, whether a backup file shall be generated upon save</string> </property> - <property name="text" > + <property name="text"> <string>Create backup file upon save</string> </property> </widget> @@ -208,48 +209,48 @@ </layout> </item> <item> - <layout class="QHBoxLayout" > + <layout class="QHBoxLayout"> <item> - <widget class="QLabel" name="TextLabel13_3_3" > - <property name="text" > + <widget class="QLabel" name="TextLabel13_3_3"> + <property name="text"> <string>Autosave interval:</string> </property> </widget> </item> <item> - <widget class="QSlider" name="autosaveSlider" > - <property name="toolTip" > + <widget class="QSlider" name="autosaveSlider"> + <property name="toolTip"> <string>Move to set the autosave interval in minutes (0 to disable)</string> </property> - <property name="minimum" > + <property name="minimum"> <number>0</number> </property> - <property name="maximum" > + <property name="maximum"> <number>30</number> </property> - <property name="value" > + <property name="value"> <number>5</number> </property> - <property name="orientation" > + <property name="orientation"> <enum>Qt::Horizontal</enum> </property> - <property name="tickInterval" > + <property name="tickInterval"> <number>1</number> </property> </widget> </item> <item> - <widget class="QLCDNumber" name="autosaveLCD" > - <property name="toolTip" > + <widget class="QLCDNumber" name="autosaveLCD"> + <property name="toolTip"> <string>Displays the selected autosave interval.</string> </property> - <property name="numDigits" > + <property name="numDigits"> <number>2</number> </property> - <property name="segmentStyle" > + <property name="segmentStyle"> <enum>QLCDNumber::Flat</enum> </property> - <property name="value" stdset="0" > + <property name="value" stdset="0"> <double>5.000000000000000</double> </property> </widget> @@ -260,41 +261,41 @@ </widget> </item> <item> - <widget class="QGroupBox" name="groupBox" > - <property name="title" > + <widget class="QGroupBox" name="groupBox"> + <property name="title"> <string>Encoding</string> </property> - <layout class="QGridLayout" name="gridLayout" > - <item row="0" column="0" colspan="2" > - <widget class="QCheckBox" name="advEncodingCheckBox" > - <property name="toolTip" > + <layout class="QGridLayout" name="gridLayout"> + <item row="0" column="0" colspan="2"> + <widget class="QCheckBox" name="advEncodingCheckBox"> + <property name="toolTip"> <string>Select to use the advanced encoding detection </string> </property> - <property name="whatsThis" > - <string><b>Advanced encoding detection</b> -<p>Select to use the advanced encoding detection based on the &quot;universal character encoding detector&quot; from <a href="http://chardet.feedparser.org">http://chardet.feedparser.org</a>.</p></string> + <property name="whatsThis"> + <string><b>Advanced encoding detection</b> +<p>Select to use the advanced encoding detection based on the &quot;universal character encoding detector&quot; from <a href="http://chardet.feedparser.org">http://chardet.feedparser.org</a>.</p></string> </property> - <property name="text" > + <property name="text"> <string>Use advanced encoding detection</string> </property> </widget> </item> - <item row="1" column="0" > - <widget class="QLabel" name="label_4" > - <property name="text" > + <item row="1" column="0"> + <widget class="QLabel" name="label_4"> + <property name="text"> <string>Default Encoding:</string> </property> </widget> </item> - <item row="1" column="1" > - <widget class="QComboBox" name="defaultEncodingComboBox" > - <property name="sizePolicy" > - <sizepolicy vsizetype="Fixed" hsizetype="Expanding" > + <item row="1" column="1"> + <widget class="QComboBox" name="defaultEncodingComboBox"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Fixed"> <horstretch>0</horstretch> <verstretch>0</verstretch> </sizepolicy> </property> - <property name="toolTip" > + <property name="toolTip"> <string>Select the string encoding to be used.</string> </property> </widget> @@ -303,27 +304,27 @@ </widget> </item> <item> - <widget class="QGroupBox" name="groupBox_2" > - <property name="title" > + <widget class="QGroupBox" name="groupBox_2"> + <property name="title"> <string>Default File Filters</string> </property> - <layout class="QGridLayout" > - <item row="0" column="0" > - <widget class="QLabel" name="label_2" > - <property name="text" > + <layout class="QGridLayout"> + <item row="0" column="0"> + <widget class="QLabel" name="label_2"> + <property name="text"> <string>Open Files:</string> </property> </widget> </item> - <item row="0" column="1" > - <widget class="QComboBox" name="openFilesFilterComboBox" /> + <item row="0" column="1"> + <widget class="QComboBox" name="openFilesFilterComboBox"/> </item> - <item row="0" column="2" > + <item row="0" column="2"> <spacer> - <property name="orientation" > + <property name="orientation"> <enum>Qt::Horizontal</enum> </property> - <property name="sizeHint" stdset="0" > + <property name="sizeHint" stdset="0"> <size> <width>40</width> <height>20</height> @@ -331,25 +332,133 @@ </property> </spacer> </item> - <item row="1" column="0" > - <widget class="QLabel" name="label_3" > - <property name="text" > + <item row="1" column="0"> + <widget class="QLabel" name="label_3"> + <property name="text"> <string>Save Files:</string> </property> </widget> </item> - <item row="1" column="1" > - <widget class="QComboBox" name="saveFilesFilterComboBox" /> + <item row="1" column="1"> + <widget class="QComboBox" name="saveFilesFilterComboBox"/> + </item> + </layout> + </widget> + </item> + <item> + <widget class="QGroupBox" name="groupBox_6"> + <property name="title"> + <string>Additional File Filters</string> + </property> + <layout class="QGridLayout" name="gridLayout_2"> + <item row="0" column="0" colspan="2"> + <widget class="QLabel" name="label_5"> + <property name="text"> + <string><b>Note:</b> Save file filters must contain one wildcard pattern only.</string> + </property> + <property name="wordWrap"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="1" column="0" colspan="2"> + <layout class="QHBoxLayout" name="horizontalLayout"> + <item> + <widget class="QRadioButton" name="openFiltersButton"> + <property name="toolTip"> + <string>Select to edit the open file filters</string> + </property> + <property name="text"> + <string>Open Files</string> + </property> + <property name="checked"> + <bool>true</bool> + </property> + </widget> + </item> + <item> + <widget class="QRadioButton" name="savFiltersButton"> + <property name="toolTip"> + <string>Select to edit the save file filters</string> + </property> + <property name="text"> + <string>Save Files</string> + </property> + </widget> + </item> + </layout> + </item> + <item row="2" column="0" rowspan="4"> + <widget class="QListWidget" name="fileFiltersList"> + <property name="sizePolicy"> + <sizepolicy hsizetype="Expanding" vsizetype="Preferred"> + <horstretch>0</horstretch> + <verstretch>0</verstretch> + </sizepolicy> + </property> + <property name="minimumSize"> + <size> + <width>0</width> + <height>200</height> + </size> + </property> + <property name="alternatingRowColors"> + <bool>true</bool> + </property> + <property name="sortingEnabled"> + <bool>true</bool> + </property> + </widget> + </item> + <item row="2" column="1"> + <widget class="QPushButton" name="addFileFilterButton"> + <property name="text"> + <string>Add...</string> + </property> + </widget> + </item> + <item row="3" column="1"> + <widget class="QPushButton" name="editFileFilterButton"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Edit...</string> + </property> + </widget> + </item> + <item row="4" column="1"> + <widget class="QPushButton" name="deleteFileFilterButton"> + <property name="enabled"> + <bool>false</bool> + </property> + <property name="text"> + <string>Delete</string> + </property> + </widget> + </item> + <item row="5" column="1"> + <spacer> + <property name="orientation"> + <enum>Qt::Vertical</enum> + </property> + <property name="sizeHint" stdset="0"> + <size> + <width>20</width> + <height>40</height> + </size> + </property> + </spacer> </item> </layout> </widget> </item> <item> <spacer> - <property name="orientation" > + <property name="orientation"> <enum>Qt::Vertical</enum> </property> - <property name="sizeHint" stdset="0" > + <property name="sizeHint" stdset="0"> <size> <width>435</width> <height>20</height> @@ -375,6 +484,12 @@ <tabstop>defaultEncodingComboBox</tabstop> <tabstop>openFilesFilterComboBox</tabstop> <tabstop>saveFilesFilterComboBox</tabstop> + <tabstop>openFiltersButton</tabstop> + <tabstop>savFiltersButton</tabstop> + <tabstop>fileFiltersList</tabstop> + <tabstop>addFileFilterButton</tabstop> + <tabstop>editFileFilterButton</tabstop> + <tabstop>deleteFileFilterButton</tabstop> </tabstops> <resources/> <connections> @@ -384,11 +499,11 @@ <receiver>autosaveLCD</receiver> <slot>display(int)</slot> <hints> - <hint type="sourcelabel" > + <hint type="sourcelabel"> <x>272</x> <y>58</y> </hint> - <hint type="destinationlabel" > + <hint type="destinationlabel"> <x>420</x> <y>55</y> </hint>