Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
PantsuDango committed Feb 29, 2020
0 parents commit 076a672
Show file tree
Hide file tree
Showing 20 changed files with 588 additions and 0 deletions.
102 changes: 102 additions & 0 deletions Range.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import tkinter
from PIL import Image, ImageTk
import os
import UI

from PIL import ImageGrab
import tkinter
import tkinter.messagebox


def get_Coordinates():

path = os.getcwd() + '\\config\\'
os.startfile(path+'获取屏幕坐标.exe')


def get_image(X1,Y1,X2,Y2):

path = os.getcwd() + '\\config\\'

x1 = int(X1.get(1.0,'end').replace('\n','').replace(' ',''))
y1 = int(Y1.get(1.0,'end').replace('\n','').replace(' ',''))
x2 = int(X2.get(1.0,'end').replace('\n','').replace(' ',''))
y2 = int(Y2.get(1.0,'end').replace('\n','').replace(' ',''))

try:
bbox = (x1,y1,x2,y2)
image = ImageGrab.grab(bbox)
image.save(path+'image.png')
os.startfile(path+'image.png')
except Exception:
tkinter.messagebox.showerror(title='error', message='坐标错误!')


def Range_save(X1,Y1,X2,Y2,Range_window):

x1 = X1.get(1.0,'end').replace('\n','').replace(' ','')
y1 = Y1.get(1.0,'end').replace('\n','').replace(' ','')
x2 = X2.get(1.0,'end').replace('\n','').replace(' ','')
y2 = Y2.get(1.0,'end').replace('\n','').replace(' ','')

path = os.getcwd() + '\\config\\'
with open(path+'屏幕坐标.txt', 'w') as file:
file.write('%s,%s,%s,%s'%(x1,y1,x2,y2))

Range_window.destroy()


def Range_UI(x1,y1,x2,y2):

path = os.getcwd() + '\\config\\'

Range_window = tkinter.Tk()
Range_window.wm_attributes('-topmost',1)
Range_window.geometry('260x230')
Range_window.iconbitmap(path+'图标.ico')
Range_window.title('翻译范围设置')

tkinter.Label(Range_window , text='文本框左上角坐标:').place(x=20, y=10, anchor='nw')

tkinter.Label(Range_window , text='X1:').place(x=20, y=30, anchor='nw')
X1 = tkinter.Text(Range_window, width=10, height=1)
X1.place(x=40, y=34)

tkinter.Label(Range_window , text='Y1:').place(x=130, y=30, anchor='nw')
Y1 = tkinter.Text(Range_window, width=10, height=1)
Y1.place(x=160, y=34)

tkinter.Label(Range_window , text='文本框右下角坐标:').place(x=20, y=60, anchor='nw')

tkinter.Label(Range_window , text='X2:').place(x=20, y=80, anchor='nw')
X2 = tkinter.Text(Range_window, width=10, height=1)
X2.place(x=40, y=84)

tkinter.Label(Range_window , text='Y2:').place(x=130, y=80, anchor='nw')
Y2 = tkinter.Text(Range_window, width=10, height=1)
Y2.place(x=160, y=84)

X1.insert(0.0,x1)
Y1.insert(0.0,y1)
X2.insert(0.0,x2)
Y2.insert(0.0,y2)

tkinter.Label(Range_window , text='*填入获取到的坐标值,保存后生效').place(x=20, y=110, anchor='nw')

tkinter.Button(Range_window, text="获取坐标", width=7, height=1, command=get_Coordinates).place(x=45, y=140, anchor='nw')
tkinter.Button(Range_window, text="查看效果", width=7, height=1, command=lambda:get_image(X1,Y1,X2,Y2)).place(x=150, y=140, anchor='nw')
tkinter.Button(Range_window, text="保存", width=7, height=1, command=lambda:Range_save(X1,Y1,X2,Y2,Range_window)).place(x=45, y=180, anchor='nw')
tkinter.Button(Range_window, text="取消", width=7, height=1, command=Range_window.destroy).place(x=150, y=180, anchor='nw')

Range_window.mainloop()


def Range_main(window):

window.destroy()
path = os.getcwd() + '\\config\\'
with open(path+'屏幕坐标.txt') as file:
x1,y1,x2,y2 = file.read().split(',')

Range_UI(x1,y1,x2,y2)
UI.UI_main()
178 changes: 178 additions & 0 deletions Settin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
import tkinter
from PIL import Image, ImageTk
import os
import UI


def Baidu_API_save(APP_ID,password,Baidu_API_window):

API_Key = APP_ID.get(1.0,'end').replace('\n','').replace(' ','')
Secret_Key = password.get(1.0,'end').replace('\n','').replace(' ','')

path = os.getcwd() + '\\config\\'
with open(path+'Baidu_Key.txt', 'w') as file:
file.write('%s,%s'%(API_Key,Secret_Key))

Baidu_API_window.destroy()


def Baidu_API():

path = os.getcwd() + '\\config\\'
with open(path+'Baidu_Key.txt') as file:
API_Key,Secret_Key = file.read().split(',')

Baidu_API_window = tkinter.Tk()
Baidu_API_window.wm_attributes('-topmost',1)
Baidu_API_window.geometry('260x180')
Baidu_API_window.iconbitmap(path+'图标.ico')
Baidu_API_window.title('百度翻译API设定')

tkinter.Label(Baidu_API_window , text='APP ID:').place(x=20, y=10, anchor='nw')
APP_ID = tkinter.Text(Baidu_API_window, width=30, height=1)
APP_ID.place(x=20, y=34)

tkinter.Label(Baidu_API_window, text='密钥:').place(x=20, y=60, anchor='nw')
password = tkinter.Text(Baidu_API_window, width=30, height=1)
password.place(x=20, y=84)

tkinter.Button(Baidu_API_window, text="保存", width=7, height=1, command=lambda:Baidu_API_save(APP_ID,password,Baidu_API_window)).place(x=45, y=125, anchor='nw')
tkinter.Button(Baidu_API_window, text="取消", width=7, height=1, command=Baidu_API_window.destroy).place(x=150, y=125, anchor='nw')

APP_ID.insert(0.0,API_Key)
password.insert(0.0,Secret_Key)

Baidu_API_window.mainloop()


def Tencent_API_save(APP_ID,password,Tencent_API_window):

API_Key = APP_ID.get(1.0,'end').replace('\n','').replace(' ','')
Secret_Key = password.get(1.0,'end').replace('\n','').replace(' ','')

path = os.getcwd() + '\\config\\'
with open(path+'Tencent_Key.txt', 'w') as file:
file.write('%s,%s'%(API_Key,Secret_Key))

Tencent_API_window.destroy()


def Tencent_API():

path = os.getcwd() + '\\config\\'
with open(path+'Tencent_Key.txt') as file:
API_Key,Secret_Key = file.read().split(',')

Tencent_API_window = tkinter.Tk()
Tencent_API_window.wm_attributes('-topmost',1)
Tencent_API_window.geometry('310x180')
Tencent_API_window.iconbitmap(path+'图标.ico')
Tencent_API_window.title('腾讯翻译API设定')

tkinter.Label(Tencent_API_window , text='SecretId:').place(x=20, y=10, anchor='nw')
APP_ID = tkinter.Text(Tencent_API_window, width=37, height=1)
APP_ID.place(x=20, y=34)

tkinter.Label(Tencent_API_window, text='SecretKey:').place(x=20, y=60, anchor='nw')
password = tkinter.Text(Tencent_API_window, width=37, height=1)
password.place(x=20, y=84)

tkinter.Button(Tencent_API_window, text="保存", width=7, height=1, command=lambda:Tencent_API_save(APP_ID,password,Tencent_API_window)).place(x=55, y=125, anchor='nw')
tkinter.Button(Tencent_API_window, text="取消", width=7, height=1, command=Tencent_API_window.destroy).place(x=160, y=125, anchor='nw')

APP_ID.insert(0.0,API_Key)
password.insert(0.0,Secret_Key)

Tencent_API_window.mainloop()


def Settin_save(API_Key_Entry,Secret_Key_Entry,Settin_window,var1,var2,time_Scale,var4):

API_Key = API_Key_Entry.get(1.0,'end').replace('\n','').replace(' ','')
Secret_Key = Secret_Key_Entry.get(1.0,'end').replace('\n','').replace(' ','')

path = os.getcwd() + '\\config\\'
with open(path+'ORC_Key.txt', 'w') as file:
file.write('%s,%s'%(API_Key,Secret_Key))

var1 = var1.get()
var2 = var2.get()
time = time_Scale.get()
var4 = var4.get()
with open(path+'Init.txt', 'w') as file:
file.write('%s,%s,%s,%s'%(var1,var2,time,var4))

Settin_window.destroy()


def Settin_UI(API_Key,Secret_Key,value1,value2,value3,value4):

path = os.getcwd() + '\\config\\'
Settin_window = tkinter.Tk()
Settin_window.wm_attributes('-topmost',1)
Settin_window.geometry('320x430')
Settin_window.iconbitmap(path+'图标.ico')
Settin_window.title('设置')

tkinter.Label(Settin_window, text='ORC API Key:').place(x=20, y=10, anchor='nw')
API_Key_Entry = tkinter.Text(Settin_window, width=38, height=1)
API_Key_Entry.place(x=20, y=35, anchor='nw')

tkinter.Label(Settin_window, text='ORC Secret Key:').place(x=20, y=60, anchor='nw')
Secret_Key_Entry = tkinter.Text(Settin_window, width=38, height=1)
Secret_Key_Entry.place(x=20, y=80, anchor='nw')

tkinter.Label(Settin_window, text='翻译源设定:').place(x=20, y=110, anchor='nw')
frame1 = tkinter.Frame(Settin_window).pack()
var1 = tkinter.IntVar()
tkinter.Radiobutton(frame1, text='有道翻译', variable=var1, value=1,).place(x=20, y=135, anchor='nw')

tkinter.Radiobutton(frame1, text='百度翻译', variable=var1, value=2,).place(x=120, y=135, anchor='nw')
tkinter.Button(Settin_window, text="设定", width=7, height=1, command=Baidu_API).place(x=130, y=165, anchor='nw')

tkinter.Radiobutton(frame1, text='腾讯翻译', variable=var1, value=3,).place(x=220, y=135, anchor='nw')
tkinter.Button(Settin_window, text="设定", width=7, height=1, command=Tencent_API).place(x=230, y=165, anchor='nw')

var1.set(int(value1))

tkinter.Label(Settin_window, text='翻译方式设定:').place(x=20, y=200, anchor='nw')

frame2 = tkinter.Frame(Settin_window).pack()
var2 = tkinter.IntVar()
tkinter.Radiobutton(frame2, text='手动翻译(建议)', variable=var2, value=1,).place(x=20, y=225, anchor='nw')
tkinter.Radiobutton(frame2, text='自动翻译', variable=var2, value=2,).place(x=170, y=225, anchor='nw')
var2.set(int(value2))

frame3 = tkinter.Frame(Settin_window).pack()
var3=tkinter.IntVar()
tkinter.Label(Settin_window, text='自动时的翻译频率设定(秒):').place(x=20, y=260, anchor='nw')
time_Scale = tkinter.Scale(frame3, from_=2, to=10, orient=tkinter.HORIZONTAL, variable=var3, length=270, showvalue=0,tickinterval=1, resolution=1)
time_Scale.place(x=20, y=285, anchor='nw')
var3.set(int(value3))

frame4 = tkinter.Frame(Settin_window).pack()
var4=tkinter.IntVar()
Checkbutton = tkinter.Checkbutton(frame4, text='是否显示原文',variable=var4, onvalue=1, offvalue=0).place(x=20, y=330, anchor='nw')
var4.set(int(value4))

tkinter.Button(Settin_window, text="保存", width=7, height=1, command=lambda:Settin_save(API_Key_Entry,Secret_Key_Entry,Settin_window,var1,var2,time_Scale,var4)).place(x=70, y=365, anchor='nw')
tkinter.Button(Settin_window, text="取消", width=7, height=1, command=Settin_window.destroy).place(x=170, y=365, anchor='nw')

API_Key_Entry.insert(0.0,API_Key)
Secret_Key_Entry.insert(0.0,Secret_Key)

Settin_window.mainloop()


def Settin_main(window):

window.destroy()
path = os.getcwd() + '\\config\\'
with open(path+'ORC_Key.txt') as file:
API_Key,Secret_Key = file.read().split(',')

with open(path+'Init.txt') as file:
value1,value2,value3,value4 = file.read().split(',')

Settin_UI(API_Key,Secret_Key,value1,value2,value3,value4)
UI.UI_main()
39 changes: 39 additions & 0 deletions UI.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import tkinter
import tkinter.font as tkFont
from PIL import Image, ImageTk
import os

from Range import Range_main
from Settin import Settin_main
from translate import translate_main


def UI_main():

path = os.getcwd() + '\\config\\'

window = tkinter.Tk()
window.wm_attributes('-topmost',1)
window.geometry('600x115')
window.iconbitmap(path+'图标.ico')
window.title(' Galgame翻译器 ver 1.0 --- By:胖次团子 交流群:779594427')

canvas = tkinter.Canvas(window, width=600, height=115, bg='white')
image = Image.open(path+'背景.gif')
photo = ImageTk.PhotoImage(image)
canvas.create_image(540, 220, image=photo)
canvas.pack()

tkinter.Button(window, text="翻译", width=7, height=1, command=lambda:translate_main(Text,window)).place(x=520, y=8, anchor='nw')
tkinter.Button(window, text="设置", width=7, height=1, command=lambda:Settin_main(window)).place(x=520, y=43, anchor='nw')
tkinter.Button(window, text="范围", width=7, height=1, command=lambda:Range_main(window)).place(x=520, y=78, anchor='nw')

font = tkFont.Font(family='华康方圆体W7',size=15)
Text = tkinter.Text(window, fg='#FF69B4', font=font)
Text.place(x=15, y=15, width=480, height=85)

scrollbar = tkinter.Scrollbar(Text, command=Text.yview)
scrollbar.pack(side=tkinter.RIGHT, fill=tkinter.Y)
Text.config(yscrollcommand=scrollbar.set)

window.mainloop()
Empty file added config/Access_Token.txt
Empty file.
1 change: 1 addition & 0 deletions config/Baidu_Key.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,
1 change: 1 addition & 0 deletions config/Init.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
1,1,2,0
1 change: 1 addition & 0 deletions config/ORC_Key.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,
1 change: 1 addition & 0 deletions config/Tencent_Key.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,
Binary file added config/image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added config/图标.ico
Binary file not shown.
1 change: 1 addition & 0 deletions config/屏幕坐标.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
,,,
Binary file added config/背景.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added config/获取屏幕坐标.exe
Binary file not shown.
11 changes: 11 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from UI import UI_main


def main():

UI_main()


if __name__ == '__main__':

main()
Loading

0 comments on commit 076a672

Please sign in to comment.