def file_drop(self, file: Path, destination_index: QModelIndex): self._select_drop_index(destination_index) order = int( destination_index.siblingAtColumn(Kg.ORDER).data(Qt.DisplayRole) or '-1') + 1 LOGGER.debug('File Drop@%s: %s', order, file.as_posix()) if file.suffix.casefold() in self.supported_file_types: cam_info_img = KnechtImageCameraInfo(file) cam_info_img.read_image() if cam_info_img.is_valid(): cam_item = self.view.editor.create.create_camera_item( file.name, cam_info_img.camera_info) cam_item.setData(Kg.ORDER, f'{order:03d}') self.view.editor.create_top_level_rows([cam_item]) else: if cam_info_img.file_is_valid and not cam_info_img.info_is_valid: self.view.info_overlay.display( _('Keine Kamera Daten in Datei gefunden.\n'), 3000) LOGGER.error('Camera data could not be found in %s', file.as_posix()) else: self.view.info_overlay.display( _('Konnte Datei mit Kamera Daten nicht lesen.\n'), 3000) LOGGER.error('Could not read file with camera data %s', file.as_posix()) else: self.view.file_dropped.emit(file) return # Validate created camera items self.camera_item_verification_timer.start(150)
def data(self, index: QModelIndex, role: int): left_col = index.siblingAtColumn(0) col = index.column() app = typing.cast(_InternalData, left_col.internalPointer()) if "data" not in app: # Folder if role == Qt.DisplayRole: if col == 0: return app["id"] elif role == Qt.DecorationRole: if col == 0: return QIcon.fromTheme("folder") return None if role in (Qt.DisplayRole, Qt.ToolTipRole): if col == 0: return app["data"]["appName"] elif col == 1: return app["data"]["appUrl"] elif col == 2: return app["data"]["description"] elif role == Qt.DecorationRole and col == 0: return self.store.icon(app["id"]) else: return None
def deleteFrame(self, index: QtC.QModelIndex) -> Tuple[PIL.Image.Image, float]: removeColumn = True columnCount = self.columnCount(QtC.QModelIndex()) - 1 for direction in range(self.directions()): if direction == index.row(): continue # Remove the column if all other directions *DON'T* have a frame in it removeColumn = removeColumn and (len(self.state.icons[direction]) != columnCount) # If this is the case, removing this frame should delete the final column if removeColumn: self.beginRemoveColumns(QtC.QModelIndex(), columnCount - 1, columnCount - 1) image = self.state.icons[index.row()].pop(index.column()) delay = self.state.delays[index.row()].pop(index.column()) if removeColumn: self.endRemoveColumns() newColumnCount = self.columnCount(QtC.QModelIndex()) if index.column() >= newColumnCount: self.dataChanged.emit(index, index.siblingAtColumn(newColumnCount - 1)) return (image, delay)
def get_order_data(index: QModelIndex, order: int = 0) -> int: if not index.isValid(): return 0 if order == 0: order_data = index.siblingAtColumn(Kg.ORDER).data(Qt.DisplayRole) if order_data and order_data.isdigit(): order = int(order_data) return order
def _fakom_item_pressed(self, prx_index: QModelIndex): if not prx_index.flags() & Qt.ItemIsSelectable: return self.fakom_tree.model().clear_filter() already_selected = False current_fa_name = prx_index.siblingAtColumn(Kg.NAME).data(Qt.DisplayRole) current_trim_idx = self.get_index_group_parent(prx_index) current_model_code = current_trim_idx.siblingAtColumn(Kg.VALUE).data(Qt.DisplayRole) # -- Lookup if index is already selected for model_code, fa_name_ls in self.wizard.session.data.fakom_selection.items(): if current_model_code == model_code: if current_fa_name in fa_name_ls: already_selected = True if already_selected: # Remove entry self.wizard.session.data.fakom_selection[current_model_code].remove(current_fa_name) if not self.wizard.session.data.fakom_selection[current_model_code]: self.wizard.session.data.fakom_selection.pop(current_model_code) else: # Add entry self.wizard.session.data.fakom_selection.update( {current_model_code: (self.wizard.session.data.fakom_selection.get(current_model_code) or []) + [current_fa_name] } ) # -- Style selected items with checkmark src_idx_selection_ls = list() for model_code, fa_src_idx, fa_item in self.iter_all_fakom_items(): if fa_src_idx.data(Qt.DisplayRole) in (self.wizard.session.data.fakom_selection.get(model_code) or []): self._style_index_checked(fa_src_idx) src_idx_selection_ls.append(fa_src_idx) else: if fa_src_idx.data(Qt.DecorationRole): self.fakom_tree.model().sourceModel().setData(fa_src_idx, QIcon(), Qt.DecorationRole) self.fakom_tree.model().apply_last_filter() # Empty selection if not src_idx_selection_ls: self.wizard.session.data.fakom_selection = dict() self.completeChanged.emit() self.result_tree.clear() return self.populate_result_tree(src_idx_selection_ls) self.completeChanged.emit()
def addFrame(self, index: QtC.QModelIndex, image: Optional[PIL.Image.Image] = None, delay: float = 0.0) -> None: if image is None: image = PIL.Image.new('RGBA', self.state.size) columnEnd = self.columnCount(QtC.QModelIndex()) - 1 # In this case, we're going to insert a column insertColumn = len(self.state.icons[index.row()]) == columnEnd if insertColumn: self.beginInsertColumns(QtC.QModelIndex(), columnEnd, columnEnd) self.state.icons[index.row()].insert(index.column(), image) self.state.delays[index.row()].insert(index.column(), delay) if insertColumn: self.endInsertColumns() self.dataChanged.emit( index, index.siblingAtColumn(self.columnCount(QtC.QModelIndex()) - 1))