def dropEvent(self, event: QtGui.QDropEvent) -> None: item: QtWidgets.QTreeWidgetItem = self.itemAt(event.pos()) if not item: return event.setDropAction(Qt.IgnoreAction) source = self.preset_for_item(self.currentItem()) target = self.preset_for_item(item) if source is None or target is None: return event.setDropAction(Qt.IgnoreAction) if source.game != target.game or source.base_preset_uuid is None: return event.setDropAction(Qt.IgnoreAction) try: source_preset = source.get_preset() except InvalidPreset: return event.setDropAction(Qt.IgnoreAction) self.window_manager.preset_manager.add_new_preset( VersionedPreset.with_preset( dataclasses.replace(source_preset, base_preset_uuid=target.uuid))) return super().dropEvent(event)
def dropEvent(self, event: QtGui.QDropEvent): super().dropEvent(event) if event.mimeData().hasFormat("text/uri-list"): pos = QtCore.QRect() pos.setX(int(event.pos().x())) pos.setY(int(event.pos().y())) pos.setWidth(200) # TODO find a better way to set default width db = QtCore.QMimeDatabase() if "image" in db.mimeTypeForUrl(event.mimeData().urls()[0]).name(): image = event.mimeData().urls()[0].url() id = self._next_id("Image") item = PageItem(id, pos, img=image, height_from_width=True) self._add_item(item) elif "application/octet-stream" in db.mimeTypeForUrl( event.mimeData().urls()[0]).name(): # If it's a stream, we need to download it. However, that could be arbitrarily huge # For now, we're going to base the decision on the file extension. url = event.mimeData().urls()[0].url() if url.endswith(".png") or url.endswith( ".jpg") or url.endswith(".jpeg") or url.endswith( ".gif"): id = self._next_id("Image") item = PageItem(id, pos, img=url, height_from_width=True) self._add_item(item) event.accept()
def dropEvent(self, event: QtGui.QDropEvent): item_index = self.indexAt(event.pos()) item = self.model.itemFromIndex(item_index) morpheme_item = self._current_row[0] if isinstance(item, MorphemeItem): parent_index = item_index.parent() parent = self.model.itemFromIndex(parent_index) parent.appendRow(self._current_row) self.model.dictionary.edit(morpheme_item.morpheme.dict_id, 'is_stem', item.morpheme.is_stem) elif isinstance(item, FixedItem): item.appendRow(self._current_row) if item.text() == 'Stems': self.model.dictionary.edit(morpheme_item.morpheme.dict_id, 'is_stem', True) elif item.text() == 'Affixes': self.model.dictionary.edit(morpheme_item.morpheme.dict_id, 'is_stem', True) else: self.model.dictionary.edit(morpheme_item.morpheme.dict_id, 'is_stem', None) else: raise TypeError('{} instead of MorphemeItem ' 'or FixedItem'.format(type(item))) self._current_row = None
def drop_event(self, e: QDropEvent): mime: QMimeData = e.mimeData() src = e.source() # -- File drop -- if mime.hasUrls(): destination_index = self.view.indexAt(e.pos()) for url in mime.urls(): local_path = Path(url.toLocalFile()) if not path_exists(local_path): continue self.file_drop(local_path, destination_index) e.accept() return # --- Internal View Drops --- if not isinstance(src, self.view.__class__): e.ignore() return e.setDropAction(Qt.MoveAction) if src is not self.view: e.setDropAction(Qt.CopyAction) if e.keyboardModifiers() == Qt.ShiftModifier: e.setDropAction(Qt.CopyAction) # -- Copy drop -- if e.dropAction() is Qt.CopyAction: destination_index = self.view.indexAt(e.pos()) self.copy_drop(src, destination_index) e.accept() # -- Drag move -- if e.dropAction() is Qt.MoveAction: destination_index = self.view.indexAt(e.pos()) self.move_drop(destination_index) # Ignore default view behaviour e.ignore()
def dropEvent(self, event: QDropEvent): dir_or_path = event.mimeData().text().replace('file://', '').replace( '\r', '').replace('\n', '') fns = [] if os.path.isdir(dir_or_path): if not dir_or_path.endswith('/'): dir_or_path += '/' for f in os.listdir(dir_or_path): fns.append(dir_or_path + f) else: fns.append(dir_or_path) # sorted by the last interger preceding the .tif fns = sorted(fns, key=lambda x: int(re.search('(\d+)\.tif', x).group(1))) if self.vol1.geometry().contains(event.pos()): self.vol1_fns = fns.copy() self.Vol1show(1) # start with 1 not 0 self.refresh_plot_and_label(self.vol1_fns, self.accumulated_value1, self.accum_plot1) elif self.vol2.geometry().contains(event.pos()): self.vol2_fns = fns.copy() self.Vol2show(1) # start with 1 not 0 self.refresh_plot_and_label(self.vol2_fns, self.accumulated_value2, self.accum_plot2) else: # ignore if been dropped at elsewhere pass if self.vol1_fns and self.vol2_fns is not None: if self.vol1_fns.__len__ != self.vol2_fns.__len__: self.log_window(Msg='vol1 and vol2 do not have same shape') # set slider and LCD max_slide = len( self.vol1_fns if self.vol1_fns is not None else self.vol2_fns) self.Slider.setMaximum(max_slide) self.setLED(actual=1, total=max_slide)
def dropEvent(self, event: QtGui.QDropEvent) -> None: # pragma: no cover dest = self.tabAt(event.pos()) src, ok = event.mimeData().data("application/x-pew2tabbar").toInt() if ok and event.source() == self: self.moveTab(src, dest) event.acceptProposedAction() elif ok and isinstance(event.source(), ViewTabBar): text = event.source().tabText(src) widget = event.source().view.stack.widget(src) event.source().view.removeTab(src) index = self.view.insertTab(dest, text, widget) self.setCurrentIndex(index) widget.activate() event.acceptProposedAction() else: event.rejectProposedAction()
def dropEvent(self, a0: QtGui.QDropEvent) -> None: drag_end_row = self.indexAt(a0.pos()).row() self.model().moveRow(QModelIndex(), self.drag_start_row, QModelIndex(), drag_end_row) a0.acceptProposedAction()