mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2025-01-14 16:33:54 +08:00
.
This commit is contained in:
parent
a93c1b9e1a
commit
80b1956756
@ -1,4 +1,6 @@
|
||||
|
||||
#include <wil/com.h>
|
||||
#include <uiautomation.h>
|
||||
DECLARE_API void showintab(HWND hwnd, bool show, bool tool)
|
||||
{
|
||||
// WS_EX_TOOLWINDOW可以立即生效,WS_EX_APPWINDOW必须切换焦点才生效。但是WS_EX_TOOLWINDOW会改变窗口样式,因此只对无边框窗口使用。
|
||||
@ -155,3 +157,60 @@ DECLARE_API bool check_window_viewable(HWND hwnd)
|
||||
RECT _;
|
||||
return IntersectRect(&_, &windowRect, &monitorInfo.rcWork);
|
||||
}
|
||||
|
||||
DECLARE_API void GetSelectedText(void (*cb)(const wchar_t *))
|
||||
{
|
||||
CoInitialize(nullptr);
|
||||
try
|
||||
{
|
||||
// 初始化 COM
|
||||
wil::com_ptr<IUIAutomation> automation;
|
||||
if (FAILED(CoCreateInstance(CLSID_CUIAutomation, nullptr, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&automation))) || !automation)
|
||||
{
|
||||
throw std::runtime_error("无法初始化 UI Automation.");
|
||||
}
|
||||
|
||||
// 获取焦点元素
|
||||
wil::com_ptr<IUIAutomationElement> focusedElement;
|
||||
if (FAILED(automation->GetFocusedElement(&focusedElement)) || !focusedElement)
|
||||
{
|
||||
throw std::runtime_error("无法获取当前焦点元素.");
|
||||
}
|
||||
|
||||
// 检查是否支持 TextPattern
|
||||
wil::com_ptr<IUIAutomationTextPattern> textPattern;
|
||||
if (FAILED(focusedElement->GetCurrentPatternAs(UIA_TextPatternId, IID_PPV_ARGS(&textPattern))) || !textPattern)
|
||||
{
|
||||
throw std::runtime_error("当前元素不支持 TextPattern.");
|
||||
}
|
||||
|
||||
// 获取选定的文本范围
|
||||
wil::com_ptr<IUIAutomationTextRangeArray> selection;
|
||||
if (FAILED(textPattern->GetSelection(&selection)) || !selection)
|
||||
{
|
||||
throw std::runtime_error("无法获取选定的文本范围.");
|
||||
}
|
||||
|
||||
// 获取第一个选定范围
|
||||
wil::com_ptr<IUIAutomationTextRange> range;
|
||||
if (FAILED(selection->GetElement(0, &range)) || !range)
|
||||
{
|
||||
throw std::runtime_error("没有选定文本.");
|
||||
}
|
||||
|
||||
// 提取文本
|
||||
BSTR text;
|
||||
if (FAILED(range->GetText(-1, &text)) || !text)
|
||||
{
|
||||
throw std::runtime_error("无法提取选定的文本.");
|
||||
}
|
||||
std::wstring selectedText(text, SysStringLen(text));
|
||||
SysFreeString(text);
|
||||
cb(selectedText.c_str());
|
||||
}
|
||||
catch (std::exception &e)
|
||||
{
|
||||
printf(e.what());
|
||||
}
|
||||
CoUninitialize();
|
||||
}
|
||||
|
@ -130,6 +130,9 @@
|
||||
|
||||
### **Dictionary Lookup**
|
||||
|
||||
1. #### Search for keywords
|
||||
Search for words in the text currently selected by the mouse
|
||||
|
||||
1. #### Anki Recording
|
||||
Shortcut key for the recording function in the Anki add interface in the dictionary lookup window.
|
||||
|
||||
|
@ -130,6 +130,9 @@
|
||||
|
||||
### **辞書検索**
|
||||
|
||||
1. #### 単語を調べる
|
||||
現在のマウスで選択されているテキストの単語検索
|
||||
|
||||
1. #### Anki録音
|
||||
辞書検索ウィンドウのAnki追加インターフェースの録音機能のショートカットキー。
|
||||
|
||||
|
@ -131,6 +131,9 @@
|
||||
|
||||
### **查词**
|
||||
|
||||
1. #### 查词
|
||||
对当前鼠标选取到的文本查词
|
||||
|
||||
1. #### Anki 录音
|
||||
查词窗口中的Anki添加界面中的录音功能的快捷键
|
||||
|
||||
|
@ -387,7 +387,6 @@ class MAINUI:
|
||||
maybehaspremt = {}
|
||||
skip_other_on_success = False
|
||||
fix_rank = globalconfig["fix_translate_rank_rank"].copy()
|
||||
print(is_auto_run , globalconfig["fanyi"]["rengong"].get("manual", False))
|
||||
if ("rengong" in self.translators) and (
|
||||
not (is_auto_run and globalconfig["fanyi"]["rengong"].get("manual", False))
|
||||
):
|
||||
|
@ -12,17 +12,17 @@ class jisho(cishubase):
|
||||
contents = []
|
||||
idx = 0
|
||||
for title, res in allres:
|
||||
idx += 1
|
||||
btns.append(
|
||||
"""<button type="button" onclick="onclickbtn_xxxxxx_internal('buttonid_xxxxx_internal{idx}')" id="buttonid_xxxxx_internal{idx}" class="tab-button_xxxx_internal{klass}" data-tab="tab_xxxxx_internal{idx}">{title}</button>""".format(
|
||||
idx=idx, title=title, klass='' if idx==0 else ' active'
|
||||
idx=idx, title=title, klass='' if idx!=0 else ' active'
|
||||
)
|
||||
)
|
||||
contents.append(
|
||||
"""<div id="tab_xxxxx_internal{idx}" class="tab-pane_xxxxx_internal{klass}">{res}</div>""".format(
|
||||
idx=idx, res=res,klass='' if idx==0 else ' active'
|
||||
idx=idx, res=res,klass='' if idx!=0 else ' active'
|
||||
)
|
||||
)
|
||||
idx += 1
|
||||
commonstyle = """
|
||||
<script>
|
||||
function onclickbtn_xxxxxx_internal(_id) {
|
||||
|
@ -22,8 +22,8 @@ from myutils.config import (
|
||||
from gui.usefulwidget import (
|
||||
saveposwindow,
|
||||
getboxlayout,
|
||||
MySwitch,
|
||||
IconButton,
|
||||
statusbutton,
|
||||
getsimplecombobox,
|
||||
FQLineEdit,
|
||||
FocusCombo,
|
||||
@ -58,34 +58,22 @@ class dialog_savedgame_integrated(saveposwindow):
|
||||
dialog_savedgame_v3,
|
||||
dialog_savedgame_legacy,
|
||||
][type]
|
||||
|
||||
[self.layout1btn, self.layout2btn, self.layout3btn][(type) % 3].setEnabled(
|
||||
False
|
||||
)
|
||||
[self.layout1btn, self.layout2btn, self.layout3btn][
|
||||
(type + 1) % 3
|
||||
].setEnabled(False)
|
||||
[self.layout1btn, self.layout2btn, self.layout3btn][
|
||||
(type + 2) % 3
|
||||
].setEnabled(False)
|
||||
[self.layout1btn, self.layout2btn, self.layout3btn][
|
||||
(type + 1) % 3
|
||||
].setChecked(False)
|
||||
[self.layout1btn, self.layout2btn, self.layout3btn][
|
||||
(type + 2) % 3
|
||||
].setChecked(False)
|
||||
btns = [self.layout1btn, self.layout2btn, self.layout3btn]
|
||||
btns[(type + 0) % 3].setEnabled(False)
|
||||
btns[(type + 1) % 3].setEnabled(False)
|
||||
btns[(type + 2) % 3].setEnabled(False)
|
||||
btns[(type + 0) % 3].setChecked(True)
|
||||
btns[(type + 1) % 3].setChecked(False)
|
||||
btns[(type + 2) % 3].setChecked(False)
|
||||
_old = self.internallayout.takeAt(0).widget()
|
||||
_old.hide()
|
||||
_ = klass(self)
|
||||
self.internallayout.addWidget(_)
|
||||
_.directshow()
|
||||
_old.deleteLater()
|
||||
[self.layout1btn, self.layout2btn, self.layout3btn][
|
||||
(type + 1) % 3
|
||||
].setEnabled(True)
|
||||
[self.layout1btn, self.layout2btn, self.layout3btn][
|
||||
(type + 2) % 3
|
||||
].setEnabled(True)
|
||||
btns[(type + 0) % 3].setEnabled(False)
|
||||
btns[(type + 1) % 3].setEnabled(True)
|
||||
btns[(type + 2) % 3].setEnabled(True)
|
||||
self.__internal = _
|
||||
except:
|
||||
print_exc()
|
||||
@ -106,15 +94,21 @@ class dialog_savedgame_integrated(saveposwindow):
|
||||
self.__internal = None
|
||||
self.internallayout.addWidget(QWidget())
|
||||
self.setCentralWidget(w)
|
||||
self.layout1btn = MySwitch(self, icon="fa.th")
|
||||
self.layout2btn = MySwitch(self, icon="fa.th-list")
|
||||
self.layout3btn = MySwitch(self, icon="fa.list")
|
||||
self.layout1btn.clicked.connect(functools.partial(self.selectlayout, 0))
|
||||
self.layout2btn.clicked.connect(functools.partial(self.selectlayout, 1))
|
||||
self.layout3btn.clicked.connect(functools.partial(self.selectlayout, 2))
|
||||
self.layout1btn.setFixedSize(QSize(20, 25))
|
||||
self.layout2btn.setFixedSize(QSize(20, 25))
|
||||
self.layout3btn.setFixedSize(QSize(20, 25))
|
||||
|
||||
def createbtn(icon, i):
|
||||
btn = statusbutton(
|
||||
p=self,
|
||||
icons=icon,
|
||||
border=False,
|
||||
colors=["", globalconfig["buttoncolor2"]],
|
||||
)
|
||||
btn.clicked.connect(functools.partial(self.selectlayout, i))
|
||||
btn.setFixedSize(QSize(20, 25))
|
||||
return btn
|
||||
|
||||
self.layout1btn = createbtn("fa.th", 0)
|
||||
self.layout2btn = createbtn("fa.th-list", 1)
|
||||
self.layout3btn = createbtn("fa.list", 2)
|
||||
self.syssettingbtn = IconButton(icon="fa.gear", parent=self)
|
||||
self.syssettingbtn.setFixedSize(QSize(25, 25))
|
||||
self.syssettingbtn.clicked.connect(self.syssetting)
|
||||
@ -128,16 +122,15 @@ class dialog_savedgame_integrated(saveposwindow):
|
||||
)
|
||||
|
||||
def resizeEvent(self, e: QResizeEvent):
|
||||
self.layout1btn.move(e.size().width() - self.layout1btn.width() - 5, 0)
|
||||
self.layout1btn.move(e.size().width() - self.layout1btn.width(), 0)
|
||||
self.layout2btn.move(
|
||||
e.size().width() - self.layout2btn.width() - self.layout1btn.width() - 5, 0
|
||||
e.size().width() - self.layout2btn.width() - self.layout1btn.width(), 0
|
||||
)
|
||||
self.layout3btn.move(
|
||||
e.size().width()
|
||||
- self.layout3btn.width()
|
||||
- self.layout2btn.width()
|
||||
- self.layout1btn.width()
|
||||
- 5,
|
||||
- self.layout1btn.width(),
|
||||
0,
|
||||
)
|
||||
self.syssettingbtn.move(
|
||||
@ -145,8 +138,7 @@ class dialog_savedgame_integrated(saveposwindow):
|
||||
- self.syssettingbtn.width()
|
||||
- self.layout3btn.width()
|
||||
- self.layout2btn.width()
|
||||
- self.layout1btn.width()
|
||||
- 5,
|
||||
- self.layout1btn.width(),
|
||||
0,
|
||||
)
|
||||
|
||||
|
@ -382,18 +382,18 @@ class viewpixmap_x(QWidget):
|
||||
self.centerwidgetlayout = QVBoxLayout()
|
||||
audio = QHBoxLayout()
|
||||
self.recordbtn = statusbutton(
|
||||
icons=["fa.microphone", "fa.stop"], colors=["", ""]
|
||||
icons=["fa.microphone", "fa.stop"]
|
||||
)
|
||||
self.recordbtn.statuschanged.connect(self.startorendrecord)
|
||||
self.recordbtn.clicked.connect(self.startorendrecord)
|
||||
self.centerwidget.setLayout(self.centerwidgetlayout)
|
||||
self.centerwidgetlayout.addWidget(self.timenothide)
|
||||
self.centerwidgetlayout.addWidget(self.pathandopen)
|
||||
self.centerwidgetlayout.addWidget(self.commentedit)
|
||||
self.centerwidgetlayout.addLayout(audio)
|
||||
audio.addWidget(self.recordbtn)
|
||||
self.btnplay = statusbutton(icons=["fa.play", "fa.stop"], colors=["", ""])
|
||||
self.btnplay = statusbutton(icons=["fa.play", "fa.stop"])
|
||||
audio.addWidget(self.btnplay)
|
||||
self.btnplay.statuschanged.connect(self.playorstop)
|
||||
self.btnplay.clicked.connect(self.playorstop)
|
||||
gobject.baseobject.hualang_recordbtn = self.recordbtn
|
||||
self.centerwidget.setVisible(False)
|
||||
self.pathview = fadeoutlabel(self)
|
||||
@ -419,11 +419,11 @@ class viewpixmap_x(QWidget):
|
||||
return False
|
||||
return True
|
||||
|
||||
def playorstop(self, idx):
|
||||
def playorstop(self, check):
|
||||
if not self.checkplayable():
|
||||
return
|
||||
mp3 = extradatas["imagerefmp3"][self.currentimage]
|
||||
if idx == 1:
|
||||
if check:
|
||||
self.play_context = playonce(mp3, globalconfig["ttscommon"]["volume"])
|
||||
self.sigtime = time.time()
|
||||
|
||||
@ -439,8 +439,8 @@ class viewpixmap_x(QWidget):
|
||||
return
|
||||
self.play_context = None
|
||||
|
||||
def startorendrecord(self, idx):
|
||||
if idx == 1:
|
||||
def startorendrecord(self, check):
|
||||
if check:
|
||||
if self.play_context:
|
||||
self.btnplay.click()
|
||||
self.btnplay.setEnabled(False)
|
||||
@ -897,6 +897,8 @@ class dialog_savedgame_v3(QWidget):
|
||||
|
||||
spl.setSizes(globalconfig["dialog_savegame_layout"]["listitemwidth_2"])
|
||||
spl.splitterMoved.connect(__)
|
||||
spl.setStretchFactor(0, 0)
|
||||
spl.setStretchFactor(1, 1)
|
||||
rightlay.addWidget(self.pixview)
|
||||
|
||||
isfirst = True
|
||||
|
@ -39,6 +39,8 @@ class TabWidget(QWidget):
|
||||
self.tab_widget.tabBar().hide()
|
||||
self.splitter.addWidget(self.list_widget)
|
||||
self.splitter.addWidget(self.tab_widget)
|
||||
self.splitter.setStretchFactor(0, 0)
|
||||
self.splitter.setStretchFactor(1, 1)
|
||||
self.currentChanged.connect(
|
||||
self.tab_widget.setCurrentIndex
|
||||
) # 监听 Tab 切换事件
|
||||
|
@ -20,7 +20,6 @@ from gui.usefulwidget import (
|
||||
D_getcolorbutton,
|
||||
D_getsimplecombobox,
|
||||
)
|
||||
from gui.showword import showdiction
|
||||
from gui.setting_about import offlinelinks
|
||||
|
||||
|
||||
@ -300,10 +299,7 @@ def setTabcishu_l(self):
|
||||
lambda: gobject.baseobject.searchwordW.showsignal.emit(),
|
||||
"fa.search",
|
||||
),
|
||||
D_getIconButton(
|
||||
lambda: showdiction(self).show(),
|
||||
"fa.book",
|
||||
),
|
||||
"",
|
||||
"",
|
||||
"辞书显示顺序",
|
||||
D_getIconButton(
|
||||
|
@ -143,9 +143,8 @@ def createinternalfontsettings(self, forml: LFormLayout, group, _type):
|
||||
lineW = getcolorbutton(
|
||||
dd,
|
||||
key,
|
||||
transparent=False,
|
||||
callback=functools.partial(
|
||||
lambda dd, key, _: selectcolor(
|
||||
lambda dd, key: selectcolor(
|
||||
self, dd, key, self.miaobian_color_button
|
||||
),
|
||||
dd,
|
||||
|
@ -93,6 +93,9 @@ def registrhotkeys(self):
|
||||
"36": lambda: gobject.baseobject.textgetmethod(
|
||||
winsharedutils.clipboard_get(), False
|
||||
),
|
||||
"37": lambda: gobject.baseobject.searchwordW.search_word.emit(
|
||||
winsharedutils.GetSelectedText(), False
|
||||
),
|
||||
}
|
||||
for name in self.bindfunctions:
|
||||
regist_or_not_key(self, name)
|
||||
@ -105,7 +108,7 @@ hotkeys = [
|
||||
["剪贴板", ["36", "_4", "_28"]],
|
||||
["TTS", ["_32", "_7", "_7_1"]],
|
||||
["游戏", ["_15", "_20", "_21", "_22", "_25", "_27", "_31"]],
|
||||
["查词", ["_29", "_30", "_35", "_33"]],
|
||||
["查词", ["37", "_29", "_30", "_35", "_33"]],
|
||||
]
|
||||
|
||||
|
||||
|
@ -421,7 +421,7 @@ class AnkiWindow(QWidget):
|
||||
windows.keybd_event(mode, 0, windows.KEYEVENTF_KEYUP, 0)
|
||||
|
||||
def startorendrecord(self, ii, target: QLineEdit, idx):
|
||||
if idx == 1:
|
||||
if idx:
|
||||
self.recorders[ii] = loopbackrecorder()
|
||||
self.simulate_key(ii)
|
||||
else:
|
||||
@ -478,12 +478,12 @@ class AnkiWindow(QWidget):
|
||||
|
||||
self.example.textChanged.connect(__)
|
||||
self.remarks = FQPlainTextEdit()
|
||||
recordbtn1 = statusbutton(icons=["fa.microphone", "fa.stop"], colors=["", ""])
|
||||
recordbtn1.statuschanged.connect(
|
||||
recordbtn1 = statusbutton(icons=["fa.microphone", "fa.stop"])
|
||||
recordbtn1.clicked.connect(
|
||||
functools.partial(self.startorendrecord, 1, self.audiopath)
|
||||
)
|
||||
recordbtn2 = statusbutton(icons=["fa.microphone", "fa.stop"], colors=["", ""])
|
||||
recordbtn2.statuschanged.connect(
|
||||
recordbtn2 = statusbutton(icons=["fa.microphone", "fa.stop"])
|
||||
recordbtn2.clicked.connect(
|
||||
functools.partial(self.startorendrecord, 2, self.audiopath_sentence)
|
||||
)
|
||||
self.recordbtn1 = recordbtn1
|
||||
@ -518,7 +518,9 @@ class AnkiWindow(QWidget):
|
||||
btn = LPushButton("添加")
|
||||
btn.clicked.connect(functools.partial(self.errorwrap, False))
|
||||
btn.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
||||
btn.customContextMenuRequested.connect(functools.partial(self.errorwrap, True))
|
||||
btn.customContextMenuRequested.connect(
|
||||
functools.partial(self.errorwrap, True)
|
||||
)
|
||||
return btn
|
||||
|
||||
layout.addLayout(
|
||||
@ -871,7 +873,7 @@ class kpQTreeView(QTreeView):
|
||||
super().keyPressEvent(e)
|
||||
|
||||
|
||||
class showdiction(LMainWindow):
|
||||
class showdiction(QWidget):
|
||||
def setwordfilter(self, index=None):
|
||||
w = self.word.text()
|
||||
if index is None:
|
||||
@ -940,33 +942,33 @@ class showdiction(LMainWindow):
|
||||
self.word = FQLineEdit()
|
||||
self.word.returnPressed.connect(self.setwordfilter)
|
||||
wordfilter.addWidget(self.word)
|
||||
butn = getIconButton(self.setwordfilter, "fa.filter")
|
||||
butn = getIconButton(self.setwordfilter, "fa.search")
|
||||
wordfilter.addWidget(butn)
|
||||
|
||||
self.resize(400, parent.height())
|
||||
self.setWindowTitle("查看")
|
||||
self.setWindowIcon(qtawesome.icon("fa.book"))
|
||||
refresh = getIconButton(self.refresh, "fa.refresh")
|
||||
wordfilter.addWidget(refresh)
|
||||
self.tree = kpQTreeView(self)
|
||||
self.tree.setUniformRowHeights(True)
|
||||
self.tree.setHeaderHidden(True)
|
||||
self.tree.setEditTriggers(QAbstractItemView.EditTrigger.NoEditTriggers)
|
||||
__c = QWidget()
|
||||
__lay = QVBoxLayout()
|
||||
__c.setLayout(__lay)
|
||||
self.setLayout(__lay)
|
||||
__lay.setSpacing(0)
|
||||
__lay.setContentsMargins(0, 0, 0, 0)
|
||||
__lay.addLayout(wordfilter)
|
||||
__lay.addWidget(self.tree)
|
||||
self.setCentralWidget(__c)
|
||||
|
||||
self.model = DynamicTreeModel(self.setwordfilter)
|
||||
self.tree.setModel(self.model)
|
||||
self.tree.expanded.connect(self.model.loadChildren)
|
||||
root = self.model.invisibleRootItem()
|
||||
self.tree.doubleClicked.connect(self.model.onDoubleClicked)
|
||||
self.tree.enterpressed.connect(self.model.onDoubleClicked)
|
||||
self.tree.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
||||
self.tree.customContextMenuRequested.connect(self.showmenu)
|
||||
self.refresh()
|
||||
|
||||
def refresh(self):
|
||||
self.model.clear()
|
||||
root = self.model.invisibleRootItem()
|
||||
rows = []
|
||||
for k in globalconfig["cishuvisrank"]:
|
||||
cishu = gobject.baseobject.cishus[k]
|
||||
@ -1089,15 +1091,15 @@ class searchwordW(closeashidewindow):
|
||||
self.vboxlayout.addLayout(self.searchlayout)
|
||||
self.searchtext = FQLineEdit()
|
||||
self.searchtext.textChanged.connect(self.ankiwindow.reset)
|
||||
self.history_last_btn = statusbutton(
|
||||
icons=["fa.arrow-left", "fa.arrow-left"], colors=["", ""]
|
||||
|
||||
self.dictbutton = statusbutton(
|
||||
icons="fa.book", colors=["", globalconfig["buttoncolor2"]]
|
||||
)
|
||||
self.history_last_btn = statusbutton(icons=["fa.arrow-left", "fa.arrow-left"])
|
||||
self.history_last_btn.clicked.connect(
|
||||
functools.partial(self.__move_history_search, -1)
|
||||
)
|
||||
self.history_next_btn = statusbutton(
|
||||
icons=["fa.arrow-right", "fa.arrow-right"], colors=["", ""]
|
||||
)
|
||||
self.history_next_btn = statusbutton(icons=["fa.arrow-right", "fa.arrow-right"])
|
||||
self.history_next_btn.clicked.connect(
|
||||
functools.partial(self.__move_history_search, 1)
|
||||
)
|
||||
@ -1105,6 +1107,7 @@ class searchwordW(closeashidewindow):
|
||||
self.trace_history = []
|
||||
self.trace_history_idx = -1
|
||||
self.__set_history_btn_able()
|
||||
self.searchlayout.addWidget(self.dictbutton)
|
||||
self.searchlayout.addWidget(self.history_last_btn)
|
||||
self.searchlayout.addWidget(self.history_next_btn)
|
||||
self.searchlayout.addWidget(self.searchtext)
|
||||
@ -1126,9 +1129,9 @@ class searchwordW(closeashidewindow):
|
||||
self.searchlayout.addWidget(soundbutton)
|
||||
|
||||
ankiconnect = statusbutton(
|
||||
icons=["fa.adn", "fa.adn"], colors=["", globalconfig["buttoncolor2"]]
|
||||
icons="fa.adn", colors=["", globalconfig["buttoncolor2"]]
|
||||
)
|
||||
ankiconnect.statuschanged.connect(self.onceaddankiwindow)
|
||||
ankiconnect.clicked.connect(self.onceaddankiwindow)
|
||||
ankiconnect.setContextMenuPolicy(Qt.ContextMenuPolicy.CustomContextMenu)
|
||||
ankiconnect.customContextMenuRequested.connect(
|
||||
lambda _: self.ankiwindow.errorwrap()
|
||||
@ -1183,12 +1186,29 @@ class searchwordW(closeashidewindow):
|
||||
w.setLayout(tablayout)
|
||||
self.vboxlayout.addWidget(self.spliter)
|
||||
self.isfirstshowanki = True
|
||||
self.isfirstshowdictwidget = True
|
||||
self.spliter.setOrientation(Qt.Orientation.Vertical)
|
||||
|
||||
self.spliter.addWidget(w)
|
||||
self.dict_textoutput_spl = QSplitter()
|
||||
self.dict_textoutput_spl.addWidget(w)
|
||||
self.spliter.addWidget(self.dict_textoutput_spl)
|
||||
self.dictbutton.clicked.connect(self.onceaddshowdictwidget)
|
||||
|
||||
def onceaddshowdictwidget(self, idx):
|
||||
if idx:
|
||||
if self.isfirstshowdictwidget:
|
||||
self.showdictwidget = showdiction(self)
|
||||
self.dict_textoutput_spl.insertWidget(0, self.showdictwidget)
|
||||
self.dict_textoutput_spl.setStretchFactor(0, 0)
|
||||
self.dict_textoutput_spl.setStretchFactor(1, 1)
|
||||
else:
|
||||
self.showdictwidget.show()
|
||||
else:
|
||||
self.showdictwidget.hide()
|
||||
self.isfirstshowdictwidget = False
|
||||
|
||||
def onceaddankiwindow(self, idx):
|
||||
if idx == 1:
|
||||
if idx:
|
||||
if self.isfirstshowanki:
|
||||
self.spliter.addWidget(self.ankiwindow)
|
||||
self.ankiwindow.setMinimumHeight(1)
|
||||
|
@ -643,56 +643,6 @@ class MySwitch(commonsolveevent):
|
||||
pass
|
||||
|
||||
|
||||
class IconButton(commonsolveevent):
|
||||
clicked = pyqtSignal()
|
||||
|
||||
def sizeHint(self):
|
||||
return QSize(
|
||||
int(1.42 * globalconfig["buttonsize2"]),
|
||||
int(1.42 * globalconfig["buttonsize2"]),
|
||||
)
|
||||
|
||||
def __init__(self, icon, enable=True, qicon=None, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)
|
||||
self.setCursor(Qt.CursorShape.PointingHandCursor)
|
||||
self.enable = enable
|
||||
self._icon = icon
|
||||
self._qicon = qicon
|
||||
|
||||
def setEnabled(self, enable):
|
||||
self.enable = enable
|
||||
self.update()
|
||||
|
||||
def isEnabled(self):
|
||||
return self.enable
|
||||
|
||||
def paintEvent(self, event):
|
||||
painter = QPainter(self)
|
||||
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
||||
painter.setPen(Qt.PenStyle.NoPen)
|
||||
if self._qicon:
|
||||
icon = self._qicon
|
||||
|
||||
else:
|
||||
|
||||
__ = QColor(globalconfig["buttoncolor2"])
|
||||
if not self.enable:
|
||||
__ = disablecolor(__)
|
||||
icon: QIcon = qtawesome.icon(self._icon, color=__)
|
||||
bigw = self.size().width() - self.sizeHint().width()
|
||||
bigh = self.size().height() - self.sizeHint().height()
|
||||
x = bigw // 2
|
||||
y = bigh // 2
|
||||
painter.drawPixmap(x, y, icon.pixmap(self.sizeHint()))
|
||||
|
||||
def mouseReleaseEvent(self, event) -> None:
|
||||
if not self.enable:
|
||||
return
|
||||
if event.button() == Qt.MouseButton.LeftButton:
|
||||
self.clicked.emit()
|
||||
|
||||
|
||||
class resizableframeless(saveposwindow):
|
||||
def __init__(self, parent, flags, poslist) -> None:
|
||||
super().__init__(parent, poslist, flags)
|
||||
@ -971,29 +921,17 @@ def getcolorbutton(
|
||||
icon="fa.paint-brush",
|
||||
constcolor=None,
|
||||
enable=True,
|
||||
transparent=True,
|
||||
qicon=None,
|
||||
sizefixed=False,
|
||||
):
|
||||
if qicon is None:
|
||||
qicon = qtawesome.icon(icon, color=constcolor if constcolor else d[key])
|
||||
b = QPushButton()
|
||||
b.setIcon(qicon)
|
||||
b.setEnabled(enable)
|
||||
b = IconButton(None, enable=enable, parent=parent, qicon=qicon)
|
||||
sz = int(1.42 * globalconfig["buttonsize2"])
|
||||
b.setIconSize(QSize(sz, sz))
|
||||
if sizefixed:
|
||||
b.setFixedSize(QSize(sz, sz))
|
||||
if transparent:
|
||||
b.setStyleSheet(
|
||||
"""background-color: rgba(255, 255, 255, 0);
|
||||
color: black;
|
||||
border: 0px;
|
||||
font: 100 10pt;"""
|
||||
)
|
||||
if callback:
|
||||
b.clicked.connect(callback)
|
||||
b.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)
|
||||
if name:
|
||||
setattr(parent, name, b)
|
||||
return b
|
||||
@ -1008,7 +946,6 @@ def D_getcolorbutton(
|
||||
icon="fa.paint-brush",
|
||||
constcolor=None,
|
||||
enable=True,
|
||||
transparent=True,
|
||||
qicon=None,
|
||||
sizefixed=False,
|
||||
):
|
||||
@ -1021,7 +958,6 @@ def D_getcolorbutton(
|
||||
icon,
|
||||
constcolor,
|
||||
enable,
|
||||
transparent,
|
||||
qicon,
|
||||
sizefixed,
|
||||
)
|
||||
@ -1748,7 +1684,7 @@ def makegroupingrid(args):
|
||||
if title:
|
||||
group.setTitle(title)
|
||||
else:
|
||||
group.setObjectName('notitle')
|
||||
group.setObjectName("notitle")
|
||||
|
||||
if _type == "grid":
|
||||
grid = QGridLayout()
|
||||
@ -1832,9 +1768,7 @@ def automakegrid(grid: QGridLayout, lis, save=False, savelist=None):
|
||||
grid.setRowMinimumHeight(nowr, 25)
|
||||
|
||||
|
||||
def makegrid(
|
||||
grid=None, save=False, savelist=None, savelay=None, delay=False
|
||||
):
|
||||
def makegrid(grid=None, save=False, savelist=None, savelay=None, delay=False):
|
||||
|
||||
class gridwidget(QWidget):
|
||||
pass
|
||||
@ -2389,28 +2323,72 @@ class pixmapviewer(QWidget):
|
||||
|
||||
|
||||
class statusbutton(QPushButton):
|
||||
statuschanged = pyqtSignal(int)
|
||||
|
||||
def __init__(self, icons, colors):
|
||||
super().__init__()
|
||||
self.idx = 0
|
||||
self.icons = icons
|
||||
def __init__(self, icons, colors=None, border=True, p=None):
|
||||
super().__init__(p)
|
||||
if colors:
|
||||
self.colors = colors
|
||||
self.clicked.connect(self.setChecked)
|
||||
else:
|
||||
self.colors = ["", ""]
|
||||
if isinstance(icons, str):
|
||||
self.icons = [icons, icons]
|
||||
else:
|
||||
self.icons = icons
|
||||
self.setCheckable(True)
|
||||
self.seticon()
|
||||
self.clicked.connect(self.seticon)
|
||||
if not border:
|
||||
self.setStyleSheet("border:transparent")
|
||||
|
||||
def seticon(self):
|
||||
color = QColor(self.colors[self.idx])
|
||||
color = QColor(self.colors[self.isChecked()])
|
||||
if not self.isEnabled():
|
||||
color = disablecolor(color)
|
||||
icon = qtawesome.icon(self.icons[self.idx], color=color)
|
||||
icon = qtawesome.icon(self.icons[self.isChecked()], color=color)
|
||||
self.setIcon(icon)
|
||||
|
||||
def setChecked(self, a0):
|
||||
super().setChecked(a0)
|
||||
self.seticon()
|
||||
|
||||
def setEnabled(self, _):
|
||||
super().setEnabled(_)
|
||||
self.seticon()
|
||||
|
||||
|
||||
class IconButton(QPushButton):
|
||||
clicked = pyqtSignal()
|
||||
|
||||
def sizeHint(self):
|
||||
return QSize(
|
||||
int(1.42 * globalconfig["buttonsize2"]),
|
||||
int(1.42 * globalconfig["buttonsize2"]),
|
||||
)
|
||||
|
||||
def __init__(self, icon, enable=True, qicon=None, parent=None):
|
||||
super().__init__(parent)
|
||||
super().clicked.connect(self.clicked)
|
||||
self._icon = icon
|
||||
self._qicon = qicon
|
||||
self.setSizePolicy(QSizePolicy.Policy.Fixed, QSizePolicy.Policy.Fixed)
|
||||
self.setCursor(Qt.CursorShape.PointingHandCursor)
|
||||
self.setIconSize(self.sizeHint())
|
||||
self.setStyleSheet("border:transparent")
|
||||
self.setEnabled(enable)
|
||||
self.setFocusPolicy(Qt.FocusPolicy.NoFocus)
|
||||
|
||||
def seticon(self):
|
||||
if self._qicon:
|
||||
icon = self._qicon
|
||||
else:
|
||||
__ = QColor(globalconfig["buttoncolor2"])
|
||||
if not self.isEnabled():
|
||||
__ = disablecolor(__)
|
||||
icon: QIcon = qtawesome.icon(self._icon, color=__)
|
||||
self.setIcon(icon)
|
||||
|
||||
def setChecked(self, a0):
|
||||
super().setChecked(a0)
|
||||
self.idx += 1
|
||||
self.idx %= 2
|
||||
self.statuschanged.emit(self.idx)
|
||||
self.seticon()
|
||||
|
||||
def setEnabled(self, _):
|
||||
@ -2542,7 +2520,7 @@ class VisLFormLayout(LFormLayout):
|
||||
class CollapsibleBox(QGroupBox):
|
||||
def __init__(self, delayloadfunction=None, parent=None, margin0=True):
|
||||
super(CollapsibleBox, self).__init__(parent)
|
||||
self.setObjectName('notitle')
|
||||
self.setObjectName("notitle")
|
||||
lay = QVBoxLayout(self)
|
||||
if margin0:
|
||||
lay.setContentsMargins(0, 0, 0, 0)
|
||||
@ -2622,10 +2600,15 @@ class editswitchTextBrowser(QWidget):
|
||||
self.setLayout(l)
|
||||
l.setContentsMargins(0, 0, 0, 0)
|
||||
l.addWidget(stack)
|
||||
self.switch = MySwitch(self, icon="fa.edit")
|
||||
self.switch = statusbutton(
|
||||
p=self,
|
||||
icons="fa.edit",
|
||||
colors=["", globalconfig["buttoncolor2"]],
|
||||
border=False,
|
||||
)
|
||||
self.switch.setFixedSize(QSize(25, 25))
|
||||
self.switch.raise_()
|
||||
self.switch.clicked.connect(lambda c: stack.setCurrentIndex(not c))
|
||||
self.switch.clicked.connect(stack.setCurrentIndex)
|
||||
|
||||
def settext(self, text):
|
||||
self.edit.setPlainText(text)
|
||||
|
@ -363,3 +363,13 @@ StopCaptureAsync.argtypes = (HANDLE,)
|
||||
check_window_viewable = utilsdll.check_window_viewable
|
||||
check_window_viewable.argtypes = (HWND,)
|
||||
check_window_viewable.restype = c_bool
|
||||
_GetSelectedText = utilsdll.GetSelectedText
|
||||
_GetSelectedText.argtypes = (c_void_p,)
|
||||
|
||||
|
||||
def GetSelectedText():
|
||||
ret = []
|
||||
_GetSelectedText(CFUNCTYPE(None, c_wchar_p)(ret.append))
|
||||
if len(ret):
|
||||
return ret[0]
|
||||
return None
|
||||
|
@ -1051,6 +1051,11 @@
|
||||
"name": "复制到剪贴板_翻译",
|
||||
"keystring": ""
|
||||
},
|
||||
"37": {
|
||||
"use": false,
|
||||
"name": "查词",
|
||||
"keystring": ""
|
||||
},
|
||||
"_29": {
|
||||
"use": false,
|
||||
"name": "Anki_录音",
|
||||
|
Loading…
x
Reference in New Issue
Block a user