def test_value(self): self.field = ColorField({"value": "#fff", "format": "FFF"}, None) value2 = self.field.get_value() self.assertEqual("#fff", value2, 'incorrect value') self.field = ColorField({"value": "#fff", "format": "FFFFFF"}, None) value1 = "#f0f0f0" self.field.set_value(value1) value2 = self.field.get_value() self.assertEqual(value1, value2, 'incorrect value') self.field = ColorField({"value": "#fff", "format": "FFFFFF"}, None) value1 = 0 self.field.set_value(int(value1)) value2 = self.field.get_value() self.assertEqual("#000000", value2, 'incorrect value') self.field = ColorField({"value": "#fff", "format": ""}, None) value1 = "00:00:00:00" self.field.set_value(value1) value2 = self.field.get_value() self.assertEqual("rgb(0,0,0)", value2, 'incorrect value') self.field = ColorField({"value": "#fff", "format": ""}, None) value1 = "00:00:00" self.field.set_value(value1) value2 = self.field.get_value() self.assertEqual("rgb(0,0,0)", value2, 'incorrect value')
class TestColorField(TestCase): def setUp(self): """Do the test basic setup.""" data = {"label": ("Type"), "name": "type", "value": "255:255:255:255"} self.colorfield = ColorField(data, self) # ---------------------------------------------------------------------- def test_set_parent_window(self): self.assertIsNone(self.colorfield.set_parent_window(None)) # ---------------------------------------------------------------------- def test_on_choose_color(self): self.assertIsNone(self.colorfield.on_choose_color(None)) # ---------------------------------------------------------------------- def test_get_value(self): self.assertTrue(self.colorfield.get_value()) # ---------------------------------------------------------------------- def test_set_value(self): value = "#FFFFFF" self.assertIsNone(self.colorfield.set_value(value)) value = "255" self.assertIsNone(self.colorfield.set_value(value)) value = "234:233" self.assertIsNone(self.colorfield.set_value(value)) value = "12:233:12" self.assertIsNone(self.colorfield.set_value(value)) value = 22 self.assertIsNone(self.colorfield.set_value(value)) value = "" self.assertIsNone(self.colorfield.set_value(value))
def test_click(self): data = {"value": "#fff", "format": "FFFFFF"} self.field = ColorField(data, self.event) self.field.set_parent_window(Gtk.Window.new(Gtk.WindowType.TOPLEVEL)) # 0 is the label, 1 is the box vbox = self.field.get_children()[1] # 0 is the frame, 1 is the button button = vbox.get_children()[1] self.t1 = threading.Thread(target=button.clicked) self.t1.start() sleep(0.5) self.close_window()
def setUp(self): """Do the test basic setup.""" data = {"label": _("Type"), "name":"type", "value": "255:255:255:255"} self.field = ColorField(data, self.callback) value = self.field.get_value() assert response == "#FFFFFF" value = "#FF0000" selt.field.set_value(value) assert value == self.field.get_value() value = "#FF0000FF" selt.field.set_value(value) assert "#FF0000" == self.field.get_value()
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 setUp(self): ColorField(None, None) self.field = ColorField({"label": "test", "value": "#fff"}, None) self.field = ColorField({"label": "test", "value": "#fff000"}, None) self.field = ColorField({}, self.event) self.field.set_parent_window(Gtk.Window.new(Gtk.WindowType.TOPLEVEL))
class TestColorField(unittest.TestCase): def setUp(self): ColorField(None, None) self.field = ColorField({"label": "test", "value": "#fff"}, None) self.field = ColorField({"label": "test", "value": "#fff000"}, None) self.field = ColorField({}, self.event) self.field.set_parent_window(Gtk.Window.new(Gtk.WindowType.TOPLEVEL)) def close_window(self): self.field.dialog.response(Gtk.ResponseType.OK) self.t1.join() def event(widget, event): pass def test_click(self): data = {"value": "#fff", "format": "FFFFFF"} self.field = ColorField(data, self.event) self.field.set_parent_window(Gtk.Window.new(Gtk.WindowType.TOPLEVEL)) # 0 is the label, 1 is the box vbox = self.field.get_children()[1] # 0 is the frame, 1 is the button button = vbox.get_children()[1] self.t1 = threading.Thread(target=button.clicked) self.t1.start() sleep(0.5) self.close_window() def test_value(self): self.field = ColorField({"value": "#fff", "format": "FFF"}, None) value2 = self.field.get_value() self.assertEqual("#fff", value2, 'incorrect value') self.field = ColorField({"value": "#fff", "format": "FFFFFF"}, None) value1 = "#f0f0f0" self.field.set_value(value1) value2 = self.field.get_value() self.assertEqual(value1, value2, 'incorrect value') self.field = ColorField({"value": "#fff", "format": "FFFFFF"}, None) value1 = 0 self.field.set_value(int(value1)) value2 = self.field.get_value() self.assertEqual("#000000", value2, 'incorrect value') self.field = ColorField({"value": "#fff", "format": ""}, None) value1 = "00:00:00:00" self.field.set_value(value1) value2 = self.field.get_value() self.assertEqual("rgb(0,0,0)", value2, 'incorrect value') self.field = ColorField({"value": "#fff", "format": ""}, None) value1 = "00:00:00" self.field.set_value(value1) value2 = self.field.get_value() self.assertEqual("rgb(0,0,0)", value2, 'incorrect value')
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()
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)
def setUp(self): """Do the test basic setup.""" data = {"label": ("Type"), "name": "type", "value": "255:255:255:255"} self.colorfield = ColorField(data, self)
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()