def __init__( self, *, structure_type: typing.Optional[str] = None, source: typing.Optional[Persistence.PersistentObject] = None ) -> None: super().__init__() self.__properties: typing.Dict[str, typing.Any] = dict() self.__referenced_object_proxies: typing.Dict[ str, Persistence.PersistentObjectProxy[Persistence. PersistentObject]] = dict() self.define_type("data_structure") self.define_property("structure_type", structure_type, changed=self.__structure_type_changed, hidden=True) self.define_property("source_specifier", changed=self.__source_specifier_changed, key="source_uuid", hidden=True) # properties is handled explicitly self.data_structure_changed_event = Event.Event() self.data_structure_objects_changed_event = Event.Event() self.__source_reference = self.create_item_reference(item=source) self.source_specifier = Persistence.write_persistent_specifier( source.uuid) if source else None self.__entity: typing.Optional[Schema.Entity] = None self.__entity_property_changed_event_listener: typing.Optional[ Event.EventListener] = None self.__create_entity()
def insert_display_item(self, before_index: int, display_item: DisplayItem.DisplayItem) -> None: assert display_item not in self.__display_items self.__display_items.insert(before_index, display_item) self.notify_insert_item("display_items", display_item, before_index) self.update_counted_display_items(collections.Counter([display_item])) display_item_specifiers = self.display_item_specifiers display_item_specifier = Persistence.write_persistent_specifier(display_item.uuid) assert display_item_specifier is not None display_item_specifiers.insert(before_index, display_item_specifier) self.display_item_specifiers = display_item_specifiers self.notify_property_changed("display_item_specifiers")
def mime_data_put_layer(mime_data: UserInterface.MimeData, index: int, display_item: DisplayItem.DisplayItem, label: typing.Optional[str], fill_color: typing.Optional[str], stroke_color: typing.Optional[str]) -> None: legend_data: Persistence.PersistentDictType = { "index": index, } if label: legend_data["label"] = label if fill_color: legend_data["fill_color"] = fill_color if stroke_color: legend_data["stroke_color"] = stroke_color mime_dict = { "legend_data": legend_data, "display_item_specifier": Persistence.write_persistent_specifier(display_item.uuid) } mime_data.set_data_as_string(LAYER_MIME_TYPE, json.dumps(mime_dict))
def __init__( self, type: str, *, parent: typing.Optional[Persistence.PersistentObject] = None ) -> None: super().__init__() self.define_type(type) self.define_property("parent_specifier", changed=self.__parent_specifier_changed, key="parent_uuid", hidden=True) self.__parent_reference = self.create_item_reference(item=parent) self.parent_specifier = Persistence.write_persistent_specifier( parent.uuid) if parent else None
def mime_data_put_display_items(mime_data: UserInterface.MimeData, display_items: typing.Sequence[DisplayItem.DisplayItem]) -> None: mime_data_content = [{"display_item_specifier": Persistence.write_persistent_specifier(display_item.uuid)} for display_item in display_items] mime_data.set_data_as_string(DISPLAY_ITEMS_MIME_TYPE, json.dumps(mime_data_content))
def mime_data_put_display_item(mime_data: UserInterface.MimeData, display_item: DisplayItem.DisplayItem) -> None: mime_data_content = {"display_item_specifier": Persistence.write_persistent_specifier(display_item.uuid)} mime_data.set_data_as_string(DISPLAY_ITEM_MIME_TYPE, json.dumps(mime_data_content))
def mime_data_put_data_source(mime_data: UserInterface.MimeData, display_item: DisplayItem.DisplayItem, graphic: typing.Optional[Graphics.Graphic]) -> None: mime_data_content = dict() mime_data_content["display_item_specifier"] = Persistence.write_persistent_specifier(display_item.uuid) if graphic and graphic.project: mime_data_content["graphic_specifier"] = Persistence.write_persistent_specifier(graphic.uuid) mime_data.set_data_as_string(DATA_SOURCE_MIME_TYPE, json.dumps(mime_data_content))
def mime_data_put_panel(mime_data: UserInterface.MimeData, display_item: typing.Optional[DisplayItem.DisplayItem], d: Persistence.PersistentDictType) -> None: if display_item: d = dict(d) d["display_item_specifier"] = Persistence.write_persistent_specifier(display_item.uuid) mime_data.set_data_as_string(DISPLAY_PANEL_MIME_TYPE, json.dumps(d))
def source(self, source: typing.Optional[Persistence.PersistentObject]) -> None: self.__source_reference.item = source self.source_specifier = Persistence.write_persistent_specifier( source.uuid) if source else None
def __init__( self, source: typing.Optional[Persistence.PersistentObject] = None, source_property: typing.Optional[str] = None, target: typing.Optional[Persistence.PersistentObject] = None, target_property: typing.Optional[str] = None, *, parent: typing.Optional[Persistence.PersistentObject] = None ) -> None: super().__init__("property-connection", parent=parent) self.define_property("source_specifier", Persistence.write_persistent_specifier( source.uuid) if source else None, changed=self.__source_specifier_changed, key="source_uuid", hidden=True) self.define_property("source_property", hidden=True) self.define_property("target_specifier", Persistence.write_persistent_specifier( target.uuid) if target else None, changed=self.__target_specifier_changed, key="target_uuid", hidden=True) self.define_property("target_property", hidden=True) # these are only set in persistent object context changed self.__binding: typing.Optional[Binding.Binding] = None self.__target_property_changed_listener: typing.Optional[ Event.EventListener] = None self.__source_reference = self.create_item_reference(item=source) self.__target_reference = self.create_item_reference(item=target) # suppress messages while we're setting source or target self.__suppress = False # set up the proxies def configure_binding() -> None: if self._source and self._target: assert not self.__binding self.__binding = Binding.PropertyBinding( self._source, self.source_property) self.__binding.target_setter = self.__set_target_from_source # while reading, the data item in the display data channel will not be connected; # we still set its value here. when the data item becomes valid, it will update. self.__binding.update_target_direct( self.__binding.get_target_value()) def release_binding() -> None: if self.__binding: self.__binding.close() self.__binding = None if self.__target_property_changed_listener: self.__target_property_changed_listener.close() self.__target_property_changed_listener = None self.__source_reference.on_item_registered = lambda x: configure_binding( ) self.__source_reference.on_item_unregistered = lambda x: release_binding( ) def configure_target() -> None: def property_changed(target: typing.Optional[ Persistence.PersistentObject], property_name: str) -> None: if property_name == self.target_property: self.__set_source_from_target( getattr(target, property_name)) assert self.__target_property_changed_listener is None if self._target: self.__target_property_changed_listener = self._target.property_changed_event.listen( functools.partial(property_changed, self._target)) configure_binding() self.__target_reference.on_item_registered = lambda x: configure_target( ) self.__target_reference.on_item_unregistered = lambda x: release_binding( ) # but set up if we were passed objects if source is not None: self.__source_reference.item = source if source_property: self.source_property = source_property if target is not None: self.__target_reference.item = target if target_property: self.target_property = target_property if self._target: configure_target()
def parent(self, parent: typing.Optional[Persistence.PersistentObject]) -> None: self.__parent_reference.item = parent self.parent_specifier = Persistence.write_persistent_specifier( parent.uuid) if parent else None
def __init__( self, display_item: typing.Optional[DisplayItem.DisplayItem] = None, line_profile: typing.Optional[Graphics.LineProfileGraphic] = None, *, parent: typing.Optional[Persistence.PersistentObject] = None ) -> None: super().__init__("interval-list-connection", parent=parent) self.define_property("source_specifier", Persistence.write_persistent_specifier( display_item.uuid) if display_item else None, changed=self.__source_specifier_changed, key="source_uuid", hidden=True) self.define_property( "target_specifier", Persistence.write_persistent_specifier(line_profile.uuid) if line_profile and line_profile.project else None, changed=self.__target_specifier_changed, key="target_uuid", hidden=True) # these are only set in persistent object context changed self.__item_inserted_event_listener: typing.Optional[ Event.EventListener] = None self.__item_removed_event_listener: typing.Optional[ Event.EventListener] = None self.__interval_mutated_listeners: typing.List[ Event.EventListener] = list() self.__source_reference = self.create_item_reference(item=display_item) self.__target_reference = self.create_item_reference(item=line_profile) def detach() -> None: for listener in self.__interval_mutated_listeners: listener.close() self.__interval_mutated_listeners = list() def reattach() -> None: detach() interval_descriptors = list() if isinstance(self._source, DisplayItem.DisplayItem): for region in self._source.graphics: if isinstance(region, Graphics.IntervalGraphic): interval_descriptor = { "interval": region.interval, "color": "#F00" } interval_descriptors.append(interval_descriptor) self.__interval_mutated_listeners.append( region.property_changed_event.listen( lambda k: reattach())) if isinstance(self._target, Graphics.LineProfileGraphic): if self._target.interval_descriptors != interval_descriptors: self._target.interval_descriptors = interval_descriptors def item_inserted(key: str, value: typing.Any, before_index: int) -> None: if key == "graphics" and self._target: reattach() def item_removed(key: str, value: typing.Any, index: int) -> None: if key == "graphics" and self._target: reattach() def source_registered(source: Persistence.PersistentObject) -> None: if self._source: self.__item_inserted_event_listener = self._source.item_inserted_event.listen( item_inserted) self.__item_removed_event_listener = self._source.item_removed_event.listen( item_removed) reattach() def target_registered(target: Persistence.PersistentObject) -> None: reattach() def unregistered(item: Persistence.PersistentObject) -> None: if self.__item_inserted_event_listener: self.__item_inserted_event_listener.close() self.__item_inserted_event_listener = None if self.__item_removed_event_listener: self.__item_removed_event_listener.close() self.__item_removed_event_listener = None self.__source_reference.on_item_registered = source_registered self.__source_reference.on_item_unregistered = unregistered self.__target_reference.on_item_registered = target_registered self.__target_reference.on_item_unregistered = unregistered # but setup if we were passed objects if display_item is not None: self.__source_reference.item = display_item source_registered(display_item) if line_profile is not None: self.__target_reference.item = line_profile target_registered(line_profile)