Skip to content

Commit

Permalink
v0.0.7 release
Browse files Browse the repository at this point in the history
  • Loading branch information
elliottzheng committed Nov 28, 2018
1 parent 8cebddd commit 961290e
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 58 deletions.
4 changes: 2 additions & 2 deletions copyTranslator/CopyTranslator.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import wx

from copyTranslator.setting import Setting
from copyTranslator.controller import Controller


# import subprocess

def main():
# subprocess.Popen('shortcut.bat',stdin = subprocess.PIPE, stdout = subprocess.PIPE)
app = wx.App()
setting = Setting()
controller = Controller()

app.MainLoop()

Expand Down
7 changes: 3 additions & 4 deletions copyTranslator/color_ctrl.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ def __init__(self, parent=None, id=None, style=0, setting=None):
self.setting = setting
self.lang = self.setting.lang
if style == 0:
style = wx.TE_RICH2 | wx.TE_MULTILINE | wx.TE_PROCESS_ENTER
style = wx.TE_RICH2 | wx.TE_MULTILINE | wx.TE_PROCESS_ENTER | wx.TE_NOHIDESEL
super(ColoredCtrl, self).__init__(parent=parent, id=id, style=style)

self.Bind(wx.EVT_RIGHT_DOWN, self.OnShowPopup)
Expand Down Expand Up @@ -117,8 +117,6 @@ def CreateContextMenu(self):

# menu.Append(self.ID_Mode2, self.lang(self.setting.config.Mode2))



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

Expand Down Expand Up @@ -181,7 +179,8 @@ def show_word(self, result):
# Color.black)

self.ColoredAppend('\nBasic Explains:\n', Color.blue)
self.ColoredAppend('\t' + '\n\t'.join(result['basic']['explains']) + '\n', Color.black)
filtered = filter(lambda x: x is not None, result['basic']['explains'])
self.ColoredAppend('\t' + '\n\t'.join(filtered) + '\n', Color.black)

if 'translation' in result:
self.ColoredAppend('Google Translation:\n', Color.blue)
Expand Down
52 changes: 32 additions & 20 deletions copyTranslator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

import json
import os
import threading
import webbrowser

import wx
from pynput import mouse

from constant import version
from constant import *
from copyTranslator.youdao import YoudaoSpider
from focusframe import FocusFrame
from googletranslator import GoogleTranslator
Expand All @@ -27,24 +29,24 @@ def __init__(self, setting):
self.mouseListener = mouse.Listener(on_click=self.setting.onLongClick)
self._default_value = {'author': 'Elliott Zheng',
'version': version,
'is_listen': False,
'is_listen': True,
'is_copy': False,
'is_dete': False,
'stay_top': True,
'stay_top': False,
'continus': False,
'smart_dict': True,
'frame_mode': FrameMode.main,
'translator_type': TranslatorType.GOOGLE,
'font_size': 15,
'focus_x': 100,
'focus_y': 100,
'focus_height': 150,
'focus_width': 300,
'focus_height': 300,
'focus_width': 500,
'source': 'English',
'target': 'Chinese (Simplified)',
'last_ask': 0,
'language': 'Chinese (Simplified)',
'autohide': True,
'autohide': False,
'autoshow': False
}
self.value = self._default_value
Expand All @@ -71,6 +73,8 @@ def activate(self):
self.is_copy = self.is_copy
self.frame_mode = self.frame_mode
self.is_dict = self.is_dict
self.autoshow = self.autoshow
self.autohide = self.autohide
self.switch_translator()

def detect(self, string):
Expand All @@ -95,17 +99,18 @@ def target(self):
def target(self, value):
self['target'] = value

def load(self):
def load(self): # 只有版本相同才会被保留,因为配置文件在不同版本间变化很大。
if not os.path.exists(self.filepath):
FirstThread().start()
self.save(self.filepath)
return self
myfile = open(self.filepath, 'r')
value = json.load(myfile)
myfile.close()
if value['version'] < 'v0.0.7.0':
self.inherent(value)
elif value['version'] >= 'v0.0.7.0':
if value['version'] == version:
self.value = value
else:
FirstThread().start()
self.save(self.filepath)
return self

Expand All @@ -116,16 +121,6 @@ def save(self, filepath=None):
json.dump(self.value, myfile, indent=4)
myfile.close()

def inherent(self, old_value):
self.continus = old_value['continus']
self.stay_top = old_value['stay_top']
self.is_listen = old_value['is_listen']
self.is_dete = old_value['is_dete']
self.is_copy = old_value['is_copy']
self.frame_mode = FrameMode.main if old_value['is_main'] else FrameMode.focus # TODO
self.font_size = old_value['pixel_size']
self.is_dict = old_value['smart_dict']

def switch_translator(self, type=TranslatorType.GOOGLE):
if type == TranslatorType.GOOGLE:
self.translator = GoogleTranslator()
Expand Down Expand Up @@ -293,6 +288,7 @@ def autohide(self):
@autohide.setter
def autohide(self, value):
self.value['autohide'] = value
self.setting.mainFrame.hideCheck.SetValue(value)

@property
def autoshow(self):
Expand All @@ -301,3 +297,19 @@ def autoshow(self):
@autoshow.setter
def autoshow(self, value):
self.value['autoshow'] = value
self.setting.mainFrame.showCheck.SetValue(value)


class FirstThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)

def run(self):
box = wx.MessageDialog(None,
'If you found it useful, please give me a star on GitHub or introduce to your friend.\n\n如果您感觉本软件对您有所帮助,请在项目Github上给个star或是介绍给您的朋友,谢谢。\n\n本软件免费开源,如果您是以付费的方式获得本软件,那么你应该是被骗了。[○・`Д´・ ○]\n\n这是您首次使用,本软件功能非常丰富,需要查看使用指南才能完全发挥功能,前往软件官网查看?',
project_name + ' ' + version + ' by Elliott Zheng',
wx.YES_NO | wx.STAY_ON_TOP | wx.ICON_QUESTION)
answer = box.ShowModal()
if answer == wx.ID_YES:
webbrowser.open(usage_url)
box.Destroy()
3 changes: 2 additions & 1 deletion copyTranslator/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,13 @@
# @Software: PyCharm

logopath = 'logo.ico'
version = 'v0.0.7.0-Kirin-Alpha'
version = 'v0.0.7-Kylin-RC0'
project_name = 'CopyTranslator'
update_json_url = 'https://hypercube.top/copytranslator/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://hypercube.top/copytranslator/'
usage_url = 'https://github.com/elliottzheng/CopyTranslator/wiki/Usage-%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97'
level = 3

levels_log = {
Expand Down
32 changes: 19 additions & 13 deletions copyTranslator/setting.py → copyTranslator/controller.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
# -*- coding: utf-8 -*-
# @Time : 2018/9/25 0025 17:49
# @Author : Elliott Zheng
# @FileName: setting.py
# @FileName: contraller.py
# @Software: PyCharm

import threading
import time

import pyperclip as smart_clipboard
import regex as re
from pynput.keyboard import Key, Controller
from pynput.keyboard import Controller as KeyboardController
from pynput.keyboard import Key

from config import Config
from copyTranslator.focusframe import FocusFrame
Expand Down Expand Up @@ -56,10 +57,10 @@ def check_contain_chinese(check_str):
return False


class Setting():
class Controller():
def __init__(self):
# Collect events until released
self.keyboard = Controller()
self.keyboard = KeyboardController()
self.ori_x = 0
self.ori_y = 0
self.t1 = time.time()
Expand Down Expand Up @@ -132,6 +133,8 @@ def ToWriting(self, event):

def save_config(self):
self.config['focus_x'], self.config['focus_y'] = self.subFrame.GetPosition()
if self.config['focus_y'] < 0:
self.config['focus_y'] = 0
self.config['focus_width'], self.config['focus_height'] = self.subFrame.GetSize()
self.config.source, self.config.target = self.get_src_target()
self.config.save()
Expand Down Expand Up @@ -277,13 +280,15 @@ def AutoHide(self, event=False):
else: # 收起
x, y_now = frame.GetPosition()
# 不贴边不自动收起
if (y_now > 0 or not self.config.autohide) and event is not None:
if (y_now > 0 or not self.config.autohide) and event is not False:
return
_, height = frame.GetSize()
target = -height + 10
while (y_now >= target):
frame.SetPosition((x, y_now))
y_now -= 2
if event == False:
self.mainFrame.SetFocus()
except:
pass

Expand All @@ -296,14 +301,14 @@ def OnTaskBarLeftDClick(self, event):
frame.Raise()

def BossKey(self, evt):
value = self.config.frame_mode
if value == FrameMode.main:
frame = self.mainFrame
elif value == FrameMode.focus:
frame = self.subFrame
else:
frame = self.writingFrame

# value = self.config.frame_mode
# if value == FrameMode.main:
# frame = self.mainFrame
# elif value == FrameMode.focus:
# frame = self.subFrame
# else:
# frame = self.writingFrame
frame = self.get_current_frame()
frame.Iconize(not frame.IsIconized())

if not frame.IsIconized():
Expand Down Expand Up @@ -399,3 +404,4 @@ def switch_hide(self, event):

def switch_show(self, event):
self.config.autoshow = not self.config.autoshow

20 changes: 16 additions & 4 deletions copyTranslator/mainframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ def __init__(self, setting):

self.SetIcon(wx.Icon(logopath, wx.BITMAP_TYPE_ICO))
self.SetWindowStyle(MainFrame.mainStyle)
# self.SetMinSize((465, 385))
self.setting = setting
self.lang = self.setting.lang
TextPanel = wx.Panel(self, -1)
Expand All @@ -45,6 +46,14 @@ def __init__(self, setting):
self.continusCheck = wx.CheckBox(buttonPanel, -1, self.lang('Incremental Copy'))
self.Bind(wx.EVT_CHECKBOX, self.setting.ReverseContinus, self.continusCheck)

# 贴边隐藏
self.hideCheck = wx.CheckBox(buttonPanel, -1, self.lang('Auto Hide'))
self.Bind(wx.EVT_CHECKBOX, self.setting.switch_hide, self.hideCheck)

# 自动显示
self.showCheck = wx.CheckBox(buttonPanel, -1, self.lang('Auto Show'))
self.Bind(wx.EVT_CHECKBOX, self.setting.switch_show, self.showCheck)

# 连续复制模式
self.dictCheck = wx.CheckBox(buttonPanel, -1, self.lang('Smart Dict'))
self.Bind(wx.EVT_CHECKBOX, self.setting.ReverseDict, self.dictCheck)
Expand Down Expand Up @@ -91,9 +100,10 @@ def __init__(self, setting):

TextPanel.SetSizer(panel1sizer)

panel2sizer = wx.FlexGridSizer(13, 1, 6, 0)
panel2sizer = wx.FlexGridSizer(15, 1, 6, 0)
panel2sizer.AddMany(
[self.topCheck, self.listenCheck, self.copyCheck, self.dictCheck, self.continusCheck, self.detectCheck,
self.hideCheck, self.showCheck,
self.fromlabel,
self.fromchoice,
tolabel, self.tochoice, self.switchBtn, self.transBtn, self.copyBtn])
Expand All @@ -103,13 +113,15 @@ def __init__(self, setting):
panel2sizer.AddGrowableRow(3, 0)
panel2sizer.AddGrowableRow(4, 0)
panel2sizer.AddGrowableRow(5, 0)
# panel2sizer.AddGrowableRow(6, 0)
panel2sizer.AddGrowableRow(6, 0)
panel2sizer.AddGrowableRow(7, 0)
# panel2sizer.AddGrowableRow(8, 0)
#panel2sizer.AddGrowableRow(8, 0)
panel2sizer.AddGrowableRow(9, 0)
panel2sizer.AddGrowableRow(10, 0)
#panel2sizer.AddGrowableRow(10, 0)
panel2sizer.AddGrowableRow(11, 0)
panel2sizer.AddGrowableRow(12, 0)
panel2sizer.AddGrowableRow(13, 0)
panel2sizer.AddGrowableRow(14, 0)

buttonPanel.SetSizer(panel2sizer)

Expand Down
8 changes: 4 additions & 4 deletions copyTranslator/mypanel.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@ def __init__(self, parent, setting=None):

def OnLeftDClick(self, evt):
# self.parentFrame.setting.ChangeMode(evt)
if self.setting.config.autohide:
self.setting.AutoHide(False)
else:
self.setting.get_current_frame().OnIconfiy(evt)
# if self.setting.config.autohide:
self.setting.AutoHide(False)
# else:
# self.setting.get_current_frame().OnIconfiy(evt)

def OnLeftDown(self, evt):
self.CaptureMouse()
Expand Down
4 changes: 2 additions & 2 deletions copyTranslator/shortcut.bat
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ set Program=%~dp0CopyTranslator.exe

::设置快捷方式名称(必选)

set LnkName=Copy Translator
set LnkName=CopyTranslator



Expand All @@ -20,7 +20,7 @@ set WorkDir=%~dp0

::设置快捷方式显示的说明(可选)

set Desc=Copy, translate and paste with Google translate API.
set Desc=Foreign language assisted reading and translation solution



Expand Down
8 changes: 7 additions & 1 deletion copyTranslator/taskbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class TaskBarIcon(wx.adv.TaskBarIcon):
ID_ENGLISH = wx.NewId()
ID_Hide = wx.NewId()
ID_Format = wx.NewId()
ID_AutoShow = wx.NewId()

def __init__(self, setting):
self.setting = setting
Expand All @@ -60,6 +61,7 @@ def __init__(self, setting):
self.Bind(wx.EVT_MENU, self.OnLanguage, id=self.ID_ENGLISH)
self.Bind(wx.EVT_MENU, self.OnLanguage, id=self.ID_CHINESE)
self.Bind(wx.EVT_MENU, self.setting.switch_hide, id=self.ID_Hide)
self.Bind(wx.EVT_MENU, self.setting.switch_show, id=self.ID_AutoShow)

def OnLanguage(self, event):
if event.Id == self.ID_ENGLISH:
Expand All @@ -73,13 +75,14 @@ def OnExchange(self, event):
def OnAbout(self, event):
UpdateThread(self.setting).start()
box = wx.MessageDialog(self.setting.get_current_frame(),
'If you found it useful, please give me a star on GitHub or introduce to your friend.\n\n如果您感觉本软件对您有所帮助,请在项目Github上给个star或是介绍给您的朋友,谢谢。\n\n 本软件免费开源,如果您是以付费的方式获得本软件,那么你应该是被骗了。[○・`Д´・ ○]',
'If you found it useful, please give me a star on GitHub or introduce to your friend.\n\n如果您感觉本软件对您有所帮助,请在项目Github上给个star或是介绍给您的朋友,谢谢。\n\n本软件免费开源,如果您是以付费的方式获得本软件,那么你应该是被骗了。[○・`Д´・ ○]\n\n前往软件官网?',
project_name + ' ' + version + ' by Elliott Zheng', wx.YES_NO | wx.ICON_QUESTION)
answer = box.ShowModal()
if answer == wx.ID_YES:
webbrowser.open(project_url)
box.Destroy()


# 右键菜单
def CreatePopupMenu(self):
menu = wx.Menu()
Expand All @@ -106,6 +109,9 @@ def CreatePopupMenu(self):
hide = menu.AppendCheckItem(self.ID_Hide, self.lang('Auto Hide'), 'Auto Hide')
hide.Check(self.setting.config.autohide)

autoShow = menu.AppendCheckItem(self.ID_AutoShow, self.lang('Auto Show'), 'Auto Show')
autoShow.Check(self.setting.config.autoshow)

# hide = menu.AppendCheckItem(self.ID_Format, self.lang('Auto Formation'), 'Auto Hide')
# hide.Check(self.setting.config.autohide)

Expand Down
Loading

0 comments on commit 961290e

Please sign in to comment.