#! /usr/bin/env python
"""LLazy 

Usage: python llazy.py [options] 
Options:
  -g ..., --gui=...       use specified gui backend, default Qt4
  -h, --help              show this help
  -d                      show debugging information while parsing

        print self.sender.__class__
Examples:
  python llazy.py -g Qt
"""

from optparse import OptionParser

import sys
import LLazyView
import LLazyModel
import LLazyModules
import Core


class LLazy:
    """
    The LLazy class.
    """
    def __init__(self, options):
        self.view = None
    
        db = LLazyModel.TreeDataBase.TreeDBMethods.getTDB(Core.Config.ldapdb)
        db.setParam(Core.Config.ldapdb,Core.Config.base,Core.Config.login,Core.Config.passwd,Core.Config.proto)
    
        "fetch the LLazy branch from the LLazy ldap backend"
        llazy = LLazyModel.TreeDataBase.TreeDBMethods.getNode(Core.Config.base, LLazyModel.SCOPE_SUBTREE, db)
    
        "instanciate the widget factory with option GUI passed in command line parameters"
        LLazyView.WidgetFactory.Widget_factory().set_backend(options.gui)
        
        "create the application widget"
        self.builder = LLazyView.WidgetFactory.Widget_builder()
        self.view = self.builder.build(self, llazy)
        
        
    def run(self):
        self.view.draw()
        pass

def parseCommandLine():
    """
    Parse command line parameters.
    """
    usage = "usage: %prog [options] arg"
    parser = OptionParser(usage)
    parser.add_option("-g", "--gui", dest="gui",
                      help="use specified gui backend, default Qt4", metavar="GUI",
                      default = "Qt4")

    (options, args) = parser.parse_args()
    return options

def main(argv):
    """
    The main class,
    create an instance of LLazy with command line parameters in parameter
    """
    
    LLazy(parseCommandLine()).run()

if __name__ == "__main__":
    main(sys.argv[1:])

