Skip to content

Commit

Permalink
almost done, but test
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottzheng committed Sep 27, 2018
1 parent 212ff57 commit 4974f36
Show file tree
Hide file tree
Showing 18 changed files with 201 additions and 115 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Copy, Translate, and Paste with Google translate API.

3. **Config memorization**, your config will be save in the disk, and auto reload on the next start.

4. `Continus copy`, append the copied text to the source other than replace it, especially useful when the paragraph is separated in different page. Check the `Continus Copy ` option to enable it.
4. `'Incremental Copy`, append the copied text to the source other than replace it, especially useful when the paragraph is separated in different page. Check the `'Incremental Copy ` option to enable it.

5. **Copy source**, you can copy the source by the menu of the taskbar icon.

Expand Down
71 changes: 48 additions & 23 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

## Windows用户使用手册
### 公告
**v0.0.5.2版本及以前版本,由于google翻译的机制改变,现在已经无法使用,该问题已在v0.0.5.3之后修复,请大家及时下载更新。**
v0.0.5.2版本及以前版本,由于google翻译的机制改变,现在已经无法使用,该问题已在v0.0.5.3之后修复,请大家及时下载更新。
### 更新日志

#### v0.0.6.0 全面赋能专注模式
Expand All @@ -15,7 +15,7 @@

1. **智能互译**`CopyTranslator`会自动识别所复制的文字,根据所设置的`source``target`进行自动智能互译,也就是说,如果您复制的是`source`,会翻译为`target`,复制`target`则会翻译为`source`。(不用担心,`Auto Copy`不会与此机制相互影响。)

2. **智能词典**(基于[Translator](https://github.com/93Alliance/Translator)提供的有道API
2. **智能词典**(基于[Youdao](https://github.com/93Alliance/Translator)提供的API

单词少于3的**外语句子**将被视为短语或单词,您将在专注模式上看到更详细的解释。勾选`Smart Dict`选项以启用它。**注:查词限于有道支持的语言,但是您无需也无法手动选择语言。**

Expand All @@ -29,7 +29,7 @@

4. **设置记忆**,您的设置将自动保存在磁盘中,并在下次启动时自动重新加载。

5. **连续复制**, 将复制的文本附加到原文而不是替换它,**当段落在不同页面中分隔时尤其有用。**勾选`Continus Copy`选项以启用它。
5. **连续复制**, 将复制的文本附加到原文而不是替换它,**当段落在不同页面中分隔时尤其有用。**勾选`'Incremental Copy`选项以启用它。


5. **复制原文**,您可以通过任务栏图标的菜单点击`Copy Source`以在`Auto Copy`模式下暂时复制原文,而不是译文。
Expand Down Expand Up @@ -91,30 +91,48 @@

![chtoen](https://s1.ax1x.com/2018/09/13/iEiHsO.png).

3. **重新定义复译的 复制** 为减少多次按ctrl+c或者是右键复制所带来的麻烦,复译引入一个选中长按自动复制的机制,在打开监听剪贴板选项后,只需选中文字,并将鼠标悬停在选中文字上方**长按不动超过0.1s后释放鼠标(其实0.1s你基本没感觉自己长按了),**也就是**长按后释放**,即可复制。这可以避免我们过度移动鼠标(右键再选择复制)或者是疯狂按ctrl+c按得很累。
3. **重新定义复译的 复制** 为减少多次按ctrl+c或者是右键复制所带来的麻烦,复译引入一个选中长按自动复制的机制,在打开监听剪贴板选项后,只需选中文字,并将鼠标悬停在选中文字上方**长按不动超过0.3s后释放鼠标(其实0.3s你基本没感觉自己长按了),**也就是**长按后释放**,即可复制。这可以避免我们过度移动鼠标(右键再选择复制)或者是疯狂按ctrl+c按得很累。

![longpresscopy](https://s1.ax1x.com/2018/09/13/iEibLD.gif)

4. 两种窗口模式可供选择,`主模式``专注模式`,专注模式只提供译文窗口,便于您关注结果。使用专注模式时注意勾选`Stay on top``Listen clipboard`,必要时应勾选`Auto Copy`
5. 支持各种语言互译,google翻译支持啥我们就支持啥。
6. 占用内存小,别看安装包挺大, 运行时常驻内存只有十几兆,安装包大是因为打包了python库的问题。
4. **智能互译**`CopyTranslator`会自动识别所复制的文字,**根据所设置的**`source``target`**进行自动智能互译**,也就是说,如果您复制的是`source`,会翻译为`target`,复制`target`则会翻译为`source`。(不用担心,`Auto Copy`不会与此机制相互影响。)

5. **智能词典**(基于[Youdao](https://github.com/93Alliance/Translator)提供的API)

单词少于3的**外语句子**将被视为短语或单词,您将在专注模式上看到更详细的解释。勾选`Smart Dict`选项以启用它。**注:查词限于有道支持的语言,但是您无需也无法手动选择语言。**

![1537871607106](assets/1537871607106.png)

![1537871905985](assets/1537871905985.png)

6. **字体可调整大小**,使用`shift + F3``shift + F4`缩小或增大专注模式的字体大小

![1537871658665](assets/1537871658665.png)

7. **连续复制**, 将复制的文本附加到原文而不是替换它,**当段落在不同页面中分隔时尤其有用。**勾选`'Incremental Copy`选项以启用它。

8. 两种窗口模式可供选择,`主模式``专注模式`,专注模式只提供译文窗口,便于您关注结果。使用专注模式时注意勾选`Stay on top``Listen clipboard`,必要时应勾选`Auto Copy`

9. 支持各种语言互译,Google翻译支持啥我们就支持啥。

10. 占用内存小,别看安装包挺大, 运行时常驻内存只有十几兆,安装包大是因为打包了python库的问题。

### 项目地址

https://github.com/elliottzheng/CopyTranslator

### 安装

1. 以下列方式下载最新的Windows版本 [![Download](https://api.bintray.com/packages/elliottzheng/CopyTranslator/CopyTranslator/images/download.svg) ](https://bintray.com/elliottzheng/CopyTranslator/CopyTranslator/_latestVersion)
1. 以下列方式下载最新的Windows版本 [![Download](https://api.bintray.com/packages/elliottzheng/CopyTranslator/CopyTranslator/images/download.svg) ](https://bintray.com/elliottzheng/CopyTranslator/CopyTranslator/_latestVersion)
- 非程序员用户推荐从百度云下载 [https://pan.baidu.com/s/1Lhb6uQK786RMzMjLrDw7fg](https://pan.baidu.com/s/1Lhb6uQK786RMzMjLrDw7fg)
- [Github Releases](https://github.com/elliottzheng/CopyTranslator/releases)
- [Gitee Releases](https://gitee.com/ylzheng/CopyTranslator/releases)
2. 解压压缩包到任意位置,在程序目录中运行`shortcut.bat`它会在桌面上创建一个复译的快捷方式
2. 解压压缩包到任意位置,在程序目录中运行`shortcut.bat`它会在桌面上创建一个`CopyTranslator`的快捷方式

### 使用

附上我朋友录制的介绍视频链接
[https://www.bilibili.com/video/av31396414/](https://www.bilibili.com/video/av31396414/)
[https://www.bilibili.com/video/av31396414/](https://www.bilibili.com/video/av31396414/),更详细的功能还请看本文档。

有两种可供选择的模式。

Expand All @@ -133,19 +151,25 @@ https://github.com/elliottzheng/CopyTranslator

#### 主模式

主模式提供了一个交互式框架。
主模式提供了一个交互式框架,可以快速地设置

- `Stay on top`:让`CopyTranslator`窗口总是在其他窗口上方。

- `Listen on Clipboard`:监听剪贴板并自动翻译。

- `Auto detect language`:自动检测源文本语言。

- `Auto copy`:如果您想在自动翻译后自动复制结果,请勾选它。

- `Smart Dict`: 启用智能词典,单词少于3的**外语句子**将被视为短语或单词,您将在专注模式上看到更详细的解释。

- `'Incremental Copy`, 启用连续复制模式,将复制的文本附加到原文而不是替换它,**当段落在不同页面中分隔时尤其有用。**

- `Detect language`:自动检测源文本语言。

- `Source language`:默认是English。

- `Target language`:默认是简体中文.
- `Target language`:默认是简体中文.

`v0.0.6.0`后,`source``target`均是相对而言的,`CopyTranslator`会自动识别所复制的文字,**根据所设置的**`source``target`**进行自动智能互译**,也就是说,如果您复制的是`source`,会翻译为`target`,复制`target`则会翻译为`source`。(不用担心,`Auto Copy`不会与此机制相互影响。)

- `Switch Mode`: 在主模式和专注模式间切换

Expand All @@ -154,20 +178,21 @@ https://github.com/elliottzheng/CopyTranslator

专注模式只提供一个结果窗口,让您更好地关注结果。 (注意选中`Listen on Clipboard``Stay on top`选项。)

你可以对它自由拉伸。
1. 你可以对它自由拉伸。

- 拖动窗口顶部橙色(你的电脑的主题颜色)区域,或者是边框可以拉伸变形这个窗口;
拖动窗口顶部橙色(你的电脑的主题颜色)区域,或者是边框可以拉伸变形这个窗口;

- 定义**顶部蓝线以上,橙色以下偏灰色区域**`闪区`
定义**顶部蓝线以上,橙色以下偏灰色区域**`闪区`
- 拖动`闪区`可以整体移动窗口

- 拖动`闪区`可以整体移动窗口
- 双击`闪区`可以隐藏窗口

- 双击`闪区`可以隐藏窗口

- 右击`闪区`可以复制翻译结果
![1528470182001](https://gitee.com/ylzheng/CopyTranslator/raw/master/screenshot/newfocus.png)
- 右击`闪区`可以复制翻译结果
![1528470182001](https://gitee.com/ylzheng/CopyTranslator/raw/master/screenshot/newfocus.png)

2. **字体可调整大小**,使用`shift + F3``shift + F4`缩小或增大专注模式的字体大小

![1537871658665](assets/1537871658665.png)

## TODO
- ~~翻译历史~~ 意义不大?如果有兴趣的话可以提issue说明场景,我会考虑是否要加。
Expand All @@ -178,7 +203,7 @@ https://github.com/elliottzheng/CopyTranslator

## 致谢

感谢[wxpython](https://wxpython.org/), [googletrans](https://github.com/ssut/py-googletrans), [pyperclip](https://github.com/asweigart/pyperclip), [Translator](https://github.com/93Alliance/Translator) 的开发者以及我亲爱的朋友们。
感谢[wxpython](https://wxpython.org/), [googletrans](https://github.com/ssut/py-googletrans), [pyperclip](https://github.com/asweigart/pyperclip), [Youdao](https://github.com/longcw/youdao) 的开发者以及我亲爱的朋友们。

## License

Expand Down
Binary file added assets/1537871607106.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 assets/1537871658665.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 assets/1537871871793.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 assets/1537871905985.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 assets/resize.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
76 changes: 76 additions & 0 deletions copyTranslator/color_ctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,88 @@ class Color:
class ColoredCtrl(wx.TextCtrl):
ERROR = 0
WORD = 1
ID_Top = wx.NewId()
ID_Listen = wx.NewId()
ID_Copy = wx.NewId()
ID_Dict = wx.NewId()
ID_Dete = wx.NewId()
ID_Continus = wx.NewId()
ID_Show = wx.NewId()
ID_Main = wx.NewId()
ID_Exchange = wx.NewId()
ID_Focus = wx.NewId()
ID_About = wx.NewId()
ID_Closeshow = wx.NewId()
ID_Switch = wx.NewId()
ID_Copy_result = wx.NewId()
ID_Clear = wx.NewId()

def __init__(self, parent=None, id=None, style=0):
self.parent = parent
self.setting = self.parent.parentFrame.setting
if style == 0:
style = wx.TE_RICH2 | wx.TE_MULTILINE | wx.TE_READONLY
super(ColoredCtrl, self).__init__(parent=parent, id=id, style=style)

self.Bind(wx.EVT_RIGHT_DOWN, self.OnShowPopup)

self.Bind(wx.EVT_MENU, self.setting.ReverseStayTop, id=self.ID_Top)
self.Bind(wx.EVT_MENU, self.setting.ReverseListen, id=self.ID_Listen)
self.Bind(wx.EVT_MENU, self.setting.ReverseDict, id=self.ID_Dict)
self.Bind(wx.EVT_MENU, self.setting.ReverseDete, id=self.ID_Dete)
self.Bind(wx.EVT_MENU, self.setting.ReverseCopy, id=self.ID_Copy)
self.Bind(wx.EVT_MENU, self.setting.ReverseContinus, id=self.ID_Continus)

self.Bind(wx.EVT_MENU, self.setting.ChangeMode, id=self.ID_Switch)
self.Bind(wx.EVT_MENU, self.setting.taskbar.OnExchange, id=self.ID_Exchange)
self.Bind(wx.EVT_MENU, self.setting.Copy, id=self.ID_Copy_result)

self.Bind(wx.EVT_MENU, self.setting.taskbar.OnAbout, id=self.ID_About)
self.Bind(wx.EVT_MENU, self.setting.clear, id=self.ID_Clear)
self.Bind(wx.EVT_MENU, self.close, id=self.ID_Closeshow)

# 右键菜单
def OnShowPopup(self, event):
self.PopupMenu(self.CreateContextMenu())

def close(self, event):
self.setting.mainFrame.Destroy()
self.setting.taskbar.Destroy()
self.setting.subFrame.Destroy()

def CreateContextMenu(self):
menu = wx.Menu()

menu.Append(self.ID_Exchange, 'Copy Source')

menu.Append(self.ID_Copy_result, 'Copy Result')

menu.Append(self.ID_Clear, 'Clear')

menu.Append(self.ID_Switch, 'Main Mode' if not self.setting.is_main else 'Focus Mode')

copy = menu.AppendCheckItem(self.ID_Copy, 'Auto Copy', 'Auto copy result to clipboard.')
copy.Check(self.setting.is_copy)

continus = menu.AppendCheckItem(self.ID_Continus, 'Incremental Copy', 'Incremental Copy content to source.')
continus.Check(self.setting.continus)

is_dict = menu.AppendCheckItem(self.ID_Dict, 'Smart Dict', 'Enable Youdao smart dictionary')
is_dict.Check(self.setting.is_dict)

listen = menu.AppendCheckItem(self.ID_Listen, 'Listen Clipboard', 'Listen to Clipboard and auto translate.')
listen.Check(self.setting.is_listen)

listen = menu.AppendCheckItem(self.ID_Top, 'Stay on Top', 'Always stay on Top.')
listen.Check(self.setting.stay_top)

dete = menu.AppendCheckItem(self.ID_Dete, 'Detect Language', 'Detect the input language.')
dete.Check(self.setting.is_dete)

menu.Append(self.ID_About, 'Help and Update')
menu.Append(self.ID_Closeshow, 'Exit')
return menu

def ColoredAppend(self, text, color):
style = self.GetDefaultStyle()
color = wx.Colour(color[0], color[1], color[2])
Expand Down
24 changes: 20 additions & 4 deletions copyTranslator/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,25 @@
# @Software: PyCharm

logopath = 'logo.ico'
version = 'v0.0.6.0'
version = 'v0.0.5.0'
project_name = 'CopyTranslator'
update_json_url = 'https://gitee.com/ylzheng/CopyTranslator/raw/master/CopyTranslator/version.json'
install_url = 'https://github.com/elliottzheng/CopyTranslator/blob/master/README_zh.md#%E5%AE%89%E8%A3%85'
update_json_url = 'http://onhdz331f.bkt.clouddn.com/version.json'
install_url = 'https://github.com/elliottzheng/CopyTranslator/wiki/Downloads-%E4%B8%8B%E8%BD%BD%E4%B8%8E%E5%AE%89%E8%A3%85'
log_path = 'update_log.txt'
project_url = 'https://github.com/elliottzheng/CopyTranslator'
project_url = 'https://github.com/elliottzheng/CopyTranslator/wiki'
level = 3

levels_log = {
1: 'Small Enhancements',
2: 'Small Fix.',
3: 'Important Enhancements.',
4: 'Emergency Fix.'
}

'''
level说明:
1 无关紧要的小增强
2 无关紧要的小修复
3 重要增强,强烈建议更新
4 严重bug修复
'''
17 changes: 2 additions & 15 deletions copyTranslator/mainframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,8 @@

import wx
import wx.adv
import regex as re
from googletrans import Translator
from googletrans import LANGCODES
from googletrans import LANGUAGES

from pynput import mouse
import time
import pyperclip
import win32con
from pynput.keyboard import Key, Controller
import webbrowser
import os
import json
from copyTranslator.youdao import YoudaoSpider
from copyTranslator.color_ctrl import ColoredCtrl

from copyTranslator.constant import *


Expand Down Expand Up @@ -56,7 +43,7 @@ def __init__(self, setting):
self.Bind(wx.EVT_CHECKBOX, self.setting.ReverseCopy, self.copyCheck)

# 连续复制模式
self.continusCheck = wx.CheckBox(buttonPanel, -1, 'Continus Copy')
self.continusCheck = wx.CheckBox(buttonPanel, -1, 'Incremental Copy')
self.Bind(wx.EVT_CHECKBOX, self.setting.ReverseContinus, self.continusCheck)

# 连续复制模式
Expand Down
3 changes: 2 additions & 1 deletion copyTranslator/mypanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ def __init__(self, parent):
self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftDown)
self.Bind(wx.EVT_LEFT_UP, self.OnLeftUp)
self.Bind(wx.EVT_LEFT_DCLICK, self.OnLeftDClick)
self.Bind(wx.EVT_RIGHT_DOWN, self.parentFrame.setting.taskbar.OnExchange)
self.Bind(wx.EVT_MOTION, self.OnMouseMove)
self.Bind(wx.EVT_RIGHT_UP, self.parentFrame.setting.Copy)
self.Bind(wx.EVT_RIGHT_DOWN, self.parentFrame.setting.Copy)

def OnLeftDClick(self, evt):
# self.parentFrame.setting.ChangeMode(evt)
self.parentFrame.Close()

def OnLeftDown(self, evt):
Expand Down
Loading

0 comments on commit 4974f36

Please sign in to comment.