def __init__(self, shape=PySI.PointVector(), uuid="", kwargs={}): super(Cursor, self).__init__(shape, uuid, "", Cursor.regiontype, Cursor.regionname, kwargs) self.qml_path = self.set_QML_path("Cursor.qml") self.color = PySI.Color(255, 0, 0, 0) self.assigned_effect = "" self.is_drawing_blocked = False self.width = Cursor.region_width self.height = Cursor.region_height self.with_border = False self.clicks = 0 self.set_QML_data("width", self.width, PySI.DataType.INT) self.set_QML_data("height", self.height, PySI.DataType.INT) self.parent_canvas = None self.move_target = None self.btn_target = None self.image_editor_tool = [] self.image_editor_tooltype = None self.left_mouse_active = False self.right_mouse_active = False
def test_scope_datastructure_StringVector(self): sv = PySI.StringVector() self.assertNotEqual(sv, None) self.assertEqual(len(sv), 0) sv = PySI.StringVector(["hello", "world", "test", "test2"]) self.assertEqual(len(sv), 4) # get # StringVector is currently Write-Only # get slice # same functionality for all exposed vectors # therefore, tested in PointVector # set sv[0] = "HELLO" # del # same functionality for all exposed vectors # therefore, tested in PointVector # add sv.append("TEST3") self.assertEqual(len(sv), 5)
def __init__(self, shape=PySI.PointVector(), uuid="", kwargs={}): super(Dummy2, self).__init__(shape, uuid, "", Dummy2.regiontype, Dummy2.regionname, kwargs) self.shape = shape self.aabb self._uuid = uuid self.source = "testSI" self.x = 0 self.y = 0 self.cap_emit = PySI.String2String2FunctionMapMap({ "TEST2": {PySI.CollisionEvent.ON_ENTER: self.test_on_enter_emit, PySI.CollisionEvent.ON_CONTINUOUS: self.test_on_continuous_emit, PySI.CollisionEvent.ON_LEAVE: self.test_on_leave_emit} }) self.cap_recv = PySI.String2String2FunctionMapMap({ "TEST1": {PySI.CollisionEvent.ON_ENTER: self.test_on_enter_recv, PySI.CollisionEvent.ON_CONTINUOUS: self.test_on_continuous_recv, PySI.CollisionEvent.ON_LEAVE: self.test_on_leave_recv} }) self.cap_link_emit = PySI.String2FunctionMap({ PySI.LinkingCapability.POSITION: self.position, PySI.LinkingCapability.SCALE: self.scale, PySI.LinkingCapability.ROTATION: self.rotation }) self.cap_link_recv = PySI.String2String2FunctionMapMap({ PySI.LinkingCapability.POSITION: {PySI.LinkingCapability.POSITION: self.set_position_from_position}, PySI.LinkingCapability.COLOR: {PySI.LinkingCapability.POSITION: self.set_position_from_color}, PySI.LinkingCapability.ROTATION: {PySI.LinkingCapability.ROTATION: self.set_rotation_from_rotation} })
def __init__(self, shape=PySI.PointVector(), uuid="", kwargs={}): if kwargs["value"]: super(Button, self).__init__(shape, uuid, "res/backward.png", Button.regiontype, Button.regionname, kwargs) else: super(Button, self).__init__(shape, uuid, "res/forward.png", Button.regiontype, Button.regionname, kwargs) self.with_border = False self.qml_path = self.set_QML_path("Button.qml") self.color = PySI.Color(192, 192, 192, 0) self.value = kwargs["value"] if len(kwargs.keys()) else False self.parent = str(kwargs["parent"]) if len(kwargs.keys()) else "" self.is_triggered = False self.is_triggered_reported = False self.icon_width = 100 self.icon_height = 100 self.width = Button.region_width self.height = Button.region_height self.set_QML_data("icon_width", self.icon_width, PySI.DataType.INT) self.set_QML_data("icon_height", self.icon_height, PySI.DataType.INT) self.parent = "" self.is_open_entry_capability_blocked = False
def on_open_entry_leave_recv(self, is_other_controlled): if self.parent == "" and self.is_open_entry_capability_blocked: x = self.relative_x_pos() y = self.relative_y_pos() self.width = self.icon_width * 2 self.height = self.icon_height + self.text_height self.shape = PySI.PointVector([[x, y], [x, y + self.height], [x + self.width, y + self.height], [x + self.width, y]]) self.is_icon_visible = True self.is_opened_visible = False self.color = PySI.Color(25, 0, 0, 0) self.with_border = False self.set_QML_data("container_width", self.width, PySI.DataType.INT) self.set_QML_data("container_height", self.height, PySI.DataType.INT) self.set_QML_data("is_icon_visible", self.is_icon_visible, PySI.DataType.BOOL) self.set_QML_data("is_opened_visible", self.is_opened_visible, PySI.DataType.BOOL) self.is_open_entry_capability_blocked = False for child in self.children: child.delete() self.snap_to_mouse()
def __init__(self, shape=PySI.PointVector(), uuid="", kwargs={}): super(ImageEditorBlurToolSetter, self).__init__(shape, uuid, "", ImageEditorBlurToolSetter.regiontype, ImageEditorBlurToolSetter.regionname, kwargs) self.source = "libStdSI" self.color = PySI.Color(0, 0, 0, 0) self.assigned_uuid = "" self.is_active = False self.getter = kwargs[ "getter_segment"] if "getter_segment" in kwargs else None if self.getter != None: self.getter.setter = self self.create_link(self.getter._uuid, PySI.LinkingCapability.POSITION, self._uuid, PySI.LinkingCapability.POSITION) self.create_link(self.getter._uuid, "PUSH_CONVOLUTION_OUTPUT", self._uuid, "PUSH_CONVOLUTION_OUTPUT") for tool in kwargs["other"].image_editor_tool: tool.delete() kwargs["other"].image_editor_tool = [self, self.getter]
def on_open_entry_continuous_recv(self, is_other_controlled): if self.parent == "" and not self.is_open_entry_capability_blocked and not self.is_under_user_control and not is_other_controlled: x = self.relative_x_pos() y = self.relative_y_pos() self.width = self.preview_width self.height = self.preview_height self.shape = PySI.PointVector([[x, y], [x, y + self.height], [x + self.width, y + self.height], [x + self.width, y]]) self.is_icon_visible = False self.is_opened_visible = True self.with_border = True self.color = PySI.Color(250, 250, 250, 255) self.set_QML_data("container_width", self.width, PySI.DataType.INT) self.set_QML_data("container_height", self.height, PySI.DataType.INT) self.set_QML_data("is_icon_visible", self.is_icon_visible, PySI.DataType.BOOL) self.set_QML_data("is_opened_visible", self.is_opened_visible, PySI.DataType.BOOL) self.show_current_folder_contents_page() self.is_open_entry_capability_blocked = True
def __init__(self, shape=PySI.PointVector(), uuid="", kwargs={}): super(SliderBase, self).__init__(shape, uuid, "", SliderBase.regiontype, SliderBase.regionname, kwargs) self.color = E.id.slider_base_color self.set_QML_data("color", kwargs["color_channel"], PySI.DataType.STRING) self.qml_path = self.set_QML_path("SliderBase.qml") controller_width = E.id.slider_base_controller_width controller_height = E.id.slider_base_controller_height controller_x = self.relative_x_pos() - controller_width / 4 controller_y = self.relative_y_pos() - controller_height / 4 controller_shape = PySI.PointVector( [[controller_x, controller_y], [controller_x, controller_y + controller_height], [ controller_x + controller_width, controller_y + controller_height ], [controller_x + controller_width, controller_y]]) self.create_region_via_name(controller_shape, SliderController.regionname, False, kwargs)
def on_preview_leave_recv(self): if self.is_in_preview and self.parent == "": self.color = PySI.Color(10, 0, 0, 0) self.is_in_preview = False x = self.relative_x_pos() y = self.relative_y_pos() self.set_QML_data("img_path", self.path, PySI.DataType.STRING) self.set_QML_data("is_in_preview", self.is_in_preview, PySI.DataType.BOOL) self.set_QML_data("container_width", self.width, PySI.DataType.INT) self.set_QML_data("container_height", self.height, PySI.DataType.INT) self.set_QML_data("icon_width", self.icon_width, PySI.DataType.INT) self.set_QML_data("icon_height", self.icon_height, PySI.DataType.INT) self.width = self.icon_width * 2 self.height = self.icon_height + self.text_height self.shape = PySI.PointVector([[x, y], [x, y + self.height], [x + self.width, y + self.height], [x + self.width, y]]) if self.is_under_user_control: self.snap_to_mouse()
def __init__(self, shape=PySI.PointVector(), uuid="", kwargs={}): super(Deletion, self).__init__(shape, uuid, "res/deletion.png", Deletion.regiontype, Deletion.regionname, kwargs) self.qml_path = self.set_QML_path("Deletion.qml") self.color = PySI.Color(255, 255, 204, 255) self.is_under_user_control = False
def __init__(self, shape=PySI.PointVector(), uuid="", kwargs={}): super(ImageEditorBlurToolGetter, self).__init__(shape, uuid, "", ImageEditorBlurToolGetter.regiontype, ImageEditorBlurToolGetter.regionname, kwargs) self.parent_uuid = "" self.kwargs = kwargs self.link_partner = kwargs[ "link_partner"] if "link_partner" in kwargs else "" self.matrix_size = kwargs["mat_size"] if "mat_size" in kwargs else 3 self.pixel_size = kwargs["pixel_size"] self.color = PySI.Color(55, 55, 55, 255) self.required_num_regions = self.matrix_size**2 self.setter = None if self.link_partner != "": x = kwargs["other_pos"][2] + ( (self.matrix_size // 2) * self.pixel_size) - 18 - self.pixel_size // 2 y = kwargs["other_pos"][3] + ( (self.matrix_size // 2) * self.pixel_size) - 24 - self.pixel_size // 2 self.shape = PySI.PointVector( [[x, y], [x, y + self.matrix_size * self.pixel_size], [ x + self.matrix_size * self.pixel_size, y + self.matrix_size * self.pixel_size ], [x + self.matrix_size * self.pixel_size, y]]) self.create_link(self.link_partner, PySI.LinkingCapability.POSITION, self._uuid, PySI.LinkingCapability.POSITION) self.color = PySI.Color(55, 55, 55, 80) setter_kwargs = {} setter_kwargs["pixel_size"] = self.pixel_size setter_kwargs["other"] = kwargs["other"] setter_kwargs["getter_segment"] = self tool_shape = PySI.PointVector( [[x + self.pixel_size, y + self.pixel_size], [x + self.pixel_size, y + self.pixel_size * 2], [x + self.pixel_size * 2, y + self.pixel_size * 2], [x + self.pixel_size * 2, y + self.pixel_size]]) self.create_region_via_name(tool_shape, ImageEditorBlurToolSetter.regionname, kwargs=setter_kwargs) self.assigned_uuid = "" self.pixels = {} self.convoluted_color = (0, 0, 0, 0)
def __init__(self, shape=PySI.PointVector(), uuid="", kwargs={}): super(ImageEditorPixel, self).__init__(shape, uuid, "", ImageEditorPixel.regiontype, ImageEditorPixel.regionname, kwargs) self.parent_uuid = "" self.index = kwargs["index"] r, g, b, a = kwargs["color"] if "color" in kwargs else (255, 255, 255, 255) self.color = PySI.Color(r, g, b, a)
def set_color_value_from_color_value(self, values): channel = values["channel"] color_value = values["col"] if channel == "r": self.color = PySI.Color(color_value, self.color.g, self.color.b, self.color.a) if channel == "g": self.color = PySI.Color(self.color.r, color_value, self.color.b, self.color.a) if channel == "b": self.color = PySI.Color(self.color.r, self.color.g, color_value, self.color.a) if channel == "a": self.color = PySI.Color(self.color.r, self.color.g, self.color.b, color_value)
def test_scope_datastructure_String2FunctionMap(self): sfm = PySI.String2FunctionMap() self.assertNotEqual(sfm, None) self.assertEqual(len(sfm), 0) sfm = PySI.String2FunctionMap({ "test": inner_test, "test2": inner_test2 }) # self.assertEqual(len(sfm), 1) # set sfm["test"] = inner_test2
def on_preview_enter_recv(self): if not self.is_in_preview and self.parent == "": self.is_in_preview = True x = self.relative_x_pos() y = self.relative_y_pos() self.width = int(self.img_height / 2 * (self.img_width / self.img_height)) self.height = int(self.img_height / 2) self.shape = PySI.PointVector([[x, y], [x, y + self.height], [x + self.width, y + self.height], [x + self.width, y]]) self.set_QML_data("img_path", self.path, PySI.DataType.STRING) self.set_QML_data("is_in_preview", self.is_in_preview, PySI.DataType.BOOL) self.set_QML_data("container_width", self.width, PySI.DataType.INT) self.set_QML_data("container_height", self.height, PySI.DataType.INT) self.set_QML_data("icon_width", self.width, PySI.DataType.INT) self.set_QML_data("icon_height", self.height, PySI.DataType.INT) self.snap_to_mouse()
def __init__(self, shape=PySI.PointVector(), uuid="", kwargs={}): super(Selector, self).__init__(shape, uuid, "", Selector.regiontype, Selector.regionname, kwargs) self.qml_path = self.set_QML_path("Selector.qml") self.color = kwargs["target_color"] self.target_name = kwargs["target_name"] self.target_display_name = kwargs["target_display_name"] self.target_texture_path = kwargs["target_texture"] self.name = "Selector for " + self.target_display_name self.parent = kwargs["parent"] self.img_width = 40 self.img_height = 40 self.set_QML_data("img_path", self.target_texture_path, PySI.DataType.STRING) self.set_QML_data("visible", False, PySI.DataType.BOOL) self.set_QML_data("text", "", PySI.DataType.STRING) self.set_QML_data("img_width", self.img_width, PySI.DataType.INT) self.set_QML_data("img_height", self.img_height, PySI.DataType.INT) self.set_QML_data("text", self.target_display_name, PySI.DataType.STRING) self.set_QML_data("width", self.width, PySI.DataType.INT) self.set_QML_data("height", self.height, PySI.DataType.INT) self.create_link(self.parent, PySI.LinkingCapability.POSITION, self._uuid, PySI.LinkingCapability.POSITION)
def add_point_to_region_drawing(self, x: float, y: float, cursor_id: str) -> None: if self.region_type is int(PySI.EffectType.SI_CANVAS): if cursor_id not in self.__partial_regions__.keys(): self.__partial_regions__[cursor_id] = PySI.PointVector() self.__partial_regions__[cursor_id].append([x, y])
def test_scope_datastructure_String2String2FunctionMapMap(self): ssfmm = PySI.String2String2FunctionMapMap() self.assertNotEqual(ssfmm, None) self.assertEqual(len(ssfmm), 0) ssfmm = PySI.String2String2FunctionMapMap({ "TEST": {"TEST1_1": None, "TEST1_2": None, "TEST1_3": None}, "TEST2": {"TEST2_1": None, "TEST2_2": None, "TEST2_3": None} }) self.assertEqual(len(ssfmm), 2) #set ssfmm["TEST"] = {"TEST4_1": None, "TEST4_2": None, "TEST4_3": None}
def __init__(self, shape=PySI.PointVector(), uuid="", kwargs={}): super(Tag, self).__init__(shape, uuid, E.id.tag_texture, Tag.regiontype, Tag.regionname, kwargs) self.qml_path = self.set_QML_path(E.id.tag_qml_file_name) self.color = E.id.tag_color self.text = "Hello World"
def remove_link(self, sender_uuid: str, sender_attribute: str, receiver_uuid: str, receiver_attribute: str) -> None: if sender_uuid != "" and sender_attribute != "" and receiver_uuid != "" and receiver_attribute != "": lr = PySI.LinkRelation(sender_uuid, sender_attribute, receiver_uuid, receiver_attribute) if lr in self.link_relations: del self.link_relations[self.link_relations.index(lr)]
def __init__(self, shape=PySI.PointVector(), uuid="", r="", t="", s="", kwargs={}): super(Movable, self).__init__(shape, uuid, r, t, s, kwargs)
def on_parent_enter_recv(self, parent_uuid, target_color): if self.parent_uuid == "": self.parent_uuid = parent_uuid self.create_link(parent_uuid, PySI.LinkingCapability.POSITION, self._uuid, PySI.LinkingCapability.POSITION) self.disable_effect("IMAGE_PARENT", self.RECEPTION) r, g, b, a = target_color self.color = PySI.Color(r, g, b, a)
def add_annotation_color(): w, h = PySI.Startup.context_dimensions( )[0], PySI.Startup.context_dimensions()[1] tw, th = 100, 100 x = w // 2 - tw // 2 y = 200 shape = [[x, y], [x, y + th], [x + tw, y + th], [x + tw, y]] PySI.Startup.create_region_by_name( shape, Color.regionname, {"color": PySI.Color(100, 100, 20, 255)})
def __init__(self, shape=PySI.PointVector(), uuid="", kwargs={}): super(SliderController, self).__init__(shape, uuid, "", SliderController.regiontype, SliderController.regionname, kwargs) self.color = E.id.slider_controller_color self.color_value = E.id.slider_controller_min_value self.target_color_channel = kwargs[ E.id.slider_controller_color_channel]
def test_scope_datastructure_LinkRelation(self): lr = PySI.LinkRelation("test", "attrib_test", "test2", "attrib_test2") self.assertNotEqual(lr, None) self.assertEqual(lr.sender, "test") self.assertEqual(lr.sender_attrib, "attrib_test") self.assertEqual(lr.recv, "test2") self.assertEqual(lr.recv_attrib, "attrib_test2")
def __init__(self, shape=PySI.PointVector(), uuid="", r="", t="", s="", kwargs={}): super(Lassoable, self).__init__(shape, uuid, r, t, s, kwargs) self.source = "libStdSI"
def test_scope_datastructure_LinkRelationVector(self): lv = PySI.LinkRelationVector() self.assertNotEqual(lv, None) lv = PySI.LinkRelationVector([["test", "test_attrib", "test2", "test_attrib2"], ["test3", "test_attrib3", "test4", "test_attrib4"]]) self.assertEqual(len(lv), 2) # get self.assertEqual(lv[0].sender, "test") self.assertEqual(lv[0].sender_attrib, "test_attrib") self.assertEqual(lv[0].recv, "test2") self.assertEqual(lv[0].recv_attrib, "test_attrib2") self.assertEqual(lv[1].sender, "test3") self.assertEqual(lv[1].sender_attrib, "test_attrib3") self.assertEqual(lv[1].recv, "test4") self.assertEqual(lv[1].recv_attrib, "test_attrib4") # get slice # same functionality for all exposed vectors # therefore, tested in PointVector # set lv[0] = ["test5", "test_attrib5", "test6", "test_attrib6"] self.assertEqual(lv[0].sender, "test5") self.assertEqual(lv[0].sender_attrib, "test_attrib5") self.assertEqual(lv[0].recv, "test6") self.assertEqual(lv[0].recv_attrib, "test_attrib6") # del # same functionality for all exposed vectors # therefore, tested in PointVector # add lv.append(["test7", "test_attrib7", "test8", "test_attrib8"]) self.assertEqual(len(lv), 3) self.assertEqual(lv[2].sender, "test7") self.assertEqual(lv[2].sender_attrib, "test_attrib7") self.assertEqual(lv[2].recv, "test8") self.assertEqual(lv[2].recv_attrib, "test_attrib8")
def __init__(self, shape: PySI.PointVector = PySI.PointVector(), uuid: str = "", kwargs: dict = {}) -> None: super().__init__(shape, uuid, "", Dummy3.regiontype, Dummy3.regionname, kwargs) self.source = "libStdSI" self.qml_path = "" print("WTF")
def __init__(self, shape=PySI.PointVector(), uuid="", r="", t="", s="", kwargs={}): super(PositionLinkable, self).__init__(shape, uuid, r, t, s, kwargs) self.transform_x = 0 self.transform_y = 0
def set_geometry_from_geometry(self, abs_x, abs_y, width, height): if self.width == width and self.height == height: self.move(abs_x, abs_y) else: self.has_data_changed = True self.move(0, 0) # self.move(abs_x - abs(abs_x - self.x), abs_y) self.shape = PySI.PointVector( [[abs_x - 5, abs_y - 5], [abs_x - 5, abs_y + height + 30], [abs_x + width + 5, abs_y + height + 30], [abs_x + width + 5, abs_y - 5]])