Loading ballontranslator/dl/inpaint/lama.py +1 −2 Original line number Diff line number Diff line Loading @@ -247,9 +247,9 @@ class MPE(nn.Module): rel_pos_emb = self.rel_pos_emb(rel_pos).reshape(b, h, w, -1).permute(0, 3, 1, 2) * self.alpha5 direct = direct.reshape(b, h * w, 4).to(torch.float32) direct_emb = self.direct_emb(direct).reshape(b, h, w, -1).permute(0, 3, 1, 2) * self.alpha6 return rel_pos_emb, direct_emb class LamaFourier: def __init__(self, build_discriminator=True, use_mpe=False) -> None: # super().__init__() Loading @@ -268,7 +268,6 @@ class LamaFourier: 'enable_lfu': False } ) self.enable_fp16 = False self.discriminator = NLayerDiscriminator() if build_discriminator else None self.inpaint_only = False if use_mpe: Loading ballontranslator/ui/canvas.py +1 −6 Original line number Diff line number Diff line Loading @@ -385,13 +385,8 @@ class Canvas(QGraphicsScene): menu = QMenu() delete_act = menu.addAction(self.tr("Delete")) rst = menu.exec_(event.screenPos()) blk_item = self.txtblkShapeControl.blk_item selected = self.selectedItems() if rst == delete_act: if selected: self.delete_textblks.emit() elif blk_item: blk_item.delete() def on_hide_canvas(self): self.alt_pressed = False Loading ballontranslator/ui/scenetext_manager.py +39 −47 Original line number Diff line number Diff line Loading @@ -12,28 +12,31 @@ from .imgtranspanel import TextPanel, TextEditListScrollArea, SourceTextEdit, Tr from .texteditshapecontrol import TextBlkShapeControl class MoveItemCommand(QUndoCommand): def __init__(self, item: TextBlkItem, parent=None): super(MoveItemCommand, self).__init__(parent) self.item = item self.oldPos = item.oldPos self.newPos = item.pos() class MoveBlkItemsCommand(QUndoCommand): def __init__(self, items: List[TextBlkItem], parent=None): super(MoveBlkItemsCommand, self).__init__() self.items = items self.old_pos_lst = [] self.new_pos_lst = [] for item in items: self.old_pos_lst.append(item.oldPos) self.new_pos_lst.append(item.pos()) item.oldPos = item.pos() def redo(self): self.item.setPos(self.newPos) for item, new_pos in zip(self.items, self.new_pos_lst): item.setPos(new_pos) def undo(self): self.item.setPos(self.oldPos) for item, old_pos in zip(self.items, self.old_pos_lst): item.setPos(old_pos) def mergeWith(self, command: QUndoCommand): item = command.item if self.item != item: return False self.newPos = item.pos() if command.new_pos_lst == self.new_pos_lst: return True return False # according to https://doc.qt.io/qt-5/qundocommand.html # some of following commands are done twice after initialization class ReshapeItemCommand(QUndoCommand): def __init__(self, item: TextBlkItem, parent=None): super(ReshapeItemCommand, self).__init__(parent) Loading @@ -54,6 +57,7 @@ class ReshapeItemCommand(QUndoCommand): self.newRect = item.rect() return True class RotateItemCommand(QUndoCommand): def __init__(self, item: TextBlkItem, new_angle: float): super(RotateItemCommand, self).__init__() Loading @@ -76,6 +80,7 @@ class RotateItemCommand(QUndoCommand): self.new_angle = item.angle return True class OrientationItemCommand(QUndoCommand): def __init__(self, item: TextBlkItem, ctrl): super(OrientationItemCommand, self).__init__() Loading @@ -100,26 +105,6 @@ class OrientationItemCommand(QUndoCommand): self.oldVertical = command.oldVertical return True class DeleteItemCommand(QUndoCommand): def __init__(self, item: TextBlkItem, ctrl, parent=None): super().__init__(parent) self.item = item self.p_widget = ctrl.pairwidget_list[item.idx] self.ctrl: SceneTextManager = ctrl def redo(self): self.ctrl.deleteTextblkItem(self.item) def undo(self): self.ctrl.recoverTextblkItem(self.item, self.p_widget) def mergeWith(self, command: QUndoCommand): item = command.item if self.item != item: return False self.item = item self.p_widget = command.p_widget return True class CreateItemCommand(QUndoCommand): def __init__(self, blk_item: TextBlkItem, ctrl, parent=None): Loading @@ -141,8 +126,9 @@ class CreateItemCommand(QUndoCommand): self.blk_item = blk_item return True class DeleteItemListCommand(QUndoCommand): def __init__(self, blk_list: TextBlkItem, ctrl, parent=None): class DeleteBlkItemsCommand(QUndoCommand): def __init__(self, blk_list: List[TextBlkItem], ctrl, parent=None): super().__init__(parent) self.blk_list = [] self.pwidget_list = [] Loading Loading @@ -176,7 +162,7 @@ class SceneTextManager(QObject): self.canvas = canvas self.canvas.scalefactor_changed.connect(self.adjustSceneTextRect) self.canvas.end_create_textblock.connect(self.onEndCreateTextBlock) self.canvas.delete_textblks.connect(self.onDeleteTextBlks) self.canvas.delete_textblks.connect(self.onDeleteBlkItems) self.canvasUndoStack = self.canvas.undoStack self.txtblkShapeControl = canvas.txtblkShapeControl self.textpanel = textpanel Loading Loading @@ -266,7 +252,6 @@ class SceneTextManager(QObject): textblk_item.moved.connect(self.onTextBlkItemMoved) textblk_item.reshaped.connect(self.onTextBlkItemReshaped) textblk_item.rotated.connect(self.onTextBlkItemRotated) textblk_item.to_delete.connect(self.onDeleteTextBlkItem) textblk_item.content_changed.connect(self.onTextBlkItemContentChanged) textblk_item.doc_size_changed.connect(self.onTextBlkItemSizeChanged) return textblk_item Loading Loading @@ -353,14 +338,19 @@ class SceneTextManager(QObject): self.canvas.hovering_textblkitem = blk_item def onTextBlkItemHoverLeave(self, blk_id: int): blk_item = self.textblk_item_list[blk_id] self.canvas.hovering_textblkitem = None def onTextBlkItemMoving(self, item: TextBlkItem): self.txtblkShapeControl.updateBoundingRect() def onTextBlkItemMoved(self, item: TextBlkItem): self.canvasUndoStack.push(MoveItemCommand(item)) def onTextBlkItemMoved(self): selections = self.canvas.selectedItems() selected_blks = [] for selection in selections: if isinstance(selection, TextBlkItem): selected_blks.append(selection) if len(selected_blks) > 0: self.canvasUndoStack.push(MoveBlkItemsCommand(selected_blks, self)) def onTextBlkItemReshaped(self, item: TextBlkItem): self.canvasUndoStack.push(ReshapeItemCommand(item)) Loading @@ -370,12 +360,14 @@ class SceneTextManager(QObject): if blk_item: self.canvasUndoStack.push(RotateItemCommand(blk_item, new_angle)) def onDeleteTextBlkItem(self, item: TextBlkItem): self.canvasUndoStack.push(DeleteItemCommand(item, self)) def onDeleteTextBlks(self): def onDeleteBlkItems(self): selections = self.canvas.selectedItems() self.canvasUndoStack.push(DeleteItemListCommand(selections, self)) selected_blks = [] for selection in selections: if isinstance(selection, TextBlkItem): selected_blks.append(selection) if len(selected_blks) > 0: self.canvasUndoStack.push(DeleteBlkItemsCommand(selected_blks, self)) def onEndCreateTextBlock(self, rect: QRectF): scale_f = self.canvas.scale_factor Loading ballontranslator/ui/textitem.py +2 −6 Original line number Diff line number Diff line Loading @@ -20,10 +20,9 @@ class TextBlkItem(QGraphicsTextItem): hover_enter = pyqtSignal(int) hover_leave = pyqtSignal(int) hover_move = pyqtSignal(int) moved = pyqtSignal(QGraphicsTextItem) moved = pyqtSignal() moving = pyqtSignal(QGraphicsTextItem) rotated = pyqtSignal(float) to_delete = pyqtSignal(QGraphicsTextItem) reshaped = pyqtSignal(QGraphicsTextItem) content_changed = pyqtSignal(QGraphicsTextItem) leftbutton_pressed = pyqtSignal(int) Loading Loading @@ -394,7 +393,7 @@ class TextBlkItem(QGraphicsTextItem): def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent) -> None: if event.button() == Qt.LeftButton: if self.oldPos != self.pos(): self.moved.emit(self) self.moved.emit() super().mouseReleaseEvent(event) def hoverMoveEvent(self, event: QGraphicsSceneHoverEvent) -> None: Loading Loading @@ -438,9 +437,6 @@ class TextBlkItem(QGraphicsTextItem): def alignment(self): return self.document().defaultTextOption().alignment() def delete(self): self.to_delete.emit(self) def get_fontformat(self) -> FontFormat: fmt = self.textCursor().charFormat() font = fmt.font() Loading Loading
ballontranslator/dl/inpaint/lama.py +1 −2 Original line number Diff line number Diff line Loading @@ -247,9 +247,9 @@ class MPE(nn.Module): rel_pos_emb = self.rel_pos_emb(rel_pos).reshape(b, h, w, -1).permute(0, 3, 1, 2) * self.alpha5 direct = direct.reshape(b, h * w, 4).to(torch.float32) direct_emb = self.direct_emb(direct).reshape(b, h, w, -1).permute(0, 3, 1, 2) * self.alpha6 return rel_pos_emb, direct_emb class LamaFourier: def __init__(self, build_discriminator=True, use_mpe=False) -> None: # super().__init__() Loading @@ -268,7 +268,6 @@ class LamaFourier: 'enable_lfu': False } ) self.enable_fp16 = False self.discriminator = NLayerDiscriminator() if build_discriminator else None self.inpaint_only = False if use_mpe: Loading
ballontranslator/ui/canvas.py +1 −6 Original line number Diff line number Diff line Loading @@ -385,13 +385,8 @@ class Canvas(QGraphicsScene): menu = QMenu() delete_act = menu.addAction(self.tr("Delete")) rst = menu.exec_(event.screenPos()) blk_item = self.txtblkShapeControl.blk_item selected = self.selectedItems() if rst == delete_act: if selected: self.delete_textblks.emit() elif blk_item: blk_item.delete() def on_hide_canvas(self): self.alt_pressed = False Loading
ballontranslator/ui/scenetext_manager.py +39 −47 Original line number Diff line number Diff line Loading @@ -12,28 +12,31 @@ from .imgtranspanel import TextPanel, TextEditListScrollArea, SourceTextEdit, Tr from .texteditshapecontrol import TextBlkShapeControl class MoveItemCommand(QUndoCommand): def __init__(self, item: TextBlkItem, parent=None): super(MoveItemCommand, self).__init__(parent) self.item = item self.oldPos = item.oldPos self.newPos = item.pos() class MoveBlkItemsCommand(QUndoCommand): def __init__(self, items: List[TextBlkItem], parent=None): super(MoveBlkItemsCommand, self).__init__() self.items = items self.old_pos_lst = [] self.new_pos_lst = [] for item in items: self.old_pos_lst.append(item.oldPos) self.new_pos_lst.append(item.pos()) item.oldPos = item.pos() def redo(self): self.item.setPos(self.newPos) for item, new_pos in zip(self.items, self.new_pos_lst): item.setPos(new_pos) def undo(self): self.item.setPos(self.oldPos) for item, old_pos in zip(self.items, self.old_pos_lst): item.setPos(old_pos) def mergeWith(self, command: QUndoCommand): item = command.item if self.item != item: return False self.newPos = item.pos() if command.new_pos_lst == self.new_pos_lst: return True return False # according to https://doc.qt.io/qt-5/qundocommand.html # some of following commands are done twice after initialization class ReshapeItemCommand(QUndoCommand): def __init__(self, item: TextBlkItem, parent=None): super(ReshapeItemCommand, self).__init__(parent) Loading @@ -54,6 +57,7 @@ class ReshapeItemCommand(QUndoCommand): self.newRect = item.rect() return True class RotateItemCommand(QUndoCommand): def __init__(self, item: TextBlkItem, new_angle: float): super(RotateItemCommand, self).__init__() Loading @@ -76,6 +80,7 @@ class RotateItemCommand(QUndoCommand): self.new_angle = item.angle return True class OrientationItemCommand(QUndoCommand): def __init__(self, item: TextBlkItem, ctrl): super(OrientationItemCommand, self).__init__() Loading @@ -100,26 +105,6 @@ class OrientationItemCommand(QUndoCommand): self.oldVertical = command.oldVertical return True class DeleteItemCommand(QUndoCommand): def __init__(self, item: TextBlkItem, ctrl, parent=None): super().__init__(parent) self.item = item self.p_widget = ctrl.pairwidget_list[item.idx] self.ctrl: SceneTextManager = ctrl def redo(self): self.ctrl.deleteTextblkItem(self.item) def undo(self): self.ctrl.recoverTextblkItem(self.item, self.p_widget) def mergeWith(self, command: QUndoCommand): item = command.item if self.item != item: return False self.item = item self.p_widget = command.p_widget return True class CreateItemCommand(QUndoCommand): def __init__(self, blk_item: TextBlkItem, ctrl, parent=None): Loading @@ -141,8 +126,9 @@ class CreateItemCommand(QUndoCommand): self.blk_item = blk_item return True class DeleteItemListCommand(QUndoCommand): def __init__(self, blk_list: TextBlkItem, ctrl, parent=None): class DeleteBlkItemsCommand(QUndoCommand): def __init__(self, blk_list: List[TextBlkItem], ctrl, parent=None): super().__init__(parent) self.blk_list = [] self.pwidget_list = [] Loading Loading @@ -176,7 +162,7 @@ class SceneTextManager(QObject): self.canvas = canvas self.canvas.scalefactor_changed.connect(self.adjustSceneTextRect) self.canvas.end_create_textblock.connect(self.onEndCreateTextBlock) self.canvas.delete_textblks.connect(self.onDeleteTextBlks) self.canvas.delete_textblks.connect(self.onDeleteBlkItems) self.canvasUndoStack = self.canvas.undoStack self.txtblkShapeControl = canvas.txtblkShapeControl self.textpanel = textpanel Loading Loading @@ -266,7 +252,6 @@ class SceneTextManager(QObject): textblk_item.moved.connect(self.onTextBlkItemMoved) textblk_item.reshaped.connect(self.onTextBlkItemReshaped) textblk_item.rotated.connect(self.onTextBlkItemRotated) textblk_item.to_delete.connect(self.onDeleteTextBlkItem) textblk_item.content_changed.connect(self.onTextBlkItemContentChanged) textblk_item.doc_size_changed.connect(self.onTextBlkItemSizeChanged) return textblk_item Loading Loading @@ -353,14 +338,19 @@ class SceneTextManager(QObject): self.canvas.hovering_textblkitem = blk_item def onTextBlkItemHoverLeave(self, blk_id: int): blk_item = self.textblk_item_list[blk_id] self.canvas.hovering_textblkitem = None def onTextBlkItemMoving(self, item: TextBlkItem): self.txtblkShapeControl.updateBoundingRect() def onTextBlkItemMoved(self, item: TextBlkItem): self.canvasUndoStack.push(MoveItemCommand(item)) def onTextBlkItemMoved(self): selections = self.canvas.selectedItems() selected_blks = [] for selection in selections: if isinstance(selection, TextBlkItem): selected_blks.append(selection) if len(selected_blks) > 0: self.canvasUndoStack.push(MoveBlkItemsCommand(selected_blks, self)) def onTextBlkItemReshaped(self, item: TextBlkItem): self.canvasUndoStack.push(ReshapeItemCommand(item)) Loading @@ -370,12 +360,14 @@ class SceneTextManager(QObject): if blk_item: self.canvasUndoStack.push(RotateItemCommand(blk_item, new_angle)) def onDeleteTextBlkItem(self, item: TextBlkItem): self.canvasUndoStack.push(DeleteItemCommand(item, self)) def onDeleteTextBlks(self): def onDeleteBlkItems(self): selections = self.canvas.selectedItems() self.canvasUndoStack.push(DeleteItemListCommand(selections, self)) selected_blks = [] for selection in selections: if isinstance(selection, TextBlkItem): selected_blks.append(selection) if len(selected_blks) > 0: self.canvasUndoStack.push(DeleteBlkItemsCommand(selected_blks, self)) def onEndCreateTextBlock(self, rect: QRectF): scale_f = self.canvas.scale_factor Loading
ballontranslator/ui/textitem.py +2 −6 Original line number Diff line number Diff line Loading @@ -20,10 +20,9 @@ class TextBlkItem(QGraphicsTextItem): hover_enter = pyqtSignal(int) hover_leave = pyqtSignal(int) hover_move = pyqtSignal(int) moved = pyqtSignal(QGraphicsTextItem) moved = pyqtSignal() moving = pyqtSignal(QGraphicsTextItem) rotated = pyqtSignal(float) to_delete = pyqtSignal(QGraphicsTextItem) reshaped = pyqtSignal(QGraphicsTextItem) content_changed = pyqtSignal(QGraphicsTextItem) leftbutton_pressed = pyqtSignal(int) Loading Loading @@ -394,7 +393,7 @@ class TextBlkItem(QGraphicsTextItem): def mouseReleaseEvent(self, event: QGraphicsSceneMouseEvent) -> None: if event.button() == Qt.LeftButton: if self.oldPos != self.pos(): self.moved.emit(self) self.moved.emit() super().mouseReleaseEvent(event) def hoverMoveEvent(self, event: QGraphicsSceneHoverEvent) -> None: Loading Loading @@ -438,9 +437,6 @@ class TextBlkItem(QGraphicsTextItem): def alignment(self): return self.document().defaultTextOption().alignment() def delete(self): self.to_delete.emit(self) def get_fontformat(self) -> FontFormat: fmt = self.textCursor().charFormat() font = fmt.font() Loading