Skip to content

Commit

Permalink
fix #56
Browse files Browse the repository at this point in the history
  • Loading branch information
dmMaze committed Nov 29, 2022
1 parent 02b5e7f commit bc7060c
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 18 deletions.
2 changes: 1 addition & 1 deletion ballontranslator/dl/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
VALID_OCR = list(OCR.module_dict.keys())
2 changes: 1 addition & 1 deletion ballontranslator/ui/canvas.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions ballontranslator/ui/mainwindow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
41 changes: 27 additions & 14 deletions ballontranslator/ui/textedit_area.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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')
Expand Down

0 comments on commit bc7060c

Please sign in to comment.