Ejemplo n.º 1
0
    def __init__(self, code_template_manager, code_template_name):
        self.code_template_manager = code_template_manager
        Gtk.Dialog.__init__(self, _("Code Template Editor"),
                            self.code_template_manager, 0,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                             Gtk.STOCK_SAVE, Gtk.ResponseType.OK))

        self.main_control = self
        self.set_default_size(600, 300)

        vbox = Gtk.VBox()
        box = self.get_content_area()
        box.pack_start(vbox, True, True, 0)

        self.name = StringField({"label": _("Name")}, None)
        self.type = StringField({"label": _("Type")}, None)
        self.description = StringField({"label": _("Description")}, None)
        self.language = StringField({"label": _("Language")}, None)
        self.command = CodeField({"label": _("")}, None)
        self.extension = StringField({"label": _("Extension")}, None)
        self.code = CodeField({"label": _("")}, None)

        if code_template_name is not None:
            System()
            self.name.set_value(System.code_templates[code_template_name].name)
            self.type.set_value(System.code_templates[code_template_name].type)
            self.description.set_value(
                System.code_templates[code_template_name].description)
            self.language.set_value(
                System.code_templates[code_template_name].language)
            self.command.set_value(
                System.code_templates[code_template_name].command)
            self.extension.set_value(
                System.code_templates[code_template_name].extension)
            self.code.set_value(System.code_templates[code_template_name].code)

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

        self.codes = Gtk.Notebook()
        self.codes.set_scrollable(True)
        vbox.pack_start(self.codes, True, True, 1)

        self.codes.append_page(self.code, Gtk.Label(_("Code")))
        self.codes.append_page(self.command, Gtk.Label(_("Command")))

        self.show_all()
        result = self.run()
        if result == Gtk.ResponseType.OK:
            self.__save()
        self.close()
        self.destroy()
Ejemplo n.º 2
0
class TestCodeField(TestCase):
    def setUp(self):
        """Do the test basic setup."""
        data = {"label": ("Type"), "name": "type", "value": "True"}
        self.codefield = CodeField(data, self)

    # ----------------------------------------------------------------------
    def test_get_value(self):
        self.assertTrue(self.codefield.get_value())

    # ----------------------------------------------------------------------
    def test_set_value(self):
        value = "Teste"
        self.assertIsNone(self.codefield.set_value(value))
        value = "True"
        self.assertIsNone(self.codefield.set_value(value))
        value = ""
        self.assertIsNone(self.codefield.set_value(value))
        value = "Algo"
        self.assertIsNone(self.codefield.set_value(value))

    # ----------------------------------------------------------------------
    def test_insert_at_cursor(self):
        value = "Teste"
        self.assertIsNone(self.codefield.set_value(value))
        value = "True"
        self.assertIsNone(self.codefield.set_value(value))
        value = ""
        self.assertIsNone(self.codefield.set_value(value))
        value = "Algo"
        self.assertIsNone(self.codefield.set_value(value))
Ejemplo n.º 3
0
    def __create_side_panel(self, configuration):
        self.__clean_side_panel()

        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()
Ejemplo n.º 4
0
    def __init__(self, block_editor, block):
        Gtk.ScrolledWindow.__init__(self)

        self.block_editor = block_editor
        self.block = block

        for widget in self.get_children():
            self.remove(widget)
        vbox = Gtk.VBox()
        self.add(vbox)

        # Button bar
        button_bar = Gtk.HBox()
        vbox.pack_start(button_bar, False, False, 1)
        self.__populate_combos(button_bar)

        self.code_notebook = Gtk.Notebook()
        self.code_notebook.set_scrollable(True)
        vbox.pack_start(self.code_notebook, True, True, 1)

        self.code_widgets = []
        count = 0
        for code_value in self.block.codes:
            data = {"label": _("Code " + str(count)), "value": code_value}
            self.code_widgets.append(CodeField(data, self.__on_edit))
            self.code_notebook.append_page(self.code_widgets[count],
                                           Gtk.Label(_("Code " + str(count))))
            count = count + 1

        self.show_all()
Ejemplo n.º 5
0
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 __init__(self, code_template_manager, code_template_name):
        Gtk.Dialog.__init__(self, _("Code Template Editor"),
                            code_template_manager,
                            0, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                Gtk.STOCK_SAVE, Gtk.ResponseType.OK))

        self.code_template_manager = code_template_manager
        system_code_template = System.get_code_templates()
        if code_template_name is not None:
            self.code_template = system_code_template[code_template_name]
        else:
            self.code_template = CodeTemplate()

        self.main_control = self
        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_tab = Gtk.VBox()
        code_tab = Gtk.VBox()
        command_tab = Gtk.VBox()

        self.tabs.append_page(common_tab, Gtk.Label(_("Common")))
        self.tabs.append_page(code_tab, Gtk.Label(_("Code")))
        self.tabs.append_page(command_tab, Gtk.Label(_("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, 0)
        common_tab.pack_start(self.name, False, False, 0)
        common_tab.pack_start(self.extension, False, False, 0)
        common_tab.pack_start(self.type, False, False, 0)
        common_tab.pack_start(self.description, False, False, 0)
        common_tab.pack_start(self.code_parts, False, False, 0)

        # Second Tab: Code properties

        # Button bar
        button_bar = Gtk.HBox()
        code_tab.pack_start(button_bar, False, False, 0)
        self.__populate_combos(button_bar)

        self.code = CodeField({"label": _("")}, None)
        code_tab.pack_end(self.code, True, True, 0)

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

        if code_template_name is not None:
            System()
            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()
        result = self.run()
        if result == Gtk.ResponseType.OK:
            self.__save()
        self.close()
        self.destroy()
class CodeTemplateEditor(Gtk.Dialog):
    """
    This class contains methods related the CodeTemplateEditor class
    """

    # ----------------------------------------------------------------------
    def __init__(self, code_template_manager, code_template_name):
        Gtk.Dialog.__init__(self, _("Code Template Editor"),
                            code_template_manager,
                            0, (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                                Gtk.STOCK_SAVE, Gtk.ResponseType.OK))

        self.code_template_manager = code_template_manager
        system_code_template = System.get_code_templates()
        if code_template_name is not None:
            self.code_template = system_code_template[code_template_name]
        else:
            self.code_template = CodeTemplate()

        self.main_control = self
        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_tab = Gtk.VBox()
        code_tab = Gtk.VBox()
        command_tab = Gtk.VBox()

        self.tabs.append_page(common_tab, Gtk.Label(_("Common")))
        self.tabs.append_page(code_tab, Gtk.Label(_("Code")))
        self.tabs.append_page(command_tab, Gtk.Label(_("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, 0)
        common_tab.pack_start(self.name, False, False, 0)
        common_tab.pack_start(self.extension, False, False, 0)
        common_tab.pack_start(self.type, False, False, 0)
        common_tab.pack_start(self.description, False, False, 0)
        common_tab.pack_start(self.code_parts, False, False, 0)

        # Second Tab: Code properties

        # Button bar
        button_bar = Gtk.HBox()
        code_tab.pack_start(button_bar, False, False, 0)
        self.__populate_combos(button_bar)

        self.code = CodeField({"label": _("")}, None)
        code_tab.pack_end(self.code, True, True, 0)

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

        if code_template_name is not None:
            System()
            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()
        result = self.run()
        if result == Gtk.ResponseType.OK:
            self.__save()
        self.close()
        self.destroy()

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

    # ----------------------------------------------------------------------
    def __save(self):
        code_template = CodeTemplate()
        code_template.name = self.name.get_value()
        code_template.language = self.language.get_value()
        code_template.type = self.type.get_value()
        code_template.description = self.description.get_value()
        code_template.command = self.command.get_value()
        code_template.extension = self.extension.get_value()
        code_template.code = self.code.get_value()
        code_template.code_parts = self.code_parts.get_value().split(",")
        self.code_template_manager.add_code_template(code_template)

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

        # Code Parts
        values = []
        for code_part in self.code_template.code_parts:
            values.append("$single_code[" + code_part + "]$")
            values.append("$code[" + code_part + "]$")
            values.append("$code[" + code_part + ",connection]$")
        values.append("$connections$")
        values.sort()
        data = {"label": _("Code Parts"),
                "name":"code_parts",
                "values": values}
        self.select_code_parts = ComboField(data, self.__on_select)
        button_bar.pack_start(self.select_code_parts, False, False, 0)

        # Refresh Button
        button = Gtk.Button.new_with_label("Refresh")
        button.connect("clicked", self.__refresh, button_bar)
        button_bar.pack_start(button, False, False, 0)

        button_bar.show_all()

    # ----------------------------------------------------------------------
    def __refresh(self, widget, button_bar):
        """
        This method monitors if the button was clicked.

            Parameters:

        """
        self.__populate_combos(button_bar)

    # ----------------------------------------------------------------------
    def __on_select(self, widget=None, data=None):
        value = widget.get_parent().get_value()
        self.code.insert_at_cursor(value)
    def __init__(self, port_manager, port):
        self.port_manager = port_manager
        self.port = System.get_ports()[port]
        Gtk.Dialog.__init__(self, _("Port Editor"), self.port_manager, 0,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                             Gtk.STOCK_SAVE, Gtk.ResponseType.OK))

        self.main_control = self
        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(_("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)

        if port is not None:
            System()
            self.type.set_value(port)
            self.language.set_value(self.port.language)
            self.hint.set_value(self.port.hint)
            self.color.set_value(self.port.color)
            self.multiple.set_value(self.port.multiple)
            self.var_name.set_value(self.port.var_name)

        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(_("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)
        if port is not None:
            System()
            self.code.set_value(self.port.code)

        self.show_all()
        result = self.run()
        if result == Gtk.ResponseType.OK:
            self.__save()
        self.close()
        self.destroy()
class PortEditor(Gtk.Dialog):
    """
    This class contains methods related the PortEditor class
    """

    # ----------------------------------------------------------------------
    def __init__(self, port_manager, port):
        self.port_manager = port_manager
        self.port = System.get_ports()[port]
        Gtk.Dialog.__init__(self, _("Port Editor"), self.port_manager, 0,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                             Gtk.STOCK_SAVE, Gtk.ResponseType.OK))

        self.main_control = self
        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(_("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)

        if port is not None:
            System()
            self.type.set_value(port)
            self.language.set_value(self.port.language)
            self.hint.set_value(self.port.hint)
            self.color.set_value(self.port.color)
            self.multiple.set_value(self.port.multiple)
            self.var_name.set_value(self.port.var_name)

        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(_("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)
        if port is not None:
            System()
            self.code.set_value(self.port.code)

        self.show_all()
        result = self.run()
        if result == Gtk.ResponseType.OK:
            self.__save()
        self.close()
        self.destroy()

    # ----------------------------------------------------------------------
    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 __save(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()
        self.port_manager.add_port(port)
Ejemplo n.º 10
0
 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)
Ejemplo n.º 11
0
    def __init__(self, port_manager, port):
        self.port_manager = port_manager
        Gtk.Dialog.__init__(self, _("Port Editor"), self.port_manager, 0,
                            (Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL,
                             Gtk.STOCK_SAVE, Gtk.ResponseType.OK))

        self.main_control = self
        self.set_default_size(600, 300)

        vbox = Gtk.VBox()
        box = self.get_content_area()
        box.pack_start(vbox, True, True, 0)

        self.type = StringField({"label": _("Type")}, None)
        self.language = StringField({"label": _("Language")}, None)
        self.label = StringField({"label": _("Label")}, None)
        self.color = ColorField({"label": _("Color")}, None)
        self.color.set_parent_window(self)
        self.code = CodeField({"label": _("Code")}, None)
        self.multiple = CheckField({"label": _("Multiple")}, None)

        self.input_code_widgets = []
        self.output_code_widgets = []
        for code in BlockModel().codes:
            self.input_code_widgets.append(CodeField({"label": ""}, None))
            self.output_code_widgets.append(CodeField({"label": ""}, None))

        if port is not None:
            System()
            self.type.set_value(port)
            self.language.set_value(System.ports[port].language)
            self.label.set_value(System.ports[port].label)
            self.color.set_value(System.ports[port].color)
            self.code.set_value(System.ports[port].code)
            self.multiple.set_value(System.ports[port].multiple)

            count = 0
            for code in BlockModel().codes:
                self.input_code_widgets[count].set_value(
                    System.ports[port].input_codes[count])
                self.output_code_widgets[count].set_value(
                    System.ports[port].output_codes[count])
                count = count + 1

        vbox.pack_start(self.type, False, False, 1)
        vbox.pack_start(self.language, False, False, 1)
        vbox.pack_start(self.label, False, False, 1)
        vbox.pack_start(self.color, False, False, 1)
        vbox.pack_start(self.multiple, False, False, 1)

        self.code_notebook = Gtk.Notebook()
        self.code_notebook.set_scrollable(True)
        vbox.pack_start(self.code_notebook, True, True, 1)
        self.code_notebook.append_page(self.code,
                                       Gtk.Label(_("Connection Code")))

        count = 0
        for code_widget in self.input_code_widgets:
            self.code_notebook.append_page(code_widget, Gtk.Label(_("Input Code " + \
                    str(count))))
            count = count + 1

        count = 0
        for code_widget in self.output_code_widgets:
            self.code_notebook.append_page(code_widget, Gtk.Label(_("Output Code " + \
                    str(count))))
            count = count + 1

        self.show_all()
        result = self.run()
        if result == Gtk.ResponseType.OK:
            self.__save()
        self.close()
        self.destroy()
Ejemplo n.º 12
0
 def setUp(self):
     """Do the test basic setup."""
     data = {"label": ("Type"), "name": "type", "value": "True"}
     self.codefield = CodeField(data, self)