def __init__(self, code_template_manager, code_template):
        Gtk.Dialog.__init__(self,
                            title=_("Code Template Editor"),
                            transient_for=code_template_manager)

        self.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
        self.add_buttons(Gtk.STOCK_SAVE, Gtk.ResponseType.OK)

        self.set_default_size(800, 300)
        self.code_template = code_template
        self.tabs = Gtk.Notebook()
        self.tabs.set_scrollable(True)
        box = self.get_content_area()
        box.pack_start(self.tabs, True, True, 0)

        common_tab = Gtk.VBox()
        property_tab = PropertyEditor(self.code_template)
        code_tab = CodeTemplateCodeEditor(self.code_template)
        command_tab = Gtk.VBox()

        self.tabs.append_page(common_tab, Gtk.Label.new(_("Common")))
        self.tabs.append_page(property_tab, Gtk.Label.new(_("Properties")))
        self.tabs.append_page(code_tab, Gtk.Label.new(_("Codes")))
        self.tabs.append_page(command_tab, Gtk.Label.new(_("Command")))

        # First Tab: Common properties
        self.name = StringField({"label": _("Name")}, self.__edit)
        self.language = StringField({"label": _("Language")}, self.__edit)
        self.extension = StringField({"label": _("Extension")}, self.__edit)
        self.type = StringField({"label": _("Type")}, None)
        self.description = StringField({"label": _("Description")}, None)
        self.code_parts = StringField({"label": _("Code Parts")}, None)

        common_tab.pack_start(self.language, False, False, 1)
        common_tab.pack_start(self.name, False, False, 1)
        common_tab.pack_start(self.extension, False, False, 1)
        common_tab.pack_start(self.type, False, False, 1)
        common_tab.pack_start(self.description, False, False, 1)
        common_tab.pack_start(self.code_parts, False, False, 1)

        # Third Tab: Command properties
        self.command = CodeField({"label": _("")}, None)
        command_tab.pack_start(self.command, True, True, 1)

        self.name.set_value(self.code_template.name)
        self.type.set_value(self.code_template.type)
        self.description.set_value(self.code_template.description)
        self.language.set_value(self.code_template.language)
        self.command.set_value(self.code_template.command)
        #self.extension.set_value(self.code_template.extension)
        #self.code.set_value(self.code_template.code)
        code_parts_string = ', '.join(self.code_template.code_parts)
        self.code_parts.set_value(code_parts_string)

        self.show_all()
Exemple #2
0
    def __init__(self, port_manager, port):
        Gtk.Dialog.__init__(self,
                            title=_("Port Editor"),
                            transient_for=port_manager)
        self.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
        self.add_buttons(Gtk.STOCK_SAVE, Gtk.ResponseType.OK)

        self.port_manager = port_manager
        self.set_default_size(800, 300)

        self.tabs = Gtk.Notebook()
        self.tabs.set_scrollable(True)
        box = self.get_content_area()
        box.pack_start(self.tabs, True, True, 0)

        # Common Properties --------------------------------------------------
        common_tab = Gtk.VBox()
        self.tabs.append_page(common_tab,
                              Gtk.Label.new(_("Common Properties")))
        self.type = StringField({"label": _("Type")}, None)
        self.language = StringField({"label": _("Language")}, None)
        self.hint = StringField({"label": _("Hint")}, None)
        self.color = ColorField({"label": _("Color")}, None)
        self.color.set_parent_window(self)
        self.multiple = CheckField({"label": _("Multiple")}, None)
        self.var_name = StringField({"label": _("Var Name")}, None)

        common_tab.pack_start(self.type, False, False, 1)
        common_tab.pack_start(self.language, False, False, 1)
        common_tab.pack_start(self.hint, False, False, 1)
        common_tab.pack_start(self.color, False, False, 1)
        common_tab.pack_start(self.multiple, False, False, 1)
        common_tab.pack_start(self.var_name, False, False, 1)

        # Connection Code ----------------------------------------------------
        code_tab = Gtk.VBox()
        self.tabs.append_page(code_tab, Gtk.Label.new(_("Connection Code")))

        # Top Button bar
        top_button_bar = Gtk.HBox()
        code_tab.pack_start(top_button_bar, False, False, 1)
        self.__populate_combos(top_button_bar)

        self.code = CodeField({"label": _("Connection Code")}, None)
        code_tab.pack_start(self.code, True, True, 1)

        self.code.set_value(port.code)
        self.type.set_value(port.type)
        self.language.set_value(port.language)
        self.hint.set_value(port.hint)
        self.color.set_value(port.color)
        self.multiple.set_value(port.multiple)
        self.var_name.set_value(port.var_name)
        self.show_all()
Exemple #3
0
    def __create_side_panel(self, configuration):
        self.__clean_side_panel()

        data = {"label": _("File Name"), "name": "name"}
        field = StringField(data, None)
        self.side_panel.pack_start(field, False, False, 1)
        try:
            field.set_value(configuration["name"])
        except:
            pass

        data = {"label": _("Code"), "name": "code"}
        field = CodeField(data, None)
        self.side_panel.pack_start(field, True, True, 1)
        try:
            field.set_value(configuration["code"])
        except:
            pass

        field.field.connect("populate-popup", self.__populate_menu)

        button = Gtk.Button.new_with_label("Save")
        button.connect("clicked", self.__add_code_part)
        self.side_panel.pack_start(button, False, False, 1)
        self.side_panel.show_all()
class TestCodeField(unittest.TestCase):
    def setUp(self):
        CodeField(None, None)
        self.field = CodeField({"label": "test", "value": "False"}, None)
        self.field = CodeField({"label": "test", "value": "True"}, None)
        self.field = CodeField({}, self.test_value)

    def test_value(self):
        value1 = "False"
        self.field.set_value(value1)
        value2 = self.field.get_value()
        self.assertEqual(value1, value2, 'incorrect value')
        value1 = "True"
        self.field.set_value(value1)
        value2 = self.field.get_value()
        self.assertEqual(value1, value2, 'incorrect value')
        self.field.insert_at_cursor("Test")
    def __create_side_panel(self, configuration):
        self.__clean_side_panel()

        code_parts = []
        code_templates = System.get_code_templates()
        for key in code_templates:
            if code_templates[key].language == self.block.language:
                code_parts = code_parts + code_templates[key].code_parts

        data = {
            "label": _("Code Part Name"),
            "name": "name",
            "values": code_parts
        }
        field = ComboField(data, None)
        #        data = {"label": _("Code Part Name"), "name":"name"}
        #        field = StringField(data, None)
        self.side_panel.pack_start(field, False, False, 1)
        try:
            field.set_value(configuration["name"])
        except:
            pass

        data = {"label": _("Code"), "name": "code"}
        field = CodeField(data, None)
        self.side_panel.pack_start(field, True, True, 1)
        try:
            field.set_value(configuration["code"])
        except:
            pass

        field.field.connect("populate-popup", self.__populate_menu)

        button = Gtk.Button.new_with_label("Save")
        button.connect("clicked", self.__add_code_part)
        self.side_panel.pack_start(button, False, False, 1)
        self.side_panel.show_all()
Exemple #6
0
class PortEditor(Gtk.Dialog):
    """
    This class contains methods related the PortEditor class
    """

    # ----------------------------------------------------------------------
    def __init__(self, port_manager, port):
        Gtk.Dialog.__init__(self,
                            title=_("Port Editor"),
                            transient_for=port_manager)
        self.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
        self.add_buttons(Gtk.STOCK_SAVE, Gtk.ResponseType.OK)

        self.port_manager = port_manager
        self.set_default_size(800, 300)

        self.tabs = Gtk.Notebook()
        self.tabs.set_scrollable(True)
        box = self.get_content_area()
        box.pack_start(self.tabs, True, True, 0)

        # Common Properties --------------------------------------------------
        common_tab = Gtk.VBox()
        self.tabs.append_page(common_tab,
                              Gtk.Label.new(_("Common Properties")))
        self.type = StringField({"label": _("Type")}, None)
        self.language = StringField({"label": _("Language")}, None)
        self.hint = StringField({"label": _("Hint")}, None)
        self.color = ColorField({"label": _("Color")}, None)
        self.color.set_parent_window(self)
        self.multiple = CheckField({"label": _("Multiple")}, None)
        self.var_name = StringField({"label": _("Var Name")}, None)

        common_tab.pack_start(self.type, False, False, 1)
        common_tab.pack_start(self.language, False, False, 1)
        common_tab.pack_start(self.hint, False, False, 1)
        common_tab.pack_start(self.color, False, False, 1)
        common_tab.pack_start(self.multiple, False, False, 1)
        common_tab.pack_start(self.var_name, False, False, 1)

        # Connection Code ----------------------------------------------------
        code_tab = Gtk.VBox()
        self.tabs.append_page(code_tab, Gtk.Label.new(_("Connection Code")))

        # Top Button bar
        top_button_bar = Gtk.HBox()
        code_tab.pack_start(top_button_bar, False, False, 1)
        self.__populate_combos(top_button_bar)

        self.code = CodeField({"label": _("Connection Code")}, None)
        code_tab.pack_start(self.code, True, True, 1)

        self.code.set_value(port.code)
        self.type.set_value(port.type)
        self.language.set_value(port.language)
        self.hint.set_value(port.hint)
        self.color.set_value(port.color)
        self.multiple.set_value(port.multiple)
        self.var_name.set_value(port.var_name)
        self.show_all()

    # ----------------------------------------------------------------------
    def __populate_combos(self, top_button_bar):
        # clean the bar
        for widget in top_button_bar.get_children():
            top_button_bar.remove(widget)

        # Port Common Properties
        data = {
            "label": _("Common Properties"),
            "name": "common",
            "values": ["$input$", "$output$"]
        }

        self.commons = ComboField(data, self.__on_select)
        top_button_bar.pack_start(self.commons, False, False, 0)
        top_button_bar.show_all()

    # ----------------------------------------------------------------------
    def __on_select(self, widget=None, data=None):
        value = widget.get_parent().get_value()
        self.code.insert_at_cursor(value)

    # ----------------------------------------------------------------------
    def get_element(self):
        port = Port()
        port.type = self.type.get_value()
        port.language = self.language.get_value()
        port.hint = self.hint.get_value()
        port.color = self.color.get_value()
        port.multiple = self.multiple.get_value()
        port.code = self.code.get_value()
        port.var_name = self.var_name.get_value()
        return port
 def setUp(self):
     CodeField(None, None)
     self.field = CodeField({"label": "test", "value": "False"}, None)
     self.field = CodeField({"label": "test", "value": "True"}, None)
     self.field = CodeField({}, self.test_value)
class CodeTemplateEditor(Gtk.Dialog):
    """
    This class contains methods related the CodeTemplateEditor class
    """

    # ----------------------------------------------------------------------
    def __init__(self, code_template_manager, code_template):
        Gtk.Dialog.__init__(self,
                            title=_("Code Template Editor"),
                            transient_for=code_template_manager)

        self.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
        self.add_buttons(Gtk.STOCK_SAVE, Gtk.ResponseType.OK)

        self.set_default_size(800, 300)
        self.code_template = code_template
        self.tabs = Gtk.Notebook()
        self.tabs.set_scrollable(True)
        box = self.get_content_area()
        box.pack_start(self.tabs, True, True, 0)

        common_tab = Gtk.VBox()
        property_tab = PropertyEditor(self.code_template)
        code_tab = CodeTemplateCodeEditor(self.code_template)
        command_tab = Gtk.VBox()

        self.tabs.append_page(common_tab, Gtk.Label.new(_("Common")))
        self.tabs.append_page(property_tab, Gtk.Label.new(_("Properties")))
        self.tabs.append_page(code_tab, Gtk.Label.new(_("Codes")))
        self.tabs.append_page(command_tab, Gtk.Label.new(_("Command")))

        # First Tab: Common properties
        self.name = StringField({"label": _("Name")}, self.__edit)
        self.language = StringField({"label": _("Language")}, self.__edit)
        self.extension = StringField({"label": _("Extension")}, self.__edit)
        self.type = StringField({"label": _("Type")}, None)
        self.description = StringField({"label": _("Description")}, None)
        self.code_parts = StringField({"label": _("Code Parts")}, None)

        common_tab.pack_start(self.language, False, False, 1)
        common_tab.pack_start(self.name, False, False, 1)
        common_tab.pack_start(self.extension, False, False, 1)
        common_tab.pack_start(self.type, False, False, 1)
        common_tab.pack_start(self.description, False, False, 1)
        common_tab.pack_start(self.code_parts, False, False, 1)

        # Third Tab: Command properties
        self.command = CodeField({"label": _("")}, None)
        command_tab.pack_start(self.command, True, True, 1)

        self.name.set_value(self.code_template.name)
        self.type.set_value(self.code_template.type)
        self.description.set_value(self.code_template.description)
        self.language.set_value(self.code_template.language)
        self.command.set_value(self.code_template.command)
        #self.extension.set_value(self.code_template.extension)
        #self.code.set_value(self.code_template.code)
        code_parts_string = ', '.join(self.code_template.code_parts)
        self.code_parts.set_value(code_parts_string)

        self.show_all()

    # ----------------------------------------------------------------------
    def __edit(self, data=None):
        language = self.language.get_value()
        name = self.name.get_value()
        extension = self.extension.get_value()
        self.type.set_value("" + language + \
                "." + name + "." + extension)

    # ----------------------------------------------------------------------
    def get_element(self):
        self.code_template.name = self.name.get_value()
        self.code_template.language = self.language.get_value()
        self.code_template.type = self.type.get_value()
        self.code_template.description = self.description.get_value()
        self.code_template.command = self.command.get_value()
        self.code_template.extension = self.extension.get_value()
        self.code_template.code_parts = self.code_parts.get_value().split(",")
        # Removing trailing spaces
        self.code_template.code_parts = [
            s.strip() for s in self.code_template.code_parts
        ]
        return self.code_template

    # ----------------------------------------------------------------------
    def __on_select(self, widget=None, data=None):
        value = widget.get_parent().get_value()
        self.code.insert_at_cursor(value)