Exemplo n.º 1
0
 def test_value(self):
     data = {"label": "Test", "value": "a", "name": "", "values": ["a"]}
     self.field = ComboField(data, None)
     value1 = "a"
     self.field.set_value(value1)
     value2 = self.field.get_value()
     self.assertEqual(value1, value2, 'incorrect value')
Exemplo n.º 2
0
    def __create_side_panel(self, configuration):
        self.__clean_side_panel()

        connectors = []
        for key in System.ports:
            if System.ports[key].language == self.block.language:
                connectors.append(key)

        data = {"label": _("Type"), "name":"type", "values": connectors}
        field = ComboField(data, None)
        self.side_panel.pack_start(field, False, False, 1)
        if configuration is not None: field.set_value(configuration["type"])

        data = {"label": _("Label"), "name":"label"}
        field = StringField(data, None)
        self.side_panel.pack_start(field, False, False, 1)
        if configuration is not None: field.set_value(configuration["label"])

        data = {"label": _("Name"), "name":"name"}
        field = StringField(data, None)
        self.side_panel.pack_start(field, False, False, 1)
        if configuration is not None: field.set_value(configuration["name"])

        button = Gtk.Button.new_with_label("Save")
        button.connect("clicked", self.__on_save, None)
        self.side_panel.pack_start(button, False, False, 1)
        self.side_panel.show_all()
 def __new(self, widget=None, data=None):
     for widget in self.side_panel.get_children():
         self.side_panel.remove(widget)
     fieldtypes = []
     for key in component_list:
         fieldtypes.append(key)
     data = {"label": _("Field Type"), "values": fieldtypes}
     self.field_type = ComboField(data, self.__select_property_field_type)
     self.side_panel.pack_start(self.field_type, False, False, 1)
Exemplo n.º 4
0
 def setUp(self):
     """Do the test basic setup."""
     data = {
         "label": ("Type"),
         "name": "type",
         "value": "Banana",
         "values": ["Banana", "Apple", "Orange"]
     }
     self.combofield = ComboField(data, self)
Exemplo n.º 5
0
 def setUp(self):
     """Do the test basic setup."""
     data = {
         "label": _("Type"),
         "name": "type",
         "value": "Banana",
         "values": ["Banana", "Apple", "Orange"]
     }
     self.field = ComboField(data, self.callback)
     value = self.field.get_value()
     assert response == "Banana"
     value = "Orange"
     selt.field.set_value(value)
     assert value == self.field.get_value()
Exemplo n.º 6
0
class TestComboField(unittest.TestCase):
    def setUp(self):
        ComboField(None, None)
        data = {"label": "Test", "value": "a", "name": "", "values": ["a"]}
        self.field = ComboField(data, None)
        self.field = ComboField({"label": "test", "value": True}, None)
        self.field = ComboField({}, self.test_value)

    def test_value(self):
        data = {"label": "Test", "value": "a", "name": "", "values": ["a"]}
        self.field = ComboField(data, None)
        value1 = "a"
        self.field.set_value(value1)
        value2 = self.field.get_value()
        self.assertEqual(value1, value2, 'incorrect value')
    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()
Exemplo n.º 8
0
    def __populate_combos(self, button_bar):
        # clean the bar
        for widget in button_bar.get_children():
            button_bar.remove(widget)

        # Block Common Properties
        data = {
            "label":
            _("Common Properties"),
            "name":
            "common",
            "values": [
                "id", "label", "x", "y", "type", "language", "framework",
                "group", "color", "help"
            ]
        }
        self.commons = ComboField(data, self.__on_select)
        button_bar.pack_start(self.commons, False, False, 0)

        # Block Properties
        values = []
        for prop in self.block.get_properties():
            values.append("prop[" + prop["name"] + "]")
        values.sort()
        data = {
            "label": _("Block Properties"),
            "name": "props",
            "values": values
        }
        self.props = ComboField(data, self.__on_select)
        button_bar.pack_start(self.props, 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)

        # Generate Default Code Button
        button = Gtk.Button.new_with_label("Generate Default Code")
        button.connect("clicked", self.__generate_default, None)
        button_bar.pack_start(button, False, False, 0)

        button_bar.show_all()
Exemplo n.º 9
0
    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()
Exemplo n.º 10
0
class TestComboField(TestCase):
    def setUp(self):
        """Do the test basic setup."""
        data = {
            "label": ("Type"),
            "name": "type",
            "value": "Banana",
            "values": ["Banana", "Apple", "Orange"]
        }
        self.combofield = ComboField(data, self)

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

    # ----------------------------------------------------------------------
    def test_set_value(self):
        value = "Teste"
        self.assertIsNone(self.combofield.set_value(value))
        value = "Algo"
        self.assertIsNone(self.combofield.set_value(value))
        value = "Banana"
        self.assertIsNone(self.combofield.set_value(value))
Exemplo n.º 11
0
    def __init__(self, main_window, template_list):
        """
        This method is the constructor.
        """
        Gtk.Dialog.__init__(self, _("Select Code Template"), main_window, 0,
                            (Gtk.STOCK_OK, Gtk.ResponseType.OK))

        self.template_list = template_list

        templates = []
        for code_template in template_list:
            templates.append(code_template.description)

        data = {
            "label": _("Code Template"),
            "name": "template",
            "values": templates
        }
        self.field = ComboField(data, None)
        self.field.field.set_active(0)
        self.get_content_area().add(self.field)
class BlockPropertyEditor(Gtk.ScrolledWindow):
    """
    This class contains methods related the BlockPropertyEditor class
    """

    # ----------------------------------------------------------------------
    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)

        hbox = Gtk.HBox()
        vbox2 = Gtk.VBox()
        self.add(hbox)

        self.tree_view = TreeView(_("Properties"), self.__on_props_row_activated)
        self.__populate_property()
        vbox2.pack_start(self.tree_view, True, True, 1)

        # Button bar
        button_bar = ButtonBar()
        button_bar.add_button({"icone":Gtk.STOCK_NEW, "action": self.__new, "data":None})
        button_bar.add_button({"icone":Gtk.STOCK_DELETE, "action": self.__delete, "data":None})
        button_bar.add_button({"icone":Gtk.STOCK_GO_UP, "action": self.__up, "data":None})
        button_bar.add_button({"icone":Gtk.STOCK_GO_DOWN, "action": self.__down, "data":None})
        vbox2.pack_start(button_bar, False, False, 1)

        hbox.pack_start(vbox2, True, True, 2)
        vbox = Gtk.VBox()
        hbox.pack_start(vbox, True, True, 2)
        self.side_panel = Gtk.VBox()
        vbox.pack_start(self.side_panel, True, True, 1)

        self.set_shadow_type(Gtk.ShadowType.IN)
        self.show_all()

    # ----------------------------------------------------------------------
    def __populate_property(self):
        block_label = []
        for prop in self.block.get_properties():
            block_label.append(prop.get("label"))
        self.tree_view.populate(block_label)

    # ----------------------------------------------------------------------
    def __new(self, widget=None, data=None):
        for widget in self.side_panel.get_children():
            self.side_panel.remove(widget)
        fieldtypes = []
        for key in component_list:
            fieldtypes.append(key)
        data = {"label": _("Field Type"), "values": fieldtypes}
        self.field_type = ComboField(data, self.__select_property_field_type)
        self.side_panel.pack_start(self.field_type, False, False, 1)

    # ----------------------------------------------------------------------
    def __delete(self, widget=None, data=None):
        treeselection = self.tree_view.get_selection()
        model, iterac = treeselection.get_selected()
        if iterac is None:
            return None
        dialog = Dialog().confirm_dialog(_("Are you sure?"),
                self.block_editor)
        result = dialog.run()
        dialog.destroy()
        if result != Gtk.ResponseType.OK:
            return
        path = model.get_path(iterac)
        del self.block.get_properties()[int(str(path))]
        self.__populate_property()
        self.__clean_side_panel()

    # ----------------------------------------------------------------------
    def __up(self, widget=None, data=None):
        treeselection = self.tree_view.get_selection()
        model, iterac = treeselection.get_selected()
        if iterac is None:
            return None
        path = model.get_path(iterac)
        if int(str(path)) == 0:
            return
        self.block.get_properties()[int(str(path))], \
            self.block.get_properties()[int(str(path)) - 1] = \
            self.block.get_properties()[int(str(path)) - 1], \
            self.block.get_properties()[int(str(path))]
        self.__populate_property()

    # ----------------------------------------------------------------------
    def __down(self, widget=None, data=None):
        treeselection = self.tree_view.get_selection()
        model, iterac = treeselection.get_selected()
        if iterac is None:
            return None
        path = model.get_path(iterac)
        if int(str(path)) == len(self.block.get_properties()) - 1:
            return
        self.block.get_properties()[int(str(path))], \
            self.block.get_properties()[int(str(path)) + 1] = \
            self.block.get_properties()[int(str(path)) + 1], \
            self.block.get_properties()[int(str(path))]
        self.__populate_property()

    # ----------------------------------------------------------------------
    def __clean_side_panel(self):
        for widget in self.side_panel.get_children():
            self.side_panel.remove(widget)

    # ----------------------------------------------------------------------
    def __create_side_panel(self, configuration):
        self.__clean_side_panel()
        for key in configuration:
            data = {"label": _(key),
                    "name":key,
                    "value":str(configuration[key])}
            field = StringField(data, None)
            if key == "type":
                field.field.set_property("editable", False)
            self.side_panel.pack_start(field, False, False, 1)
        button = Gtk.Button.new_with_label("Save")
        button.connect("clicked", self.__on_props_edit_ok, None)
        self.side_panel.pack_start(button, False, False, 1)
        self.side_panel.show_all()

    # ----------------------------------------------------------------------
    def __select_property_field_type(self, widget=None, data=None):
        field_type = self.field_type.get_value()
        configuration = component_list[field_type].get_configuration()
        configuration["type"] = field_type
        self.__create_side_panel(configuration)

    # ----------------------------------------------------------------------
    def __on_props_row_activated(self, tree_view, path, column, data=None):
        configuration = self.block.get_properties()[int(str(path))]
        self.__create_side_panel(configuration)

    # ----------------------------------------------------------------------
    def __on_props_edit_ok(self, widget=None, data=None):
        configuration = {}
        for widget in self.side_panel.get_children():
            try:
                configuration[widget.get_name()] = widget.get_value()
            except:
                pass
        if "label" not in configuration or "name" not in configuration or \
                "value" not in configuration:
            return
        if configuration["label"] == "":
            message = "Label can not be empty"
            Dialog().message_dialog("Error", message, self.block_editor)
            return
        if configuration["name"] == "":
            message = "Name can not be empty"
            Dialog().message_dialog("Error", message, self.block_editor)
            return
        contains = False
        i = 0
        for props in self.block.properties:
            if props["label"] == configuration["label"]:
                self.block.properties[i] = configuration
                contains = True
            i += 1
        if not contains:
            self.block.properties.append(configuration)
        self.__populate_property()
        self.__clean_side_panel()
Exemplo n.º 13
0
    def __create_side_panel(self, configuration):
        self.__clean_side_panel()

        connectors = []
        ports = System.get_ports()
        for key in ports:
            if ports[key].language == self.block.language:
                connectors.append(key)

        data = {"label": _("Port Type"), "name": "type", "values": connectors}
        field = ComboField(data, None)
        self.side_panel.pack_start(field, False, False, 1)
        if configuration is not None: field.set_value(configuration.type)

        data = {
            "label": _("Connection Type"),
            "name": "conn_type",
            "values": [Port.INPUT, Port.OUTPUT]
        }
        field = ComboField(data, None)
        self.side_panel.pack_start(field, False, False, 1)
        if configuration is not None: field.set_value(configuration.conn_type)

        data = {"label": _("Label"), "name": "label"}
        field = StringField(data, None)
        self.side_panel.pack_start(field, False, False, 1)
        if configuration is not None: field.set_value(configuration.label)

        data = {"label": _("Name"), "name": "name"}
        field = StringField(data, None)
        self.side_panel.pack_start(field, False, False, 1)
        if configuration is not None: field.set_value(configuration.name)

        button = Gtk.Button.new_with_label("Save")
        button.connect("clicked", self.__on_save, None)
        self.side_panel.pack_start(button, False, False, 1)
        self.side_panel.show_all()
Exemplo n.º 14
0
 def setUp(self):
     ComboField(None, None)
     data = {"label": "Test", "value": "a", "name": "", "values": ["a"]}
     self.field = ComboField(data, None)
     self.field = ComboField({"label": "test", "value": True}, None)
     self.field = ComboField({}, self.test_value)