示例#1
0
    def __createLayout( self ):
        """ Creates the dialog layout """

        self.resize( 600, 300 )
        self.setSizeGripEnabled( True )

        verticalLayout = QVBoxLayout( self )
        self.__namesBrowser = NamesBrowser( self )
        verticalLayout.addWidget( self.__namesBrowser )

        self.findCombo = EnterSensitiveComboBox( self )
        self.__tuneCombo( self.findCombo )
        self.findCombo.lineEdit().setToolTip( "Regular expression to search for" )
        verticalLayout.addWidget( self.findCombo )
        self.findCombo.enterClicked.connect( self.__enterInFilter )
        return
示例#2
0
    def __createLayout( self ):
        """ Creates the dialog layout """

        self.resize( 600, 300 )
        self.setSizeGripEnabled( True )

        verticalLayout = QVBoxLayout( self )
        self.__filesBrowser = FilesBrowser( self )
        verticalLayout.addWidget( self.__filesBrowser )

        self.findCombo = EnterSensitiveComboBox( self )
        self.__tuneCombo( self.findCombo )
        self.findCombo.lineEdit().setToolTip( "Regular expression to search for" )
        verticalLayout.addWidget( self.findCombo )
        self.findCombo.enterClicked.connect( self.__enterInFilter )
        return
示例#3
0
class FindFileDialog(QDialog):
    " Find file dialog implementation "

    def __init__(self, parent=None):
        QDialog.__init__(self, parent)

        self.__filesBrowser = None
        self.findCombo = None
        self.__projectLoaded = GlobalData().project.fileName != ""

        QApplication.setOverrideCursor(QCursor(Qt.WaitCursor))
        self.__createLayout()
        self.findCombo.setFocus()
        QApplication.restoreOverrideCursor()

        # Set the window title and restore the previous searches
        if self.__projectLoaded:
            self.__findFileHistory = GlobalData().project.findFileHistory
        else:
            self.__findFileHistory = Settings().findFileHistory
        self.findCombo.addItems(self.__findFileHistory)
        self.findCombo.setEditText("")

        self.findCombo.editTextChanged.connect(self.__filterChanged)

        self.__highlightFirst()
        self.__updateTitle()
        return

    def __highlightFirst(self):
        " Sets the selection to the first item in the files list "
        if self.__filesBrowser.getVisible() == 0:
            return
        self.__filesBrowser.clearSelection()

        first = self.__filesBrowser.model().index(0, 0, QModelIndex())
        self.__filesBrowser.setCurrentIndex(first)
        self.__filesBrowser.scrollTo(first)
        return

    def __updateTitle(self):
        " Updates the window title "
        title = "Find file in the "
        if self.__projectLoaded:
            title += "project: "
        else:
            title += "opened files: "
        title += str( self.__filesBrowser.getVisible() ) + " of " + \
                 str( self.__filesBrowser.getTotal() )
        self.setWindowTitle(title)
        return

    def __createLayout(self):
        """ Creates the dialog layout """

        self.resize(600, 300)
        self.setSizeGripEnabled(True)

        verticalLayout = QVBoxLayout(self)
        self.__filesBrowser = FilesBrowser(self)
        verticalLayout.addWidget(self.__filesBrowser)

        self.findCombo = EnterSensitiveComboBox(self)
        self.__tuneCombo(self.findCombo)
        self.findCombo.lineEdit().setToolTip(
            "Regular expression to search for")
        verticalLayout.addWidget(self.findCombo)
        self.findCombo.enterClicked.connect(self.__enterInFilter)
        return

    @staticmethod
    def __tuneCombo(comboBox):
        " Sets the common settings for a combo box "
        sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(comboBox.sizePolicy().hasHeightForWidth())
        comboBox.setSizePolicy(sizePolicy)
        comboBox.setEditable(True)
        comboBox.setInsertPolicy(QComboBox.InsertAtTop)
        comboBox.setAutoCompletion(False)
        comboBox.setDuplicatesEnabled(False)
        return

    def __filterChanged(self, text):
        " Triggers when the filter text changed "
        self.__filesBrowser.setFilter(text)
        self.__highlightFirst()
        self.__updateTitle()
        return

    def onClose(self):
        """ Called when an item has been selected and
            the cursor jumped where it should """

        # Save the current filter if needed
        filterText = self.findCombo.currentText().strip()
        if filterText != "":
            if filterText in self.__findFileHistory:
                self.__findFileHistory.remove(filterText)
            self.__findFileHistory.insert(0, filterText)
            if len(self.__findFileHistory) > 32:
                self.__findFileHistory = self.__findFileHistory[:32]

            if GlobalData().project.fileName != "":
                GlobalData().project.setFindFileHistory(self.__findFileHistory)
            else:
                Settings().findFileHistory = self.__findFileHistory
        self.close()
        return

    def __enterInFilter(self):
        " Handles ENTER and RETURN keys in the find combo "
        if self.__filesBrowser.getVisible() == 0:
            return
        self.__filesBrowser.openCurrentItem()
        return
示例#4
0
class FindFileDialog( QDialog ):
    " Find file dialog implementation "

    def __init__( self, parent = None ):
        QDialog.__init__( self, parent )

        self.__filesBrowser = None
        self.findCombo = None
        self.__projectLoaded = GlobalData().project.fileName != ""

        QApplication.setOverrideCursor( QCursor( Qt.WaitCursor ) )
        self.__createLayout()
        self.findCombo.setFocus()
        QApplication.restoreOverrideCursor()

        # Set the window title and restore the previous searches
        if self.__projectLoaded:
            self.__findFileHistory = GlobalData().project.findFileHistory
        else:
            self.__findFileHistory = Settings().findFileHistory
        self.findCombo.addItems( self.__findFileHistory )
        self.findCombo.setEditText( "" )

        self.findCombo.editTextChanged.connect( self.__filterChanged )

        self.__highlightFirst()
        self.__updateTitle()
        return

    def __highlightFirst( self ):
        " Sets the selection to the first item in the files list "
        if self.__filesBrowser.getVisible() == 0:
            return
        self.__filesBrowser.clearSelection()

        first = self.__filesBrowser.model().index( 0, 0, QModelIndex() )
        self.__filesBrowser.setCurrentIndex( first )
        self.__filesBrowser.scrollTo( first )
        return

    def __updateTitle( self ):
        " Updates the window title "
        title = "Find file in the "
        if self.__projectLoaded:
            title += "project: "
        else:
            title += "opened files: "
        title += str( self.__filesBrowser.getVisible() ) + " of " + \
                 str( self.__filesBrowser.getTotal() )
        self.setWindowTitle( title )
        return

    def __createLayout( self ):
        """ Creates the dialog layout """

        self.resize( 600, 300 )
        self.setSizeGripEnabled( True )

        verticalLayout = QVBoxLayout( self )
        self.__filesBrowser = FilesBrowser( self )
        verticalLayout.addWidget( self.__filesBrowser )

        self.findCombo = EnterSensitiveComboBox( self )
        self.__tuneCombo( self.findCombo )
        self.findCombo.lineEdit().setToolTip( "Regular expression to search for" )
        verticalLayout.addWidget( self.findCombo )
        self.findCombo.enterClicked.connect( self.__enterInFilter )
        return

    @staticmethod
    def __tuneCombo( comboBox ):
        " Sets the common settings for a combo box "
        sizePolicy = QSizePolicy( QSizePolicy.Expanding, QSizePolicy.Fixed )
        sizePolicy.setHorizontalStretch( 0 )
        sizePolicy.setVerticalStretch( 0 )
        sizePolicy.setHeightForWidth(
                            comboBox.sizePolicy().hasHeightForWidth() )
        comboBox.setSizePolicy( sizePolicy )
        comboBox.setEditable( True )
        comboBox.setInsertPolicy( QComboBox.InsertAtTop )
        comboBox.setAutoCompletion( False )
        comboBox.setDuplicatesEnabled( False )
        return

    def __filterChanged( self, text ):
        " Triggers when the filter text changed "
        self.__filesBrowser.setFilter( text )
        self.__highlightFirst()
        self.__updateTitle()
        return

    def onClose( self ):
        """ Called when an item has been selected and
            the cursor jumped where it should """

        # Save the current filter if needed
        filterText = self.findCombo.currentText().strip()
        if filterText != "":
            if filterText in self.__findFileHistory:
                self.__findFileHistory.remove( filterText )
            self.__findFileHistory.insert( 0, filterText )
            if len( self.__findFileHistory ) > 32:
                self.__findFileHistory = self.__findFileHistory[ : 32 ]

            if GlobalData().project.fileName != "":
                GlobalData().project.setFindFileHistory(
                                        self.__findFileHistory )
            else:
                Settings().findFileHistory = self.__findFileHistory
        self.close()
        return

    def __enterInFilter( self ):
        " Handles ENTER and RETURN keys in the find combo "
        if self.__filesBrowser.getVisible() == 0:
            return
        self.__filesBrowser.openCurrentItem()
        return