PLearn 0.1
Public Member Functions | Public Attributes | Static Protected Attributes | Private Types
PLearn::Plide Class Reference

Command to start the PLearn Integrated Development Environment (PLIDE) More...

#include <Plide.h>

Inheritance diagram for PLearn::Plide:
Inheritance graph
[legend]
Collaboration diagram for PLearn::Plide:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Plide ()
virtual void run (const std::vector< std::string > &args)
 The actual implementation of the 'Plide' command.
PythonObjectWrapper versionString (const TVec< PythonObjectWrapper > &args) const
 PLearn version string.
PythonObjectWrapper getAllClassnames (const TVec< PythonObjectWrapper > &args) const
 List of classes registered for serialization (does not return abstract classes since the user may not instantiate them)
PythonObjectWrapper helpResourcesPath (const TVec< PythonObjectWrapper > &args)
 Establish the directory in which elements for HTML help generation should be found.
PythonObjectWrapper helpIndex (const TVec< PythonObjectWrapper > &args) const
 Return the help index as a string.
PythonObjectWrapper helpCommands (const TVec< PythonObjectWrapper > &args) const
 Generate list of registered commands.
PythonObjectWrapper helpClasses (const TVec< PythonObjectWrapper > &args) const
 Generate list of registered classes.
PythonObjectWrapper helpOnCommand (const TVec< PythonObjectWrapper > &args) const
 Generate documentation for a given command.
PythonObjectWrapper helpOnClass (const TVec< PythonObjectWrapper > &args) const
 Generate documentation for a given class.
PythonObjectWrapper setOptionLevel (const TVec< PythonObjectWrapper > &args) const
 Option level for class help.
PythonObjectWrapper toggleOptionFlag (const TVec< PythonObjectWrapper > &args) const
 Toggle flags to display for class help.
PythonObjectWrapper precisOnClass (const TVec< PythonObjectWrapper > &args) const
 Generate the short (one-line) documentation for a given class, as well as the list of all BUILD options it supports.
PythonObjectWrapper loggingControl (const TVec< PythonObjectWrapper > &args) const
 Logging control.
void executePyPLearn (const string &script_code, const string &root_dir) const
 Execute .pyplearn script (given as a character string) using the specified directory as cwd.

Public Attributes

PP< PythonCodeSnippetm_python
 Make available the puthon snippet to supporting classes (e.g.
HTMLHelpCommandm_help_command
 HTML generator for the Help system (points to the systemwide command instance)
PP< HTMLHelpConfigm_help_config
 Configuration object for the HTML Help system.

Static Protected Attributes

static PLearnCommandRegistry reg_
 This allows to register the 'Plide' command in the command registry.

Private Types

typedef PLearnCommand inherited

Detailed Description

Command to start the PLearn Integrated Development Environment (PLIDE)

Upon running, this command starts up a graphical user interface to interface more easily with PLearn.

Definition at line 59 of file Plide.h.


Member Typedef Documentation

Definition at line 61 of file Plide.h.


Constructor & Destructor Documentation

PLearn::Plide::Plide ( )

Definition at line 225 of file Plide.cc.

    : PLearnCommand(
        "plide",
        "Starts up the PLearn Integrated Development Environment (PLIDE)",
        "Upon running, this command starts up a graphical user interface to\n"
        "interface more easily with PLearn.\n"
        )
{ }

Member Function Documentation

void PLearn::Plide::executePyPLearn ( const string &  script_code,
const string &  root_dir 
) const

Execute .pyplearn script (given as a character string) using the specified directory as cwd.

Definition at line 493 of file Plide.cc.

References PLearn::chdir(), PLearn::PStream::good(), PLearn::openString(), PLASSERT, PLearn::PStream::plearn_ascii, PLearn::readObject(), and PLearn::PStream::skipBlanksAndCommentsAndSeparators().

Referenced by run().

{
    PLearn::chdir(PPath(root_dir));
    PStream pyplearn_in = openString(script_code, PStream::plearn_ascii);
    PP<PyPLearnScript> pyplearn_script = new PyPLearnScript;
    pyplearn_in >> pyplearn_script;
    PLASSERT( pyplearn_script );

    string pyplearn_script_string = pyplearn_script->getScript();
    PStream plearn_in = openString(pyplearn_script_string,
                                   PStream::plearn_ascii);
    while (plearn_in.good()) {
        PP<Object> o = readObject(plearn_in);
        o->run();
        plearn_in.skipBlanksAndCommentsAndSeparators();
    }

    // Save out experiment.plearn and metainfos.txt
    pyplearn_script->close();
}

Here is the call graph for this function:

Here is the caller graph for this function:

PythonObjectWrapper PLearn::Plide::getAllClassnames ( const TVec< PythonObjectWrapper > &  args) const

List of classes registered for serialization (does not return abstract classes since the user may not instantiate them)

Definition at line 337 of file Plide.cc.

References PLearn::TypeFactory::getTypeMap(), PLearn::TypeFactory::instance(), PLERROR, PLearn::TVec< T >::push_back(), PLearn::TVec< T >::resize(), and PLearn::TVec< T >::size().

Referenced by run().

{
    if (args.size() != 0)
        PLERROR("%sExpecting 0 argument; got %d", __FUNCTION__, args.size());

    const TypeMap& tm = TypeFactory::instance().getTypeMap();
    TVec<string> all_classes;
    all_classes.resize(0, tm.size());
    for (TypeMap::const_iterator it = tm.begin(), end = tm.end()
             ; it != end ; ++it)
    {
        // Skip abstract classes
        if (it->second.constructor)
            all_classes.push_back(it->second.type_name);
    }
    return PythonObjectWrapper(all_classes);
}

Here is the call graph for this function:

Here is the caller graph for this function:

PythonObjectWrapper PLearn::Plide::helpClasses ( const TVec< PythonObjectWrapper > &  args) const

Generate list of registered classes.

Definition at line 399 of file Plide.cc.

References PLearn::HTMLHelpCommand::helpClasses(), m_help_command, m_help_config, PLASSERT, PLERROR, and PLearn::TVec< T >::size().

Referenced by run().

{
    if (args.size() != 0)
        PLERROR("%sExpecting 0 argument; got %d", __FUNCTION__, args.size());

    PLASSERT( m_help_config && m_help_command );
    ostringstream os;
    m_help_command->helpClasses(os, m_help_config);
    return PythonObjectWrapper(os.str());
}

Here is the call graph for this function:

Here is the caller graph for this function:

PythonObjectWrapper PLearn::Plide::helpCommands ( const TVec< PythonObjectWrapper > &  args) const

Generate list of registered commands.

Definition at line 388 of file Plide.cc.

References PLearn::HTMLHelpCommand::helpCommands(), m_help_command, m_help_config, PLASSERT, PLERROR, and PLearn::TVec< T >::size().

Referenced by run().

{
    if (args.size() != 0)
        PLERROR("%sExpecting 0 argument; got %d", __FUNCTION__, args.size());

    PLASSERT( m_help_config && m_help_command );
    ostringstream os;
    m_help_command->helpCommands(os, m_help_config);
    return PythonObjectWrapper(os.str());
}

Here is the call graph for this function:

Here is the caller graph for this function:

PythonObjectWrapper PLearn::Plide::helpIndex ( const TVec< PythonObjectWrapper > &  args) const

Return the help index as a string.

Definition at line 377 of file Plide.cc.

References PLearn::HTMLHelpCommand::helpIndex(), m_help_command, m_help_config, PLASSERT, PLERROR, and PLearn::TVec< T >::size().

Referenced by run().

{
    if (args.size() != 0)
        PLERROR("%sExpecting 0 argument; got %d", __FUNCTION__, args.size());

    PLASSERT( m_help_config && m_help_command );
    ostringstream os;
    m_help_command->helpIndex(os, m_help_config);
    return PythonObjectWrapper(os.str());
}

Here is the call graph for this function:

Here is the caller graph for this function:

PythonObjectWrapper PLearn::Plide::helpOnClass ( const TVec< PythonObjectWrapper > &  args) const

Generate documentation for a given class.

Definition at line 421 of file Plide.cc.

References PLearn::HTMLHelpCommand::helpOnClass(), m_help_command, m_help_config, PLASSERT, PLERROR, and PLearn::TVec< T >::size().

Referenced by run().

{
    if (args.size() != 1)
        PLERROR("%sExpecting 1 argument; got %d", __FUNCTION__, args.size());

    PLASSERT( m_help_config && m_help_command );
    ostringstream os;
    m_help_command->helpOnClass(args[0].as<string>(), os, m_help_config);
    return PythonObjectWrapper(os.str());
}

Here is the call graph for this function:

Here is the caller graph for this function:

PythonObjectWrapper PLearn::Plide::helpOnCommand ( const TVec< PythonObjectWrapper > &  args) const

Generate documentation for a given command.

Definition at line 410 of file Plide.cc.

References PLearn::HTMLHelpCommand::helpOnCommand(), m_help_command, m_help_config, PLASSERT, PLERROR, and PLearn::TVec< T >::size().

Referenced by run().

{
    if (args.size() != 1)
        PLERROR("%sExpecting 1 argument; got %d", __FUNCTION__, args.size());

    PLASSERT( m_help_config && m_help_command );
    ostringstream os;
    m_help_command->helpOnCommand(args[0].as<string>(), os, m_help_config);
    return PythonObjectWrapper(os.str());
}

Here is the call graph for this function:

Here is the caller graph for this function:

PythonObjectWrapper PLearn::Plide::helpResourcesPath ( const TVec< PythonObjectWrapper > &  args)

Establish the directory in which elements for HTML help generation should be found.

This comes from Python since it's relative to the location of the Plide Python code.

Definition at line 355 of file Plide.cc.

Referenced by run().

{
// DEPRECATED: see HelpSystem
/*
    if (args.size() != 1)
        PLERROR("%sExpecting 1 argument; got %d", __FUNCTION__, args.size());

    PPath base_path = args[0].as<string>();
    m_help_config   = new HTMLHelpConfig;
    m_help_config->html_index_document  = "";
    m_help_config->html_prolog_document = base_path / "help_prolog.html";
    m_help_config->html_epilog_document = base_path / "help_epilog.html";
    
    m_help_command = dynamic_cast<HTMLHelpCommand*>(
        PLearnCommandRegistry::commands()["htmlhelp"]);
    if (! m_help_command)
        PLERROR("%sThe PLearn command 'HTMLHelpCommand' must be linked into "
                "the executable in order to use the Plide help system.", __FUNCTION__);
*/
    return PythonObjectWrapper();
}

Here is the caller graph for this function:

PythonObjectWrapper PLearn::Plide::loggingControl ( const TVec< PythonObjectWrapper > &  args) const

Logging control.

This function should be called with two arguments: 1) Desired verbosity level (integer) 2) List of module names to activate in named logging (list of strings)

Definition at line 478 of file Plide.cc.

References PLearn::PL_Log::enableNamedLogging(), PLearn::PL_Log::instance(), PLERROR, PLearn::TVec< T >::size(), and PLearn::PL_Log::verbosity().

Referenced by run().

{
    if (args.size() != 2)
        PLERROR("%sExpecting 2 arguments; got %d", __FUNCTION__, args.size());

    int desired_verbosity = args[0].as<int>();
    vector<string> module_names = args[1].as< vector<string> >();
    PL_Log::instance().verbosity(desired_verbosity);
    PL_Log::instance().enableNamedLogging(module_names);
    return PythonObjectWrapper();
}

Here is the call graph for this function:

Here is the caller graph for this function:

PythonObjectWrapper PLearn::Plide::precisOnClass ( const TVec< PythonObjectWrapper > &  args) const

Generate the short (one-line) documentation for a given class, as well as the list of all BUILD options it supports.

This is returned as a pair (doc, options_list). Return None if no such class exists.

Definition at line 451 of file Plide.cc.

References PLearn::OptionBase::buildoption, PLearn::TypeMapEntry::getoptionlist_method, PLearn::TypeFactory::getTypeMapEntry(), PLearn::TypeFactory::instance(), PLearn::TypeFactory::isRegistered(), PLearn::TypeMapEntry::one_line_descr, PLERROR, PLearn::TVec< T >::push_back(), PLearn::TVec< T >::resize(), and PLearn::TVec< T >::size().

Referenced by run().

{
    if (args.size() != 1)
        PLERROR("%sExpecting 1 argument; got %d", __FUNCTION__, args.size());

    string classname = args[0].as<string>();
    if (TypeFactory::instance().isRegistered(classname)) {
        const TypeMapEntry& tme = TypeFactory::instance().getTypeMapEntry(classname);
        OptionList& options = (*tme.getoptionlist_method)();
        TVec<string> build_options;
        build_options.resize(0, options.size());

        // Determine buildoptions
        for (OptionList::iterator it=options.begin(), end=options.end()
                 ; it != end ; ++it)
        {
            int flags = (*it)->flags();
            if (flags & OptionBase::buildoption)
                build_options.push_back((*it)->optionname());
        }
        return PythonObjectWrapper(make_pair(tme.one_line_descr, build_options));
    }
    else
        return PythonObjectWrapper();        // None
}

Here is the call graph for this function:

Here is the caller graph for this function:

void PLearn::Plide::run ( const std::vector< std::string > &  args) [virtual]

The actual implementation of the 'Plide' command.

Implements PLearn::PLearnCommand.

Definition at line 237 of file Plide.cc.

References PLearn::endl(), executePyPLearn(), getAllClassnames(), PLearn::PL_Log::getCurrentPlugin(), PLearn::ProgressBar::getCurrentPlugin(), helpClasses(), helpCommands(), helpIndex(), helpOnClass(), helpOnCommand(), helpResourcesPath(), PLearn::PL_Log::instance(), loggingControl(), m_python, PLearn::PLearnError::message(), PLearn::PL_Log::outmode(), PLERROR, PLearn::plide_code, precisOnClass(), PLearn::PStream::pretty_ascii, setOptionLevel(), PLearn::PL_Log::setPlugin(), PLearn::ProgressBar::setPlugin(), PLearn::TVec< T >::size(), toggleOptionFlag(), and versionString().

{
    m_python = new PythonCodeSnippet(plide_code);
    m_python->build();

    // A bunch of injections
    m_python->inject("versionString",     this, &Plide::versionString);
    m_python->inject("getAllClassnames",  this, &Plide::getAllClassnames);
    m_python->inject("helpResourcesPath", this, &Plide::helpResourcesPath);
    m_python->inject("helpIndex",         this, &Plide::helpIndex);
    m_python->inject("helpCommands",      this, &Plide::helpCommands);
    m_python->inject("helpClasses",       this, &Plide::helpClasses);
    m_python->inject("helpOnCommand",     this, &Plide::helpOnCommand);
    m_python->inject("helpOnClass",       this, &Plide::helpOnClass);
    m_python->inject("setOptionLevel",    this, &Plide::setOptionLevel);
    m_python->inject("toggleOptionFlag",  this, &Plide::toggleOptionFlag);
    m_python->inject("precisOnClass",     this, &Plide::precisOnClass);
    m_python->inject("loggingControl",    this, &Plide::loggingControl);

    // Start the thing!
    m_python->invoke("StartPlide", args);

    // Link progress bar stuff to GUI elements
    PP<ProgressBarPlugin> previous_progress_plugin = ProgressBar::getCurrentPlugin();
    PP<ProgressBarPlugin> pp_ppp = new PlideProgressPlugin(m_python);
    ProgressBar::setPlugin(pp_ppp);

    // Link logging stuff to GUI elements; change stream mode to pretty ascii
    PL_Log::instance().outmode(PStream::pretty_ascii);
    PP<PL_LogPlugin> previous_log_plugin = PL_Log::instance().getCurrentPlugin();
    PP<PL_LogPlugin> log_plugin = new PlideLogPlugin(m_python);
    PL_Log::instance().setPlugin(log_plugin);
    
    // Main loop: get work, dispatch, start again
    while (true) {
        TVec<string> work = m_python->invoke("GetWork").as< TVec<string> >();

        if (work.size() != 4)
            PLERROR("%sExpected to receive a work vector with 4 elements; got %d",
                    __FUNCTION__, work.size());

        const string& request_id  = work[0];
        const string& script_code = work[1];
        const string& root_dir    = work[2];
        const string& script_kind = work[3];
        MODULE_LOG << "Got work request " << request_id
                   << " in directory "    << root_dir
                   << " with script (subset):\n"
                   << script_code.substr(0,100)
                   << endl;

        if (script_code == "Quit()")
            break;

        string result_code;
        string result_details;
        try {
            if (script_kind == "pyplearn")
                executePyPLearn(script_code, root_dir);
            else
                PLERROR("%sUnknown/unsupported script kind '%s'",
                        __FUNCTION__, script_kind.c_str());
        }
        catch (const PLearnError& e) {
            result_code = "PLearnError";
            result_details = e.message();
        }
        catch (const std::exception& e) {
            result_code = "std::exception";
            result_details = e.what();
        }
        catch (...) 
        {
            result_code = "UnknownError";
            result_details =
                "uncaught unknown exception "
                "(ex: out-of-memory when allocating a matrix)";
        }

        m_python->invoke("PostWorkResults", request_id, result_code, result_details);
    }

    // Finally, quit the GTK loop
    m_python->invoke("QuitPlide");

    // Bring back previous plugin before shutting down Python
    PL_Log::instance().setPlugin(previous_log_plugin);
    ProgressBar::setPlugin(previous_progress_plugin);
}

Here is the call graph for this function:

PythonObjectWrapper PLearn::Plide::setOptionLevel ( const TVec< PythonObjectWrapper > &  args) const

Option level for class help.

Definition at line 432 of file Plide.cc.

References PLERROR, PLearn::OptionBase::setCurrentOptionLevel(), and PLearn::TVec< T >::size().

Referenced by run().

{
    if (args.size() != 1)
        PLERROR("%sExpecting 1 argument; got %d", __FUNCTION__, args.size());
    OptionBase::OptionLevel desired_level = args[0].as<OptionBase::OptionLevel>();
    OptionBase::setCurrentOptionLevel(desired_level);
    return PythonObjectWrapper();
}

Here is the call graph for this function:

Here is the caller graph for this function:

PythonObjectWrapper PLearn::Plide::toggleOptionFlag ( const TVec< PythonObjectWrapper > &  args) const

Toggle flags to display for class help.

Definition at line 441 of file Plide.cc.

References PLearn::OptionBase::getCurrentFlags(), PLERROR, PLearn::OptionBase::setCurrentFlags(), and PLearn::TVec< T >::size().

Referenced by run().

{
    if (args.size() != 1)
        PLERROR("%sExpecting 1 argument; got %d", __FUNCTION__, args.size());
    OptionBase::flag_t flag_to_toggle = args[0].as<OptionBase::flag_t>();
    OptionBase::setCurrentFlags(OptionBase::getCurrentFlags() ^ flag_to_toggle);
    return PythonObjectWrapper();
}

Here is the call graph for this function:

Here is the caller graph for this function:

PythonObjectWrapper PLearn::Plide::versionString ( const TVec< PythonObjectWrapper > &  args) const

PLearn version string.

Definition at line 330 of file Plide.cc.

References PLERROR, PLearn::TVec< T >::size(), and PLearn::version_string().

Referenced by run().

{
    if (args.size() != 0)
        PLERROR("%sExpecting 0 argument; got %d", __FUNCTION__, args.size());
    return PythonObjectWrapper(version_string());
}

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

HTML generator for the Help system (points to the systemwide command instance)

Definition at line 126 of file Plide.h.

Referenced by helpClasses(), helpCommands(), helpIndex(), helpOnClass(), and helpOnCommand().

Configuration object for the HTML Help system.

Definition at line 129 of file Plide.h.

Referenced by helpClasses(), helpCommands(), helpIndex(), helpOnClass(), and helpOnCommand().

Make available the puthon snippet to supporting classes (e.g.

progress bars that display in the GUI environment)

Definition at line 122 of file Plide.h.

Referenced by run().

This allows to register the 'Plide' command in the command registry.

Definition at line 132 of file Plide.h.


The documentation for this class was generated from the following files:
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines