Пример #1
0
    def _ClosePageNum(self, idx, deletepg=True):
        """Close the given page
        @param idx: int
        @keyword deletepg: bool (Internal Use Only!)
        @return bool: was page deleted?

        """
        result = True
        try:
            page = self.GetPage(idx)
            result = page.CanCloseTab()

            # TODO: this makes very little sense, why did this deletepg
            #       value get added, this function is useless when it
            #       is not true...
            if result and deletepg:
                evt = aui.AuiNotebookEvent(
                    aui.wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSE, SIMULATED_EVT_ID)
                evt.SetSelection(idx)
                self.OnPageClosing(evt)
                with eclib.Freezer(self.TopLevelParent) as _tmp:
                    self.DeletePage(idx)
                evt = aui.AuiNotebookEvent(
                    aui.wxEVT_COMMAND_AUINOTEBOOK_PAGE_CLOSED,
                    SIMULATED_EVT_ID)
                evt.SetSelection(idx)
                self.OnPageClosed(evt)
        except Exception:
            # TODO: workaround for crash in base on destruction
            pass

        return result
Пример #2
0
    def DoItemExpanding(self, item):
        """Handle when an item is expanding to display the folder contents
        @param item: TreeItem

        """
        busy = wx.BusyCursor()  # can take a few seconds

        d = None
        try:
            d = self.GetPyData(item)
        except wx.PyAssertionError:
            util.Log("[FileBrowser][err] FileBrowser2.DoItemExpanding")
            return

        if d and os.path.exists(d) and os.access(d, os.R_OK):
            contents = FileBrowser2.GetDirContents(d)
            t1 = time.time()
            with eclib.Freezer(self) as _tmp:
                self.AppendFileNodes(item, self.FilterFileList(contents))
                self.SortChildren(item)
            util.Log("[FileBrowser][info] Tree expand time: %f" %
                     (time.time() - t1))

            if not self._monitor.AddDirectory(d):
                self.SetItemImage(item, self._mime.IMG_NO_ACCESS)
                return

        # Update tree image
        self.SetItemImage(item, self._mime.GetImageIndex(d, True))
Пример #3
0
    def RefreshStyles(self):
        """Refreshes the colorization of the window by reloading any
        style tags that may have been modified.
        @postcondition: all style settings are refreshed in the control

        """
        with eclib.Freezer(self) as _tmp:
            self.StyleClearAll()
            self.SetSyntax(self.GetSyntaxParams())
            self.DefineMarkers()
        self.Refresh()
Пример #4
0
    def PopulateCtrl(self):
        """Populates the list of plugins and sets the
        values of their states. Any successive calls to
        this function will clear the list and Repopulate it
        with current config values. Returns the number of
        items populated to the list
        @postcondition: list is populated with all plugins that are
                        currently loaded and sets the checkmarks accordingly
        @return: number of items added to list

        """
        p_mgr = wx.GetApp().GetPluginManager()
        if self._list.GetItemCount():
            self._list.DeleteAllItems()

        p_mgr.ReInit()
        config = p_mgr.GetConfig()
        keys = sorted([ed_txt.DecodeString(name) for name in config.keys()],
                      key=unicode.lower)
        uninstalled = Profile_Get('UNINSTALL_PLUGINS', default=list())

        with eclib.Freezer(self._list) as _tmp:
            for item in keys:
                val = config[item]
                mod = sys.modules.get(item)
                dist = p_mgr.GetPluginDistro(item)
                if dist is not None:
                    item = dist.project_name
                    version = dist.version
                else:
                    version = str(getattr(mod, '__version__', _("Unknown")))

                pdata = PluginData()
                pdata.SetName(item)
                desc = getattr(mod, '__doc__', None)
                if not isinstance(desc, basestring):
                    desc = _("No Description Available")
                pdata.SetDescription(desc.strip())
                pdata.SetAuthor(getattr(mod, '__author__', _("Unknown")))
                pdata.SetVersion(version)
                pdata.SetDist(dist)
                pbi = PBPluginItem(self._list, mod, pdata, None)

                pbi.SetChecked(val)
                util.Log("[pluginmgr][info] Adding %s to list" % item)
                self._list.AppendItem(pbi)
                if pbi.GetInstallPath() in uninstalled:
                    pbi.Enable(False)

        self._list.SendSizeEvent()
        return self._list.GetItemCount()
Пример #5
0
    def OpenDocPointer(self, ptr, doc, title=u''):
        """Open a page using an stc document poiner
        @param ptr: EdEditorView document Pointer
        @param doc: EdFile instance
        @keyword title: tab title

        """
        with eclib.Freezer(self.TopLevelParent) as _tmp:
            nbuff = self.GetCurrentPage()
            need_add = False
            if nbuff.GetFileName() or nbuff.GetLength():
                need_add = True
                nbuff = ed_editv.EdEditorView(self)

            nbuff.SetDocPointer(ptr)
            nbuff.SetDocument(doc)
            doc.AddModifiedCallback(nbuff.FireModified)
            nbuff.FindLexer()

            path = nbuff.GetFileName()
            if Profile_Get('SAVE_POS'):
                pos = self.DocMgr.GetPos(path)
                nbuff.SetCaretPos(pos)
                nbuff.ScrollToColumn(0)

            if title:
                filename = title
            else:
                filename = ebmlib.GetFileName(path)

            if need_add:
                self.AddPage(nbuff, filename)
            else:
                self.SetPageText(self.GetSelection(), filename)

            self.LOG("[ed_pages][evt] Opened Page: %s" % filename)

            # Set tab image
            self.SetPageBitmap(self.GetSelection(), nbuff.GetTabImage())

            # Refocus on selected page
            self.control = nbuff
            self.GoCurrentPage()
            ed_msg.PostMessage(ed_msg.EDMSG_FILE_OPENED,
                               nbuff.GetFileName(),
                               context=self.frame.Id)
Пример #6
0
    def PopulateErrors(self):
        """Populates the list of plugins and sets the
        values of their states. Any successive calls to
        this function will clear the list and Repopulate it
        with current config values. Returns the number of
        items populated to the list
        @postcondition: list is populated with all plugins that are
                        currently loaded and sets the checkmarks accordingly
        @return: number of items added to list

        """
        p_mgr = wx.GetApp().GetPluginManager()
        if self._list.GetItemCount():
            self._list.DeleteAllItems()

        p_mgr.ReInit()
        errors = p_mgr.GetIncompatible()
        keys = sorted([ed_txt.DecodeString(name) for name in errors.keys()],
                      key=unicode.lower)
        bmp = wx.ArtProvider.GetBitmap(wx.ART_ERROR, wx.ART_TOOLBAR, (32, 32))
        msg = _("This plugin requires a newer version of Editra.")

        with eclib.Freezer(self._list) as _tmp:
            for item in keys:
                val = errors[item]
                mod = sys.modules.get(val)
                dist = p_mgr.GetPluginDistro(item)
                if dist is not None:
                    item = dist.project_name
                    version = dist.version
                else:
                    version = unicode(getattr(mod, '__version__',
                                              _("Unknown")))

                pin = PluginData()
                pin.SetName(item)
                pin.SetAuthor(getattr(mod, '__author__', _("Unknown")))
                pin.SetVersion(version)
                pin.SetDist(dist)
                pbi = PluginErrorItem(self._list, pin, msg, bmp=bmp)

                self._list.AppendItem(pbi)

        self._list.SendSizeEvent()
        return self._list.GetItemCount()
Пример #7
0
    def PopulateList(self):
        """Populates the list control based off data in the plugin data
        list. The plugin data list is set as a result of calling UpdateList
        it is not recommended to call this directly.

        @return: number of items added to control

        """
        if self._list.GetItemCount():
            self._list.DeleteAllItems()
        pins = sorted([name for name in self._p_list.keys()],
                      key=unicode.lower)
        with eclib.Freezer(self) as _tmp:
            for item in pins:
                pbi = PBDownloadItem(self._list, self._p_list[item], None)
                self._list.AppendItem(pbi)
        self._list.SendSizeEvent()
        return self._list.GetItemCount()
Пример #8
0
    def OpenFileObject(self, fileobj):
        """Open a new text editor page with the given file object. The file
        object must be an instance of ed_txt.EdFile.
        @param fileobj: File Object

        """
        # Create the control
        with eclib.Freezer(self.TopLevelParent) as _tmp:
            control = ed_editv.EdEditorView(self)
            control.Hide()

            # Load the files data
            path = fileobj.GetPath()
            filename = ebmlib.GetFileName(path)
            control.SetDocument(fileobj)
            result = control.ReloadFile()

            # Setup the buffer
            fileobj.AddModifiedCallback(control.FireModified)

            # Setup the notebook
            self.control = control
            self.control.FindLexer()
            self.control.EmptyUndoBuffer()
            self.control.Show()
            self.AddPage(self.control, filename)

            self.frame.AddFileToHistory(path)
            self.SetPageText(self.GetSelection(), filename)
            self.LOG("[ed_pages][evt] Opened Page: %s" % filename)

            # Set tab image
            cpage = self.GetSelection()
            self.SetPageBitmap(cpage, self.control.GetTabImage())

        # Refocus on selected page
        self.GoCurrentPage()
        ed_msg.PostMessage(ed_msg.EDMSG_FILE_OPENED,
                           self.control.GetFileName(),
                           context=self.frame.Id)

        if Profile_Get('WARN_EOL', default=True) and not fileobj.IsRawBytes():
            self.control.CheckEOL()
Пример #9
0
    def OnPageClosed(self, evt):
        """Handles Paged Closed Event
        @param evt: aui.EVT_AUINOTEBOOK_PAGE_CLOSED

        """
        frame = self.TopLevelParent
        with eclib.Freezer(frame) as _tmp:
            cpage = evt.GetSelection()
            evt.Skip()
            self.LOG("[ed_pages][evt] Closed Page: #%d" % cpage)
            self.UpdateIndexes()
            ed_msg.PostMessage(ed_msg.EDMSG_UI_NB_CLOSED, (self, cpage),
                               context=self.frame.Id)

            if not self.GetPageCount() and \
               hasattr(frame, 'IsExiting') and not frame.IsExiting():
                self.NewPage()
            elif not self.frame.IsExiting():
                self.SaveCurrentSession()
Пример #10
0
    def NewPage(self):
        """Create a new notebook page with a blank text control
        @postcondition: a new page with an untitled document is opened

        """
        frame = self.TopLevelParent
        with eclib.Freezer(frame) as _tmp:
            self.control = ed_editv.EdEditorView(self)
            self.LOG("[ed_pages][evt] New Page Created")
            self.AddPage(self.control)

        # Set the control up the the preferred default lexer
        dlexer = Profile_Get('DEFAULT_LEX', 'str', synglob.LANG_TXT)
        ext_reg = syntax.ExtensionRegister()
        ext_lst = ext_reg.get(dlexer, ['txt', ])
        self.control.FindLexer(ext_lst[0])
        self.SetPageBitmap(self.GetSelection(), self.control.GetTabImage())

        # Set the modified callback notifier
        doc = self.control.GetDocument()
        doc.AddModifiedCallback(self.control.FireModified)
    def DoItemExpanding(self, item):
        """Handle when an item is expanding to display the folder contents
        @param item: TreeItem

        """
        busy = wx.BusyCursor()
        d = None
        try:
            d = self.GetPyData(item)
        except wx.PyAssertionError:
            util.Log("[PyStudio][err] ProjectTree.DoItemExpanding")
            return

        if d and os.path.exists(d) and os.access(d, os.R_OK):
            contents = ProjectTree.GetDirContents(d)
            contents = self.FilterFileList(contents)
            with eclib.Freezer(self):
                self.AppendFileNodes(item, contents)
                self.SortChildren(item)

            if not self._monitor.AddDirectory(d):
                self.SetItemImage(item, ProjectUtil.FileIcons.IMG_NO_ACCESS)
                return
    def OnFilesChanged(self, added, deleted, modified):
        """DirectoryMonitor callback - synchronize the view
        with the filesystem.

        """
        nodes = self.GetExpandedNodes()
        visible = list()
        for node in nodes:
            visible.extend(self.GetChildNodes(node))

        # Remove any deleted file objects
        for fobj in deleted:
            for item in visible:
                path = self.GetPyData(item)
                if fobj.Path == path:
                    self.Delete(item)
                    visible.remove(item)
                    break

        # Add any new file objects to the view
        needsort = list()
        added = self.FilterFileList([fobj.Path for fobj in added])
        for fobj in added:
            dpath = os.path.dirname(fobj)
            for item in nodes:
                path = self.GetPyData(item)
                if path == dpath:
                    self.AppendFileNode(item, fobj)
                    if item not in needsort:
                        needsort.append(item)
                    break

        # Resort display
        with eclib.Freezer(self):
            for item in needsort:
                self.SortChildren(item)
Пример #13
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)

        # Resolve links to real file
        if ebmlib.IsLink(path2file):
            path2file = ebmlib.ResolveRealPath(path2file)
            path = ebmlib.GetPathName(path2file)
            filename = ebmlib.GetFileName(path2file)

        if self.DocDuplicated(path2file):
            return

        # 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 dependencies 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
        with eclib.Freezer(self.TopLevelParent) as _tmp:
            new_pg = True
            if self.GetPageCount():
                if self.control.GetModify() or self.control.GetLength() or \
                   self.control.GetFileName() != u'':
                    control = ed_editv.EdEditorView(self, wx.ID_ANY)
                    control.Hide()
                else:
                    new_pg = False
                    control = self.control
            else:
                control = ed_editv.EdEditorView(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()

                    return
            else: