def cmd_PickDir(event): """cmd_PickDir - Show user a folder picker to create """ c = event.get('c') p = c.p aList = g.get_directives_dict_list(p) path = c.scanAtPathDirectives(aList) if p.h.startswith('@'): # see if it's a @<file> node of some sort nodepath = p.h.split(None, 1)[-1] nodepath = g.os_path_join(path, nodepath) if not g.os_path_isdir(nodepath): # remove filename nodepath = g.os_path_dirname(nodepath) if g.os_path_isdir(nodepath): # append if it's a directory path = nodepath ocwd = os.getcwd() try: os.chdir(path) except OSError: g.es("Couldn't find path %s" % path) dir_ = g.app.gui.runOpenDirectoryDialog("Pick a folder", "Pick a folder") os.chdir(ocwd) if not dir_: g.es("No folder selected") return nd = c.p.insertAfter() nd.h = "@path %s" % dir_ c.redraw()
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()
def _path_from_pos(c, p): """_path_from_pos - get folder for position FIXME: should be in Leo core somewhere. Args: p (position): position Returns: str: path """ p = p.copy() def atfile(p): word0 = p.h.split()[0] return (word0 in g.app.atFileNames | set(['@auto']) or word0.startswith('@auto-')) aList = g.get_directives_dict_list(p) path = c.scanAtPathDirectives(aList) while c.positionExists(p): if atfile(p): # see if it's a @<file> node of some sort nodepath = p.h.split(None, 1)[-1] nodepath = g.os_path_join(path, nodepath) if not g.os_path_isdir(nodepath): # remove filename nodepath = g.os_path_dirname(nodepath) if g.os_path_isdir(nodepath): # append if it's a directory path = nodepath break p.moveToParent() return path
def _path_from_pos(c, p): """_path_from_pos - get folder for position FIXME: should be in Leo core somewhere. Args: p (position): position Returns: str: path """ p = p.copy() def atfile(p): word0 = p.h.split()[0] return ( word0 in g.app.atFileNames|set(['@auto']) or word0.startswith('@auto-') ) aList = g.get_directives_dict_list(p) path = c.scanAtPathDirectives(aList) while c.positionExists(p): if atfile(p): # see if it's a @<file> node of some sort nodepath = p.h.split(None, 1)[-1] nodepath = g.os_path_join(path, nodepath) if not g.os_path_isdir(nodepath): # remove filename nodepath = g.os_path_dirname(nodepath) if g.os_path_isdir(nodepath): # append if it's a directory path = nodepath break p.moveToParent() return path
def cmd_PickDir(c): """cmd_PickDir - Show user a folder picker to create a new top level @path node :Parameters: - `c`: outline """ p = c.p aList = g.get_directives_dict_list(p) path = c.scanAtPathDirectives(aList) if p.h.startswith('@'): # see if it's a @<file> node of some sort nodepath = p.h.split(None, 1)[-1] nodepath = g.os_path_join(path, nodepath) if not g.os_path_isdir(nodepath): # remove filename nodepath = g.os_path_dirname(nodepath) if g.os_path_isdir(nodepath): # append if it's a directory path = nodepath ocwd = os.getcwd() try: os.chdir(path) except OSError: g.es("Couldn't find path %s"%path) dir_ = g.app.gui.runOpenDirectoryDialog("Pick a folder", "Pick a folder") os.chdir(ocwd) if not dir_: g.es("No folder selected") return nd = c.p.insertAfter() nd.h = "@path %s" % dir_ c.redraw()
def finalize(self, p): """Finalize p's path.""" c = self.c aList = g.get_directives_dict_list(p) path = self.c.scanAtPathDirectives(aList) path = c.expand_path_expression(path) # #1341. fn = p.anyAtFileNodeName() fn = c.expand_path_expression(fn) # #1341. return g.os_path_finalize_join(path, fn)
def getPath(self, c, p): for n in p.self_and_parents(): if n.h.startswith('@path'): break else: return None # must have a full fledged @path in parents aList = g.get_directives_dict_list(p) path = c.scanAtPathDirectives(aList) return path
def test_c_scanAtPathDirectives(self): c, p = self.c, self.c.p child = p.insertAfter() child.h = '@path one' grand = child.insertAsLastChild() grand.h = '@path two' great = grand.insertAsLastChild() great.h = 'xyz' aList = g.get_directives_dict_list(great) path = c.scanAtPathDirectives(aList) endpath = g.os_path_normpath('one/two') assert path.endswith(endpath), f"expected '{endpath}' got '{path}'"
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) print("import files from",path)
def mail_refresh(event): c = event['c'] p = c.p assert p.h.startswith('@mbox') aList = g.get_directives_dict_list(p) path = c.scanAtPathDirectives(aList) mb = path + "/" + p.h.split(None,1)[1] folder = mailbox.mbox(mb) g.es(folder) r = p.insertAsLastChild() for message in folder: emit_message(c,r, message) c.redraw()
def mail_refresh(event): c = event['c'] p = c.p assert p.h.startswith('@mbox') aList = g.get_directives_dict_list(p) path = c.scanAtPathDirectives(aList) mb = path + "/" + p.h.split(None, 1)[1] folder = mailbox.mbox(mb) g.es(folder) r = p.insertAsLastChild() for message in folder: emit_message(c, r, message) c.redraw()
def find(self, p): '''Return True and add p's path to self.seen if p is a Python @<file> node.''' c = self.c found = False if p.isAnyAtFileNode(): aList = g.get_directives_dict_list(p) path = c.scanAtPathDirectives(aList) fn = p.anyAtFileNodeName() if fn.endswith('.py'): fn = g.os_path_finalize_join(path, fn) if fn not in self.seen: self.seen.append(fn) found = True return found
def test_c_scanAtPathDirectives_same_name_subdirs(self): c = self.c # p2 = p.firstChild().firstChild().firstChild() p = c.p child = p.insertAfter() child.h = '@path again' grand = child.insertAsLastChild() grand.h = '@path again' great = grand.insertAsLastChild() great.h = 'xyz' aList = g.get_directives_dict_list(great) path = c.scanAtPathDirectives(aList) endpath = g.os_path_normpath('again/again') self.assertTrue(path and path.endswith(endpath))
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) print("import files from", path)
def check(self, p, rc_fn): '''Check a single node. Return True if it is a Python @<file> node.''' c = self.c found = False if p.isAnyAtFileNode(): # Fix bug: https://github.com/leo-editor/leo-editor/issues/67 aList = g.get_directives_dict_list(p) path = c.scanAtPathDirectives(aList) fn = p.anyAtFileNodeName() if fn.endswith('.py'): fn = g.os_path_finalize_join(path, fn) if p.v not in self.seen: self.seen.append(p.v) self.run_pylint(fn, rc_fn) found = True return found
def getPath(c, p): for n in p.self_and_parents(): if n.h.startswith('@path'): break else: return None # must have a full fledged @path in parents aList = g.get_directives_dict_list(p) path = c.scanAtPathDirectives(aList) if (not isDirNode(p)): # add file name h = p.h.split(None, 1) if h[0].startswith('@') and len(h) == 2: path = os.path.join(path, h[1]) else: path = os.path.join(path, p.h.strip()) return path
def get_fn(self, p): ''' Finalize p's file name. Return if p is not an @file node for a python file. ''' c = self.c if not p.isAnyAtFileNode(): g.trace('not an @<file> node: %r' % p.h) return None # #67. aList = g.get_directives_dict_list(p) path = c.scanAtPathDirectives(aList) fn = p.anyAtFileNodeName() if not fn.endswith('.py'): g.trace('not a python file: %r' % p.h) return None return g.os_path_finalize_join(path, fn)
def select_node(self, tag, kwargs): c = kwargs['c'] if c != self.c: return p = kwargs['new_p'] self.v = p.v # to ensure unselect_node is working on the right node # currently (20130814) insert doesn't trigger unselect/select, but # even if it did, this would be safest data = self.template if p.b.startswith('<'): # already rich text, probably content = p.b self.was_rich = True else: self.was_rich = p.b.strip() == '' # put anything except whitespace in a <pre/> content = "<pre>%s</pre>" % p.b if not self.was_rich else '' data = data.replace('[CONTENT]', content) # replace textarea with CKEditor, with or without config. if self.config: data = data.replace('[CONFIG]', ', ' + self.config) else: data = data.replace('[CONFIG]', '') # try and make the path for URL evaluation relative to the node's path aList = g.get_directives_dict_list(p) path = c.scanAtPathDirectives(aList) if p.h.startswith('@'): # see if it's a @<file> node of some sort nodepath = p.h.split(None, 1)[-1] nodepath = g.os_path_join(path, nodepath) if not g.os_path_isdir(nodepath): # remove filename nodepath = g.os_path_dirname(nodepath) if g.os_path_isdir(nodepath): # append if it's a directory path = nodepath self.webview.setHtml(data, QtCore.QUrl.fromLocalFile(path + "/"))
def select_node(self, tag, kwargs): c = kwargs['c'] if c != self.c: return p = kwargs['new_p'] self.v = p.v # to ensure unselect_node is working on the right node # currently (20130814) insert doesn't trigger unselect/select, but # even if it did, this would be safest data = self.template if p.b.startswith('<'): # already rich text, probably content = p.b self.was_rich = True else: self.was_rich = p.b.strip() == '' # put anything except whitespace in a <pre/> content = "<pre>%s</pre>" % p.b if not self.was_rich else '' data = data.replace('[CONTENT]', content) # replace textarea with CKEditor, with or without config. if self.config: data = data.replace('[CONFIG]', ', '+self.config) else: data = data.replace('[CONFIG]', '') # try and make the path for URL evaluation relative to the node's path aList = g.get_directives_dict_list(p) path = c.scanAtPathDirectives(aList) if p.h.startswith('@'): # see if it's a @<file> node of some sort nodepath = p.h.split(None, 1)[-1] nodepath = g.os_path_join(path, nodepath) if not g.os_path_isdir(nodepath): # remove filename nodepath = g.os_path_dirname(nodepath) if g.os_path_isdir(nodepath): # append if it's a directory path = nodepath self.webview.setHtml(data, QtCore.QUrl.fromLocalFile(path+"/"))
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()
def mail_refresh(event): c = event['c'] p = c.p if p.h.startswith('@mbox'): aList = g.get_directives_dict_list(p) path = c.scanAtPathDirectives(aList) h = p.h[5:].strip() mb = g.os_path_finalize_join(path, h) if g.os_path_exists(mb): n = 0 root = p.copy() parent = None for message in mailbox.mbox(mb): n += 1 parent = emit_message(c, parent, root, message) c.redraw() g.es_print('created %s messages in %s threads' % ( n, root.numberOfChildren())) else: g.trace('not found', mb) else: g.es_print('Please select an @mbox node.')
def mail_refresh(event): c = event['c'] p = c.p if p.h.startswith('@mbox'): aList = g.get_directives_dict_list(p) path = c.scanAtPathDirectives(aList) h = p.h[5:].strip() mb = g.os_path_finalize_join(path, h) if g.os_path_exists(mb): n = 0 root = p.copy() parent = None for message in mailbox.mbox(mb): n += 1 parent = emit_message(c, parent, root, message) c.redraw() g.es_print('created %s messages in %s threads' % (n, root.numberOfChildren())) else: g.trace('not found', mb) else: g.es_print('Please select an @mbox node.')
def finalize(self, p): aList = g.get_directives_dict_list(p) path = self.c.scanAtPathDirectives(aList) fn = p.anyAtFileNodeName() return g.os_path_finalize_join(path, fn)