Skip to content

Commit

Permalink
完善界面
Browse files Browse the repository at this point in the history
  • Loading branch information
xxNull-lsk committed Jan 14, 2023
1 parent 5877201 commit 1e345ac
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 16 deletions.
4 changes: 4 additions & 0 deletions src/UI/find_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,7 @@ def on_find(self):
txt = self.edit_text.toPlainText()
self.result.reset(txt)
self.online.translate(txt)

def showEvent(self, e) -> None:
super().showEvent(e)
self.edit_text.setFocus()
4 changes: 4 additions & 0 deletions src/UI/find_word.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ def on_find(self):
if k in setting.dicts_for_query\
or (count == 1 and setting.dicts_for_query[0] == "*"):
self.result.add_word_result(k, res[k])

def showEvent(self, e) -> None:
super().showEvent(e)
self.edit_word.setFocus()
14 changes: 12 additions & 2 deletions src/UI/result.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from src.events import events
from src.util import load_icon
from src.backend.youdao import YouDaoFanYi
from src.setting import setting


class ResultWindow(QWidget):
Expand Down Expand Up @@ -144,13 +145,16 @@ def _add_online_word_result(self, result):
index += 1
res = self.css + "<div class=\"title\">{}</div><p>".format(result["server"]) + res + "</p>"

self.btn_uk.hide()
self.label_uksm.hide()
self.btn_us.hide()
self.label_ussm.hide()
if 'uk' in result:
uk = result['uk']
if uk['speach'] != '':
self.media_player_uk.setMedia(
QMediaContent(QUrl(YouDaoFanYi.voice_addr(uk['speach'])))
)
self.media_player_uk.play()
self.btn_uk.show()
if uk['sm'] != '':
self.label_uksm.setText("[{}]".format(uk['sm']))
Expand All @@ -162,11 +166,17 @@ def _add_online_word_result(self, result):
self.media_player_us.setMedia(
QMediaContent(QUrl(YouDaoFanYi.voice_addr(us['speach'])))
)
self.media_player_us.play()
self.btn_us.show()
if us['sm'] != '':
self.label_ussm.setText("[{}]".format(us['sm']))
self.label_ussm.show()

# 自动播放
if setting.auto_play_sound:
if self.btn_us.isVisible():
self.media_player_us.play()
elif self.btn_uk.isVisible():
self.media_player_uk.play()

html = self.edit_res.toHtml()
self.edit_res.setHtml("{}{}".format(res, html))
Expand Down
10 changes: 6 additions & 4 deletions src/UI/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def __init__(self, parent, star_dict: StartDict):
self.edit_main_hotkey.setFlat(True)

self.checkbox_use_dark_skin = QCheckBox("使用灰色主题")

self.checkbox_auto_play_sound = QCheckBox("取词后自动播放声音")
self.checkbox_support_clipboard = QCheckBox("支持剪贴板取词")
self.slider_clipboard_count_label = QLabel(" 复制相同内容{}次触发".format(setting.clipboard_count))
self.slider_clipboard_second_label = QLabel(" 同一内容{:.1f}秒后失效".format(setting.clipboard_second))
Expand Down Expand Up @@ -200,11 +200,10 @@ def __init__(self, parent, star_dict: StartDict):
create_multi_line(["取词词典:", self.list_clipboard_dicts])
])
items = [
[self.checkbox_auto_startup],
[self.checkbox_show_main_window_when_startup],
[self.checkbox_auto_startup, self.checkbox_show_main_window_when_startup],
[self.checkbox_hide_when_close],
[" 显示主窗口热键:", create_line([self.edit_main_hotkey])],
[self.checkbox_use_dark_skin],
[self.checkbox_use_dark_skin, self.checkbox_auto_play_sound],
[self.checkbox_support_clipboard],
[self.slider_clipboard_count_label, create_line([self.slider_clipboard_count]), ],
[self.slider_clipboard_second_label, create_line([self.slider_clipboard_second]), ],
Expand All @@ -219,6 +218,7 @@ def __init__(self, parent, star_dict: StartDict):

self.init_data()
self.checkbox_use_dark_skin.clicked.connect(self.on_save)
self.checkbox_auto_play_sound.clicked.connect(self.on_save)
self.checkbox_support_clipboard.clicked.connect(self.on_save)
self.slider_clipboard_count.valueChanged.connect(self.on_clipboard_count_changed)
self.slider_clipboard_second.valueChanged.connect(self.on_clipboard_second_changed)
Expand Down Expand Up @@ -249,6 +249,7 @@ def init_data(self):
)
self.edit_ocr_server.setText(setting.ocr_server)
self.checkbox_use_dark_skin.setChecked(setting.use_dark_skin)
self.checkbox_auto_play_sound.setChecked(setting.auto_play_sound)
self.edit_ocr_hotkey.setText(
" - ".join(setting.ocr_hotkey).upper() if len(setting.ocr_hotkey) > 0 else '禁用'
)
Expand Down Expand Up @@ -366,6 +367,7 @@ def on_clipboard_second_changed(self, val):
def on_save(self):
setting.hide_when_close = self.checkbox_hide_when_close.isChecked()
setting.use_dark_skin = self.checkbox_use_dark_skin.isChecked()
setting.auto_play_sound = self.checkbox_auto_play_sound.isChecked()
setting.support_clipboard = self.checkbox_support_clipboard.isChecked()
setting.support_ocr = self.checkbox_support_ocr.isChecked()
setting.show_main_window_when_startup = self.checkbox_show_main_window_when_startup.isChecked()
Expand Down
9 changes: 0 additions & 9 deletions src/UI/tip_window.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from PyQt5.QtCore import QRect, QTimer, Qt, QSize, pyqtSignal, QPoint
from PyQt5.QtGui import QCursor, QFont, QColor, QMouseEvent
from PyQt5.QtMultimedia import QMediaPlayer
from PyQt5.QtWidgets import QVBoxLayout, QLabel, QApplication, QPushButton
from system_hotkey import SystemHotkey

Expand Down Expand Up @@ -150,14 +149,6 @@ def on_clipboard(self, txt):
return False
return self.query(txt, QCursor.pos())

@staticmethod
def on_play(media_player: QMediaPlayer):
try:
media_player.stop()
media_player.play()
except Exception as ex:
print("Exception", ex)

def check_last_text(self, txt):
now = datetime.datetime.now()
if self.last_text != txt:
Expand Down
1 change: 1 addition & 0 deletions src/setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class DefaultSetting:
word_book = "{}/word_book.db".format(setting_folder)
show_main_window_when_startup = True
auto_start = True
auto_play_sound = True
use_dark_skin = True
dicts_for_query = ["*"]
dicts_for_clipboard = ["youdao"]
Expand Down
4 changes: 3 additions & 1 deletion src/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from PyQt5.QtGui import QIcon, QPixmap

version = {
"curr": "0.6.13",
"curr": "0.6.14",
"history": {
"0.0.1": "实现基本功能:\n"
" 1、查词界面\n"
Expand Down Expand Up @@ -39,6 +39,8 @@
"0.6.12": "1、完善无托盘区域的兼容性。\n"
"2、提高archlinux、centos的兼容性。\n",
"0.6.13": "1、完善gnome桌面环境的兼容性。\n",
"0.6.14": "1、优化控件焦点。\n"
"2、新增配置项:取词后自动播放声音。\n",
}
}

Expand Down

0 comments on commit 1e345ac

Please sign in to comment.