def update_rst(self, s, keywords): trace = False and not g.unitTesting pc = self c = pc.c p = c.p s = s.strip().strip('"""').strip("'''").strip() isHtml = s.startswith('<') and not s.startswith('<<') if trace: g.trace('isHtml', isHtml, p.h) # Do this regardless of whether we show the widget or not. w = pc.ensure_text_widget() assert pc.w if s: pc.show() if not got_docutils: isHtml = True s = '<pre>\n%s</pre>' % s if not isHtml: # Not html: convert to html. path = g.scanAllAtPathDirectives(c, p) or c.getNodePath(p) if not os.path.isdir(path): path = os.path.dirname(path) if os.path.isdir(path): os.chdir(path) try: msg = '' # The error message from docutils. if pc.title: s = pc.underline(pc.title) + s pc.title = None # Call docutils to get the string. s = publish_string(s, writer_name='html') s = g.toUnicode(s) # 2011/03/15 show = True except SystemMessage as sm: # g.trace(sm,sm.args) msg = sm.args[0] if 'SEVERE' in msg or 'FATAL' in msg: s = 'RST error:\n%s\n\n%s' % (msg, s) sb = w.verticalScrollBar() if sb: d = pc.scrollbar_pos_dict if pc.node_changed: # Set the scrollbar. pos = d.get(p.v, sb.sliderPosition()) sb.setSliderPosition(pos) else: # Save the scrollbars d[p.v] = pos = sb.sliderPosition() if pc.default_kind in ('big', 'rst', 'html', 'md'): w.setHtml(s) if pc.default_kind == 'big': w.zoomIn(4) # Doesn't work. else: w.setPlainText(s) if sb and pos: # Restore the scrollbars sb.setSliderPosition(pos)
def update_md(self, s, keywords): '''Update markdown text in the vr pane.''' pc = self c = pc.c p = c.p s = s.strip().strip('"""').strip("'''").strip() isHtml = s.startswith('<') and not s.startswith('<<') if trace: g.trace('isHtml:', isHtml, p.h) # Do this regardless of whether we show the widget or not. w = pc.ensure_text_widget() assert pc.w if s: pc.show() if not got_markdown: isHtml = True s = '<pre>\n%s</pre>' % s if not isHtml: # Not html: convert to html. path = g.scanAllAtPathDirectives(c, p) or c.getNodePath(p) if not os.path.isdir(path): path = os.path.dirname(path) if os.path.isdir(path): os.chdir(path) try: msg = '' # The error message from docutils. if pc.title: s = pc.underline(pc.title) + s pc.title = None mdext = c.config.getString( 'view-rendered-md-extensions') or 'extra' mdext = [x.strip() for x in mdext.split(',')] s = markdown(s, mdext) s = g.toUnicode(s) except SystemMessage as sm: msg = sm.args[0] if 'SEVERE' in msg or 'FATAL' in msg: s = 'MD error:\n%s\n\n%s' % (msg, s) sb = w.verticalScrollBar() if sb: d = pc.scrollbar_pos_dict if pc.node_changed: # Set the scrollbar. pos = d.get(p.v, sb.sliderPosition()) sb.setSliderPosition(pos) else: # Save the scrollbars d[p.v] = pos = sb.sliderPosition() # 2016/03/25: honor @language md. colorizer = c.frame.body.colorizer language = colorizer.scanColorDirectives(p) if (language in ('markdown', 'md') or pc.default_kind in ('big', 'rst', 'html', 'md')): w.setHtml(s) if pc.default_kind == 'big': w.zoomIn(4) # Doesn't work. else: w.setPlainText(s) if sb and pos: # Restore the scrollbars sb.setSliderPosition(pos)
def update_rst(self, s, keywords): """Update rst in the vr pane.""" pc = self c = pc.c p = c.p s = s.strip().strip('"""').strip("'''").strip() isHtml = s.startswith("<") and not s.startswith("<<") if trace: g.trace("isHtml", isHtml, p.h) # Do this regardless of whether we show the widget or not. w = pc.ensure_text_widget() assert pc.w if s: pc.show() if not got_docutils: isHtml = True s = "<pre>\n%s</pre>" % s if not isHtml: # Not html: convert to html. path = g.scanAllAtPathDirectives(c, p) or c.getNodePath(p) if not os.path.isdir(path): path = os.path.dirname(path) if os.path.isdir(path): os.chdir(path) try: msg = "" # The error message from docutils. if pc.title: s = pc.underline(pc.title) + s pc.title = None # Call docutils to get the string. s = publish_string(s, writer_name="html") if trace: g.trace("after docutils", len(s)) s = g.toUnicode(s) # 2011/03/15 show = True except SystemMessage as sm: # g.trace(sm,sm.args) msg = sm.args[0] if "SEVERE" in msg or "FATAL" in msg: s = "RST error:\n%s\n\n%s" % (msg, s) sb = w.verticalScrollBar() if sb: d = pc.scrollbar_pos_dict if pc.node_changed: # Set the scrollbar. pos = d.get(p.v, sb.sliderPosition()) sb.setSliderPosition(pos) else: # Save the scrollbars d[p.v] = pos = sb.sliderPosition() if pc.default_kind in ("big", "rst", "html", "md"): w.setHtml(s) if pc.default_kind == "big": w.zoomIn(4) # Doesn't work. else: w.setPlainText(s) if sb and pos: # Restore the scrollbars sb.setSliderPosition(pos)
def update_md(self, s, keywords): '''Update markdown text in the vr pane.''' pc = self; c = pc.c; p = c.p s = s.strip().strip('"""').strip("'''").strip() isHtml = s.startswith('<') and not s.startswith('<<') if trace: g.trace('isHtml:', isHtml, p.h) # Do this regardless of whether we show the widget or not. w = pc.ensure_text_widget() assert pc.w if s: pc.show() if not got_markdown: isHtml = True s = '<pre>\n%s</pre>' % s if not isHtml: # Not html: convert to html. path = g.scanAllAtPathDirectives(c, p) or c.getNodePath(p) if not os.path.isdir(path): path = os.path.dirname(path) if os.path.isdir(path): os.chdir(path) try: msg = '' # The error message from docutils. if pc.title: s = pc.underline(pc.title) + s pc.title = None mdext = c.config.getString('view-rendered-md-extensions') or 'extra' mdext = [x.strip() for x in mdext.split(',')] s = markdown(s, mdext) s = g.toUnicode(s) except SystemMessage as sm: msg = sm.args[0] if 'SEVERE' in msg or 'FATAL' in msg: s = 'MD error:\n%s\n\n%s' % (msg, s) sb = w.verticalScrollBar() if sb: d = pc.scrollbar_pos_dict if pc.node_changed: # Set the scrollbar. pos = d.get(p.v, sb.sliderPosition()) sb.setSliderPosition(pos) else: # Save the scrollbars d[p.v] = pos = sb.sliderPosition() # 2016/03/25: honor @language md. colorizer = c.frame.body.colorizer language = colorizer.scanColorDirectives(p) if ( language in ('markdown', 'md') or pc.default_kind in ('big', 'rst', 'html', 'md') ): w.setHtml(s) if pc.default_kind == 'big': w.zoomIn(4) # Doesn't work. else: w.setPlainText(s) if sb and pos: # Restore the scrollbars sb.setSliderPosition(pos)
def bzr_stat(c=c, p=p): path = g.scanAllAtPathDirectives(c, p) or c.getNodePath(p) cmd = subprocess.Popen(['bzr', 'stat', path], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = cmd.communicate() g.es("\n\n".join([stdout, stderr]))
def update_rst (self,s,keywords): trace = False and not g.unitTesting pc = self ; c = pc.c ; p = c.p s = s.strip().strip('"""').strip("'''").strip() isHtml = s.startswith('<') and not s.startswith('<<') if trace: g.trace('isHtml',isHtml,p.h) # Do this regardless of whether we show the widget or not. w = pc.ensure_text_widget() assert pc.w if s: pc.show() if not got_docutils: isHtml = True s = '<pre>\n%s</pre>' % s if not isHtml: # Not html: convert to html. path = g.scanAllAtPathDirectives(c,p) or c.getNodePath(p) if not os.path.isdir(path): path = os.path.dirname(path) if os.path.isdir(path): os.chdir(path) try: msg = '' # The error message from docutils. if pc.title: s = pc.underline(pc.title) + s pc.title = None # Call docutils to get the string. s = publish_string(s,writer_name='html') s = g.toUnicode(s) # 2011/03/15 show = True except SystemMessage as sm: # g.trace(sm,sm.args) msg = sm.args[0] if 'SEVERE' in msg or 'FATAL' in msg: s = 'RST error:\n%s\n\n%s' % (msg,s) sb = w.verticalScrollBar() if sb: d = pc.scrollbar_pos_dict if pc.node_changed: # Set the scrollbar. pos = d.get(p.v,sb.sliderPosition()) sb.setSliderPosition(pos) else: # Save the scrollbars d[p.v] = pos = sb.sliderPosition() if pc.default_kind in ('big','rst','html', 'md'): w.setHtml(s) if pc.default_kind == 'big': w.zoomIn(4) # Doesn't work. else: w.setPlainText(s) if sb and pos: # Restore the scrollbars sb.setSliderPosition(pos)
def convert_to_html(self, s): '''Convert s to html using docutils.''' c, p = self.c, self.c.p # Update the current path. path = g.scanAllAtPathDirectives(c, p) or c.getNodePath(p) if not os.path.isdir(path): path = os.path.dirname(path) if os.path.isdir(path): os.chdir(path) try: if self.title: s = self.underline(self.title) + s self.title = None # Call docutils to get the string. s = publish_string(s, writer_name='html') s = g.toUnicode(s) except SystemMessage as sm: msg = sm.args[0] if 'SEVERE' in msg or 'FATAL' in msg: s = 'RST error:\n%s\n\n%s' % (msg, s) return s
def convert_to_markdown(self, s): '''Convert s to html using the markdown processor.''' pc = self c, p = pc.c, pc.c.p path = g.scanAllAtPathDirectives(c, p) or c.getNodePath(p) if not os.path.isdir(path): path = os.path.dirname(path) if os.path.isdir(path): os.chdir(path) try: if pc.title: s = pc.underline(pc.title) + s pc.title = None mdext = c.config.getString('view-rendered-md-extensions') or 'extra' mdext = [x.strip() for x in mdext.split(',')] s = markdown(s, mdext) s = g.toUnicode(s) except SystemMessage as sm: msg = sm.args[0] if 'SEVERE' in msg or 'FATAL' in msg: s = 'MD error:\n%s\n\n%s' % (msg, s) return s
def openwith_rclick(c,p,menu): """ Show "Edit with" in context menu for external file root nodes (@thin, @auto...) This looks like "Edit contextmenu.py in scite" """ # define callbacks #@+others #@+node:ekr.20140613141207.17666: *4* openwith_rclick_cb def openwith_rclick_cb(): #print "Editing", path, fname if editor: cmd = '%s "%s"' % (editor, absp) g.es('Edit: %s' % cmd) subprocess.Popen(cmd, shell=True) #@+node:ekr.20140613141207.17667: *4* openfolder_rclick_cb def openfolder_rclick_cb(): g.os_startfile(path) #@+node:ekr.20140613141207.17668: *4* create_rclick_cb def create_rclick_cb(): os.makedirs(absp) g.es("Created " + absp) #@+node:ekr.20140613141207.17669: *4* importfiles_rclick_cb def importfiles_rclick_cb(): def shorten(pth, prefix): if not pth.startswith(prefix): return pth return pth[len(prefix):] aList = g.get_directives_dict_list(p) path = c.scanAtPathDirectives(aList) + "/" table = [ ("All files","*"), ("Python files","*.py"), ] fnames = g.app.gui.runOpenFileDialog(c, title = "Import files",filetypes = table, defaultextension = '.notused', multiple=True, startpath = path) adds = [guess_file_type(pth) + " " + shorten(pth, path) for pth in fnames] for a in adds: chi = p.insertAsLastChild() chi.h = a c.readAtFileNodes() #@-others h = p.h parts = h.split(None, 1) if len(parts) < 2: return fname = None # argh, we need g.getAbsFileName(c,p) head, bname = parts fname = p.anyAtFileNodeName() if not fname and head != "@path": return path = g.scanAllAtPathDirectives(c,p) editor = g.guessExternalEditor() absp = g.os_path_finalize_join(path, fname) exists = os.path.exists(absp) if not exists and head == "@path": action = menu.addAction("Create dir " + absp + "/" ) action.triggered.connect(create_rclick_cb) if exists and head == "@path": action = menu.addAction("Import files") action.triggered.connect(importfiles_rclick_cb) if editor and exists and head != "@path": action = menu.addAction("Edit " + bname + " in " + os.path.basename(editor)) action.triggered.connect(openwith_rclick_cb) action = menu.addAction("Open " + path) action.triggered.connect(openfolder_rclick_cb)
def openwith_rclick(c, p, menu): """ Show "Edit with" in context menu for external file root nodes (@thin, @auto...) This looks like "Edit contextmenu.py in scite" """ # define callbacks #@+others #@+node:ekr.20140613141207.17667: *4* function: openfolder_rclick_cb def openfolder_rclick_cb(): if g.os_path_exists(path): g.os_startfile(path) else: # #1257: g.es_print('file not found:', repr(path)) #@+node:ekr.20140613141207.17668: *4* function: create_rclick_cb def create_rclick_cb(): os.makedirs(absp) g.es("Created " + absp) #@+node:ekr.20140613141207.17669: *4* function: importfiles_rclick_cb def importfiles_rclick_cb(): def shorten(pth, prefix): if not pth.startswith(prefix): return pth return pth[len(prefix):] aList = g.get_directives_dict_list(p) path = c.scanAtPathDirectives(aList) + "/" table = [ ("All files", "*"), ("Python files", "*.py"), ] fnames = g.app.gui.runOpenFileDialog(c, title="Import files", filetypes=table, defaultextension='.notused', multiple=True, startpath=path) adds = [ guess_file_type(pth) + " " + shorten(pth, path) for pth in fnames ] for a in adds: chi = p.insertAsLastChild() chi.h = a c.readAtFileNodes() #@-others h = p.h parts = h.split(None, 1) if len(parts) < 2: return fname = None # argh, we need g.getAbsFileName(c,p) head, bname = parts fname = p.anyAtFileNodeName() if not fname and head != "@path": return path = g.scanAllAtPathDirectives(c, p) #editor = g.guessExternalEditor(c) absp = g.os_path_finalize_join(path, fname) exists = os.path.exists(absp) if not exists and head == "@path": action = menu.addAction("Create dir " + absp + "/") action.triggered.connect(create_rclick_cb) if exists and head == "@path": action = menu.addAction("Import files") action.triggered.connect(importfiles_rclick_cb) action = menu.addAction("Open " + path) action.triggered.connect(openfolder_rclick_cb)
def cmd(c=c, p=p, qcom=qcom): path = g.scanAllAtPathDirectives(c,p) or c.getNodePath(p) cmd = subprocess.Popen(['bzr', qcom, path]) cmd.communicate()
def bzr_stat(c=c, p=p): path = g.scanAllAtPathDirectives(c,p) or c.getNodePath(p) cmd = subprocess.Popen(['bzr', 'stat', path], stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout,stderr = cmd.communicate() g.es("\n\n".join([stdout,stderr]))
def openwith_rclick(c, p, menu): """ Show "Edit with" in context menu for external file root nodes (@thin, @auto...) This looks like "Edit contextmenu.py in scite" """ h = p.h parts = h.split(None, 1) if len(parts) < 2: return fname = None # argh, we need g.getAbsFileName(c,p) head, bname = parts fname = p.anyAtFileNodeName() if not fname and head != "@path": return path = g.scanAllAtPathDirectives(c, p) editor = g.guessExternalEditor() # g.trace(repr(path),repr(fname)) absp = g.os_path_finalize_join(path, fname) exists = os.path.exists(absp) def openwith_rclick_cb(): #print "Editing", path, fname if not editor: return cmd = '%s "%s"' % (editor, absp) g.es('Edit: %s' % cmd) p = subprocess.Popen(cmd, shell=True) def openfolder_rclick_cb(): g.os_startfile(path) def create_rclick_cb(): os.makedirs(absp) g.es("Created " + absp) if not exists and head == "@path": action = menu.addAction("Create dir " + absp + "/") action.triggered.connect(create_rclick_cb) def importfiles_rclick_cb(): aList = g.get_directives_dict_list(p) path = c.scanAtPathDirectives(aList) + "/" table = [ ("All files", "*"), ("Python files", "*.py"), ] fnames = g.app.gui.runOpenFileDialog(title="Import files", filetypes=table, defaultextension='.notused', multiple=True, startpath=path) def shorten(pth, prefix): if not pth.startswith(prefix): return pth return pth[len(prefix):] adds = [ guess_file_type(pth) + " " + shorten(pth, path) for pth in fnames ] for a in adds: chi = p.insertAsLastChild() chi.h = a c.readAtFileNodes() if exists and head == "@path": action = menu.addAction("Import files") action.triggered.connect(importfiles_rclick_cb) if exists and head != "@path": if editor: action = menu.addAction("Edit " + bname + " in " + os.path.basename(editor)) action.connect(action, QtCore.SIGNAL("triggered()"), openwith_rclick_cb) action = menu.addAction("Open " + path) action.connect(action, QtCore.SIGNAL("triggered()"), openfolder_rclick_cb)
def cmd(c=c, p=p, qcom=qcom): path = g.scanAllAtPathDirectives(c, p) or c.getNodePath(p) cmd = subprocess.Popen(['bzr', qcom, path]) cmd.communicate()