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 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 __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 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(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_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(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 __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 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 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 __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 test_scope_datastructure_Color(self): red = PySI.Color(255, 0, 0, 255) green = PySI.Color(0, 255, 0, 255) blue = PySI.Color(0, 0, 255, 255) no_alpha = PySI.Color(255, 0, 0, 0) self.assertEqual(red.r, 255) self.assertEqual(red.g, 0) self.assertEqual(red.b, 0) self.assertEqual(red.a, 255) self.assertEqual(green.r, 0) self.assertEqual(green.g, 255) self.assertEqual(green.b, 0) self.assertEqual(green.a, 255) self.assertEqual(blue.r, 0) self.assertEqual(blue.g, 0) self.assertEqual(blue.b, 255) self.assertEqual(blue.a, 255) self.assertEqual(no_alpha.a, 0)
def __init__(self, shape=PySI.PointVector(), uuid="", kwargs={}): super(ConveyorBelt, self).__init__(shape, uuid, "res/factory.png", ConveyorBelt.regiontype, ConveyorBelt.regionname, kwargs) self.qml_path = self.set_QML_path("ConveyorBelt.qml") self.color = PySI.Color(204, 255, 204, 255) self.conveyor_point_step = 1 self.conveyor_width = E.id.cb_width self.length = 0 self.speed = 250 self.delta_x = 0 self.delta_y = 0 self.collision_pixel_variance = 7 self.transportation_path_changed = False # will contain tuples of (item_x, item_y, overall length up to this point, distance_x_to_prev_point, distance_y_to_prev_point self.transportation_path = [] self.rebuild_shape() self.conveyed_items = {}
def __init__(self, shape=PySI.PointVector(), uuid="", regiontype=PySI.EffectType.SI_ENTRY, regionname=PySI.EffectName.SI_STD_NAME_ENTRY, kwargs={}): super(Entry, self).__init__(shape, uuid, self.TEXTURE_PATH_NONE, regiontype, regionname, kwargs) self.width = 130 self.height = 125 self.icon_width = 65 self.icon_height = 75 self.text_height = 50 self.color = PySI.Color(255, 10, 0, 0) self.text_color = "FF000000" self.path = str(kwargs["cwd"]) if len(kwargs.keys()) else "" self.parent = str(kwargs["parent"]) if len(kwargs.keys()) else "" self.filename = "" self.is_visible = True self.is_under_user_control = False self.is_open_entry_capability_blocked = False self.with_border = False if self.path != "": self.filename = self.path[self.path.rfind("/") + 1:] self.is_container_visible = True self.set_QML_data("text_height", self.text_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.set_QML_data("color", self.text_color, PySI.DataType.STRING) self.set_QML_data("name", self.filename, PySI.DataType.STRING) if self.parent != "": self.create_link(self.parent, PySI.LinkingCapability.POSITION, self._uuid, PySI.LinkingCapability.POSITION)
def __init__(self, shape=PySI.PointVector(), uuid="", kwargs={}): super(Container, self).__init__(shape, uuid, self.TEXTURE_PATH_NONE, Container.regiontype, Container.regionname, kwargs) self.color = PySI.Color(128, 128, 128, 128)
def on_tool_apply_continuous_recv(self, tool, tooltype): if tool != None and tooltype != None: if self.color != tool: self.color = PySI.Color(tool[0], tool[1], tool[2], tool[3])
def set_conv_output_from_conv_output(self, r, g, b, a): self.color = PySI.Color(r, g, b, a)
def __init__(self, shape: PySI.PointVector, uuid: str, texture_path: str, regiontype: int, regionname: str, kwargs: dict, __source__="custom") -> None: super(SIEffect, self).__init__(shape, uuid, texture_path, kwargs) ## member attribute variable serving as a rendering hint for showing a regions border self.with_border = True tmp = sys.modules[self.__class__.__module__].__file__ texture_path = tmp[0:tmp.rindex("/") + 1] + texture_path ## member attribute variable containing the shape (contour) of a drawn region as a PySI.PointVector self.shape = shape ## member attribute variable containing the axis-aligned bounding-box (aabb) of a drawn region as a PySI.PointVector # # This variable is automatically computed when shape is changed. # It is recommended to use this variable read-only. self.aabb ## member variable containing the maximum width of the region # # computed via aabb self.width = int(self.get_region_width()) ## member variable containing the maximum height of the region # # computed via aabb self.height = int(self.get_region_height()) ## member attribute variable containing the universally unique identifier (uuid) of a drawn region as a str self._uuid = uuid ## member attribute variable containing the name of a drawn region as a str self.name = regionname ## member attribute variable containing the type of effect of a drawn region as a PySI.EffectType # # Effect implementation which are currently not part of the Standard Environment Library of SIGRun are required to be of type SI_CUSTOM self.region_type = regiontype ## member attribute variable containing the source of effect of a drawn region as a str # # Effect implementation which are currently not part of the Standard Environment Library of SIGRun are encouraged to not start with "libStdSI" self.source = "libStdSI" ## member attribute variable containing the path to a QML file for styling of a drawn region as a str # # This value can be left empty if no visualization of the region is intended (e.g. Container-Regions for External Applications or MouseCursor) # @see Container # @see MouseCursor self.qml_path = "" ## member attribute variable containing the last relative movement of the region according to the x axis as a float self.delta_x = 0 ## member attribute variable containing the last relative movement of the region according to the y axis as a float self.delta_y = 0 ## member attribute variable containing the last absolute x coordinate as a float self.last_x = 0 ## member attribute variable containing the last absolute y coordinate as a float self.last_y = 0 ## member attribute variable containing the fill color of a region in RGBA as a PySI.Color self.color = PySI.Color(33, 33, 33, 127) ## member attribute variable which is true when an user directly controls the region (e.g. moving it around) as a bool self.is_under_user_control = False ## member attribute variable storing the uuids of present cursors once a region drawing is to be registered as a PySI.StringVector self.__registered_regions__ = PySI.StringVector() ## member attribute variable storing the path to the image file used as texture for a region self.texture_path = texture_path if self.texture_path != "": ## member attribute variable storing the width of a texture of a region drawing as a float # # This value is only set if texture_path is a valid path self.texture_width = 75 ## member attribute variable storing the height of a texture of a region drawing as a float # # This value is only set if texture_path is a valid path self.texture_height = 75 # apply data in QML self.set_QML_data("img_width", self.texture_width, PySI.DataType.INT) self.set_QML_data("img_height", self.texture_height, PySI.DataType.INT) self.set_QML_data("img_path", self.texture_path, PySI.DataType.STRING) self.set_QML_data("widget_width", self.width, PySI.DataType.FLOAT) self.set_QML_data("widget_height", self.height, PySI.DataType.FLOAT) self.set_QML_data("uuid", self._uuid, PySI.DataType.STRING) ## member attribute variable storing keys to functions which are called when collision events occur for emitting data to receiving regions # # This variable is a PySI.String2_String2FunctionMap_Map (c++-bindings) and uses capabilities (str) as keys to the inner String2FunctionMap. # The inner String2FunctionMap uses collision event names (PySI.ON_ENTER ("on_enter"), PySI:ON_CONTINUOUS ("on_continuous"), PySI.ON_LEAVE ("on_leave")) as keys to their corresponding functions as values # # Example: # # self.cap_emit["CAPABILITY"] = {PySI.ON_ENTER: self.<function_enter>, PySI:ON_CONTINUOUS: self.<function_continuous>, PySI.ON_LEAVE: self.<function_leave> # # Therefore, this example allows a region to emit an effect of CAPABILITY once a collision event occurred self.cap_emit = PySI.String2String2FunctionMapMap() ## member attribute variable storing keys to functions which are called when collision events occur for receiving data from emitting regions # # This variable is a PySI.String2_String2FunctionMap_Map (c++-bindings) and uses capabilities (str) as keys to the inner String2FunctionMap. # The inner String2FunctionMap uses collision event names (PySI.ON_ENTER ("on_enter"), PySI:ON_CONTINUOUS ("on_continuous"), PySI.ON_LEAVE ("on_leave")) as keys to their corresponding functions as values # # Example: # # self.cap_recv["CAPABILITY"] = {PySI.ON_ENTER: self.<function_enter>, PySI:ON_CONTINUOUS: self.<function_continuous>, PySI.ON_LEAVE: self.<function_leave> # # Therefore, this example allows a region to receive an effect of CAPABILITY once a collision event occurred self.cap_recv = PySI.String2String2FunctionMapMap() ## member attribute variable storing keys to functions which are called when linking events occur for emitting data to receiving regions # # This variable is a String2FunctionMap (c++-bindings) containing capabilities (str) as keys and functions as values # # Example with SI-integrated linking of positions for emission case: # self.cap_link_emit[PySI.POSITION] = self.<function_position_emit> # Therefore, this example emits the positional data of the region to a linked region. # Example with custom capability for linking: # self.cap_link_emit[<name of capability>] = self.<corresponding function> # Therefore, this example emits some data of the region to a linked region based on the capability self.cap_link_emit = PySI.String2FunctionMap() ## member attribute variable storing keys to functions which are called when linking events occur for emitting data to receiving regions # # This variable is a PySI.String2_String2FunctionMap_Map (c++-bindings) and uses linking event capability names (str) as keys to the inner String2FunctionMap. # The inner String2FunctionMap uses linking event capability names (PySI.POSITION, <own name as str>) as keys to their corresponding functions as values. # The outer key corresponds to the emission capability. # The inner key corresponds to the reception capability of the targeted region and points towards the function which is to be called during the linking event # Therefore, it is possible to map e.g. incomimg positional data to the color of the receiving region. # # Example with SI-integrated linking of positions for reception case: # self.cap_link_recv[PySI.POSITION][PySI.POSITION] = self.<function_position_emit> # self.cap_link_recv[PySI.POSITION][PySI.COLOR] = self.<function_color_emit> # Therefore, this example receives the positional data of a linked region and can apply this data to other categories of data according to the linking relationship. # Example with custom capability for linking: # self.cap_link_recv[<name of emission capability>][<name of reception capability>] = self.<corresponding function> # Therefore, this example receives some data of a linked region and can apply this data to other categories of data according to the linking relationship . self.cap_link_recv = PySI.String2String2FunctionMapMap() ## member attribute variable storing the x position of the mouse cursor self.mouse_x = 0 ## member attribute variable storing the y position of the mouse cursor self.mouse_y = 0
def __init__(self, shape=PySI.PointVector(), uuid="", kwargs={}): super(OpenEntry, self).__init__(shape, uuid, "res/open_entry.png", OpenEntry.regiontype, OpenEntry.regionname, kwargs) self.qml_path = self.set_QML_path("OpenEntry.qml") self.color = PySI.Color(204, 229, 255, 255)
def __init__(self, shape=PySI.PointVector(), uuid="", kwargs={}): super(Canvas, self).__init__(shape, uuid, "", Canvas.regiontype, Canvas.regionname, kwargs) self.color = PySI.Color(247, 249, 239, 255) self.log_file = open(".TEST.TXT", "r+")