Ejemplo n.º 1
0
def main():

    from class_macro import Macros
    from widget_macro import WidgetMacros
    from class_plugins import Plugins

    macros_id = request.shared_variables["macro_id"]
    plugin_id = request.shared_variables["plugin_id"]
    if macros_id:
        macros = Macros.get_by_id(macros_id)
        macros.delete()

    plugin = Plugins.get_by_id(plugin_id)
    macros = plugin.get_macros()
    config_is_exist = False
    for m in macros:
        if m.name == "config":
            config_is_exist = True

    if config_is_exist == True:
        self.button_config.visible = "1"
        self.button_create_config.visible = "0"
    else:
        self.button_config.visible = "0"
        self.button_create_config.visible = "1"

    plugin = Plugins.get_by_id(plugin_id)
    macros = plugin.get_macros()

    widget_macros = WidgetMacros()
    widget_macros.set_data(macros)
    widget_macros.render(self.datatable_macros)

    self.dialog_delete_macro.action("hide", [])
    response.shared_variables["macro_id"] = ""
Ejemplo n.º 2
0
    def export(self):
        from StringIO import StringIO
        import base64

        from class_xml_plugin import XMLPlugin
        xml_plugin = XMLPlugin()

        xml_plugin.picture = base64.b64encode(
            application.storage.readall(self.picture)) if self.picture else ''
        xml_plugin.description = self.description if self.description else ''
        xml_plugin.name = self.name if self.name else ''
        xml_plugin.version = self.version if self.version else ''
        xml_plugin.author = self.author if self.author else ''
        xml_plugin.guid = self.guid

        #raise Exception(name, description, author)
        #outp.write(xml_plugin"<plugin guid='" + self.guid + "' name='" + name + "' description='" + description + "' picture='" + picture + "' author='" + author + "' version='"+ version +"'>")

        timers = self.get_timer()
        for timer in timers:
            from class_timer import Timer
            t = Timer.get_by_id(timer.id)
            xml_plugin.append_child(t.get_xmlnode())

        custom_events = self.get_custom_event()
        for cevent in custom_events:
            from class_custom_event import CustomEvent
            ce = CustomEvent.get_by_id(cevent.id)
            xml_plugin.append_child(ce.get_xmlnode())

        from VEE_sqlite3 import DatabaseManager
        from VEE_resources import ResourceFolderManager

        db_list = DatabaseManager(self.guid).databaselist
        for db in db_list:
            from class_plugin_db import PluginDB
            plugin_db = PluginDB(db, DatabaseManager(self.guid).export_db(db))
            xml_plugin.append_child(plugin_db.get_xmlnode())

        res_list = ResourceFolderManager(self.guid).resourcelist
        for res in res_list:
            from class_resource import Resource
            resource = Resource(
                res,
                ResourceFolderManager(self.guid).export_res(res))
            xml_plugin.append_child(resource.get_xmlnode())

        macros = self.get_macros()
        for macro in macros:
            from class_macro import Macros
            m = Macros.get_by_id(macro.id)
            xml_plugin.append_child(m.get_xmlnode())

        outp = StringIO()
        outp.write(xml_plugin.toprettyxml().encode('utf8'))
        return outp
Ejemplo n.º 3
0
def check():
    from VEE_tools import compile, VScriptComlipationError, PythonCompilationError
    try:
        compile(source)
        return "Passed well."
        self.growl.action('show', ["Message", u"No errors in code."])
    except VScriptComlipationError as error:
        return u"VScript Compilation Error (Line {line}): {msg}".format(
            line=error.line, msg=error.message)
    except PythonCompilationError as error:
        return u"Python Compilation Error: {msg}".format(msg=error.message)


macro_id = request.shared_variables["macro_id"]
macro = Macros.get_by_id(macro_id)
plugin = Plugins.get_by_guid(macro.plugin_guid)
if plugin and macro:
    source = self.form_macros.codeeditor_macros_body.value = request.arguments.get(
        "codeeditor_macros_body", "")
    macro.code = source
    macro.save()
    result = check()
    self.growl.action(
        'show',
        ["Message", u"Your work is saved! Compilnig: {0}".format(result)])

else:
    self.growl.action('show', [
        "Error =(", u"Can't save code macro. Please, try to reload the page."
    ])
Ejemplo n.º 4
0
def main():

    from class_macro import Macros
    from class_plugins import Plugins
    import cgi, localization

    lang = localization.get_lang()

    macros_id = request.arguments.get("id")
    response.shared_variables["macro_id"] = macros_id
    plugin = ""
    if macros_id:
        macros = Macros.get_by_id(macros_id)
        plugin = Plugins.get_by_guid(macros.plugin_guid)
        if plugin.protected:
            response.redirect("/plugins.vdom")
        self.form_macros.codeeditor_macros_body.value = macros.code if macros.code else ""

    if "formbutton_apply" in request.arguments:
        if plugin:
            source = self.form_macros.codeeditor_macros_body.value = request.arguments.get(
                "codeeditor_macros_body", "")
            macros = Macros.get_by_id(macros_id) if macros_id else Macros()
            macros.code = source
            macros.save()
            response.redirect("/plugin_details?id=" + str(plugin.id))
        else:
            self.growl.title = lang["error"]
            self.growl.text = "Unknown macro"
            self.growl.visible = "1"

    elif "formbutton_check" in request.arguments:
        if macros_id:
            source = self.form_macros.codeeditor_macros_body.value = request.arguments.get(
                "codeeditor_macros_body", "")
            if source:

                from VEE_tools import compile, VScriptComlipationError, PythonCompilationError
                try:
                    compile(source)
                except VScriptComlipationError as error:
                    self.growl.title = lang["error"]
                    self.growl.text = u"VScript Compilation Error (Line {line}): {msg}".format(
                        line=error.line, msg=error.message)
                    self.growl.visible = "1"

                except PythonCompilationError as error:
                    self.growl.title = lang["error"]
                    self.growl.text = u"Python Compilation Error: {msg}".format(
                        msg=error.message)
                    self.growl.visible = "1"

            else:
                self.growl.title = lang["error"]
                self.growl.text = lang["type_macros_code_error"]
                self.growl.visible = "1"

        else:
            self.growl.title = lang["error"]
            self.growl.text = lang["fill_macros_fields_error"]
            self.growl.visible = "1"

    elif "formbutton_cancel" in request.arguments:
        response.redirect("/plugin_details?id=" +
                          str(plugin.id)) if plugin else response.redirect(
                              "/plugins")
Ejemplo n.º 5
0
def main():

    from class_macro import Macros
    from class_timer import Timer
    from class_custom_event import CustomEvent
    from widget_plugins import WidgetPlugins
    from widget_macro import WidgetMacros
    from class_plugins import Plugins
    import localization

    lang = localization.get_lang()

    from VEE_events import event_map

    name = self.dialog_create_macro.form_macro.formtext_name.value = request.arguments.get(
        "formtext_name", "")
    macros_type = self.dialog_create_macro.form_macro.container_back.formlist_type.selectedvalue = request.arguments.get(
        "formlist_type", Macros.MacrosType.LIBRARY)
    event = self.dialog_create_macro.form_macro.container_back.formlist_event.selectedvalue = request.arguments.get(
        "formlist_event", "")
    location = self.dialog_create_macro.form_macro.container_back.formlist_location.selectedvalue = request.arguments.get(
        "formlist_location", "")
    description = self.dialog_create_macro.form_macro.formtextarea_description.value = request.arguments.get(
        "formtextarea_description", "")
    macros_id = self.dialog_create_macro.form_macro.formtext_id.value = request.arguments.get(
        "formtext_id", "")
    page = self.dialog_create_macro.form_macro.container_back.formlist_page.selectedvalue = request.arguments.get(
        "formlist_page", "")

    import re
    guid_regex = re.compile(
        "^[a-zA-Z0-9]{8}\-[a-zA-Z0-9]{4}\-[a-zA-Z0-9]{4}\-[a-zA-Z0-9]{4}\-[a-zA-Z0-9]{12}$"
    )

    class_name = ""
    timer_guid = ""
    custom_event_guid = ""
    is_button = "0"
    on_board = "0"

    if macros_type == Macros.MacrosType.EVENT:
        is_button = "0"
        if guid_regex.match(event):
            if Timer.get_timer_by_guid(event):
                timer_guid = event
                class_name = "VEE_TimerEvent"
            elif CustomEvent.get_custom_event_by_guid(event):
                custom_event_guid = event
                class_name = "VEE_CustomEvent"
        else:
            for e in event_map:
                if e == int(event):
                    class_name = event_map[e].__name__

    elif macros_type == Macros.MacrosType.BUTTON:
        is_button = "1"
        on_board = "1" if location and location == "1" else "0"

    elif macros_type != Macros.MacrosType.LIBRARY:
        macros_type = Macros.MacrosType.LIBRARY

    plugin_id = request.shared_variables["plugin_id"]
    plugin = Plugins.get_by_id(plugin_id)
    macros = Macros.get_by_id(macros_id) if macros_id else Macros()
    macros.name = name
    macros.class_name = class_name
    macros.timer_guid = timer_guid
    macros.custom_event_guid = custom_event_guid
    macros.is_button_macros = is_button
    macros.on_board = on_board
    macros.description = description
    macros.plugin_guid = plugin.guid
    macros.page = page
    macros.type = macros_type
    macros.save()

    plugin = Plugins.get_by_id(plugin_id)
    macros = plugin.get_macros()

    widget_macros = WidgetMacros()
    widget_macros.set_data(macros)
    widget_macros.render(self.datatable_macros)
    self.dialog_create_macro.action("hide", [])
Ejemplo n.º 6
0
            "op") == "export_db":
        db_name = request.arguments.get("db", "")
        plugin = Plugins.get_by_id(int(request.arguments.get("plugin_id", 0)))
        if plugin:
            output = DatabaseManager(plugin.guid).export_db(db_name)
            from StringIO import StringIO
            outp = StringIO()
            outp.write(output.read())
            outp_len = outp.tell()
            outp.seek(0)
            response.send_file(db_name, outp_len, outp)

    if "formbutton_apply" in request.arguments:
        #raise Exception("1")
        macros_id = request.arguments.get("formtext_macro_id", "")
        macros = Macros.get_by_id(macros_id)
        if "uploader" in request.arguments:
            picture = request.arguments.get("uploader", "", castto=Attachment)
            picture_name = ""
            if picture:
                macros.macros_picture = picture_name = str(uuid4())
                application.storage.write(picture_name, picture.handler.read())
        macros.save()

        plugin_id = request.arguments.get("id", "")
        plugin = Plugins.get_by_id(int(plugin_id))
        macros = plugin.get_macros()

        widget_macros = WidgetMacros()
        widget_macros.set_data(macros)
        widget_macros.render(self.datatable_macros)
Ejemplo n.º 7
0
def main():

    from class_timer import Timer
    from class_custom_event import CustomEvent
    from class_macro import Macros
    import json, localization
    from class_plugins import Plugins
    from config import config
    from VEE_events import event_map

    lang = localization.get_lang()

    macros_id = request.shared_variables["macro_id"]
    plugin_id = request.shared_variables["plugin_id"]
    plugin = Plugins.get_by_id(plugin_id)

    macro_type = request.arguments.get("itemValue", Macros.MacrosType.UNKNOWN)

    def setup_event_type_controls():
        self.dialog_create_macro.form_macro.container_back.formlist_location.visible = "0"
        self.dialog_create_macro.form_macro.container_back.text_location.visible = "0"
        self.dialog_create_macro.form_macro.container_back.formlist_event.visible = "1"
        self.dialog_create_macro.form_macro.container_back.text_event.visible = "1"
        self.dialog_create_macro.form_macro.container_back.formlist_page.visible = "0"
        self.dialog_create_macro.form_macro.container_back.text_timer.visible = "0"

        event_dict = {}
        for event in event_map:
            event_dict[event] = lang[event_map[event].__name__]

        for timer in Timer.get_timer_by_plugin_guid(plugin.guid):
            event_dict[timer.guid] = timer.name

        for cevent in CustomEvent.get_custom_event_by_plugin_guid(plugin.guid):
            event_dict[cevent.guid] = cevent.name

        self.dialog_create_macro.form_macro.container_back.formlist_event.value = json.dumps(
            event_dict)

    def setup_button_type_controls():
        self.dialog_create_macro.form_macro.container_back.formlist_page.selectedvalue = config[
            "plugin_page_dict"].keys()[0]
        self.dialog_create_macro.form_macro.container_back.formlist_page.value = json.dumps(
            config["plugin_page_dict"])
        self.dialog_create_macro.form_macro.container_back.formlist_location.visible = "1"
        self.dialog_create_macro.form_macro.container_back.text_location.visible = "1"
        self.dialog_create_macro.form_macro.container_back.formlist_event.visible = "0"
        self.dialog_create_macro.form_macro.container_back.text_event.visible = "0"
        self.dialog_create_macro.form_macro.container_back.formlist_location.value = json.dumps(
            {
                "1": "On panel",
                "2": "In plugin menu"
            })

    def setup_library_type_controls():
        self.dialog_create_macro.form_macro.container_back.formlist_page.visible = "0"
        self.dialog_create_macro.form_macro.container_back.formlist_location.visible = "0"
        self.dialog_create_macro.form_macro.container_back.text_location.visible = "0"
        self.dialog_create_macro.form_macro.container_back.formlist_event.visible = "0"
        self.dialog_create_macro.form_macro.container_back.text_event.visible = "0"
        self.dialog_create_macro.form_macro.container_back.text_timer.visible = "0"

    if macros_id and macro_type == Macros.MacrosType.UNKNOWN:

        macros = Macros.get_by_id(macros_id)

        self.dialog_create_macro.form_macro.formtext_id.value = macros_id
        self.dialog_create_macro.form_macro.formtext_name.value = macros.name
        self.dialog_create_macro.form_macro.formtextarea_description.value = macros.description
        macro_type = macros.type

        if macros.type == Macros.MacrosType.EVENT:
            setup_event_type_controls()

            if macros.timer_guid:
                self.dialog_create_macro.form_macro.container_back.formlist_event.selectedvalue = macros.timer_guid
            elif macros.custom_event_guid:
                self.dialog_create_macro.form_macro.container_back.formlist_event.selectedvalue = macros.custom_event_guid
            elif macros.class_name:
                for event in event_map:
                    if event_map[event].__name__ == macros.class_name:
                        self.dialog_create_macro.form_macro.container_back.formlist_event.selectedvalue = event
                        break

        elif macros.type == Macros.MacrosType.BUTTON:
            setup_button_type_controls()
            self.dialog_create_macro.form_macro.container_back.formlist_location.selectedvalue = "1" if macros.on_board == "1" else "2"
            self.dialog_create_macro.form_macro.container_back.formlist_page.selectedvalue = macros.page

        else:
            setup_library_type_controls()

    self.dialog_create_macro.form_macro.container_back.formlist_type.value = json.dumps(
        {
            Macros.MacrosType.EVENT: "Event macro",
            Macros.MacrosType.BUTTON: "Button macro",
            Macros.MacrosType.LIBRARY: "Library"
        })

    if macro_type == Macros.MacrosType.UNKNOWN:
        macro_type = Macros.MacrosType.EVENT

    self.dialog_create_macro.form_macro.container_back.formlist_type.selectedvalue = macro_type

    if macro_type == Macros.MacrosType.BUTTON:
        setup_button_type_controls()

    elif macro_type in Macros.MacrosType.EVENT:
        setup_event_type_controls()

    else:
        setup_library_type_controls()