Exemple #1
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 #2
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 #3
0
def mime_data_put_display_item(mime_data: UserInterface.MimeData,
                               display_item: DisplayItem.DisplayItem) -> None:
    mime_data_content = {
        "display_item_specifier":
        display_item.project.create_specifier(display_item).write()
    }
    mime_data.set_data_as_string(DISPLAY_ITEM_MIME_TYPE,
                                 json.dumps(mime_data_content))
Exemple #4
0
def mime_data_put_graphics(
        mime_data: UserInterface.MimeData,
        graphics: typing.Sequence[Graphics.Graphic]) -> None:
    graphic_dict_list = list()
    for graphic in graphics:
        graphic_dict_list.append(graphic.mime_data_dict())
    graphics_dict = {"graphics": graphic_dict_list}
    mime_data.set_data_as_string(GRAPHICS_MIME_TYPE, json.dumps(graphics_dict))
Exemple #5
0
def mime_data_put_panel(mime_data: UserInterface.MimeData,
                        display_item: typing.Optional[DisplayItem.DisplayItem],
                        d: typing.Sequence) -> None:
    if display_item:
        d = dict(d)
        d["display_item_specifier"] = display_item.project.create_specifier(
            display_item).write()
    mime_data.set_data_as_string(DISPLAY_PANEL_MIME_TYPE, json.dumps(d))
Exemple #6
0
def mime_data_put_display_items(
        mime_data: UserInterface.MimeData,
        display_items: typing.Sequence[DisplayItem.DisplayItem]) -> None:
    mime_data_content = [{
        "display_item_specifier":
        display_item.project.create_specifier(display_item).write()
    } for display_item in display_items]
    mime_data.set_data_as_string(DISPLAY_ITEMS_MIME_TYPE,
                                 json.dumps(mime_data_content))
Exemple #7
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 #8
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 #9
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 #10
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 #11
0
def mime_data_put_layer(mime_data: UserInterface.MimeData, index: int, display_item: DisplayItem.DisplayItem, label: str, fill_color: str, stroke_color: str) -> None:
    legend_data = {
        "index": index,
        "label": label,
        "fill_color": fill_color,
        "stroke_color": stroke_color,
    }
    mime_dict = {
        "legend_data": legend_data,
        "display_item_specifier": display_item.project.create_specifier(display_item, allow_partial=False).write()
    }
    mime_data.set_data_as_string(LAYER_MIME_TYPE, json.dumps(mime_dict))
Exemple #12
0
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"] = display_item.project.create_specifier(
            display_item).write()
    if graphic:
        mime_data_content[
            "graphic_specifier"] = graphic.project.create_specifier(
                graphic).write()
    mime_data.set_data_as_string(DATA_SOURCE_MIME_TYPE,
                                 json.dumps(mime_data_content))
Exemple #13
0
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))
Exemple #14
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 #15
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 #16
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
Exemple #17
0
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))
Exemple #18
0
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))