diff --git a/ballontranslator/dl/__init__.py b/ballontranslator/dl/__init__.py index 8557e4ec..de7e1d1d 100644 --- a/ballontranslator/dl/__init__.py +++ b/ballontranslator/dl/__init__.py @@ -7,4 +7,4 @@ VALID_TEXTDETECTORS = list(TEXTDETECTORS.module_dict.keys()) VALID_TRANSLATORS = list(TRANSLATORS.module_dict.keys()) VALID_INPAINTERS = list(INPAINTERS.module_dict.keys()) -VALID_OCR = OCR.module_dict.keys() \ No newline at end of file +VALID_OCR = list(OCR.module_dict.keys()) \ No newline at end of file diff --git a/ballontranslator/ui/canvas.py b/ballontranslator/ui/canvas.py index 8c1bcaa5..d9cf24c7 100644 --- a/ballontranslator/ui/canvas.py +++ b/ballontranslator/ui/canvas.py @@ -130,7 +130,7 @@ def __init__(self, parent=None): self.ctrl_relesed = self.gv.ctrl_released self.vscroll_bar = self.gv.verticalScrollBar() self.hscroll_bar = self.gv.horizontalScrollBar() - self.default_cursor = self.gv.cursor() + # self.default_cursor = self.gv.cursor() self.rubber_band = self.addWidget(QRubberBand(QRubberBand.Shape.Rectangle)) self.rubber_band.hide() self.rubber_band_origin = None diff --git a/ballontranslator/ui/mainwindow.py b/ballontranslator/ui/mainwindow.py index 909dff70..fd0c7dd1 100644 --- a/ballontranslator/ui/mainwindow.py +++ b/ballontranslator/ui/mainwindow.py @@ -61,8 +61,6 @@ def __init__(self, app: QApplication, open_dir='', *args, **kwargs) -> None: if osp.exists(proj_dir): self.OpenProj(proj_dir) - - def setStyleSheet(self, styleSheet: str) -> None: self.imgtrans_progress_msgbox.setStyleSheet(styleSheet) self.export_doc_thread.progress_bar.setStyleSheet(styleSheet) diff --git a/ballontranslator/ui/textedit_area.py b/ballontranslator/ui/textedit_area.py index 60007a3a..d186161d 100644 --- a/ballontranslator/ui/textedit_area.py +++ b/ballontranslator/ui/textedit_area.py @@ -38,6 +38,7 @@ def __init__(self, idx, parent, *args, **kwargs): self.input_method_text = '' self.text_content_changed = False self.highlighting = False + self.ctrlv_pressed = False def block_all_signals(self, block: bool): self.blockSignals(block) @@ -62,31 +63,40 @@ def on_content_changed(self): self.text_content_changed = False if not self.highlighting: self.text_changed.emit() + if self.hasFocus() and not self.pre_editing and not self.highlighting: if not self.in_redo_undo: + change_from = self.change_from added_text = '' input_method_used = False - if self.input_method_from != -1: - added_text = self.input_method_text - change_from = self.input_method_from - input_method_used = True - - elif self.change_added > 0: - len_text = len(self.toPlainText()) + + if self.ctrlv_pressed: + self.ctrlv_pressed = False cursor = self.textCursor() - - if self.change_added > len_text: - self.change_added = 1 - change_from = self.textCursor().position() - 1 - input_method_used = True cursor.setPosition(change_from) - cursor.setPosition(change_from + self.change_added, QTextCursor.MoveMode.KeepAnchor) + cursor.setPosition(self.textCursor().position(), QTextCursor.MoveMode.KeepAnchor) added_text = cursor.selectedText() + + else: + if self.input_method_from != -1: + added_text = self.input_method_text + change_from = self.input_method_from + input_method_used = True + elif self.change_added > 0: + len_text = len(self.toPlainText()) + cursor = self.textCursor() + + if self.change_added > len_text: + self.change_added = 1 + change_from = self.textCursor().position() - 1 + input_method_used = True + cursor.setPosition(change_from) + cursor.setPosition(change_from + self.change_added, QTextCursor.MoveMode.KeepAnchor) + added_text = cursor.selectedText() self.propagate_user_edited.emit(change_from, added_text, input_method_used) - undo_steps = self.document().availableUndoSteps() new_steps = undo_steps - self.old_undo_steps if new_steps > 0: @@ -147,6 +157,9 @@ def keyPressEvent(self, e: QKeyEvent) -> None: e.accept() self.redo_signal.emit() return + elif e.key() == Qt.Key.Key_V: + self.ctrlv_pressed = True + return super().keyPressEvent(e) elif e.key() == Qt.Key.Key_Return: e.accept() self.textCursor().insertText('\n')