def test_dropping_data_source_from_different_project_works(self): # create three data items, two in the first project, one in the second project. # create the computation with the first two. then simulate a drag and drop from # the second project. recompute and make sure no error occur. with create_memory_profile_context() as profile_context: profile = profile_context.create_profile() profile.add_project_memory() document_model = DocumentModel.DocumentModel(profile=profile) document_controller = DocumentController.DocumentController(self.app.ui, document_model, workspace_id="library") with contextlib.closing(document_controller): data1 = ((numpy.abs(numpy.random.randn(8, 8)) + 1) * 10).astype(numpy.uint32) data2 = ((numpy.abs(numpy.random.randn(8, 8)) + 1) * 10).astype(numpy.uint32) data3 = ((numpy.abs(numpy.random.randn(8, 8)) + 1) * 10).astype(numpy.uint32) data_item1 = DataItem.DataItem(data1) data_item2 = DataItem.DataItem(data2) data_item3 = DataItem.DataItem(data3) document_model.append_data_item(data_item1, project=document_model.profile.projects[0]) document_model.append_data_item(data_item2, project=document_model.profile.projects[0]) document_model.append_data_item(data_item3, project=document_model.profile.projects[1]) display_item1 = document_model.get_display_item_for_data_item(data_item1) display_item2 = document_model.get_display_item_for_data_item(data_item2) display_item3 = document_model.get_display_item_for_data_item(data_item3) document_controller.select_display_items_in_data_panel([display_item1, display_item2]) document_controller.perform_action("processing.cross_correlate") computation = document_model.computations[-1] document_model.recompute_all() self.assertIsNone(document_model.computations[0].error_text) mime_data = self.app.ui.create_mime_data() MimeTypes.mime_data_put_data_source(mime_data, display_item3, None) ComputationPanel.drop_mime_data(document_controller, computation, computation.variables[1], mime_data, 0, 0) document_model.recompute_all() self.assertIsNone(document_model.computations[0].error_text)
def drag_started(self, ui: UserInterface.UserInterface, x: int, y: int, modifiers: UserInterface.KeyboardModifiers) -> typing.Tuple[typing.Optional[UserInterface.MimeData], typing.Optional[numpy.ndarray]]: if self.__display_item: mime_data = self.ui.create_mime_data() if self.__display_item: MimeTypes.mime_data_put_display_item(mime_data, self.__display_item) thumbnail_data = self.calculate_thumbnail_data() return mime_data, thumbnail_data return None, None
def drag_started(self, ui: UserInterface.UserInterface, x: int, y: int, modifiers: UserInterface.KeyboardModifiers) -> typing.Tuple[typing.Optional[UserInterface.MimeData], typing.Optional[numpy.ndarray]]: if self.__display_item: mime_data = self.ui.create_mime_data() if self.__display_item: MimeTypes.mime_data_put_display_item(mime_data, self.__display_item) thumbnail_data = self.calculate_thumbnail_data() if thumbnail_data is not None: # scaling is very slow thumbnail_data = Image.get_rgba_data_from_rgba(Image.scaled(Image.get_rgba_view_from_rgba_data(thumbnail_data), Geometry.IntSize(w=80, h=80))) return mime_data, thumbnail_data return None, None
def populate_mime_data_for_drag(self, mime_data: UserInterface.MimeData, size: Geometry.IntSize): if self.__display_item: MimeTypes.mime_data_put_display_item(mime_data, self.__display_item) rgba_image_data = self.__thumbnail_source.thumbnail_data thumbnail = Image.get_rgba_data_from_rgba( Image.scaled( Image.get_rgba_view_from_rgba_data(rgba_image_data), (size.width, size.height))) if rgba_image_data is not None else None return True, thumbnail return False, None
def populate_mime_data_for_drag( self, mime_data: UserInterface.MimeData, size: Geometry.IntSize ) -> typing.Tuple[bool, typing.Optional[_NDArray]]: if self.__display_item: MimeTypes.mime_data_put_display_item(mime_data, self.__display_item) rgba_image_data = self.__thumbnail_source.thumbnail_data if self.__thumbnail_source else None thumbnail = Image.get_rgba_data_from_rgba( Image.scaled( Image.get_rgba_view_from_rgba_data(rgba_image_data), (80, 80))) if rgba_image_data is not None else None return True, thumbnail return False, None
def drag_started(self, index: int, x: int, y: int, modifiers: UserInterface.KeyboardModifiers) -> None: mime_data = None thumbnail_data = None display_item_adapters = self.selected_display_item_adapters if len(display_item_adapters) == 1: mime_data, thumbnail_data = self.__display_item_adapters[index].drag_started(self.ui, x, y, modifiers) elif len(display_item_adapters) > 1: mime_data = self.ui.create_mime_data() anchor_index = self.__selection.anchor_index or 0 MimeTypes.mime_data_put_display_items(mime_data, [display_item_adapter.display_item for display_item_adapter in display_item_adapters if display_item_adapter.display_item]) thumbnail_data = self.__display_item_adapters[anchor_index].calculate_thumbnail_data() if mime_data: if self.on_drag_started: self.on_drag_started(mime_data, thumbnail_data)
def item_can_drop_mime_data(self, mime_data: UserInterface.MimeData, action: str, drop_index: int) -> bool: list_display_item = self.items[drop_index] is_smart_collection = list_display_item.is_smart_collection if list_display_item else False display_items = MimeTypes.mime_data_get_display_items( mime_data, list_display_item.document_model) if list_display_item and not is_smart_collection and display_items: # if the display item exists in this document, then it is copied to the # target group. if it doesn't exist in this document, then it is coming # from another document and can't be handled here. return True return False
def item_drop_mime_data(self, mime_data: UserInterface.MimeData, action: str, drop_index: int) -> str: list_display_item = self.items[drop_index] is_smart_collection = list_display_item.is_smart_collection if list_display_item else False display_items = MimeTypes.mime_data_get_display_items( mime_data, list_display_item.document_model) if list_display_item and not is_smart_collection and display_items: # if the display item exists in this document, then it is copied to the # target group. if it doesn't exist in this document, then it is coming # from another document and can't be handled here. document_controller = list_display_item.document_controller data_group = list_display_item.data_group command = document_controller.create_insert_data_group_display_items_command( data_group, len(data_group.display_items), display_items) command.perform() document_controller.push_undo_command(command) return "copy" return "ignore"