projectwizard.py :  » Development » Leo » Leo-4.7.1-final » leo » plugins » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Development » Leo 
Leo » Leo 4.7.1 final » leo » plugins » projectwizard.py
#@+leo-ver=4-thin
#@+node:ekr.20090622063842.5264:@thin projectwizard.py
#@<< docstring >>
#@+node:ville.20090614224528.8136:<< docstring >>
''' Simple @auto project wizard

Open a file dialog and recursively creates @auto & @path nodes from thepathwhereselectedfile import 
(the selected file itself doesn't matter)
'''
#@-node:ville.20090614224528.8136:<< docstring >>
#@nl

__version__ = '0.0'
#@<< version history >>
#@+node:ville.20090614224528.8137:<< version history >>
#@@killcolor
#@+at
# 
# 0.1 First released version (VMV)
#@-at
#@nonl
#@-node:ville.20090614224528.8137:<< version history >>
#@nl

#@<< imports >>
#@+node:ville.20090614224528.8138:<< imports >>
import leo.core.leoGlobals as g
import leo.core.leoPlugins as leoPlugins

g.assertUi('qt')

from PyQt4 import QtCore

# Whatever other imports your plugins uses.
#@nonl
#@-node:ville.20090614224528.8138:<< imports >>
#@nl

#@+others
#@+node:ville.20090614224528.8139:init
def init ():

    ok = True # This might depend on imports, etc.

    if ok:
        g.plugin_signon(__name__)

    install_contextmenu_handlers()
    return ok
#@-node:ville.20090614224528.8139:init
#@+node:ville.20090614224528.8141:auto_walk() and g.command('projectwizard')
def auto_walk(c, directory, parent=None, isroot=True):
    """ source: http://leo.zwiki.org/CreateShadows

    (create @auto files instead)

    """

    from os import listdir
    from os.path import join,abspath,basename,normpath,isfile
    from fnmatch import fnmatch
    import os

    RELATIVE_PATHS = False

    patterns_to_ignore = ['*.pyc', '*.leo', '*.gif', '*.png', '*.jpg', '*.json']
    patterns_to_import = ['*.py','*.c', '*.cpp']
    match = lambda s: any(fnmatch(s, p) for p in patterns_to_ignore)

    is_ignorable = lambda s: any([ s.startswith('.'), match(s) ])

    p = c.currentPosition()

    if not RELATIVE_PATHS: directory = abspath(directory)
    if isroot:
        body = "@path %s" % normpath(directory)
        c.setHeadString(p, body)
    for name in listdir(directory):


        if is_ignorable(name):
            continue

        path = join(directory, name)

        if isfile(path) and not any(fnmatch(name, p) for p in patterns_to_import):           
            continue

        if isfile(path):
            g.es('file:', path)
            headline = '@auto %s' % basename(path)
            if parent:
                node = parent
            else:
                node = p
            child = node.insertAsLastChild()
            child.initHeadString(headline)
        else:
            g.es('dir:', path)
            headline = basename(path)
            body = "@path %s" % normpath(path)
            if parent:
                node = parent
            else:
                node = p
            child = node.insertAsLastChild()
            child.initHeadString(headline)
            child.initBodyString(body)
            auto_walk(c,path, parent=child, isroot=False)

@g.command('project-wizard')
def project_wizard(event):
    """ Launch project wizard """
    import os
    c = event['c']
    table = [("All files","*"),
        ("Python files","*.py"),]

    fname = g.app.gui.runOpenFileDialog(
        title = "Open",filetypes = table,defaultextension = ".leo")

    pth = os.path.dirname(os.path.abspath(fname))

    g.es(pth)
    tgt = c.currentPosition().insertAsLastChild()
    c.selectPosition(tgt)
    auto_walk(c, pth, tgt)
    g.es('Import ok. Do read-at-auto-nodes to parse')
    c.redraw()


#project_wizard()    
#@-node:ville.20090614224528.8141:auto_walk() and g.command('projectwizard')
#@+node:ville.20090910010217.5230:context menu import
def rclick_path_importfile(c,p,menu):
    if not p.h.startswith('@path'):
        return

    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)

    action = menu.addAction("Import files")
    action.connect(action, QtCore.SIGNAL("triggered()"), importfiles_rclick_cb)        

def install_contextmenu_handlers():
    """ Install all the wanted handlers (menu creators) """
    hnd = [rclick_path_importfile]
    g.tree_popup_handlers.extend(hnd)
#@-node:ville.20090910010217.5230:context menu import
#@-others
#@nonl
#@-node:ekr.20090622063842.5264:@thin projectwizard.py
#@-leo
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.