From b5e1461f841af3ee4efbe6a71ae1bbc8e68266e6 Mon Sep 17 00:00:00 2001
From: TS2_YouGame <66993983+Shoker2@users.noreply.github.com>
Date: Fri, 30 Dec 2022 20:14:42 +0300
Subject: [PATCH] in Output add Server
---
README.md | 2 -
main.py | 37 +++++++++-
moduls/Configure.py | 4 +-
moduls/Settings.py | 46 ++++++++----
ui/Settings.ui | 168 ++++++++++++++++++++++++--------------------
5 files changed, 166 insertions(+), 91 deletions(-)
diff --git a/README.md b/README.md
index 1083b3f..9099037 100644
--- a/README.md
+++ b/README.md
@@ -116,8 +116,6 @@ TS2_ScreenTranslator.exe - саморазархивирующийся архив
### Correction
-(В настоящий момент не работает)
-

Тут находится таблица для выполнения замен в переведённом тексте (Полезно, если вы стример и хотите не переводить некоторые слова)
diff --git a/main.py b/main.py
index 233581a..33bdfbb 100644
--- a/main.py
+++ b/main.py
@@ -2,11 +2,13 @@
from PIL import Image
import keyboard
import pyperclip
+import requests
import traceback
import sys
import time
import os
+import socket
from moduls.Snip import SnippingWidget as Snipper
from moduls.ScreenOutput import Ui_Output_Ui
@@ -46,6 +48,8 @@ def apply(self, Settings):
config.update('Output', 'console', returned_settings['Output_console'])
config.update('Output', 'clipboard', returned_settings['Output_clipboard'])
config.update('Output', 'original', returned_settings['Output_original'])
+ config.update('Output', 'ts2st_server', returned_settings['Output_TS2ST_server'])
+ config.update('Output', 'ts2st_server_ip', returned_settings['Output_TS2ST_server_IP'])
config.update_dictionary('Change_list', 'json', returned_settings['correction'])
@@ -90,6 +94,8 @@ def settings_win_setup(self, event):
Settings_UI.consoleOutput.setChecked(bool(int(config.read('Output', 'console'))))
Settings_UI.clipboardOutput.setChecked(bool(int(config.read('Output', 'clipboard'))))
Settings_UI.originalOutput.setChecked(bool(int(config.read('Output', 'original'))))
+ Settings_UI.TS2ST_serverOutput.setChecked(bool(int(config.read('Output', 'ts2st_server'))))
+ Settings_UI.TS2ST_serverLineEdit.setText(config.read('Output', 'ts2st_server_ip'))
Settings_UI.set_table_from_dictionary(config.read_dictionary('Change_list', 'json'))
@@ -114,7 +120,7 @@ def end_screen_shot():
translated = Translator.translate(text, Settings_UI.langs[config.read('General', 'to')], lang, config.read('General', 'translator'))
else:
translated = text
- except (FileNotFoundError, ConnectionError):
+ except (FileNotFoundError, ConnectionError, requests.exceptions.ConnectionError):
logger.logging.error(traceback.format_exc().replace('"', '\''))
translated = 'None'
open_screen = False
@@ -138,6 +144,22 @@ def end_screen_shot():
if config.read('Output', 'clipboard') == '1':
pyperclip.copy(translated)
+
+ if translated != None and config.read('Output', 'ts2st_server') == '1':
+ if config.read('Output', 'ts2st_server_ip').find(':') != -1:
+ config_ts2st_server_ip = config.read('Output', 'ts2st_server_ip').strip().split(':')
+ ts2st_server_ip = config_ts2st_server_ip[0]
+ ts2st_server_port = config_ts2st_server_ip[1]
+
+ try:
+ socket_send_msg(translated, ts2st_server_ip, int(ts2st_server_port))
+ except ValueError:
+ print('Not correct IP')
+ except socket.gaierror:
+ print('No TS2ST_Server found with this IP')
+ except Exception:
+ print('Connection Error')
+ logger.logging.error(traceback.format_exc().replace('"', '\''))
if open_screen:
Output_Ui.show()
@@ -176,6 +198,19 @@ def replace_from_list(string:str, dic: dict):
return string
+def socket_send_msg(msg, ip, port):
+ hostname = socket.gethostname()
+ my_local_ip = socket.gethostbyname(hostname)
+
+ server = (ip, 4000)
+
+ s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
+ s.bind((my_local_ip, port))
+
+ s.sendto(msg.encode('utf-8'), server)
+
+ s.close()
+
@logger.logging_function
def main():
try:
diff --git a/moduls/Configure.py b/moduls/Configure.py
index b48665e..91f014b 100644
--- a/moduls/Configure.py
+++ b/moduls/Configure.py
@@ -26,7 +26,9 @@ def __init__(self, config_path):
'window': '1',
'console': '0',
'clipboard': '0',
- 'original': '0'
+ 'original': '0',
+ 'ts2st_server': '0',
+ 'ts2st_server_ip': ''
}
self.config['Change_list'] = {
'json': '{}'
diff --git a/moduls/Settings.py b/moduls/Settings.py
index 55c6cc8..0efde8d 100644
--- a/moduls/Settings.py
+++ b/moduls/Settings.py
@@ -129,45 +129,64 @@ def setupUi(self, Settings, icon_path=''):
self.tabWidget.addTab(self.shortcuts_page, "")
self.Output_page = QtWidgets.QWidget()
self.Output_page.setObjectName("Output_page")
- self.windowOutput = QtWidgets.QCheckBox(self.Output_page)
- self.windowOutput.setGeometry(QtCore.QRect(10, 5, 211, 20))
+ self.scrollArea = QtWidgets.QScrollArea(self.Output_page)
+ self.scrollArea.setGeometry(QtCore.QRect(0, 0, 375, 91))
+ self.scrollArea.setWidgetResizable(True)
+ self.scrollArea.setObjectName("scrollArea")
+ self.scrollAreaWidgetContents = QtWidgets.QWidget()
+ self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 352, 204))
+ self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
+ self.verticalLayout = QtWidgets.QVBoxLayout(self.scrollAreaWidgetContents)
+ self.verticalLayout.setObjectName("verticalLayout")
+ self.windowOutput = QtWidgets.QCheckBox(self.scrollAreaWidgetContents)
font = QtGui.QFont()
font.setPointSize(10)
self.windowOutput.setFont(font)
self.windowOutput.setChecked(True)
self.windowOutput.setObjectName("windowOutput")
- self.consoleOutput = QtWidgets.QCheckBox(self.Output_page)
- self.consoleOutput.setGeometry(QtCore.QRect(10, 35, 211, 20))
+ self.verticalLayout.addWidget(self.windowOutput)
+ self.consoleOutput = QtWidgets.QCheckBox(self.scrollAreaWidgetContents)
font = QtGui.QFont()
font.setPointSize(10)
self.consoleOutput.setFont(font)
self.consoleOutput.setObjectName("consoleOutput")
- self.clipboardOutput = QtWidgets.QCheckBox(self.Output_page)
- self.clipboardOutput.setGeometry(QtCore.QRect(10, 65, 211, 20))
+ self.verticalLayout.addWidget(self.consoleOutput)
+ self.clipboardOutput = QtWidgets.QCheckBox(self.scrollAreaWidgetContents)
font = QtGui.QFont()
font.setPointSize(10)
self.clipboardOutput.setFont(font)
self.clipboardOutput.setObjectName("clipboardOutput")
- self.originalOutput = QtWidgets.QCheckBox(self.Output_page)
- self.originalOutput.setGeometry(QtCore.QRect(230, 40, 141, 51))
+ self.verticalLayout.addWidget(self.clipboardOutput)
+ self.originalOutput = QtWidgets.QCheckBox(self.scrollAreaWidgetContents)
font = QtGui.QFont()
font.setPointSize(10)
self.originalOutput.setFont(font)
self.originalOutput.setChecked(False)
self.originalOutput.setObjectName("originalOutput")
+ self.verticalLayout.addWidget(self.originalOutput)
+ self.TS2ST_serverOutput = QtWidgets.QCheckBox(self.scrollAreaWidgetContents)
+ font = QtGui.QFont()
+ font.setPointSize(10)
+ self.TS2ST_serverOutput.setFont(font)
+ self.TS2ST_serverOutput.setChecked(False)
+ self.TS2ST_serverOutput.setObjectName("TS2ST_serverOutput")
+ self.verticalLayout.addWidget(self.TS2ST_serverOutput)
+ self.TS2ST_serverLineEdit = QtWidgets.QLineEdit(self.scrollAreaWidgetContents)
+ self.TS2ST_serverLineEdit.setObjectName("TS2ST_serverLineEdit")
+ self.verticalLayout.addWidget(self.TS2ST_serverLineEdit)
+ self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.tabWidget.addTab(self.Output_page, "")
self.change_list_page = QtWidgets.QWidget()
self.change_list_page.setObjectName("change_list_page")
self.tableWidget = QtWidgets.QTableWidget(self.change_list_page)
- self.tableWidget.setGeometry(QtCore.QRect(0, 0, Settings.size().width(), 91))
+ self.tableWidget.setGeometry(QtCore.QRect(0, 0, 346, 91))
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(2)
self.tableWidget.setRowCount(1)
item = QtWidgets.QTableWidgetItem()
- item.setText("1")
self.tableWidget.setVerticalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
- item.setText("Source")
+ item.setText("Before")
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
@@ -206,8 +225,9 @@ def retranslateUi(self, Settings):
self.windowOutput.setText("Output to the window")
self.consoleOutput.setText("Output to the console")
self.clipboardOutput.setText("Output to the clipboard")
- self.originalOutput.setText("Output original\nto console")
+ self.originalOutput.setText("Output original to console")
self.tabWidget.setTabText(self.tabWidget.indexOf(self.Output_page), ("Output"))
+ self.TS2ST_serverOutput.setText("Output to the TS2ST_Server")
def table_check_row_for_emptiness(self, row):
first = False
@@ -277,6 +297,8 @@ def get_all(self):
get['Output_console'] = str(int(self.consoleOutput.isChecked()))
get['Output_clipboard'] = str(int(self.clipboardOutput.isChecked()))
get['Output_original'] = str(int(self.originalOutput.isChecked()))
+ get['Output_TS2ST_server'] = str(int(self.TS2ST_serverOutput.isChecked()))
+ get['Output_TS2ST_server_IP'] = str(self.TS2ST_serverLineEdit.text())
row_count = self.tableWidget.rowCount()
if self.table_check_row_for_emptiness(row_count-1):
diff --git a/ui/Settings.ui b/ui/Settings.ui
index 8116084..ba0a4dc 100644
--- a/ui/Settings.ui
+++ b/ui/Settings.ui
@@ -6,8 +6,8 @@
0
0
- 379
- 118
+ 384
+ 124
@@ -36,7 +36,7 @@
- 4
+ 3
false
@@ -266,84 +266,102 @@
Output
-
+
- 10
- 5
- 211
- 20
+ 0
+ 0
+ 375
+ 91
-
-
- 10
-
-
-
- Output to the window
-
-
+
true
-
-
-
-
- 10
- 35
- 211
- 20
-
-
-
-
- 10
-
-
-
- Output to the console
-
-
-
-
-
- 10
- 65
- 211
- 20
-
-
-
-
- 10
-
-
-
- Output to the clipboard
-
-
-
-
-
- 230
- 40
- 141
- 51
-
-
-
-
- 10
-
-
-
- Output original
-to console
-
-
- false
-
+
+
+
+ 0
+ -115
+ 352
+ 204
+
+
+
+ -
+
+
+
+ 10
+
+
+
+ Output to the window
+
+
+ true
+
+
+
+ -
+
+
+
+ 10
+
+
+
+ Output to the console
+
+
+
+ -
+
+
+
+ 10
+
+
+
+ Output to the clipboard
+
+
+
+ -
+
+
+
+ 10
+
+
+
+ Output original to console
+
+
+ false
+
+
+
+ -
+
+
+
+ 10
+
+
+
+ Output to the TS2ST_Server
+
+
+ false
+
+
+
+ -
+
+
+
+