Skip to content

Commit

Permalink
in Output add Server
Browse files Browse the repository at this point in the history
  • Loading branch information
Shoker2 committed Dec 30, 2022
1 parent 70d842a commit b5e1461
Show file tree
Hide file tree
Showing 5 changed files with 166 additions and 91 deletions.
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@ TS2_ScreenTranslator.exe - саморазархивирующийся архив

### Correction

(В настоящий момент не работает)

![image](https://user-images.githubusercontent.com/66993983/209830709-3def4d19-c3fd-4714-9df2-eb7e447088cd.png)

Тут находится таблица для выполнения замен в переведённом тексте (Полезно, если вы стример и хотите не переводить некоторые слова)
Expand Down
37 changes: 36 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'])

Expand Down Expand Up @@ -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'))

Expand All @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 3 additions & 1 deletion moduls/Configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -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': '{}'
Expand Down
46 changes: 34 additions & 12 deletions moduls/Settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down
168 changes: 93 additions & 75 deletions ui/Settings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
<rect>
<x>0</x>
<y>0</y>
<width>379</width>
<height>118</height>
<width>384</width>
<height>124</height>
</rect>
</property>
<property name="minimumSize">
Expand Down Expand Up @@ -36,7 +36,7 @@
</rect>
</property>
<property name="currentIndex">
<number>4</number>
<number>3</number>
</property>
<property name="tabBarAutoHide">
<bool>false</bool>
Expand Down Expand Up @@ -266,84 +266,102 @@
<attribute name="title">
<string>Output</string>
</attribute>
<widget class="QCheckBox" name="windowOutput">
<widget class="QScrollArea" name="scrollArea">
<property name="geometry">
<rect>
<x>10</x>
<y>5</y>
<width>211</width>
<height>20</height>
<x>0</x>
<y>0</y>
<width>375</width>
<height>91</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Output to the window</string>
</property>
<property name="checked">
<property name="widgetResizable">
<bool>true</bool>
</property>
</widget>
<widget class="QCheckBox" name="consoleOutput">
<property name="geometry">
<rect>
<x>10</x>
<y>35</y>
<width>211</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Output to the console</string>
</property>
</widget>
<widget class="QCheckBox" name="clipboardOutput">
<property name="geometry">
<rect>
<x>10</x>
<y>65</y>
<width>211</width>
<height>20</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Output to the clipboard</string>
</property>
</widget>
<widget class="QCheckBox" name="originalOutput">
<property name="geometry">
<rect>
<x>230</x>
<y>40</y>
<width>141</width>
<height>51</height>
</rect>
</property>
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Output original
to console</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
<widget class="QWidget" name="scrollAreaWidgetContents">
<property name="geometry">
<rect>
<x>0</x>
<y>-115</y>
<width>352</width>
<height>204</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QCheckBox" name="windowOutput">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Output to the window</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="consoleOutput">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Output to the console</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="clipboardOutput">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Output to the clipboard</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="originalOutput">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Output original to console</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="TS2ST_serverOutput">
<property name="font">
<font>
<pointsize>10</pointsize>
</font>
</property>
<property name="text">
<string>Output to the TS2ST_Server</string>
</property>
<property name="checked">
<bool>false</bool>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="TS2ST_serverLineEdit"/>
</item>
</layout>
</widget>
</widget>
</widget>
<widget class="QWidget" name="change_list_page">
Expand Down

0 comments on commit b5e1461

Please sign in to comment.