Skip to content

Commit

Permalink
<feature> support detect network delay for each translation engine
Browse files Browse the repository at this point in the history
update version to v2.3.9
  • Loading branch information
anonymousException committed Jun 11, 2024
1 parent b413ae9 commit 65686a4
Show file tree
Hide file tree
Showing 34 changed files with 697 additions and 561 deletions.
9 changes: 7 additions & 2 deletions src/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ def setupUi(self, EngineDialog):
self.label_2.setWordWrap(True)
self.keyEdit = QLineEdit(EngineDialog)
self.keyEdit.setObjectName(u"keyEdit")
self.keyEdit.setGeometry(QRect(240, 68, 761, 20))
self.keyEdit.setGeometry(QRect(240, 68, 491, 20))
self.label_3 = QLabel(EngineDialog)
self.label_3.setObjectName(u"label_3")
self.label_3.setGeometry(QRect(20, 117, 211, 31))
self.label_3.setWordWrap(True)
self.secretEdit = QLineEdit(EngineDialog)
self.secretEdit.setObjectName(u"secretEdit")
self.secretEdit.setGeometry(QRect(240, 120, 761, 20))
self.secretEdit.setGeometry(QRect(240, 120, 491, 20))
self.confirmButton = QPushButton(EngineDialog)
self.confirmButton.setObjectName(u"confirmButton")
self.confirmButton.setGeometry(QRect(20, 160, 981, 24))
Expand All @@ -53,6 +53,7 @@ def setupUi(self, EngineDialog):
font = QFont()
font.setUnderline(True)
self.detailLabel.setFont(font)
self.detailLabel.setCursor(QCursor(Qt.PointingHandCursor))
self.detailLabel.setAlignment(Qt.AlignCenter)
self.detailLabel.setWordWrap(True)
self.rpmEdit = QLineEdit(EngineDialog)
Expand Down Expand Up @@ -112,6 +113,9 @@ def setupUi(self, EngineDialog):
self.maxLengthEdit.setGeometry(QRect(20, 460, 981, 31))
self.maxLengthEdit.setText(u"5000")
self.maxLengthEdit.setAlignment(Qt.AlignCenter)
self.detectButton = QPushButton(EngineDialog)
self.detectButton.setObjectName(u"detectButton")
self.detectButton.setGeometry(QRect(750, 70, 251, 71))

self.retranslateUi(EngineDialog)

Expand Down Expand Up @@ -139,5 +143,6 @@ def retranslateUi(self, EngineDialog):
self.customButton.setText(QCoreApplication.translate("EngineDialog", u"custom model", None))
self.label_9.setText(QCoreApplication.translate("EngineDialog", u"time_out (The max time wait for each request .for gpt-3.5 it's recommended to 120s , for gpt-4 it's recommened to 240s) :", None))
self.label_10.setText(QCoreApplication.translate("EngineDialog", u"max_length (The max character length for each request. The actual limit unit of openai is token which is normally a word. But it'hard to define,so use max_length as a replacement. The max tokens of openai are 4096 for each request. Make sure the token is under the exceed limit , my suggestion is to set to 5000)", None))
self.detectButton.setText(QCoreApplication.translate("EngineDialog", u"detect network delay", None))
# retranslateUi

20 changes: 18 additions & 2 deletions src/engine.ui
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<rect>
<x>240</x>
<y>68</y>
<width>761</width>
<width>491</width>
<height>20</height>
</rect>
</property>
Expand All @@ -86,7 +86,7 @@
<rect>
<x>240</x>
<y>120</y>
<width>761</width>
<width>491</width>
<height>20</height>
</rect>
</property>
Expand Down Expand Up @@ -121,6 +121,9 @@
<underline>true</underline>
</font>
</property>
<property name="cursor">
<cursorShape>PointingHandCursor</cursorShape>
</property>
<property name="text">
<string>detail information</string>
</property>
Expand Down Expand Up @@ -356,6 +359,19 @@
<set>Qt::AlignCenter</set>
</property>
</widget>
<widget class="QPushButton" name="detectButton">
<property name="geometry">
<rect>
<x>750</x>
<y>70</y>
<width>251</width>
<height>71</height>
</rect>
</property>
<property name="text">
<string>detect network delay</string>
</property>
</widget>
</widget>
<resources/>
<connections/>
Expand Down
39 changes: 39 additions & 0 deletions src/engine_form.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import _thread
import io
import json
import os
Expand All @@ -7,12 +8,27 @@
from PySide6 import QtCore
from PySide6.QtGui import QIntValidator
from PySide6.QtWidgets import QDialog
from ping3 import ping

from engine import Ui_EngineDialog
from my_log import log_print
from renpy_translate import engineDic, engineList


def get_ping_host(ip):
"""
:param node:
:return delay:
"""
ip_address = ip
response = ping(ip_address)
if response is not None:
delay = int(response * 1000)
return delay
else:
return -1


class MyEngineForm(QDialog, Ui_EngineDialog):
def __init__(self, parent=None):
super(MyEngineForm, self).__init__(parent)
Expand Down Expand Up @@ -73,6 +89,29 @@ def __init__(self, parent=None):
self.rpsEdit.setValidator(validator)
self.rpmEdit.setValidator(validator)
self.maxLengthEdit.setValidator(validator)
self.detectButton.clicked.connect(self.dect_network)

def detect_network_thread(self, engine, url):
delay = -1
try:
if len(url) > 0:
delay = get_ping_host(url)
except Exception as e:
pass
if delay != -1:
log_print(f'{engine} : {delay} ms')
else:
log_print(f'{engine} unreachable')

def dect_network(self):
for engine, dic in engineDic.items():
url = dic['url']
url = url.replace('http://', '')
url = url.replace('https://', '')
index = url.find('/')
if index != -1:
url = url[:index]
_thread.start_new_thread(self.detect_network_thread, (engine, url))

def init_openai_time_out(self):
if self.modelComboBox.currentText().startswith('gpt-3.5'):
Expand Down
2 changes: 1 addition & 1 deletion src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
sourceDic = dict()
translator = QTranslator()

VERSION = '2.3.8'
VERSION = '2.3.9'


class MyProxyForm(QDialog, Ui_ProxyDialog):
Expand Down
Binary file modified src/qm/arabic.qm
Binary file not shown.
Binary file modified src/qm/bengali.qm
Binary file not shown.
Binary file modified src/qm/chinese.qm
Binary file not shown.
Binary file modified src/qm/french.qm
Binary file not shown.
Binary file modified src/qm/german.qm
Binary file not shown.
Binary file modified src/qm/greek.qm
Binary file not shown.
Binary file modified src/qm/hindi.qm
Binary file not shown.
Binary file modified src/qm/japanese.qm
Binary file not shown.
Binary file modified src/qm/korean.qm
Binary file not shown.
Binary file modified src/qm/portuguese.qm
Binary file not shown.
Binary file modified src/qm/russian.qm
Binary file not shown.
Binary file modified src/qm/spanish.qm
Binary file not shown.
Binary file modified src/qm/turkish.qm
Binary file not shown.
Binary file modified src/qm/urdu.qm
Binary file not shown.
3 changes: 2 additions & 1 deletion src/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ pyperclip==1.8.2
openpyxl==3.1.2
qt-material==2.14
beautifulsoup4==4.12.3
pywin32==306
pywin32==306
ping3==4.0.8
Loading

0 comments on commit 65686a4

Please sign in to comment.