Example #1
0
def screen_capture_now(kwargs=None):
    """screen_capture_now - save a screenshot

    :Parameters:
    - `kwargs`: g.command arguments
    """
    if kwargs is None:
        kwargs = {}
    if not hasattr(g, '_recorder'):
        g._recorder = Recorder()
    c = g.app.commanders()[0]
    dirname = c.config.getString("screen-capture-save-path")
    if not dirname:
        dirname = g.os_path_join(
            g.computeHomeDir(),
            '.leo',
            'screen_captures'
        )
    dirname = g.os_path_expanduser(dirname)
    if not g.os_path_isdir(dirname):
        os.makedirs(dirname)
    filename = g.os_path_join(
        dirname,
        time.strftime('%Y-%m-%dT%H-%M-%S')+'.png'
    )
    g._recorder.grab_frame(filename=filename)
    # *only* print, don't want output messing up log view in screen shots
    print("Screenshot: %s"%filename)
Example #2
0
    def get_fn (self,s,tag):
        
        pc = self
        c = pc.c
        fn = s or c.p.h[len(tag):]
        fn = fn.strip()
        
        # Similar to code in g.computeFileUrl
        if fn.startswith('~'):
            # Expand '~' and handle Leo expressions.
            fn = fn[1:]
            fn = g.os_path_expanduser(fn)
            fn = g.os_path_expandExpression(fn,c=c)
            fn = g.os_path_finalize(fn)
        else:
            # Handle Leo expressions.
            fn = g.os_path_expandExpression(fn,c=c)
            # Handle ancestor @path directives.
            if c and c.openDirectory:
                base = c.getNodePath(c.p)
                fn = g.os_path_finalize_join(c.openDirectory,base,fn)
            else:
                fn = g.os_path_finalize(fn)

        ok = g.os_path_exists(fn)
        return ok,fn
Example #3
0
    def get_fn (self,s,tag):
        
        pc = self
        c = pc.c
        fn = s or c.p.h[len(tag):]
        fn = fn.strip()
        
        # Similar to code in g.computeFileUrl
        if fn.startswith('~'):
            # Expand '~' and handle Leo expressions.
            fn = fn[1:]
            fn = g.os_path_expanduser(fn)
            fn = g.os_path_expandExpression(fn,c=c)
            fn = g.os_path_finalize(fn)
        else:
            # Handle Leo expressions.
            fn = g.os_path_expandExpression(fn,c=c)
            # Handle ancestor @path directives.
            if c and c.openDirectory:
                base = c.getNodePath(c.p)
                fn = g.os_path_finalize_join(c.openDirectory,base,fn)
            else:
                fn = g.os_path_finalize(fn)

        ok = g.os_path_exists(fn)
        return ok,fn
Example #4
0
def screen_capture_now(kwargs=None):
    """screen_capture_now - save a screenshot

    :Parameters:
    - `kwargs`: g.command arguments
    """
    if kwargs is None:
        kwargs = {}
    if not hasattr(g, '_recorder'):
        g._recorder = Recorder()
    c = g.app.commanders()[0]
    dirname = c.config.getString("screen-capture-save-path")
    if not dirname:
        dirname = g.os_path_join(
            g.computeHomeDir(),
            '.leo',
            'screen_captures'
        )
    dirname = g.os_path_expanduser(dirname)
    if not g.os_path_isdir(dirname):
        os.makedirs(dirname)
    filename = g.os_path_join(
        dirname,
        time.strftime('%Y-%m-%dT%H-%M-%S')+'.png'
    )
    g._recorder.grab_frame(filename=filename)
    # *only* print, don't want output messing up log view in screen shots
    print("Screenshot: %s"%filename)
Example #5
0
def get_home():
    """Returns the user's home directory."""
    home = g.os_path_expanduser("~")
    # Windows searches the HOME, HOMEPATH and HOMEDRIVE
    # environment vars, then gives up.
    if home and len(home) > 1 and home[0] == '%' and home[-1] == '%':
        # Get the indirect reference to the true home.
        home = os.getenv(home[1:-1], default=None)
    if home:
        # Important: This returns the _working_ directory if home is None!
        # This was the source of the 4.3 .leoID.txt problems.
        home = g.os_path_finalize(home)
        if (not g.os_path_exists(home) or not g.os_path_isdir(home)):
            home = None
    return home
Example #6
0
def get_home():
    """Returns the user's home directory."""
    home = g.os_path_expanduser("~")
        # Windows searches the HOME, HOMEPATH and HOMEDRIVE
        # environment vars, then gives up.
    if home and len(home) > 1 and home[0] == '%' and home[-1] == '%':
        # Get the indirect reference to the true home.
        home = os.getenv(home[1: -1], default=None)
    if home:
        # Important: This returns the _working_ directory if home is None!
        # This was the source of the 4.3 .leoID.txt problems.
        home = g.os_path_finalize(home)
        if (
            not g.os_path_exists(home) or
            not g.os_path_isdir(home)
        ):
            home = None
    return home
Example #7
0
 def finalize(self, fn):
     '''Finalize and regularize a filename.'''
     return g.os_path_normpath(
         g.os_path_abspath(g.os_path_expanduser(fn)))
Example #8
0
 def finalize(self, fn):
     '''Finalize and regularize a filename.'''
     return g.os_path_normpath(g.os_path_abspath(g.os_path_expanduser(fn)))
Example #9
0
        if self.in_ == 't':
            self.idx[self.in_attrs['tx']].b.append(content)

    #@-others


#@+node:ekr.20120519121124.9931: ** get_leo_data
def get_leo_data(source):
    """Return the root node for the specificed .leo file (path or file)"""
    parser = LeoReader()
    if g.os_path_isfile(source):
        source = g.readFileIntoEncodedString(source)
    parseString(source, parser)
    return parser.root


#@-others
#@@language python
#@@tabwidth -4
#@@pagewidth 70

if __name__ == '__main__':
    import sys
    if len(sys.argv) > 1 and g.os_path_isfile(sys.argv[1]):
        wb = sys.argv[1]
    else:
        wb = g.os_path_expanduser(g.os_path_join('~', '.leo', 'workbook.leo'))
    leo_data = get_leo_data(g.readFileIntoUnicodeString(wb))
    print(leo_data)
#@-leo
Example #10
0
        if self.in_ == 't':
            self.idx[self.in_attrs['tx']].b.append(content)

    #@-others
#@+node:ekr.20120519121124.9931: ** get_leo_data
def get_leo_data(source):
    """Return the root node for the specificed .leo file (path or file)"""
    parser = LeoReader()
    if g.os_path_isfile(source):
        source = g.readFileIntoEncodedString(source)
    parseString(source, parser)
    return parser.root

#@-others
#@@language python
#@@tabwidth -4
#@@pagewidth 70

if __name__ == '__main__':
    import sys
    if len(sys.argv) > 1 and g.os_path_isfile(sys.argv[1]):
        wb = sys.argv[1]
    else:
        wb = g.os_path_expanduser(
            g.os_path_join('~', '.leo', 'workbook.leo')
        )
    leo_data = get_leo_data(g.readFileIntoUnicodeString(wb))
    print(leo_data)
#@-leo