issues/527 issues/528

This commit is contained in:
恍兮惚兮 2024-02-23 11:50:25 +08:00
parent 31f04609fc
commit 18c9608c3d
24 changed files with 92 additions and 33 deletions

View File

@ -38,11 +38,10 @@ class _autolock:
def __del__(self):
self.lock.release()
class MAINUI() :
def __init__(self,app) -> None:
def __init__(self) -> None:
super().__init__()
self.lasttranslatorindex=0
self.usefultranslators=0
self.app=app
self.translators={}
self.cishus={}
self.reader=None

View File

@ -74,7 +74,7 @@ if __name__ == "__main__" :
getQMessageBox(None,"错误","当前路径读写权限不足,请使用管理员权限运行!")
os._exit(0)
gobject.baseobject=MAINUI(app)
gobject.baseobject=MAINUI()
gobject.baseobject.checklang()
gobject.baseobject.aa()
app.exit(app.exec_())

View File

@ -1,7 +1,7 @@
from PyQt5.QtWidgets import QWidget,QDesktopWidget,QMainWindow,QLabel,QPushButton,QStatusBar,QDialog,QApplication
from PyQt5.QtWidgets import QMenu,QDesktopWidget,QMainWindow,QLabel,QAction,QStatusBar,QDialog,QApplication
from PyQt5.QtGui import QBitmap,QPainter,QPen,QColor,QFont,QMouseEvent,QCursor
from PyQt5.QtCore import Qt,QPoint,QRect,QEvent,pyqtSignal
from myutils.config import _TR
import gobject
from myutils.config import globalconfig
from gui.resizeablemainwindow import Mainw
@ -19,9 +19,19 @@ class rangeadjust(Mainw) :
self._rect=None
self.setWindowFlags(Qt.WindowStaysOnTopHint | Qt.FramelessWindowHint | Qt.Tool)
self.setAttribute(Qt.WA_TranslucentBackground)
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.showmenu)
for s in self.cornerGrips:
s.raise_()
def showmenu(self,p):
menu=QMenu(self )
close=QAction(_TR("关闭"))
menu.addAction(close)
action=menu.exec(self.mapToGlobal(p))
if action==close:
self._rect=None
self.close()
def setstyle(self):
self.label.setStyleSheet(" border:%spx solid %s; background-color: rgba(0,0,0, 0.01)" %(globalconfig['ocrrangewidth'],globalconfig['ocrrangecolor'] ))
def mouseMoveEvent(self, e ) :
@ -39,7 +49,8 @@ class rangeadjust(Mainw) :
self._endPos = None
def moveEvent(self,e):
rect = self.geometry()
self._rect=[(rect.left()+globalconfig['ocrrangewidth'],rect.top()+globalconfig['ocrrangewidth']),(rect.right()-globalconfig['ocrrangewidth'],rect.bottom()-globalconfig['ocrrangewidth'])]
if self._rect:
self._rect=[(rect.left()+globalconfig['ocrrangewidth'],rect.top()+globalconfig['ocrrangewidth']),(rect.right()-globalconfig['ocrrangewidth'],rect.bottom()-globalconfig['ocrrangewidth'])]
def enterEvent(self, QEvent) :
self.drag_label.setStyleSheet("background-color:rgba(0,0,0, 0.1)")
def leaveEvent(self, QEvent):
@ -48,11 +59,17 @@ class rangeadjust(Mainw) :
self.label.setGeometry(0, 0, self.width(), self.height())
rect = self.geometry()
self._rect=[(rect.left()+globalconfig['ocrrangewidth'],rect.top()+globalconfig['ocrrangewidth']),(rect.right()-globalconfig['ocrrangewidth'],rect.bottom()-globalconfig['ocrrangewidth'])]
if self._rect:
self._rect=[(rect.left()+globalconfig['ocrrangewidth'],rect.top()+globalconfig['ocrrangewidth']),(rect.right()-globalconfig['ocrrangewidth'],rect.bottom()-globalconfig['ocrrangewidth'])]
super(rangeadjust, self).resizeEvent(a0)
def getrect(self):
return self._rect
def setrect(self,rect):
self._rect=rect
if rect:
(x1,y1),(x2,y2)=rect
self.setGeometry(x1-globalconfig['ocrrangewidth'],y1-globalconfig['ocrrangewidth'],x2-x1+2*globalconfig['ocrrangewidth'],y2-y1+2*globalconfig['ocrrangewidth'])
self.show()
class rangeselct(QMainWindow) :
def __init__(self, parent ) :

View File

@ -50,6 +50,8 @@ def getocrgrid(self) :
[],
[(("多重区域模式"),12),getsimpleswitch(globalconfig ,'multiregion')],
[(("记忆选定区域"),12),getsimpleswitch(globalconfig ,'rememberocrregions')],
[],
[(("OCR范围框颜色"),12),(getcolorbutton(globalconfig,'ocrrangecolor',callback=lambda : selectcolor(self,globalconfig,'ocrrangecolor',self.ocrrangecolor_button,callback=lambda :gobject.baseobject.textsource.setstyle()),name='ocrrangecolor_button',parent=self),1)],
[(("OCR范围框宽度"),12),(getspinbox(1,100,globalconfig,'ocrrangewidth' ,callback=lambda x: gobject.baseobject.textsource.setstyle() ),4)],
[(("选取OCR范围后立即进行一次识别"),12),getsimpleswitch(globalconfig ,'ocrafterrangeselect')],

View File

@ -669,12 +669,12 @@ class QUnFrameWindow(resizableframeless):
self.tray.hide()
self.tray = None
self.hide()
saveallconfig()
if gobject.baseobject.textsource:
gobject.baseobject.textsource=None
saveallconfig()
endsubprocs()
os._exit(0)

View File

@ -382,7 +382,10 @@ def selectcolor(parent,configdict,configkey,button,item=None,name=None,callback=
configdict[configkey]=color.name()
if callback:
callback()
try:
callback()
except:
print_exc()
def getboxlayout(widgets,lc=QHBoxLayout):
cp_layout=lc()

View File

@ -45,6 +45,11 @@ class ocrtext(basetext):
self.range_ui = []
self.timestamp=time.time()
super(ocrtext,self ).__init__('0','ocr')
if globalconfig['rememberocrregions']:
for region in globalconfig['ocrregions']:
if region:
self.newrangeadjustor()
self.setrect(region)
def newrangeadjustor(self):
if len(self.range_ui)==0 or globalconfig['multiregion']:
self.range_ui.append(rangeadjust(gobject.baseobject.translation_ui))
@ -56,13 +61,13 @@ class ocrtext(basetext):
for _r in self.range_ui:
_r.move(_r.pos().x()+ x,_r.pos().y()+ y)
def setrect(self,rect):
(x1,y1),(x2,y2)=rect
self.range_ui[-1].setGeometry(x1-globalconfig['ocrrangewidth'],y1-globalconfig['ocrrangewidth'],x2-x1+2*globalconfig['ocrrangewidth'],y2-y1+2*globalconfig['ocrrangewidth'])
self.range_ui[-1].show()
self.range_ui[-1].setrect(rect)
def setstyle(self):
[_.setstyle() for _ in self.range_ui]
def showhiderangeui(self,b):
[_.setVisible(b) for _ in self.range_ui]
for _ in self.range_ui:
if _.getrect():
_.setVisible(b)
def gettextthread(self ):
if all([_.getrect() is None for _ in self.range_ui]):
time.sleep(1)
@ -155,6 +160,7 @@ class ocrtext(basetext):
def end(self):
globalconfig['ocrregions']=[_.getrect() for _ in self.range_ui]
[_.close() for _ in self.range_ui]
super().end()
ocr_end()
[_.close() for _ in self.range_ui]

View File

@ -97,6 +97,8 @@
500
],
"multiregion":false,
"rememberocrregions":false,
"ocrregions":[],
"textboxreadonly":true,
"ocr_stable_sim": 0,
"ocr_diff_sim": 0.95,

View File

@ -1,5 +1,5 @@
{
"version":"v2.37.0",
"version":"v2.37.1",
"language_list_show":["简体中文","日本語","English","Русский язык","Español","한국어","Français","繁體中文","Tiếng Việt","Türkçe","Polski","Українська Мова","Italiano","اللغة العربية","ภาษาไทย"] ,
"language_list_translator":["简体中文","日文","英文","俄语","西班牙语","韩语","法语","繁体中文","越南语","土耳其语","波兰语","乌克兰语","意大利语","阿拉伯语","泰语"],
"language_list_translator_inner":["zh", "ja", "en","ru","es","ko","fr","cht","vi","tr","pl","uk","it","ar","th"],

View File

@ -708,5 +708,7 @@
"正在使用日语模型作为代替,可能效果不佳": "استخدام النموذج الياباني بدلا من ذلك ، قد لا تعمل بشكل جيد",
"保持非重复字符": "الحفاظ على الطابع غير المتكرر",
"选择文本窗口中文本框只读": "حدد مربع النص للقراءة فقط في نافذة النص",
"多重区域模式": "وضع منطقة متعددة"
"多重区域模式": "وضع منطقة متعددة",
"记忆选定区域": "اختيار الذاكرة",
"关闭": "غلق"
}

View File

@ -708,5 +708,7 @@
"正在使用日语模型作为代替,可能效果不佳": "正在使用日語模型作為代替,可能效果不佳",
"保持非重复字符": "保持非重複字元",
"选择文本窗口中文本框只读": "選擇文字視窗中文字方塊只讀",
"多重区域模式": "多重區域模式"
"多重区域模式": "多重區域模式",
"记忆选定区域": "記憶選定區域",
"关闭": "關閉"
}

View File

@ -708,5 +708,7 @@
"正在使用日语模型作为代替,可能效果不佳": "Using Japanese models as a substitute may not be effective",
"保持非重复字符": "Keep non repeating characters",
"选择文本窗口中文本框只读": "Select read-only text boxes in the text window",
"多重区域模式": "Multi region mode"
"多重区域模式": "Multi region mode",
"记忆选定区域": "Memory selection area",
"关闭": "close"
}

View File

@ -708,5 +708,7 @@
"正在使用日语模型作为代替,可能效果不佳": "Se está utilizando el modelo japonés como sustituto y puede que no funcione bien",
"保持非重复字符": "Mantener caracteres no repetitivos",
"选择文本窗口中文本框只读": "Seleccione la ventana de texto en la que el cuadro de texto es de solo lectura",
"多重区域模式": "Modelo multiregional"
"多重区域模式": "Modelo multiregional",
"记忆选定区域": "Área seleccionada de memoria",
"关闭": "Cierre"
}

View File

@ -708,5 +708,7 @@
"正在使用日语模型作为代替,可能效果不佳": "Le modèle japonais est utilisé à la place, peut ne pas fonctionner aussi bien",
"保持非重复字符": "Garder les caractères non répétitifs",
"选择文本窗口中文本框只读": "Sélectionner une zone de texte en lecture seule dans la fenêtre de texte",
"多重区域模式": "Mode Multi - zones"
"多重区域模式": "Mode Multi - zones",
"记忆选定区域": "Mémoriser la zone sélectionnée",
"关闭": "Fermé"
}

View File

@ -708,5 +708,7 @@
"正在使用日语模型作为代替,可能效果不佳": "Utilizzare modelli giapponesi come sostituto potrebbe non essere efficace",
"保持非重复字符": "Mantieni caratteri non ripetuti",
"选择文本窗口中文本框只读": "Selezionare le caselle di testo di sola lettura nella finestra di testo",
"多重区域模式": "Modalità multi regione"
"多重区域模式": "Modalità multi regione",
"记忆选定区域": "Area di selezione della memoria",
"关闭": "chiudi"
}

View File

@ -708,5 +708,7 @@
"正在使用日语模型作为代替,可能效果不佳": "代替として日本語モデルを使用していますが、効果が低いかもしれません",
"保持非重复字符": "非反復文字の維持",
"选择文本窗口中文本框只读": "テキストウィンドウのテキストボックス読み取り専用を選択",
"多重区域模式": "複数領域モード"
"多重区域模式": "複数領域モード",
"记忆选定区域": "メモリ選択領域",
"关闭": "閉じる"
}

View File

@ -708,5 +708,7 @@
"正在使用日语模型作为代替,可能效果不佳": "일본어 모델을 대체하는 중입니다. 효과가 없을 수 있습니다",
"保持非重复字符": "비반복 문자 유지",
"选择文本窗口中文本框只读": "텍스트 선택 창의 텍스트 상자 읽기 전용",
"多重区域模式": "다중 영역 모드"
"多重区域模式": "다중 영역 모드",
"记忆选定区域": "선택한 영역 기억하기",
"关闭": "닫기"
}

View File

@ -708,5 +708,7 @@
"正在使用日语模型作为代替,可能效果不佳": "Używanie japońskich modeli jako substytutów może nie być skuteczne",
"保持非重复字符": "Zachowaj niepowtarzające się znaki",
"选择文本窗口中文本框只读": "Zaznaczanie pola tekstowe tylko do odczytu w oknie tekstowym",
"多重区域模式": "Tryb wielu regionów"
"多重区域模式": "Tryb wielu regionów",
"记忆选定区域": "Obszar wyboru pamięci",
"关闭": "zamknij"
}

View File

@ -708,5 +708,7 @@
"正在使用日语模型作为代替,可能效果不佳": "В качестве замены используется японская модель, которая может быть неэффективной",
"保持非重复字符": "Сохранить символ без повторения",
"选择文本窗口中文本框只读": "Выберите текстовое окно только для чтения",
"多重区域模式": "Многорегиональная модель"
"多重区域模式": "Многорегиональная модель",
"记忆选定区域": "Запоминание выбранной области",
"关闭": "Закрыть"
}

View File

@ -708,5 +708,7 @@
"正在使用日语模型作为代替,可能效果不佳": "ใช้แบบจำลองภาษาญี่ปุ่นแทนอาจไม่ได้ผล",
"保持非重复字符": "เก็บอักขระที่ไม่ซ้ำกัน",
"选择文本窗口中文本框只读": "เลือกกล่องข้อความในหน้าต่างข้อความ อ่านอย่างเดียว",
"多重区域模式": "โหมดหลายโซน"
"多重区域模式": "โหมดหลายโซน",
"记忆选定区域": "หน่วยความจำพื้นที่ที่เลือก",
"关闭": "ปิด"
}

View File

@ -708,5 +708,7 @@
"正在使用日语模型作为代替,可能效果不佳": "Japon modellerini yerine koymak etkili olmayabilir.",
"保持非重复字符": "Tekrarlamayan karakterleri tut",
"选择文本窗口中文本框只读": "Metin penceresindeki sadece okuyulmuş metin kutularını seçin",
"多重区域模式": "Çok bölge modu"
"多重区域模式": "Çok bölge modu",
"记忆选定区域": "Hafıza seçim alanı",
"关闭": "kapat"
}

View File

@ -708,5 +708,7 @@
"正在使用日语模型作为代替,可能效果不佳": "Використання японських моделей як заміни може бути неефективним",
"保持非重复字符": "Зберегти символи, які не повторюються",
"选择文本窗口中文本框只读": "Виберіть текстові поля для лише читання у текстовому вікні",
"多重区域模式": "Режим декількох регіонів"
"多重区域模式": "Режим декількох регіонів",
"记忆选定区域": "Область вибору пам' яті",
"关闭": "закрити"
}

View File

@ -708,5 +708,7 @@
"正在使用日语模型作为代替,可能效果不佳": "Các mô hình tiếng Nhật đang được sử dụng thay thế và có thể không hiệu quả",
"保持非重复字符": "Giữ các ký tự không trùng lặp",
"选择文本窗口中文本框只读": "Chọn hộp văn bản chỉ đọc trong cửa sổ văn bản",
"多重区域模式": "Chế độ đa vùng"
"多重区域模式": "Chế độ đa vùng",
"记忆选定区域": "Ghi nhớ vùng chọn",
"关闭": "Đóng cửa"
}

View File

@ -708,5 +708,7 @@
"正在使用日语模型作为代替,可能效果不佳": "",
"保持非重复字符": "",
"选择文本窗口中文本框只读": "",
"多重区域模式": ""
"多重区域模式": "",
"记忆选定区域": "",
"关闭": ""
}