示例#1
0
    def OpenPage(self, path, filename, quiet=False):
        """Open a File Inside of a New Page
        @param path: files base path
        @param filename: name of file to open
        @keyword quiet: Open/Switch to the file quietly if
                        it is already open.

        """
        path2file = os.path.join(path, filename)

        # Check if file needs to be opened
        # TODO: these steps could be combined together with some
        #       refactoring of the _NeedOpen method. Requires extra
        #       testing though to check for dependancies on current
        #       behavior.
        if quiet and self.HasFileOpen(path2file):
            self.GotoPage(path2file)
            return
        elif not self._NeedOpen(path2file):
            return

        # Create new control to place text on if necessary
        self.GetTopLevelParent().Freeze()
        new_pg = True
        if self.GetPageCount():
            if self.control.GetModify() or self.control.GetLength() or \
               self.control.GetFileName() != u'':
                control = ed_stc.EditraStc(self, wx.ID_ANY)
                control.Hide()
            else:
                new_pg = False
                control = self.control
        else:
            control = ed_stc.EditraStc(self, wx.ID_ANY)
            control.Hide()

        # Open file and get contents
        result = False
        if os.path.exists(path2file):
            try:
                result = control.LoadFile(path2file)
            except Exception, msg:
                self.LOG("[ed_pages][err] Failed to open file %s\n" %
                         path2file)
                self.LOG("[ed_pages][err] %s" % msg)

                # File could not be opened/read give up
                # Don't raise a dialog during a session load error as if the
                # dialog is shown before the mainwindow is ready it can cause
                # the app to freeze.
                if not self._ses_load:
                    ed_mdlg.OpenErrorDlg(self, path2file, msg)
                control.GetDocument().ClearLastError()
                control.SetFileName('')  # Reset the file name

                if new_pg:
                    control.Destroy()

                self.GetTopLevelParent().Thaw()
                return
示例#2
0
    def OpenPage(self, path, filename):
        """Open a File Inside of a New Page
        @param path: files base path
        @param filename: name of file to open

        """
        path2file = os.path.join(path, filename)

        # Check if file needs to be opened
        if not self._NeedOpen(path2file):
            return

        # Create new control to place text on if necessary
        self.GetTopLevelParent().Freeze()
        new_pg = True
        if self.GetPageCount():
            if self.control.GetModify() or self.control.GetLength() or \
               self.control.GetFileName() != u'':
                control = ed_stc.EditraStc(self, wx.ID_ANY)
                control.Hide()
            else:
                new_pg = False
                control = self.control
        else:
            control = ed_stc.EditraStc(self, wx.ID_ANY)
            control.Hide()

        # Open file and get contents
        result = False
        if os.path.exists(path2file):
            try:
                result = control.LoadFile(path2file)
            except Exception, msg:
                self.LOG("[ed_pages][err] Failed to open file %s\n" %
                         path2file)
                self.LOG("[ed_pages][err] %s" % msg)

                # File could not be opened/read give up
                # Don't raise a dialog during a session load error as if the
                # dialog is shown before the mainwindow is ready it can cause
                # the app to freeze.
                if not self._ses_load:
                    ed_mdlg.OpenErrorDlg(self, path2file, msg)
                control.GetDocument().ClearLastError()
                control.SetFileName('')  # Reset the file name

                if new_pg:
                    control.Destroy()

                self.GetTopLevelParent().Thaw()
                return
示例#3
0
    def OpenPage(self, path, filename):
        """Open a File Inside of a New Page
        @param path: files base path
        @param filename: name of file to open

        """
        path2file = os.path.join(path, filename)

        # Check if file needs to be opened
        if not self._NeedOpen(path2file):
            return

        # Create new control to place text on if necessary
        new_pg = True
        if self.GetPageCount():
            if self.control.GetModify() or self.control.GetLength() or \
               self.control.GetFileName() != u'':
                control = ed_stc.EditraStc(self, wx.ID_ANY)
                control.Hide()
            else:
                new_pg = False
        else:
            control = ed_stc.EditraStc(self, wx.ID_ANY)
            control.Hide()

        # Open file and get contents
        err = False
        in_txt = u''
        enc = u'utf-8'
        if os.path.exists(path2file):
            try:
                in_txt, enc = util.GetDecodedText(path2file)
            except (UnicodeDecodeError, IOError, OSError), msg:
                self.LOG(("[ed_pages][err] Failed to open file %s\n"
                          "[ed_pages][err] %s") % (path2file, msg))

                # File could not be opened/read give up
                err = wx.MessageDialog(self, _("Editra could not properly "
                                               "open %s\n") \
                                       % path2file, _("Error Opening File"),
                                       style=wx.OK | wx.CENTER | wx.ICON_ERROR)
                err.ShowModal()
                err.Destroy()

                if new_pg:
                    control.Destroy()
                return
示例#4
0
    def NewPage(self):
        """Create a new notebook page with a blank text control
        @postcondition: a new page with an untitled document is opened

        """
        self.pg_num += 1
        self.control = ed_stc.EditraStc(self, wx.ID_ANY)
        self.LOG("[nb_evt] Page Creation ID: %d" % self.control.GetId())
        self.AddPage(self.control, u"Untitled - %d" % self.pg_num)
        self.SetPageImage(self.GetSelection(), str(self.control.GetLangId()))
示例#5
0
    def NewPage(self):
        """Create a new notebook page with a blank text control
        @postcondition: a new page with an untitled document is opened

        """
        self.GetTopLevelParent().Freeze()
        self.pg_num += 1
        self.control = ed_stc.EditraStc(self, wx.ID_ANY)
        self.LOG("[ed_pages][evt] New Page Created ID: %d" %
                 self.control.GetId())
        self.AddPage(self.control, u"Untitled - %d" % self.pg_num)
        self.SetPageImage(self.GetSelection(), str(self.control.GetLangId()))

        # Set the control up the the preferred default lexer
        dlexer = Profile_Get('DEFAULT_LEX', 'str', 'Plain Text')
        ext_reg = syntax.ExtensionRegister()
        ext_lst = ext_reg.get(dlexer, [
            'txt',
        ])
        self.control.FindLexer(ext_lst[0])
        self.GetTopLevelParent().Thaw()