示例#1
0
class HtmlSrcPanel(wx.Panel):
    def __init__(self, parent=None, *args, text=None, **kw):
        wx.Panel.__init__(self, parent, id=-1)
        pub.subscribe(self.setPage, 'setPage')
        self.parent = parent
        self.parent = parent
        vBox = wx.BoxSizer(wx.VERTICAL)
        sizer = wx.BoxSizer(wx.VERTICAL)
        ####################################################################
        htmlsrc = self.GetParent().getHtmlFromMarkdown(text)
        self.stc = MainStc(self, text=htmlsrc)

        sizer.Add(self.stc, 1, wx.EXPAND)
        ####################################################################

        sizer.Add(vBox, 1, wx.EXPAND, 0)
        self.SetSizer(sizer)

    def setPage(self, markdownText=None, baseUrl='/'):
        try:
            window = None
            if isinstance(self.GetParent(), CreatingMarkdownPanel):
                window = self.GetParent()
            elif isinstance(self.GetParent().GetParent(),
                            CreatingMarkdownPanel):
                window = self.GetParent().GetParent()
            html = window.getHtmlFromMarkdown(markdownText)
            self.stc.SetText(html)
        except Exception as e:
            logger.error(e)
    def OpenFiles(self, files):
        """Open the list of files in Editra for editing
        @param files: list of file names

        """
        to_open = list()
        for fname in files:
            try:
                res = os.stat(fname)[0]
                if stat.S_ISREG(res) or stat.S_ISDIR(res):
                    to_open.append(fname)
            except (IOError, OSError) as msg:
                logger.debug("[filebrowser][err] %s" % str(msg))

        # TODO : Need to work on it.
        if hasattr(self.GetTopLevelParent(), '_mgr'):

            for path in to_open:
                mainStc = MainStc(self)
                mainStc.SetSavePoint()
                fileName = os.path.split(path)[-1]
                file_ext = fileName.split('.')[-1]
                mainStc.SetFileName(path)
                mainStc.SetText(FileOperations().readFile(filePath=path))
                mainStc.ConfigureLexer(file_ext)
                #                     imageName=self.iconsDictIndex[extensionName]
                self.GetTopLevelParent()._mgr.addTabByWindow(
                    window=mainStc, captionName=fileName, tabDirection=5)