예제 #1
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 __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()
예제 #3
0
 def setUp(self):
     """Do the test basic setup."""
     data = {"label": _("Type"), "name": "type", "value": "Test"}
     self.field = StringField(data, self.callback)
     value = self.field.get_value()
     assert response == "Test"
     value = "Atenção"
     selt.field.set_value(value)
     assert value == self.field.get_value()
예제 #4
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()
예제 #5
0
class TestStringField(TestCase):
    def setUp(self):
        """Do the test basic setup."""
        data = {"label": _("Type"), "name": "type", "value": "Test"}
        self.field = StringField(data, self.callback)
        value = self.field.get_value()
        assert response == "Test"
        value = "Atenção"
        selt.field.set_value(value)
        assert value == self.field.get_value()

    # ----------------------------------------------------------------------
    def callback(self, widget=None, data=None):
        pass
예제 #6
0
    def __create_user_preferences_tab(self):
        vbox = Gtk.VBox()
        self.user_preferences_tab.pack_start(vbox, True, True, 0)

        data = {"label": _("User Name:"), "value": self.properties.author}
        self.author = StringField(data, None)
        vbox.pack_start(self.author, False, True, 0)

        data = {
            "label": _("Generate Code License:"),
            "value": self.properties.license
        }
        self.license = StringField(data, None)
        vbox.pack_start(self.license, False, True, 0)

        self.user_preferences_tab.show_all()
예제 #7
0
    def __create_default_directory_tab(self):
        vbox = Gtk.VBox()
        self.default_directory_tab.pack_start(vbox, True, True, 0)

        data = {
            "label": _("Default directory:"),
            "value": self.properties.default_directory
        }
        self.default_directory = OpenFileField(data, None)
        vbox.pack_start(self.default_directory, False, True, 0)

        # Default directory
        data = {
            "label": _("Default Filename:"),
            "value": self.properties.default_filename
        }
        self.default_filename = StringField(data, None)
        vbox.pack_start(self.default_filename, False, True, 0)

        vbox.pack_start(
            Gtk.Label(
                _("\nName Wildcards:\n" + "\t%d = Date | %n = diagram name |"
                  " %t = time value | %l = language\n")), False, True, 0)

        self.default_directory_tab.show_all()
예제 #8
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()
예제 #9
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)

        data = {"label": _("Label"), "value": block.label}
        self.label_field = StringField(data, self.__on_edit)

        data = {"label": _("Language"), "value": block.language}
        self.language_field = StringField(data, self.__on_edit)

        data = {"label": _("Framework"), "value": block.framework}
        self.framework_field = StringField(data, self.__on_edit)

        data = {"label": _("Block Type"), "value": block.type}
        self.type_field = StringField(data, self.__on_edit)

        data = {"label": _("Group"), "value": block.group}
        self.group_field = StringField(data, self.__on_edit)

        data = {"label": _("Color"), "value": block.get_color()}
        self.color_field = ColorField(data, self.__on_edit)
        self.color_field.set_parent_window(self.block_editor)

        data = {"label": _("Help"), "value": block.help}
        self.help_field = CommentField(data, self.__on_edit)

        vbox.pack_start(self.label_field, False, False, 1)
        vbox.pack_start(self.language_field, False, False, 1)
        vbox.pack_start(self.framework_field, False, False, 1)
        vbox.pack_start(self.type_field, False, False, 1)
        vbox.pack_start(self.group_field, False, False, 1)
        vbox.pack_start(self.color_field, False, False, 1)
        vbox.pack_start(self.help_field, False, False, 1)

        self.show_all()
예제 #10
0
class TestStringField(TestCase):
    def setUp(self):
        """Do the test basic setup."""
        data = {"label": ("Type"), "name": "type", "value": "text"}
        self.stringfield = StringField(data, self)

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

    # ----------------------------------------------------------------------
    def test_set_value(self):

        value = "-65590"
        self.assertIsNone(self.stringfield.set_value(value))
        value = ""
        self.assertIsNone(self.stringfield.set_value(value))
        value = "Tests"
        self.assertIsNone(self.stringfield.set_value(value))
        value = "aaaaa"
        self.assertIsNone(self.stringfield.set_value(value))
 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()
예제 #12
0
class TestStringField(unittest.TestCase):
    def setUp(self):
        StringField(None, None)
        self.field = StringField({"label": "test", "value": "False"}, None)
        self.field = StringField({"label": "test", "value": "True"}, None)
        self.field = StringField({}, 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')
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)
예제 #14
0
class BlockCommonEditor(Gtk.ScrolledWindow):
    """
    This class contains methods related the BlockCommonEditor 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)
        vbox = Gtk.VBox()
        self.add(vbox)

        data = {"label": _("Label"), "value": block.label}
        self.label_field = StringField(data, self.__on_edit)

        data = {"label": _("Language"), "value": block.language}
        self.language_field = StringField(data, self.__on_edit)

        data = {"label": _("Framework"), "value": block.framework}
        self.framework_field = StringField(data, self.__on_edit)

        data = {"label": _("Block Type"), "value": block.type}
        self.type_field = StringField(data, self.__on_edit)

        data = {"label": _("Group"), "value": block.group}
        self.group_field = StringField(data, self.__on_edit)

        data = {"label": _("Color"), "value": block.get_color()}
        self.color_field = ColorField(data, self.__on_edit)
        self.color_field.set_parent_window(self.block_editor)

        data = {"label": _("Help"), "value": block.help}
        self.help_field = CommentField(data, self.__on_edit)

        vbox.pack_start(self.label_field, False, False, 1)
        vbox.pack_start(self.language_field, False, False, 1)
        vbox.pack_start(self.framework_field, False, False, 1)
        vbox.pack_start(self.type_field, False, False, 1)
        vbox.pack_start(self.group_field, False, False, 1)
        vbox.pack_start(self.color_field, False, False, 1)
        vbox.pack_start(self.help_field, False, False, 1)

        self.show_all()

    # ----------------------------------------------------------------------
    def __on_edit(self, widget=None, data=None):
        self.type_field.set_value("mosaicode.extensions." + \
                self.language_field.get_value().lower() + "." + \
                self.framework_field.get_value().lower() + "." + \
                self.label_field.get_value().lower().replace(" ","")
                )

        self.block.type = self.type_field.get_value()
        self.block.language = self.language_field.get_value()
        self.block.framework = self.framework_field.get_value()

        self.block.label = self.label_field.get_value()
        self.block.group = self.group_field.get_value()
        self.block.color = self.color_field.get_value()
        self.block.help = self.help_field.get_value()
예제 #15
0
 def setUp(self):
     """Do the test basic setup."""
     data = {"label": ("Type"), "name": "type", "value": "text"}
     self.stringfield = StringField(data, self)
    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)
예제 #18
0
 def setUp(self):
     StringField(None, None)
     self.field = StringField({"label": "test", "value": "False"}, None)
     self.field = StringField({"label": "test", "value": "True"}, None)
     self.field = StringField({}, self.test_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()
예제 #20
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()