Пример #1
0
    def openEditor(self,nfile):
        text = ""
        try:
            infile = open(nfile, 'r')
            tt = infile.read()
            if(config.encoding() == Encoding.UNICODE):
                text = unicode(tt,"utf-8")#must add utf-8 for it to work
            else:
                text = str(tt)

            #infile.close()
            self.files.append(nfile)
            config.setFile(self.files) 
            self.dirty.append(False)
            #print len(self.files)
            tab = Editor(self,text,self.syntax(nfile),self.colorStyle) 
            self.tabWidget.addTab(tab,ospathbasename(nfile))
            tab.textChanged.connect(lambda:self.setDirty(nfile))  
            if(self.files != None):
                if(len(self.files)) != 0:
                    #This line sets the opened file to display first Important not checked
                    self.tabWidget.setCurrentIndex(len(self.files)-1)
            return True
        except:
            if(nfile in self.files):
                self.files.remove(nfile)
            config.setFile(self.files)
            QMessageBox.about(self,"Can't Open","File is Being Used\n"+nfile)
            return False
        finally:
            if(infile != None):
                infile.close()
Пример #2
0
 def openEditor(self,nfile):
     text = ""
     infile = open(nfile, 'r')
     tt = infile.read()
     try:
         text = str(tt)
         self.files.append(nfile)
         config.setFile(self.files) 
         self.dirty.append(False)
         tab = Editor(self,text,nfile) 
         self.tabWidget.addTab(tab,ospathbasename(nfile))
         #print len(self.files)
         tab.textChanged.connect(lambda:self.setDirty(nfile))  
         if(self.files != None):
             if(len(self.files)) != 0:
                 self.tabWidget.setCurrentIndex(len(self.files)-1)
     except:
         if(nfile in self.files):
             self.files.remove(nfile)
         config.setFile(self.files)
         QMessageBox.about(self,"Can't Open","File is Being Used\n"+nfile)
         error("Opening: File is Being Used "+nfile)
         return False
     finally:
         if(infile != None):
             infile.close() 
             return True
         return False
Пример #3
0
 def createTab(self,nfile):
     if(nfile != None):
         if(self.files != None):
             if(len(self.files) != 0):
                     if(nfile in self.files):
                         #print "File Already Open\n"+nfile
                         self.tabWidget.setCurrentIndex(self.files.index(nfile))
                         return False
             if(ospathexists(nfile)):
                     self.openEditor(nfile)  
                     return True    
             else:
                 if(nfile in self.files):
                     self.files.remove(nfile)
                 config.setFile(self.files)
                 QMessageBox.about(self,"Can't Open","File Does Not Exist\n"+nfile) 
                 return False
Пример #4
0
 def closeTab(self,index):
     '''Boolean result invocation method.'''
     done = True
     if self.dirty[index]:
         reply = QMessageBox.question(self,
                 "Sabel IDE - Unsaved Changes",
                 "Save unsaved changes?",
                 QMessageBox.Yes|QMessageBox.No|QMessageBox.Cancel)
         if reply == QMessageBox.Cancel:
             done = False
         elif reply == QMessageBox.Yes:
             done = self.fileSave(index)
         elif reply == QMessageBox.No:
             self.clearDirty(index)
             done = True
     if(done):
         #print index
         '''Must set the editor text to None to gc the memory used by text'''
         self.files.remove(self.files[index])
         config.setFile(self.files)
         self.tabWidget.removeTab(index)