def mime_data_get_display_items( mime_data: UserInterface.MimeData, document_model: "DocumentModel.DocumentModel" ) -> typing.List[DisplayItem.DisplayItem]: display_items: typing.List[DisplayItem.DisplayItem] = list() if mime_data.has_format(DISPLAY_ITEMS_MIME_TYPE): data_sources_mime_data = json.loads( mime_data.data_as_string(DISPLAY_ITEMS_MIME_TYPE)) for data_source_mime_data in data_sources_mime_data: display_item_specifier = Persistence.PersistentObjectSpecifier.read( data_source_mime_data["display_item_specifier"]) display_item = document_model.resolve_item_specifier( display_item_specifier) if display_item: display_items.append( typing.cast(DisplayItem.DisplayItem, display_item)) if mime_data.has_format(DISPLAY_ITEM_MIME_TYPE): data_source_mime_data = json.loads( mime_data.data_as_string(DISPLAY_ITEM_MIME_TYPE)) display_item_specifier = Persistence.PersistentObjectSpecifier.read( data_source_mime_data["display_item_specifier"]) display_item = document_model.resolve_item_specifier( display_item_specifier) if display_item: display_items.append( typing.cast(DisplayItem.DisplayItem, display_item)) return display_items
def mime_data_get_display_item(mime_data: UserInterface.MimeData, document_model: DocumentModel.DocumentModel) -> typing.Optional[DisplayItem.DisplayItem]: display_item = None if mime_data.has_format(DISPLAY_ITEM_MIME_TYPE): data_source_mime_data = json.loads(mime_data.data_as_string(DISPLAY_ITEM_MIME_TYPE)) display_item_specifier = Persistence.read_persistent_specifier(data_source_mime_data["display_item_specifier"]) display_item = typing.cast(typing.Optional[DisplayItem.DisplayItem], document_model.resolve_item_specifier(display_item_specifier)) if display_item_specifier else None return display_item
def mime_data_get_panel(mime_data: UserInterface.MimeData, document_model: DocumentModel.DocumentModel) -> typing.Tuple[typing.Optional[DisplayItem.DisplayItem], Persistence.PersistentDictType]: display_item = None d: Persistence.PersistentDictType = dict() if mime_data.has_format(DISPLAY_PANEL_MIME_TYPE): d = json.loads(mime_data.data_as_string(DISPLAY_PANEL_MIME_TYPE)) if "display_item_specifier" in d: display_item_specifier = Persistence.read_persistent_specifier(d["display_item_specifier"]) display_item = typing.cast(typing.Optional[DisplayItem.DisplayItem], document_model.resolve_item_specifier(display_item_specifier)) if display_item_specifier else None return display_item, d
def mime_data_get_panel(mime_data: UserInterface.MimeData, document_model: "DocumentModel.DocumentModel") -> typing.Tuple[typing.Optional[DisplayItem.DisplayItem], typing.Dict]: display_item = None d = dict() if mime_data.has_format(DISPLAY_PANEL_MIME_TYPE): d = json.loads(mime_data.data_as_string(DISPLAY_PANEL_MIME_TYPE)) if "display_item_specifier" in d: display_item_specifier = Persistence.PersistentObjectSpecifier.read(d["display_item_specifier"]) display_item = document_model.resolve_item_specifier(display_item_specifier) return display_item, d
def mime_data_get_graphics(mime_data: UserInterface.MimeData) -> typing.Sequence[Graphics.Graphic]: graphics = list() if mime_data.has_format(GRAPHICS_MIME_TYPE): json_str = mime_data.data_as_string(GRAPHICS_MIME_TYPE) graphics_dict = json.loads(json_str) for graphic_dict in graphics_dict.get("graphics", list()): graphic = Graphics.factory(lambda t: str(graphic_dict["type"])) graphic.read_from_mime_data(graphic_dict) if graphic: graphics.append(graphic) return graphics
def mime_data_get_data_source(mime_data: UserInterface.MimeData, document_model: DocumentModel.DocumentModel) -> typing.Tuple[typing.Optional[DisplayItem.DisplayItem], typing.Optional[Graphics.Graphic]]: display_item = None graphic = None if mime_data.has_format(DATA_SOURCE_MIME_TYPE): data_source_mime_data = json.loads(mime_data.data_as_string(DATA_SOURCE_MIME_TYPE)) display_item_specifier = Persistence.read_persistent_specifier(data_source_mime_data["display_item_specifier"]) display_item = typing.cast(typing.Optional[DisplayItem.DisplayItem], document_model.resolve_item_specifier(display_item_specifier)) if display_item_specifier else None if "graphic_specifier" in data_source_mime_data: graphic_specifier = Persistence.read_persistent_specifier(data_source_mime_data["graphic_specifier"]) graphic = typing.cast(typing.Optional[Graphics.Graphic], document_model.resolve_item_specifier(graphic_specifier)) if graphic_specifier else None return display_item, graphic