Beispiel #1
0
    def open(self):
        dialog = QFileDialog(self)
        dialog.setViewMode(QFileDialog.List)
        dialog.setDirectory(os.getcwd())

        filename = dialog.getOpenFileName(self, "Save")
        
        if filename[0]:
            filePath = filename[0]
            
            try:
                with open(filePath, 'r') as f:
                    text = f.read()
                
                editor = CodeEditor(self)
                editor.setText(text) 
                editor.filename = filePath
                
                self.notebook.newTab(editor)
                x = self.notebook.count()   # number of tabs
                index = x - 1
                self.notebook.setCurrentIndex(index)
                
                tabName = os.path.basename(editor.filename)    
                self.notebook.setTabText(x, tabName)
                self.textPad = editor    
            
            except Exception as e:
                self.statusBar.showMessage(str(e), 3000)
Beispiel #2
0
 def new(self):
     editor = CodeEditor(parent=self)
     editor.filename = None
     
     self.notebook.newTab(editor)
     
     x = self.notebook.count()
     index = x - 1
     
     self.notebook.setCurrentIndex(index)
     self.textPad = editor
     self.notebook.textPad = editor
     self.mainWindow = self.textPad.mainWindow
Beispiel #3
0
    def newTab(self, editor=None, codeView=None):
        
        if not editor:
            editor = CodeEditor(parent=self.mainWindow)
            self.addTab(editor, "noname")
            editor.filename = None
           
            if self.mainWindow:
                self.codeView = self.mainWindow.codeView

            
        else:
            if editor.filename == None:
                self.addTab(editor, "noname")
            
            else:
                self.addTab(editor, os.path.basename(editor.filename))
                x = self.count() - 1
                self.setTabToolTip(x, editor.filename)
                self.codeView = self.mainWindow.codeView
Beispiel #4
0
    def onDoubleClicked(self, index):
        self.index = index  #.... wie oben ... def onClicked(...):
        indexItem = self.model.index(index.row(), 0, index.parent())

        fileName, filePath, fileDir, fileInfo = self.getFileInformation()

        if fileDir:
            filePath = self.checkPath(filePath)
            try:
                os.chdir(filePath)
            except Exception as e:
                self.mainWindow.statusBar.showMessage(str(e), 3000)
            self.path = self.checkPath(os.getcwd())

            self.model.setRootPath(filePath)

            if self.rootIsDecorated:
                self.setRootIsDecorated(False)

        else:
            self.filename = filePath

            try:
                with open(self.filename, 'r') as f:
                    self.text = f.read()
            except Exception as e:
                self.mainWindow.statusBar.showMessage(str(e), 3000)

                self.filename = None
                return

            # debug
            if self.textPad:

                if not self.textPad.filename:
                    editor = CodeEditor(self.mainWindow)
                    editor.setText(self.text)
                    editor.filename = filePath
                    self.notebook.newTab(editor)
                    self.textPad = editor

                    x = self.notebook.count()  # number of tabs
                    index = x - 1
                    self.notebook.setCurrentIndex(index)
                    tabName = os.path.basename(editor.filename)

                    self.notebook.setTabText(x, tabName)
                    self.textPad = editor
                    #self.textPad.filename = filePath

                else:
                    editor = CodeEditor(self.mainWindow)
                    editor.setText(self.text)
                    editor.filename = filePath
                    tabName = os.path.basename(editor.filename)
                    self.notebook.newTab(editor)
                    x = self.notebook.count()  # number of tabs
                    index = x - 1
                    self.notebook.setCurrentIndex(index)
                    self.textPad = editor
                    #self.textPad.filename = filePath

            if not self.textPad:
                editor = CodeEditor(self.mainWindow)
                editor.filename = None
                self.notebook.newTab(editor)
                x = self.notebook.count()
                index = x - 1
                self.notebook.setCurrentIndex(index)
                self.textPad = editor
                #self.textPad.filename = filePath

            # make codeView
            codeViewList = self.codeView.makeDictForCodeView(self.text)
            self.codeView.updateCodeView(codeViewList)

            # update textPad Autocomplete
            autocomplete = Qsci.QsciAPIs(self.textPad.lexer)
            self.textPad.autocomplete = autocomplete
            self.textPad.setPythonAutocomplete()

        self.clearSelection()