Skip to content

Commit e2f9590

Browse files
committed
.
1 parent 1c4a55d commit e2f9590

File tree

6 files changed

+64
-5
lines changed

6 files changed

+64
-5
lines changed

src/LunaTranslator/cishu/cishubase.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,11 @@ class cishubase(commonbase):
4141
def init(self):
4242
pass
4343

44-
def search(self, word) -> str: ...
44+
def search(self, word: str) -> str:
45+
...
4546

46-
def getUrl(self, word) -> str: ...
47+
def getUrl(self, word: str) -> str:
48+
...
4749

4850
def result_cache_key(self, word, sentence=None):
4951
return word, sentence, str(self.rawconfig)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from myutils.utils import checkmd5reloadmodule
2+
import gobject
3+
from cishu.cishubase import cishubase
4+
5+
6+
class selfbuild(cishubase):
7+
def __init__(self, *a):
8+
self.internal = None
9+
self.__lastm = None
10+
super().__init__(*a)
11+
12+
def mayreinit(self):
13+
module = checkmd5reloadmodule(
14+
gobject.getconfig("selfbuild_cishu.py"), "selfbuild_cishu"
15+
)
16+
if module and (module.MyCishu != self.__lastm):
17+
self.__lastm = module.MyCishu
18+
self.internal: cishubase = module.MyCishu("selfbuild")
19+
self.internal.init()
20+
21+
def search(self, word) -> str:
22+
self.mayreinit()
23+
if not self.internal:
24+
return None
25+
return self.internal.search(word)
26+
27+
def getUrl(self, word) -> str:
28+
self.mayreinit()
29+
if not self.internal:
30+
return None
31+
return self.internal.getUrl(word)

src/LunaTranslator/defaultconfig/config.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1521,6 +1521,10 @@
15211521
}
15221522
},
15231523
"type": "offline"
1524+
},
1525+
"selfbuild": {
1526+
"use": false,
1527+
"name": "自定义"
15241528
}
15251529
},
15261530
"force_rect": true,

src/LunaTranslator/gui/setting/cishu.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
from qtsymbols import *
22
import functools, os
33
import gobject
4-
from myutils.utils import splitocrtypes, dynamiccishuname
4+
from myutils.utils import splitocrtypes, dynamiccishuname, selectdebugfile
55
from myutils.config import globalconfig, _TR
66
from myutils.wrapper import Singleton
77
from gui.inputdialog import autoinitdialog_items, autoinitdialog
88
from gui.rcdownload import resourcewidget, resourcewidget2
99
from gui.usefulwidget import (
1010
LGroupBox,
1111
VisLFormLayout,
12-
MySwitch,
1312
makescrollgrid,
1413
D_getsimpleswitch,
1514
listediter,
@@ -171,6 +170,13 @@ def __(cishu):
171170
line += [
172171
D_getIconButton(callback=functools.partial(__, cishu)),
173172
]
173+
elif cishu == "selfbuild":
174+
line += [
175+
D_getIconButton(
176+
callback=lambda: selectdebugfile("selfbuild_cishu.py"),
177+
icon="fa.edit",
178+
)
179+
]
174180
else:
175181
line += [""]
176182
if i % 3 == 2:
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from cishu.cishubase import cishubase
2+
3+
4+
class MyCishu(cishubase):
5+
backgroundparser = ""
6+
use_github_md_css = False
7+
8+
def init(self):
9+
pass
10+
11+
def search(self, word: str) -> str:
12+
...
13+
14+
def getUrl(self, word: str) -> str:
15+
...

src/LunaTranslator/myutils/template/selfbuild_tts.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ def getvoicelist(self) -> "tuple[list[str], list[str]]":
1313

1414
def speak(
1515
self, content, voice, param: SpeechParam
16-
) -> "bytes|Response|TTSResult|types.GeneratorType": ...
16+
) -> "bytes|Response|TTSResult|types.GeneratorType":
17+
...

0 commit comments

Comments
 (0)