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')
def __init__(self, port_manager, port): Gtk.Dialog.__init__(self, title=_("Port Editor"), transient_for=port_manager) self.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL) self.add_buttons(Gtk.STOCK_SAVE, Gtk.ResponseType.OK) self.port_manager = port_manager self.set_default_size(800, 300) self.tabs = Gtk.Notebook() self.tabs.set_scrollable(True) box = self.get_content_area() box.pack_start(self.tabs, True, True, 0) # Common Properties -------------------------------------------------- common_tab = Gtk.VBox() self.tabs.append_page(common_tab, Gtk.Label.new(_("Common Properties"))) self.type = StringField({"label": _("Type")}, None) self.language = StringField({"label": _("Language")}, None) self.hint = StringField({"label": _("Hint")}, None) self.color = ColorField({"label": _("Color")}, None) self.color.set_parent_window(self) self.multiple = CheckField({"label": _("Multiple")}, None) self.var_name = StringField({"label": _("Var Name")}, None) common_tab.pack_start(self.type, False, False, 1) common_tab.pack_start(self.language, False, False, 1) common_tab.pack_start(self.hint, False, False, 1) common_tab.pack_start(self.color, False, False, 1) common_tab.pack_start(self.multiple, False, False, 1) common_tab.pack_start(self.var_name, False, False, 1) # Connection Code ---------------------------------------------------- code_tab = Gtk.VBox() self.tabs.append_page(code_tab, Gtk.Label.new(_("Connection Code"))) # Top Button bar top_button_bar = Gtk.HBox() code_tab.pack_start(top_button_bar, False, False, 1) self.__populate_combos(top_button_bar) self.code = CodeField({"label": _("Connection Code")}, None) code_tab.pack_start(self.code, True, True, 1) self.code.set_value(port.code) self.type.set_value(port.type) self.language.set_value(port.language) self.hint.set_value(port.hint) self.color.set_value(port.color) self.multiple.set_value(port.multiple) self.var_name.set_value(port.var_name) self.show_all()
def 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 __init__(self, block): Gtk.ScrolledWindow.__init__(self) 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": _("extension"), "value": block.extension} self.extension_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.get_parent_window()) 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.extension_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()
class PortEditor(Gtk.Dialog): """ This class contains methods related the PortEditor class """ # ---------------------------------------------------------------------- def __init__(self, port_manager, port): Gtk.Dialog.__init__(self, title=_("Port Editor"), transient_for=port_manager) self.add_buttons(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL) self.add_buttons(Gtk.STOCK_SAVE, Gtk.ResponseType.OK) self.port_manager = port_manager self.set_default_size(800, 300) self.tabs = Gtk.Notebook() self.tabs.set_scrollable(True) box = self.get_content_area() box.pack_start(self.tabs, True, True, 0) # Common Properties -------------------------------------------------- common_tab = Gtk.VBox() self.tabs.append_page(common_tab, Gtk.Label.new(_("Common Properties"))) self.type = StringField({"label": _("Type")}, None) self.language = StringField({"label": _("Language")}, None) self.hint = StringField({"label": _("Hint")}, None) self.color = ColorField({"label": _("Color")}, None) self.color.set_parent_window(self) self.multiple = CheckField({"label": _("Multiple")}, None) self.var_name = StringField({"label": _("Var Name")}, None) common_tab.pack_start(self.type, False, False, 1) common_tab.pack_start(self.language, False, False, 1) common_tab.pack_start(self.hint, False, False, 1) common_tab.pack_start(self.color, False, False, 1) common_tab.pack_start(self.multiple, False, False, 1) common_tab.pack_start(self.var_name, False, False, 1) # Connection Code ---------------------------------------------------- code_tab = Gtk.VBox() self.tabs.append_page(code_tab, Gtk.Label.new(_("Connection Code"))) # Top Button bar top_button_bar = Gtk.HBox() code_tab.pack_start(top_button_bar, False, False, 1) self.__populate_combos(top_button_bar) self.code = CodeField({"label": _("Connection Code")}, None) code_tab.pack_start(self.code, True, True, 1) self.code.set_value(port.code) self.type.set_value(port.type) self.language.set_value(port.language) self.hint.set_value(port.hint) self.color.set_value(port.color) self.multiple.set_value(port.multiple) self.var_name.set_value(port.var_name) self.show_all() # ---------------------------------------------------------------------- def __populate_combos(self, top_button_bar): # clean the bar for widget in top_button_bar.get_children(): top_button_bar.remove(widget) # Port Common Properties data = { "label": _("Common Properties"), "name": "common", "values": ["$input$", "$output$"] } self.commons = ComboField(data, self.__on_select) top_button_bar.pack_start(self.commons, False, False, 0) top_button_bar.show_all() # ---------------------------------------------------------------------- def __on_select(self, widget=None, data=None): value = widget.get_parent().get_value() self.code.insert_at_cursor(value) # ---------------------------------------------------------------------- def get_element(self): port = Port() port.type = self.type.get_value() port.language = self.language.get_value() port.hint = self.hint.get_value() port.color = self.color.get_value() port.multiple = self.multiple.get_value() port.code = self.code.get_value() port.var_name = self.var_name.get_value() return port
def setUp(self): 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): Gtk.ScrolledWindow.__init__(self) 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": _("extension"), "value": block.extension} self.extension_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.get_parent_window()) 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.extension_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("" + \ self.language_field.get_value().lower() + "." + \ self.extension_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.extension = self.extension_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()