示例#1
0
    def loadFile(self, filename, updateTabs=True):
        """ Load the specified file. 
        On success returns the item of the file, also if it was
        already open."""

        # Note that by giving the name of a tempfile, we can select that
        # temp file.

        # normalize path
        if filename[0] != '<':
            filename = normalizePath(filename)
        if not filename:
            return None

        # if the file is already open...
        for item in self._tabs.items():
            if item.id == filename:
                # id gets _filename or _name for temp files
                break
        else:
            item = None
        if item:
            self._tabs.setCurrentItem(item)
            print("File already open: '{}'".format(filename))
            return item

        # create editor
        try:
            editor = createEditor(self, filename)
        except Exception as err:
            # Notify in logger
            print("Error loading file: ", err)
            # Make sure the user knows
            m = QtGui.QMessageBox(self)
            m.setWindowTitle("Error loading file")
            m.setText(str(err))
            m.setIcon(m.Warning)
            m.exec_()
            return None

        # create list item
        item = FileItem(editor)
        self._tabs.addItem(item, updateTabs)
        if updateTabs:
            self._tabs.setCurrentItem(item)

        # store the path
        self._lastpath = os.path.dirname(item.filename)

        return item
示例#2
0
 def loadFile(self, filename, updateTabs=True):
     """ Load the specified file. 
     On success returns the item of the file, also if it was
     already open."""
     
     # Note that by giving the name of a tempfile, we can select that
     # temp file.
     
     # normalize path
     if filename[0] != '<':
         filename = normalizePath(filename)
     if not filename:
         return None
     
     # if the file is already open...
     for item in self._tabs.items():
         if item.id == filename:
             # id gets _filename or _name for temp files
             break
     else:
         item = None
     if item:
         self._tabs.setCurrentItem(item)
         print("File already open: '{}'".format(filename))
         return item
     
     # create editor
     try:
         editor = createEditor(self, filename)
     except Exception as err:
         # Notify in logger
         print("Error loading file: ", err)
         # Make sure the user knows
         m = QtGui.QMessageBox(self)
         m.setWindowTitle("Error loading file")
         m.setText(str(err))
         m.setIcon(m.Warning)
         m.exec_()
         return None
     
     # create list item
     item = FileItem(editor)
     self._tabs.addItem(item, updateTabs)        
     if updateTabs:
         self._tabs.setCurrentItem(item)
     
     # store the path
     self._lastpath = os.path.dirname(item.filename)
     
     return item
示例#3
0
    def newFile(self):
        """ Create a new (unsaved) file. """

        # create editor
        editor = createEditor(self, None)
        editor.document().setModified(False)  # Start out as OK
        # add to list
        item = FileItem(editor)
        self._tabs.addItem(item)
        self._tabs.setCurrentItem(item)
        # set focus to new file
        editor.setFocus()

        return item
示例#4
0
    def newFile(self):
        """ Create a new (unsaved) file. """
        
        # create editor
        editor = createEditor(self, None)
        editor.document().setModified(False)  # Start out as OK
        # add to list
        item = FileItem(editor)
        self._tabs.addItem(item)
        self._tabs.setCurrentItem(item)
        # set focus to new file
        editor.setFocus()

        return item