Exemple #1
0
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
Exemple #2
0
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
Exemple #3
0
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
Exemple #4
0
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
Exemple #5
0
def mime_data_get_layer(
    mime_data: UserInterface.MimeData,
    document_model: "DocumentModel.DocumentModel"
) -> typing.Tuple[typing.Dict, typing.Optional[DisplayItem.DisplayItem]]:
    mime_dict = json.loads(mime_data.data_as_string(LAYER_MIME_TYPE))
    legend_data = mime_dict["legend_data"]
    display_item_specifier = Persistence.PersistentObjectSpecifier.read(
        mime_dict["display_item_specifier"])
    display_item = document_model.resolve_item_specifier(
        display_item_specifier)
    return legend_data, display_item
Exemple #6
0
 def __insert_mime_data(self, mime_data: UserInterface.MimeData) -> None:
     text = mime_data.data_as_string("text/plain")
     text_lines = re.split("[" + re.escape("\n") + re.escape("\r") + "]",
                           text)
     if not text_lines[-1]:
         text_lines = text_lines[:-1]
     if len(text_lines) == 1 and text_lines[0] == text.rstrip():
         # special case where text has no line terminator
         self.__text_edit_widget.insert_text(text)
     else:
         self.insert_lines(text_lines)
Exemple #7
0
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
Exemple #8
0
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
Exemple #9
0
def mime_data_get_layer(mime_data: UserInterface.MimeData, document_model: DocumentModel.DocumentModel) -> typing.Tuple[Persistence.PersistentDictType, typing.Optional[DisplayItem.DisplayItem]]:
    mime_dict = json.loads(mime_data.data_as_string(LAYER_MIME_TYPE))
    legend_data = mime_dict["legend_data"]
    display_item_specifier = Persistence.read_persistent_specifier(mime_dict["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 legend_data, display_item