void ExpressionEditorWindow::slot_load_script()
{
    QString filepath =
        get_open_filename(
            this,
            "Open...",
            "Expression Scripts (*.se);;All Files (*.*)",
            m_settings,
            SETTINGS_FILE_DIALOG_PROJECTS);

    if (!filepath.isEmpty())
    {
        filepath = QDir::toNativeSeparators(filepath);

        // Open script file.
        ifstream script_file(filepath.toStdString().c_str());
        if (!script_file.is_open())
        {
            show_error_message_box(
                "Loading Error",
                "Failed to load the expression script file " + filepath.toStdString() + ".");
            return;
        }

        // Read script file into memory.
        stringstream script_buffer;
        script_buffer << script_file.rdbuf();
        script_file.close();

        // Set script as expression.
        m_editor->setExpr(script_buffer.str());
        apply_expression();
    }
}
Ejemplo n.º 2
0
void try_run_file(const boost::filesystem::path & cur)
{
	if(cur.extension().native().compare(".py"))
	{
		return;
	}

	script_file_parser script_file(cur.native());

	if(script_file.is_valid())
	{
		boost::filesystem::path work, out;
		create_directories(cur, work, out);

		auto parent = cur.parent_path();
		auto start  = parent.begin();

		for(auto p = config::tests.begin(); p != config::tests.end() && *p == *start; ++p, ++start) ;

		for(; start != parent.end(); ++start)
		{
			script_file.add_keyword((*start).native());
		}

		script_file.add_title(cur.stem().native());

		if(config::query->evaluate(script_file))
		{
			script_scheduler()->schedule_file(cur, work, out);
		}
	}
}
Ejemplo n.º 3
0
	k3d::inode* create_plugin(k3d::iplugin_factory& Factory, k3d::idocument& Document)
	{
		if(&Factory != this)
		{
			k3d::log() << error << "Cannot use factory [" << name() << "] from within a virtual plugin factory" << std::endl;
			return 0;
		}

		if(!delegate_factory)
			delegate_factory = dynamic_cast<k3d::idocument_plugin_factory*>(k3d::plugin::factory::lookup(delegate_factory_name));

		if(!delegate_factory)
		{
			k3d::log() << error << "Couldn't locate delegate factory [" << delegate_factory_name << "]" << std::endl;
			return 0;
		}

		k3d::inode* const node = delegate_factory->create_plugin(*dynamic_cast<k3d::iplugin_factory*>(delegate_factory), Document);
		return_val_if_fail(node, 0);

		k3d::filesystem::ifstream script_file(script_path);
		std::stringstream script_stream;
		script_stream << script_file.rdbuf();

		k3d::property::set_internal_value(*node, "script", script_stream.str());

		return node;
	}
Ejemplo n.º 4
0
void run_file(const boost::filesystem::path & cur)
{
	if(cur.extension().native().compare(".py"))
	{
		return;
	}

	script_file_parser script_file(cur.native());

	if(script_file.is_valid())
	{
		boost::filesystem::path work, out;
		create_directories(cur, work, out);
		script_scheduler()->schedule_file(cur, work, out);
	}
}
Ejemplo n.º 5
0
bool CPythonNode::start()
{
    // Init the PythonQt library.
    initPython();

    // Check if the script exists.
    QString script_name = getConfig().getParameter("input_script")->value.toString();
    QFile script_file(script_name);
    if(!script_file.exists()) {
        qWarning() << "Python script does not exist:"
                   << script_name;
        return false;
    }

    return true;
}
Ejemplo n.º 6
0
	void operator()(const boost::property_tree::ptree &msg) {
		try {
			boost::system::error_code ignore_ec;
			fs::path script_file("./avbot.py");
			std::time_t now_write_time = fs::last_write_time(script_file);
			if (fs::exists(script_file) && now_write_time != last_write_time_) {
				PyImport_ReloadModule(module_.ptr());
				file_changed_ = true;
				reload();
			}
			if (disable_python)
				return;
			std::stringstream ss;
			boost::property_tree::json_parser::write_json(ss, msg);
			pyhandler_.attr("on_message")(ss.str());
		}
		catch (...) {
			PyErr_Print();
		}
	}
Ejemplo n.º 7
0
	k3d::iunknown* create_plugin()
	{
		if(!delegate_factory)
			delegate_factory = dynamic_cast<k3d::iapplication_plugin_factory*>(k3d::plugin::factory::lookup(delegate_factory_name));

		if(!delegate_factory)
		{
			k3d::log() << error << "Couldn't locate delegate factory [" << delegate_factory_name << "]" << std::endl;
			return 0;
		}

		k3d::iunknown* const plugin = delegate_factory->create_plugin();
		return_val_if_fail(plugin, 0);

		k3d::filesystem::ifstream script_file(script_path);
		std::stringstream script_stream;
		script_stream << script_file.rdbuf();

		k3d::property::set_internal_value(*plugin, "script", script_stream.str());

		return plugin;
	}
Ejemplo n.º 8
0
void ExpressionEditorWindow::slot_save_script()
{
    if (m_script_filepath.empty())
    {
        QString filepath =
            get_save_filename(
                this,
                "Save As...",
                "Expression Scripts (*.se)",
                m_settings,
                SETTINGS_FILE_DIALOG_MATERIALS);

        if (!filepath.isEmpty())
        {
            if (QFileInfo(filepath).suffix().isEmpty())
                filepath += ".se";

            filepath = QDir::toNativeSeparators(filepath);

            m_script_filepath = filepath.toStdString();
        }
    }

    if (!m_script_filepath.empty())
    {
        ofstream script_file(m_script_filepath.c_str());

        if (!script_file.is_open())
        {
            show_error_message_box(
                "Saving Error",
                "Failed to save the expression script file " + m_script_filepath + ".");
            return;
        }

        script_file << m_editor->getExpr();
        script_file.close();
    }
}
Ejemplo n.º 9
0
int executeDeclarative(int argc, char *argv[])
{
    QApplication app(argc, argv);
    if (app.arguments().size() < 2)
        return usage(argc, argv);
    QString script_file(app.arguments().at(1));

    QDeclarativeView view;

    setupDeclarative(app, view, QFileInfo(script_file).absoluteFilePath());
    view.setSource(QUrl::fromLocalFile(script_file));

#if QT_VERSION < 0x050000
    view.setAttribute(Qt::WA_OpaquePaintEvent);
    view.setAttribute(Qt::WA_NoSystemBackground);
    view.viewport()->setAttribute(Qt::WA_OpaquePaintEvent);
    view.viewport()->setAttribute(Qt::WA_NoSystemBackground);
#endif

    view.showFullScreen();
    return app.exec();
}
Ejemplo n.º 10
0
	void operator()(channel_identifier cid, avbotmsg msg, send_avchannel_message_t sender, boost::asio::yield_context yield_context)
	{
		try {
			boost::system::error_code ignore_ec;
			fs::path script_file("./avbot.py");
			std::time_t now_write_time = fs::last_write_time(script_file);
			if (fs::exists(script_file) && now_write_time != last_write_time_) {
				PyImport_ReloadModule(module_.ptr());
				file_changed_ = true;
				reload();
			}
			if (disable_python)
				return;
			std::stringstream ss;
			auto json_msg = av_msg_make_json(cid, msg);
			json_msg.put("channel", channel_name_ );
			boost::property_tree::json_parser::write_json(ss, json_msg);
			pyhandler_.attr("on_message")(ss.str());
		}
		catch (...) {
			PyErr_Print();
		}
	}
Ejemplo n.º 11
0
int executeScript(int argc, char *argv[])
{
    QCoreApplication app(argc, argv);
    if (app.arguments().size() < 2)
        return usage(argc, argv);

    QString script_file(app.arguments().at(1));

    QJSEngine engine;
    auto script_env = loadEnv(app, engine);
    int rc = EXIT_SUCCESS;

    try {
        auto res = script_env->load(script_file, false);
        if (res.isError())
            rc = EXIT_FAILURE;
    } catch (Error const &e) {
        qDebug() << "Failed to eval:" << script_file;
        qDebug() << e.msg;
        rc = EXIT_FAILURE;
    }
    return rc == EXIT_SUCCESS && script_env->shouldWait()
        ? app.exec() : rc;
}
Ejemplo n.º 12
0
void shield_class::load(std::string file_name)
{
    int            temp_char_UTF32  = ' ';
    float          temp_float_data;
    int            temp_int_data;
    bool           temp_bool_data;
    std::string    temp_string_data;
    std::string    temp_string_key;
    std::string    temp_string_value;
    int            count;
    std::string    data_line;
    std::ifstream  script_file(file_name.c_str(),std::ios::in);
    if (script_file.is_open())
    {
        while ( script_file.good() )
        {
            getline(script_file,data_line);
            if (data_line.length() > 0)
            {
                if ('\r' == data_line.at(data_line.length()-1))
                {
                    data_line = data_line.substr(0, data_line.length()-1);
                }
            }
            {
                temp_char_UTF32 = data_line[0];
                if((temp_char_UTF32 != '#') && ((int)data_line.length() > 2))
                {
                    temp_char_UTF32   = '#';
                    temp_string_key   = "";
                    temp_string_value = "";
                    count = 0;
                    while(temp_char_UTF32 != ' ')
                    {
                        temp_char_UTF32 = data_line[count];
                        if(temp_char_UTF32 != ' ') temp_string_key += temp_char_UTF32;
                        count++;
                        if(count > (int)data_line.length()) (temp_char_UTF32 = ' ');
                    }
                    while((temp_char_UTF32 == ' ') || (temp_char_UTF32 == '='))
                    {
                        temp_char_UTF32 = data_line[count];
                        count++;
                        if(count > (int)data_line.length()) (temp_char_UTF32 = '#');
                    }
                    count--;
                    while(count < ((int)data_line.length()-1))
                    {
                        temp_char_UTF32  = data_line[count];
                        if (temp_char_UTF32 != '"') temp_string_value += temp_char_UTF32;
                        count++;
                    }
                    temp_string_data = temp_string_value.c_str();
                    temp_float_data  = (float) atof(temp_string_value.c_str());
                    temp_int_data    = (int)   atoi(temp_string_value.c_str());
                    if (temp_int_data == 1) temp_bool_data = true;
                    else temp_bool_data = false;
                    if (temp_string_key == "Name")        shield_class::name       = temp_string_data;
                    if (temp_string_key == "Active")      shield_class::active     = temp_bool_data;
                    if (temp_string_key == "Level")       shield_class::level      = temp_int_data;
                    if (temp_string_key == "Level_1")     shield_class::level_1    = temp_float_data;
                    if (temp_string_key == "Level_2")     shield_class::level_2    = temp_float_data;
                    if (temp_string_key == "Level_3")     shield_class::level_3    = temp_float_data;
                    if (temp_string_key == "Experience")  shield_class::experience = temp_float_data;
                    if (temp_string_key == "Image")       shield_class::image      = temp_int_data;
                    if (temp_string_key == "Absorption")  shield_class::absorption = temp_float_data;
                }
            }
        }
        script_file.close();
    }
}
Ejemplo n.º 13
0
/// Creates plugin factories at runtime based on the contents of a directory
void register_plugins(const k3d::filesystem::path& Path, k3d::iplugin_registry& Registry)
{
	k3d::log() << info << "Loading scripts from " << Path.native_console_string() << std::endl;

	boost::regex metadata_expression("((k3d|ngui|qtui):[^=]*)=\"([^\"]*)\"");

	// There are very few SDK functions that can be safely called at this point in execution, but k3d::share_path() happens to be one of them ...
	for(k3d::filesystem::directory_iterator script_path(Path); script_path != k3d::filesystem::directory_iterator(); ++script_path)
	{
		if(k3d::filesystem::is_directory(*script_path))
			continue;

		k3d::filesystem::ifstream script_file(*script_path);
		std::stringstream script_stream;
		script_stream << script_file.rdbuf();
		k3d::string_t script = script_stream.str();

		k3d::string_t plugin_class;
		k3d::string_t plugin_type;
		k3d::string_t plugin_name;
		k3d::string_t plugin_description = _("Scripted Plugin.");
		k3d::iplugin_factory::metadata_t plugin_metadata;

		for(boost::sregex_iterator metadata(script.begin(), script.end(), metadata_expression); metadata != boost::sregex_iterator(); ++metadata)
		{
			const k3d::string_t name = (*metadata)[1].str();
			const k3d::string_t value = (*metadata)[3].str();

			if(name == "k3d:plugin-class")
				plugin_class = value;
			else if(name == "k3d:plugin-type")
			{
				plugin_type = value;
				plugin_metadata.insert(std::make_pair(name, value));
			}
			else if(name == "k3d:plugin-name")
				plugin_name = value;
			else if(name == "k3d:plugin-description")
				plugin_description = value;
			else
				plugin_metadata.insert(std::make_pair(name, value));
		}

		// Automatically disable documentation for all scripted plugins ...
		plugin_metadata.insert(std::make_pair("k3d:disable-documentation", ""));

		if(plugin_class.empty())
		{
			continue;
		}

		if(plugin_class != "application" && plugin_class != "document")
		{
			k3d::log() << error << "Script [" << script_path->native_console_string() << "] using unknown plugin class [" << plugin_class << "] will not be loaded" << std::endl;
			continue;
		}

		if(plugin_type.empty())
		{
			k3d::log() << error << "Script [" << script_path->native_console_string() << "] without k3d:plugin-type property will not be loaded" << std::endl;
			continue;
		}

		if(plugin_name.empty())
		{
			k3d::log() << error << "Script [" << script_path->native_console_string() << "] without k3d:plugin-name property will not be loaded" << std::endl;
			continue;
		}

		if(plugin_class == "application")
		{
			k3d::iplugin_factory* const factory = new application_factory(
				*script_path,
				plugin_type,
				k3d::uuid::random(),
				plugin_name,
				plugin_description,
				"Scripts",
				k3d::iplugin_factory::STABLE,
				plugin_metadata);

			Registry.register_factory(*factory);
		}
		else if(plugin_class == "document")
		{
			k3d::iplugin_factory* const factory = new document_factory(
				*script_path,
				plugin_type,
				k3d::uuid::random(),
				plugin_name,
				plugin_description,
				"Scripts",
				k3d::iplugin_factory::STABLE,
				plugin_metadata);

			Registry.register_factory(*factory);
		}
	}
}
Ejemplo n.º 14
0
/* ============================ main () ============================== */
int main(int argc, char *argv[])
{
    char c;
    char command[BUFSIZ];
    int opt_index = 0;
    struct option opts[] = {
	{"help", 0, 0, 'h'},
	{"string", 1, 0, 's'},
	{"bars", 1, 0, 'b'},
	{"slider", 1, 0, 'l'},
	{"flashtime", 1, 0, 't'},
	{"clock", 1, 0, 'c'},
	{"mixer", 1, 0, 'm'},
	{"execute", 1, 0, 'e'},
	{"exit", 0, 0, 'x'},
	{"script", 1, 0, 'S'},
	{"apm-watch", 1, 0, 'a'},
	{"apm-show", 1, 0, 'A'},
	{"ppp-watch", 1, 0, 'p'},
	{"ppp-dev", 1, 0, 'd'},
    };
    if (argc == 1)
	usage(0, NULL, NULL);
    while ((c = getopt_long(argc, argv, "hxs:b:l:t:c:m:e:S:p:d:a:A:", opts, &opt_index)) >= 0) {
	switch (c) {
	case 'h':
	    usage(0, NULL, NULL);
	    exit(0);
	case 's':
	    sprintf(command, "strn(%s)", optarg);
	    break;
	case 'b':
	    sprintf(command, "bars(%s)", optarg);
	    break;
	case 'l':
	    sprintf(command, "slid(%s)", optarg);
	    break;
	case 't':
	    sprintf(command, "time(%s)", optarg);
	    break;
	case 'c':
	    sprintf(command, "clck(%s)", optarg);
	    break;
	case 'm':
	    sprintf(command, "mixr(%s)", optarg);
	    break;
	case 'e':
	    sprintf(command, "%s", optarg);
	    break;
	case 'x':
	    sprintf(command, "exit()");
	    break;
	case 'S':
	    sprintf(command, "");
	    script_file(optarg);
	    break;
	case 'p':
	    sprintf(command, "pppw(%s)", optarg);
	    break;
	case 'd':
	    sprintf(command, "pdev(%s)", optarg);
	    break;
	case 'a':
	    sprintf(command, "apmw(%s)", optarg);
	    break;
	case 'A':
	    sprintf(command, "apms(%s)", optarg);
	    break;
	default:
	    usage(1, NULL, NULL);
	    exit(1);
	}
	send_command(command);
    }
    return(0);
}