This commit is contained in:
恍兮惚兮 2024-12-27 02:38:07 +08:00
parent 95010beaff
commit 08b9ec6baa
46 changed files with 458 additions and 451 deletions

View File

@ -359,7 +359,7 @@ namespace
arg_ = arg;
argValue_ = *arg;
arg->setText(allocateString(buffer.viewW()));
arg->setText(buffer.viewW());
// if (arg->size)
// hashes_.insert(Engine::hashWCharArray(arg->text, arg->size));
// return true;
@ -452,7 +452,7 @@ namespace
arg_ = arg;
argValue_ = *arg;
arg->setText(allocateString(buffer.viewW()));
arg->setText(buffer.viewW());
}
void hookAfter(hook_context *context, HookParam *hp, TextBuffer *buffer, uintptr_t *split)

View File

@ -434,9 +434,7 @@ namespace
newData.append(trimmedText + trimmedSize, suffixSize);
arg_ = arg;
argValue_ = *arg;
static std::string data_;
data_ = newData;
arg->setText(data_);
arg->setText(newData);
}
void hookAfter(hook_context *context, HookParam *hp, TextBuffer *buffer, uintptr_t *split)
{

View File

@ -523,6 +523,8 @@ namespace
s = std::regex_replace(s, std::regex(R"(@r(.*?)@(.*?)@)"), "$1");
strReplace(s, "@n", "");
strReplace(s, "@e", "");
strReplace(s, "@k", "");
strReplace(s, "@p", "");
buffer->from(s);
};
return NewHook(hp, "NeXAS4");

View File

@ -1765,8 +1765,7 @@ namespace
{
auto arg = (TextUnionW *)(type_ == Type1 ? s->ecx : s->stack[1]);
auto argValue = *arg;
auto newText = new std::wstring(buffer.viewW());
arg->setLongText(*newText);
arg->setText(buffer.viewW());
// Restoring is indispensible, and as a result, the default hook does not work
//*arg = argValue;
@ -1836,9 +1835,7 @@ namespace OtherHook
auto arg = (TextUnionW *)s->stack[0];
arg_ = arg;
argValue_ = *arg;
static std::wstring text_;
text_ = buffer.viewW();
arg->setLongText(text_);
arg->setText(buffer.viewW());
}
ULONG search(ULONG startAddress, ULONG stopAddress)

View File

@ -265,9 +265,7 @@ void hookafter1(hook_context *s, TextBuffer buffer)
auto arg = (TextUnionA *)(s->stack[0] + sizeof(DWORD)); // arg1
arg_ = arg;
argValue_ = *arg;
static std::string data_;
data_ = newData;
arg->setText(data_);
arg->setText(newData);
}
void hookAfter(hook_context *context, HookParam *hp, TextBuffer *buffer, uintptr_t *split)

View File

@ -192,13 +192,11 @@ namespace
void hookafter(hook_context *s, TextBuffer buffer)
{
auto newData = buffer.strA();
auto newData = buffer.viewA();
auto arg = (TextUnionA *)(s->stack[0] + sizeof(DWORD)); // arg1
arg_ = arg;
argValue_ = *arg;
static std::string data_;
data_ = newData;
arg->setText(data_.c_str(), data_.size());
arg->setText(newData);
}
void hookAfter1(hook_context *context, HookParam *hp, TextBuffer *buffer, uintptr_t *split)
{

View File

@ -269,18 +269,12 @@ namespace
}
void WillPlus_extra_filter(TextBuffer *buffer, HookParam *)
{
StringFilter(buffer, L"%XS", 5); // remove %XS followed by 2 chars
std::wstring str = buffer->strW();
strReplace(str, L"\\n", L"\n");
std::wregex reg1(L"\\{(.*?):(.*?)\\}");
std::wstring result1 = std::regex_replace(str, reg1, L"$1");
std::wregex reg11(L"\\{(.*?);(.*?)\\}");
result1 = std::regex_replace(result1, reg11, L"$1");
std::wregex reg2(L"%[A-Z]+");
result1 = std::regex_replace(result1, reg2, L"");
std::wstring result1 = std::regex_replace(str, std::wregex(L"\\{(.*?):(.*?)\\}"), L"$1");
result1 = std::regex_replace(result1, std::wregex(L"\\{(.*?);(.*?)\\}"), L"$1");
result1 = std::regex_replace(result1, std::wregex(L"%[A-Z]+"), L"");
buffer->from(result1);
};
bool InsertWillPlusAHook()
@ -553,11 +547,8 @@ namespace will3
lc = 1;
str = str.substr(3);
}
std::wregex reg1(L"\\{(.*?):(.*?)\\}");
str = std::regex_replace(str, reg1, L"$1");
std::wregex reg11(L"\\{(.*?);(.*?)\\}");
str = std::regex_replace(str, reg11, L"$1");
str = std::regex_replace(str, std::wregex(L"\\{(.*?):(.*?)\\}"), L"$1");
str = std::regex_replace(str, std::wregex(L"\\{(.*?);(.*?)\\}"), L"$1");
buffer->from(str);
}
@ -1679,23 +1670,24 @@ namespace
0x85, 0xC9, // test ecx,ecx
0x74, 0x04 // je AdvHD.exe+396C6
};
ULONG range = min(processStopAddress - processStartAddress, MAX_REL_ADDR);
ULONG addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStartAddress + range);
ULONG addr = MemDbg::findBytes(bytes, sizeof(bytes), processStartAddress, processStopAddress);
if (!addr)
{
ConsoleOutput("WillPlus5: pattern not found");
return false;
}
//[241227] [とこはな] エロ漫画お姉ちゃん!! ~ダメダメな姉との甘々コスプレえっちな日々~
addr = addr + 5 + *(int *)(addr + 1);
HookParam hp = {};
hp.address = addr;
hp.offset = regoffset(esi);
hp.index = 0;
hp.split = regoffset(ebx);
hp.split_index = 0;
hp.type = CODEC_UTF16 | USING_STRING | NO_CONTEXT | USING_SPLIT;
hp.filter_fun = WillPlus_extra_filter;
ConsoleOutput("INSERT WillPlus5");
hp.type = CODEC_UTF16 | USING_STRING | USING_SPLIT | EMBED_ABLE;
hp.embed_hook_font = F_GetGlyphOutlineW;
hp.text_fun = [](hook_context *context, HookParam *hp, TextBuffer *buffer, uintptr_t *split)
{
buffer->from(((TextUnionW *)context->ecx)->getText());
*split = context->ebx;
};
hp.embed_fun = [](hook_context *context, TextBuffer buffer)
{
((TextUnionW *)context->ecx)->setText(buffer.viewW());
};
return NewHook(hp, "WillPlus5");
}

View File

@ -37,24 +37,16 @@ struct TextUnion
if (_size < ShortTextCapacity)
::memcpy(chars, _text, (_size + 1) * sizeof(CharT));
else
text = _text;
{
text = allocateString(std::basic_string_view<CharT>{_text, _size});
}
capacity = size = _size;
}
void setLongText(const CharT *_text, size_t _size)
template <typename StringT, typename = std::enable_if_t<!std::is_pointer_v<StringT>>>
void setText(const StringT &text)
{
text = _text;
size = _size;
capacity = max(ShortTextCapacity, _size);
}
void setText(const std::basic_string<CharT> &text)
{
setText((const CharT *)text.c_str(), text.size());
}
void setLongText(const std::basic_string<CharT> &text)
{
setLongText((const CharT *)text.c_str(), text.size());
setText(text.data(), text.size());
}
};

View File

@ -101,7 +101,6 @@ auto allocateString(const StringT &s) -> typename StringT::value_type *
{
size_t t = s.size();
typename StringT::value_type *_data = new typename StringT::value_type[t + 1];
strcpyEx(_data, s.data());
memcpy(_data, s.data(), strSize(s));
_data[t] = 0;
return _data;

View File

@ -2,7 +2,6 @@ import requests
from myutils.utils import urlpathjoin, createurl
from myutils.proxy import getproxy
from cishu.cishubase import cishubase
from myutils.commonbase import maybejson
from translator.gptcommon import qianfanIAM
@ -20,7 +19,7 @@ def list_models(typename, regist):
try:
return sorted([_["id"] for _ in resp.json()["data"]])
except:
raise Exception(maybejson(resp))
raise Exception(resp)
class chatgptlike(cishubase):
@ -84,7 +83,7 @@ class chatgptlike(cishubase):
return self.apiurl
return createurl(self.apiurl)
def commonparseresponse(self, response: requests.ResponseBase):
def commonparseresponse(self, response: requests.Response):
try:
message = (
response.json()["choices"][0]["message"]["content"]

View File

@ -9,9 +9,9 @@ def list_models(typename, regist):
urlpathjoin(regist["BASE_URL"]().strip(), "v1beta/models"),
params={"key": regist["SECRET_KEY"]().split("|")[0].strip()},
proxies=getproxy(("fanyi", typename)),
).json()
)
try:
models = js["models"]
models = js.json()["models"]
except:
raise Exception(js)
mm = []

View File

@ -6,24 +6,21 @@ from cishu.cishubase import cishubase
class goo(cishubase):
def init(self):
self.style = None
def search(self, word):
url = "https://dictionary.goo.ne.jp/srch/all/{}/m1u/".format(quote(word))
x = requests.get(url, proxies=self.proxy).text
xx = re.findall("<section>([\\s\\S]*?)</section>", x)
xx = "".join(xx).replace('href="/', 'href="https://dictionary.goo.ne.jp/')
temp = gobject.gettempdir("goo.css")
if os.path.exists(temp) == False:
stl = requests.get(
if not self.style:
self.style = requests.get(
"https://dictionary.goo.ne.jp/mix/css/app.css", proxies=self.proxy
).text
with open(temp, "w", encoding="utf8") as ff:
ff.write(stl)
else:
with open(temp, "r", encoding="utf8") as ff:
stl = ff.read()
if len(xx):
return '<div style="text-align: center;"><a href="{}">link</a><style>{}</style></div><div id="NR-main-in">{}</div>'.format(
url, stl, xx
url, self.style, xx
)

View File

@ -6,13 +6,18 @@ import threading, base64, re
class japandict(cishubase):
def makelinkbase64(self, link, saver):
def init(self):
self.style = {}
def makelinkbase64(self, link):
if not self.style.get(link):
html = requests.get(
link,
proxies=self.proxy,
).content.replace(b"padding-top:60px !important", b"")
base64_content = base64.b64encode(html).decode("utf-8")
saver[link] = "data:application/octet-stream;base64," + base64_content
self.style[link] = "data:application/octet-stream;base64," + base64_content
def search(self, word):
url = "https://www.japandict.com/?s={}&lang=eng&list=1".format(quote(word))
@ -28,13 +33,12 @@ class japandict(cishubase):
if not res:
return
ts = []
saver = {}
styles = '<link rel="stylesheet" href="https://www.japandict.com/static/css/japandict.ac087f3ecbc8.css" type="text/css"><link rel="preload" href="https://www.japandict.com/static/JapaneseRadicals-Regular.woff2" as="font"><link rel="preload" href="https://www.japandict.com/static/radicals_font.woff" as="font">'
for link in re.findall('href="(.*?)"', styles):
ts.append(threading.Thread(target=self.makelinkbase64, args=(link, saver)))
ts.append(threading.Thread(target=self.makelinkbase64, args=(link,)))
ts[-1].start()
for t in ts:
t.join()
for link in saver:
styles = styles.replace(link, saver[link])
for link in self.style:
styles = styles.replace(link, self.style[link])
return res + styles

View File

@ -7,6 +7,9 @@ from myutils.utils import get_element_by, simplehtmlparser_all
class jisho(cishubase):
def init(self):
self.style = {}
def generatehtml_tabswitch(self, allres):
btns = []
contents = []
@ -14,12 +17,12 @@ class jisho(cishubase):
for title, res in allres:
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
@ -127,8 +130,10 @@ function onclickbtn_xxxxxx_internal(_id) {
ss = re.search(
'href="https://assets.jisho.org/assets/application(.*)"', html
)
stl = requests.get(ss.group()[6:-1], proxies=self.proxy).text
saver["style"] = stl
link = ss.group()[6:-1]
if not self.style.get(link):
self.style[link] = requests.get(link, proxies=self.proxy).text
saver["style"] = self.style[link]
saver["primary"] = get_element_by("id", "result_area", res) + res.replace(
get_element_by("id", "main_results", res),
get_element_by("id", "primary", res),

View File

@ -2407,7 +2407,11 @@ class mdict(cishubase):
):
matches += [(_type, _) for _ in re.findall(patt, html_content)]
for _type_1, url in matches:
if url.startswith("#"): # a href # 页内跳转
if (
url.startswith("#")
or url.startswith("https:")
or url.startswith("http:")
):
continue
try:
file_content = self.tryloadurl(index, base, url, audiob64vals)
@ -2617,16 +2621,16 @@ if (content.style.display === 'block') {
extra = "display: none;"
uid = str(uuid.uuid4())
lis.append(
r"""<li><div class="collapsible-header" id="{}" onclick="mdict_flowstyle_clickcallback('{}')">{}</div><div class="collapsible-content" style="{}">
r"""<div><div class="collapsible-header" id="{}" onclick="mdict_flowstyle_clickcallback('{}')">{}</div><div class="collapsible-content" style="{}">
{}
</div></li>""".format(
</div></div>""".format(
uid, uid, title, extra, res
)
)
content += r"""
<ul class="collapsible-list">
<div class="collapsible-list">
{}
</ul>""".format(
</div>""".format(
"".join(lis)
)

View File

@ -11,7 +11,6 @@ from gui.dialog_savedgame_legacy import dialog_savedgame_legacy
from gui.dialog_savedgame_setting import dialog_setting_game, userlabelset
from myutils.wrapper import Singleton_close, tryprint
from gui.specialwidget import lazyscrollflow
from myutils.utils import str2rgba
from myutils.config import (
savehook_new_data,
savegametaged,
@ -29,7 +28,6 @@ from gui.usefulwidget import (
FocusCombo,
)
from gui.dialog_savedgame_common import (
ItemWidget,
dialog_syssetting,
tagitem,
startgamecheck,
@ -245,6 +243,161 @@ class TagWidget(QWidget):
self.__calltagschanged(signal)
class IMGWidget(QLabel):
def adaptsize(self, size: QSize):
if globalconfig["imagewrapmode"] == 0:
h, w = size.height(), size.width()
r = float(w) / h
max_r = float(self.width()) / self.height()
if r < max_r:
new_w = self.width()
new_h = int(new_w / r)
else:
new_h = self.height()
new_w = int(new_h * r)
return QSize(new_w, new_h)
elif globalconfig["imagewrapmode"] == 1:
h, w = size.height(), size.width()
r = float(w) / h
max_r = float(self.width()) / self.height()
if r > max_r:
new_w = self.width()
new_h = int(new_w / r)
else:
new_h = self.height()
new_w = int(new_h * r)
return QSize(new_w, new_h)
elif globalconfig["imagewrapmode"] == 2:
return self.size()
elif globalconfig["imagewrapmode"] == 3:
return size
def setimg(self, pixmap: QPixmap):
if not (self.height() and self.width()):
return
if self.__last == (self.size(), globalconfig["imagewrapmode"]):
return
self.__last = (self.size(), globalconfig["imagewrapmode"])
rate = self.devicePixelRatioF()
newpixmap = QPixmap(self.size() * rate)
newpixmap.setDevicePixelRatio(rate)
newpixmap.fill(Qt.GlobalColor.transparent)
painter = QPainter(newpixmap)
painter.setRenderHint(QPainter.RenderHint.SmoothPixmapTransform)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
painter.drawPixmap(self.getrect(pixmap.size()), pixmap)
painter.end()
self.setPixmap(newpixmap)
def getrect(self, size):
size = self.adaptsize(size)
rect = QRect()
rect.setX(int((self.width() - size.width()) / 2))
rect.setY(int((self.height() - size.height()) / 2))
rect.setSize(size)
return rect
def resizeEvent(self, a0):
self.setimg(self._pixmap)
return super().resizeEvent(a0)
def __init__(self, p, pixmap) -> None:
super().__init__(p)
self.setScaledContents(True)
if type(pixmap) != QPixmap:
pixmap = pixmap()
self._pixmap = pixmap
self.__last = None
def switch(self):
self.setimg(self._pixmap)
class ItemWidget(QWidget):
focuschanged = pyqtSignal(bool, str)
doubleclicked = pyqtSignal(str)
globallashfocus = None
@classmethod
def clearfocus(cls):
try: # 可能已被删除
if ItemWidget.globallashfocus:
ItemWidget.globallashfocus.focusOut()
except:
pass
ItemWidget.globallashfocus = None
def click(self):
try:
self.bottommask.show()
if self != ItemWidget.globallashfocus:
ItemWidget.clearfocus()
ItemWidget.globallashfocus = self
self.focuschanged.emit(True, self.gameuid)
except:
print_exc()
def mousePressEvent(self, ev) -> None:
self.click()
def focusOut(self):
self.bottommask.hide()
self.focuschanged.emit(False, self.gameuid)
def mouseDoubleClickEvent(self, e):
self.doubleclicked.emit(self.gameuid)
def resizeEvent(self, a0: QResizeEvent) -> None:
self.__w.resize(a0.size())
self.bottommask.resize(a0.size())
self.maskshowfileexists.resize(a0.size())
self._imgsz()
def others(self):
self._lb.setText(self.file if globalconfig["showgametitle"] else "")
self._img.switch()
self._imgsz()
def _imgsz(self):
textH = (
globalconfig["dialog_savegame_layout"]["textH"]
if globalconfig["showgametitle"]
else 0
)
margin = globalconfig["dialog_savegame_layout"]["margin2"]
self._img.setGeometry(
margin, margin, self.width() - 2 * margin, self.height() - textH
)
def __init__(self, gameuid, pixmap, file) -> None:
super().__init__()
self.gameuid = gameuid
self.file = file
self.maskshowfileexists = QLabel(self)
self._img = IMGWidget(self, pixmap)
self.__w = QWidget(self)
self.__w.setStyleSheet("background:transparent")
self._lb = QLabel(self)
self._lb.setText(file if globalconfig["showgametitle"] else "")
self._lb.setWordWrap(True)
self._lb.setObjectName("savegame_textfont1")
self._lb.setAlignment(Qt.AlignmentFlag.AlignHCenter)
l = QVBoxLayout(self.__w)
l.setContentsMargins(0, 0, 0, 0)
l.addStretch(1)
l.addWidget(self._lb)
exists = os.path.exists(get_launchpath(gameuid))
self.maskshowfileexists.setObjectName("savegame_exists" + str(exists))
if not exists:
self.maskshowfileexists.raise_()
self.bottommask = QLabel(self)
self.bottommask.hide()
self.bottommask.setObjectName("savegame_onselectcolor1")
class dialog_savedgame_new(QWidget):
def dragEnterEvent(self, event: QDragEnterEvent):
@ -311,6 +464,7 @@ class dialog_savedgame_new(QWidget):
globalconfig["dialog_savegame_layout"]["itemh"],
)
)
self.flow.setSpacing(globalconfig["dialog_savegame_layout"]["margin"])
self.formLayout.insertWidget(self.formLayout.count(), self.flow)
idx = 0
for k in self.reflist:
@ -490,6 +644,7 @@ class dialog_savedgame_new(QWidget):
globalconfig["dialog_savegame_layout"]["itemh"],
)
)
self.flow.setSpacing(globalconfig["dialog_savegame_layout"]["margin"])
self.flow.resizeandshow()
for _ in self.flow.widgets:
if not isinstance(_, ItemWidget):
@ -506,23 +661,15 @@ class dialog_savedgame_new(QWidget):
_style += "font-size:{}pt;".format(_f.pointSize())
_style += 'font-family:"{}";'.format(_f.family())
style = "#{}{{ {} }}".format(key, _style)
for exits in [True, False]:
c = globalconfig["dialog_savegame_layout"][
("onfilenoexistscolor1", "backcolor1")[exits]
]
c = str2rgba(
c,
globalconfig["dialog_savegame_layout"][
("transparentnotexits", "transparent")[exits]
],
)
style += "#savegame_exists{}{{background-color:{};}}".format(exits, c)
style += "#savegame_onselectcolor1{{background-color: {};}}".format(
str2rgba(
globalconfig["dialog_savegame_layout"]["onselectcolor1"],
globalconfig["dialog_savegame_layout"]["transparentselect"],
style += "#savegame_existsTrue{{background-color:{};}}".format(
globalconfig["dialog_savegame_layout"]["backcolor2"]
)
style += "#savegame_existsFalse{{background-color:{};}}".format(
globalconfig["dialog_savegame_layout"]["onfilenoexistscolor2"]
)
style += "#savegame_onselectcolor1{{background-color: {};}}".format(
globalconfig["dialog_savegame_layout"]["onselectcolor2"]
)
self.setStyleSheet(style)

View File

@ -37,163 +37,6 @@ def showcountgame(window, num):
window.setWindowTitle("游戏管理")
class ItemWidget(QWidget):
focuschanged = pyqtSignal(bool, str)
doubleclicked = pyqtSignal(str)
globallashfocus = None
@classmethod
def clearfocus(cls):
try: # 可能已被删除
if ItemWidget.globallashfocus:
ItemWidget.globallashfocus.focusOut()
except:
pass
ItemWidget.globallashfocus = None
def click(self):
try:
self.bottommask.show()
if self != ItemWidget.globallashfocus:
ItemWidget.clearfocus()
ItemWidget.globallashfocus = self
self.focuschanged.emit(True, self.gameuid)
except:
print_exc()
def mousePressEvent(self, ev) -> None:
self.click()
def focusOut(self):
self.bottommask.hide()
self.focuschanged.emit(False, self.gameuid)
def mouseDoubleClickEvent(self, e):
self.doubleclicked.emit(self.gameuid)
def resizeEvent(self, a0: QResizeEvent) -> None:
self.bottommask.resize(a0.size())
self.maskshowfileexists.resize(a0.size())
self.resizex()
def resizex(self):
margin = globalconfig["dialog_savegame_layout"]["margin"]
textH = (
globalconfig["dialog_savegame_layout"]["textH"]
if globalconfig["showgametitle"]
else 0
)
self._w.setFixedHeight(self.height() - textH)
self.wrap.setContentsMargins(margin, margin, margin, margin)
def others(self):
self._lb.setText(self.file if globalconfig["showgametitle"] else "")
self.resizex()
self._img.switch()
def __init__(self, gameuid, pixmap, file) -> None:
super().__init__()
self.file = file
self.maskshowfileexists = QLabel(self)
exists = os.path.exists(get_launchpath(gameuid))
self.maskshowfileexists.setObjectName("savegame_exists" + str(exists))
self.bottommask = QLabel(self)
self.bottommask.hide()
self.bottommask.setObjectName("savegame_onselectcolor1")
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
self._img = IMGWidget(pixmap)
_w = QWidget()
_w.setStyleSheet("background-color: rgba(255,255,255, 0);")
wrap = QVBoxLayout()
_w.setLayout(wrap)
self._w = _w
wrap.addWidget(self._img)
self.wrap = wrap
layout.addWidget(_w)
layout.setSpacing(0)
self._lb = QLabel()
self._lb.setText(file if globalconfig["showgametitle"] else "")
self._lb.setWordWrap(True)
self._lb.setObjectName("savegame_textfont1")
self._lb.setAlignment(Qt.AlignmentFlag.AlignHCenter)
layout.addWidget(self._lb)
self.setLayout(layout)
self.gameuid = gameuid
class IMGWidget(QLabel):
def adaptsize(self, size: QSize):
if globalconfig["imagewrapmode"] == 0:
h, w = size.height(), size.width()
r = float(w) / h
max_r = float(self.width()) / self.height()
if r < max_r:
new_w = self.width()
new_h = int(new_w / r)
else:
new_h = self.height()
new_w = int(new_h * r)
return QSize(new_w, new_h)
elif globalconfig["imagewrapmode"] == 1:
h, w = size.height(), size.width()
r = float(w) / h
max_r = float(self.width()) / self.height()
if r > max_r:
new_w = self.width()
new_h = int(new_w / r)
else:
new_h = self.height()
new_w = int(new_h * r)
return QSize(new_w, new_h)
elif globalconfig["imagewrapmode"] == 2:
return self.size()
elif globalconfig["imagewrapmode"] == 3:
return size
def setimg(self, pixmap: QPixmap):
if not (self.height() and self.width()):
return
if self.__last == (self.size(), globalconfig["imagewrapmode"]):
return
self.__last = (self.size(), globalconfig["imagewrapmode"])
rate = self.devicePixelRatioF()
newpixmap = QPixmap(self.size() * rate)
newpixmap.setDevicePixelRatio(rate)
newpixmap.fill(Qt.GlobalColor.transparent)
painter = QPainter(newpixmap)
painter.setRenderHint(QPainter.RenderHint.SmoothPixmapTransform)
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
painter.drawPixmap(self.getrect(pixmap.size()), pixmap)
painter.end()
self.setPixmap(newpixmap)
def getrect(self, size):
size = self.adaptsize(size)
rect = QRect()
rect.setX(int((self.width() - size.width()) / 2))
rect.setY(int((self.height() - size.height()) / 2))
rect.setSize(size)
return rect
def resizeEvent(self, a0):
self.setimg(self._pixmap)
return super().resizeEvent(a0)
def __init__(self, pixmap) -> None:
super().__init__()
self.setScaledContents(True)
if type(pixmap) != QPixmap:
pixmap = pixmap()
self._pixmap = pixmap
self.__last = None
def switch(self):
self.setimg(self._pixmap)
class ClickableLabel(QLabel):
def __init__(self):
super().__init__()
@ -262,7 +105,7 @@ class tagitem(QFrame):
key = (tag, _type, refdata)
self.setLayout(tagLayout)
lb = ClickableLabel()
lb.setStyleSheet("background: transparent;")
lb.setStyleSheet("background:transparent")
lb.setText(tag)
lb.clicked.connect(functools.partial(self.labelclicked.emit, key))
if removeable:
@ -327,21 +170,18 @@ def __scaletosize(_pix: QPixmap, tgt):
_pix.save(tgt)
def getcachedimage(src, small):
def getcachedimage(src, small) -> QPixmap:
if not small:
_pix = QPixmap(src)
if _pix.isNull():
return None
return _pix
return QPixmap(src)
if not os.path.exists(src):
return None
return QPixmap()
src2 = gobject.getcachedir("icon2/{}.jpg".format(__b64string(src)))
_pix = QPixmap(src2)
if not _pix.isNull():
return _pix
_pix = QPixmap(src)
if _pix.isNull():
return None
return _pix
__scaletosize(_pix, src2)
return _pix
@ -354,7 +194,7 @@ def getpixfunction(kk, small=False, iconfirst=False):
):
src = savehook_new_data[kk].get("currenticon")
pix = getcachedimage(src, small)
if pix:
if not pix.isNull():
return pix
_pix = getExeIcon(uid2gamepath[kk], False, cache=True)
return _pix
@ -364,11 +204,11 @@ def getpixfunction(kk, small=False, iconfirst=False):
):
src = savehook_new_data[kk].get("currentmainimage")
pix = getcachedimage(src, small)
if pix:
if not pix.isNull():
return pix
for _ in savehook_new_data[kk]["imagepath_all"]:
pix = getcachedimage(_, small)
if pix:
if not pix.isNull():
return pix
_pix = getExeIcon(uid2gamepath[kk], False, cache=True)
return _pix
@ -487,7 +327,7 @@ def getalistname(parent, callback, skipid=False, skipidid=None, title="添加到
"callback": functools.partial(__wrap, callback, __d, __uid),
},
],
exec_=True
exec_=True,
)
elif len(__uid):
@ -547,6 +387,7 @@ class dialog_syssetting(LDialog):
("itemw", "宽度"),
("itemh", "高度"),
("margin", "边距"),
("margin2", "边距_2"),
("textH", "文字区高度"),
]:
formLayout.addRow(
@ -594,10 +435,10 @@ class dialog_syssetting(LDialog):
)
formLayout.addRow(SplitLine())
for key, key2, name in [
("backcolor1", "transparent", "颜色"),
("onselectcolor1", "transparentselect", "选中时颜色"),
("onfilenoexistscolor1", "transparentnotexits", "游戏不存在时颜色"),
for key, name in [
("backcolor2", "颜色"),
("onselectcolor2", "选中时颜色"),
("onfilenoexistscolor2", "游戏不存在时颜色"),
]:
formLayout.addRow(
name,
@ -613,19 +454,10 @@ class dialog_syssetting(LDialog):
self,
key,
callback=self.parent().setstyle,
alpha=True,
),
name=key,
parent=self,
),
)
formLayout.addRow(
name + "_" + "不透明度",
getspinbox(
0,
100,
globalconfig["dialog_savegame_layout"],
key2,
callback=lambda _: self.parent().setstyle(),
),
)
self.show()

View File

@ -237,7 +237,7 @@ class dialog_savedgame_legacy(QWidget):
bottom.addWidget(button3)
_ = QLabel()
_.setFixedHeight(20)
_.setStyleSheet("background: transparent;")
_.setStyleSheet("background:transparent")
formLayout.addWidget(_)
formLayout.addWidget(table)
formLayout.addLayout(bottom)

View File

@ -11,7 +11,7 @@ from myutils.config import (
globalconfig,
)
from myutils.hwnd import clipboard_set_image
from myutils.utils import str2rgba, get_time_stamp, loopbackrecorder, getimagefilefilter
from myutils.utils import get_time_stamp, loopbackrecorder, getimagefilefilter
from myutils.audioplayer import playonce
from gui.inputdialog import autoinitdialog
from gui.specialwidget import stackedlist, shrinkableitem, shownumQPushButton
@ -37,11 +37,7 @@ from gui.dialog_savedgame_common import (
addgamebatch,
addgamebatch_x,
)
from gui.dynalang import (
LPushButton,
LAction,
LLabel,
)
from gui.dynalang import LAction, LLabel
class clickitem(QWidget):
@ -104,12 +100,12 @@ class clickitem(QWidget):
self.bottommask.hide()
self.bottommask.setObjectName("savegame_onselectcolor1")
_ = QLabel(self)
_.setStyleSheet("""background-color: rgba(255,255,255, 0);""")
_.setStyleSheet("background:transparent")
self.bottomline = _
_ = QLabel()
self._ = _
_.setScaledContents(True)
_.setStyleSheet("background-color: rgba(255,255,255, 0);")
_.setStyleSheet("background:transparent")
icon = getpixfunction(uid, small=True, iconfirst=True)
icon.setDevicePixelRatio(self.devicePixelRatioF())
_.setPixmap(icon)
@ -231,7 +227,7 @@ class MyQListWidget(QListWidget):
if not index.data(ImageRequestedRole):
self.model().setData(index, True, ImageRequestedRole)
image = getcachedimage(index.data(PathRole), True)
if image is None:
if image.isNull():
self.takeItem(index.row())
else:
self.item(index.row()).setIcon(QIcon(image))
@ -381,9 +377,7 @@ class viewpixmap_x(QWidget):
self.centerwidget = QWidget(self)
self.centerwidgetlayout = QVBoxLayout()
audio = QHBoxLayout()
self.recordbtn = statusbutton(
icons=["fa.microphone", "fa.stop"]
)
self.recordbtn = statusbutton(icons=["fa.microphone", "fa.stop"])
self.recordbtn.clicked.connect(self.startorendrecord)
self.centerwidget.setLayout(self.centerwidgetlayout)
self.centerwidgetlayout.addWidget(self.timenothide)
@ -794,23 +788,15 @@ class dialog_savedgame_v3(QWidget):
_style += "font-size:{}pt;".format(_f.pointSize())
_style += 'font-family:"{}";'.format(_f.family())
style = "#{}{{ {} }}".format(key, _style)
for exits in [True, False]:
c = globalconfig["dialog_savegame_layout"][
("onfilenoexistscolor1", "backcolor1")[exits]
]
c = str2rgba(
c,
globalconfig["dialog_savegame_layout"][
("transparentnotexits", "transparent")[exits]
],
)
style += "#savegame_exists{}{{background-color:{};}}".format(exits, c)
style += "#savegame_onselectcolor1{{background-color: {};}}".format(
str2rgba(
globalconfig["dialog_savegame_layout"]["onselectcolor1"],
globalconfig["dialog_savegame_layout"]["transparentselect"],
style += "#savegame_existsTrue{{background-color:{};}}".format(
globalconfig["dialog_savegame_layout"]["backcolor2"]
)
style += "#savegame_existsFalse{{background-color:{};}}".format(
globalconfig["dialog_savegame_layout"]["onfilenoexistscolor2"]
)
style += "#savegame_onselectcolor1{{background-color: {};}}".format(
globalconfig["dialog_savegame_layout"]["onselectcolor2"]
)
self.setStyleSheet(style)

View File

@ -1,7 +1,8 @@
from qtsymbols import *
import functools, importlib
from traceback import print_exc
import qtawesome, os, gobject, json
import qtawesome, os, gobject, requests
from myutils.commonbase import maybejson
from myutils.config import globalconfig, _TR
from myutils.utils import makehtml
from myutils.wrapper import Singleton_close
@ -572,6 +573,17 @@ class autoinitdialog(LDialog):
dd[refname2line[line["list_cache"]]["k"]] = items
except Exception as e:
print_exc()
if e.args and isinstance(e.args[0], requests.Response):
QMessageBox.information(
self,
"{} {}: {}".format(
e.args[0].status_code,
e.args[0].reason,
e.args[0].url,
),
str(maybejson(e.args[0])),
)
else:
QMessageBox.information(self, str(type(e))[8:-2], str(e))
if "list_function" in line:

View File

@ -17,6 +17,7 @@ from gui.usefulwidget import (
makesubtab_lazy,
makescrollgrid,
getsmalllabel,
getboxlayout,
)
@ -99,16 +100,15 @@ def createhorizontal_slider_tool(self):
self.horizontal_slider_tool.valueChanged.connect(
functools.partial(changeHorizontal_tool, self)
)
return self.horizontal_slider_tool
def createhorizontal_slider_tool_label(self):
self.horizontal_slider_tool_label = QLabel()
self.horizontal_slider_tool_label.setText(
"{}%".format(globalconfig["transparent_tool"])
)
return self.horizontal_slider_tool_label
return getboxlayout(
[self.horizontal_slider_tool, self.horizontal_slider_tool_label],
makewidget=True,
)
def createfontcombo():
@ -283,13 +283,6 @@ def mainuisetting(self):
title="文本区",
type="grid",
grid=(
[
"不透明度",
(
functools.partial(createhorizontal_slider, self),
0,
),
],
[
"背景颜色",
D_getcolorbutton(
@ -306,6 +299,13 @@ def mainuisetting(self):
parent=self,
),
"",
"不透明度",
(
functools.partial(createhorizontal_slider, self),
-1,
),
],
[
"圆角_半径",
D_getspinbox(
0,
@ -338,17 +338,6 @@ def mainuisetting(self):
title="工具栏",
type="grid",
grid=(
[
"不透明度",
(
functools.partial(createhorizontal_slider_tool, self),
0,
),
functools.partial(
createhorizontal_slider_tool_label,
self,
),
],
[
"背景颜色",
D_getcolorbutton(
@ -365,6 +354,13 @@ def mainuisetting(self):
parent=self,
),
"",
"不透明度",
(
functools.partial(createhorizontal_slider_tool, self),
-1,
),
],
[
"工具按钮颜色",
getboxlayout(
[
@ -398,10 +394,6 @@ def mainuisetting(self):
makewidget=True,
),
"",
"",
"",
],
[
"锁定工具栏",
D_getsimpleswitch(
globalconfig,

View File

@ -802,6 +802,7 @@ DictNodeRole = Qt.ItemDataRole.UserRole + 1
DeterminedhasChildren = DictNodeRole + 1
isWordNode = DeterminedhasChildren + 1
isLabeleddWord = isWordNode + 1
OriginText = isLabeleddWord + 1
class DynamicTreeModel(QStandardItemModel):
@ -872,22 +873,31 @@ class kpQTreeView(QTreeView):
class showdiction(QWidget):
def setwordfilter(self, index=None, first=False):
w = self.word.text()
if (not w) and first:
return
def setwordfilter(self, index: QModelIndex = None, first=False):
if index is None:
item = self.model.invisibleRootItem()
index = self.model.indexFromItem(self.model.invisibleRootItem())
else:
item = self.model.itemFromIndex(index)
w = self.word.text()
if first:
item.setData(item.text(), OriginText)
if not w:
item.setText(item.text() + " ({})".format((item.rowCount())))
return
cnt = 0
for i in range(item.rowCount()):
_item = item.child(i)
isw = _item.data(isWordNode)
if isw is None:
isw = False
self.tree.setRowHidden(i, index, isw and (w not in _item.text()))
hide = isw and (w not in _item.text())
self.tree.setRowHidden(i, index, hide)
cnt += 1 - hide
self.setwordfilter(self.model.indexFromItem(_item))
if item.data(OriginText):
item.setText(item.data(OriginText) + " ({})".format(cnt))
def showmenu(self, _):
idx = self.tree.currentIndex()

View File

@ -274,6 +274,9 @@ class lazyscrollflow(ScrollArea):
def setsize(self, size: QSize):
self._size = size
def setSpacing(self, s):
self._spacing = s
def spacing(self):
return self._spacing

View File

@ -15,7 +15,6 @@ from myutils.subproc import endsubprocs
from myutils.ocrutil import ocr_run, imageCut
from myutils.utils import (
loadpostsettingwindowmethod,
str2rgba,
makehtml,
loadpostsettingwindowmethod_maybe,
find_or_create_uid,
@ -88,6 +87,12 @@ class IconLabelX(LIconLabel, ButtonX):
return super().mouseReleaseEvent(ev)
def str2rgba(string, alpha100):
c = QColor(string)
c.setAlphaF(alpha100 / 100)
return c.name(QColor.NameFormat.HexArgb)
class ButtonBar(QFrame):
def __init__(self, *argc):
super().__init__(*argc)

View File

@ -1010,18 +1010,51 @@ def D_getsimpleswitch(
)
def getColor(color, parent, alpha=False):
color_dialog = QColorDialog(color, parent)
if alpha:
color_dialog.setOption(QColorDialog.ColorDialogOption.ShowAlphaChannel, True)
layout = color_dialog.layout()
clearlayout(layout.itemAt(0).layout().takeAt(0))
layout = layout.itemAt(0).layout().itemAt(0).layout().itemAt(2).widget().layout()
layout.takeAt(1).widget().hide()
layout.takeAt(1).widget().hide()
layout.takeAt(1).widget().hide()
layout.takeAt(1).widget().hide()
layout.takeAt(1).widget().hide()
layout.takeAt(1).widget().hide()
layout.takeAt(layout.count() - 1).widget().hide()
layout.takeAt(layout.count() - 1).widget().hide()
if not alpha:
layout.takeAt(layout.count() - 1).widget().hide()
layout.takeAt(layout.count() - 1).widget().hide()
if color_dialog.exec_() != QColorDialog.DialogCode.Accepted:
return QColor()
return color_dialog.selectedColor()
def selectcolor(
parent, configdict, configkey, button, item=None, name=None, callback=None
parent,
configdict,
configkey,
button,
item=None,
name=None,
callback=None,
alpha=False,
):
color = QColorDialog.getColor(QColor(configdict[configkey]), parent)
color = getColor(QColor(configdict[configkey]), parent, alpha)
if not color.isValid():
return
if button is None:
button = getattr(item, name)
button.setIcon(qtawesome.icon("fa.paint-brush", color=color.name()))
configdict[configkey] = color.name()
configdict[configkey] = (
color.name(QColor.NameFormat.HexArgb) if alpha else color.name()
)
if callback:
try:
callback()
@ -2443,9 +2476,9 @@ def clearlayout(ll: QLayout):
item = ll.takeAt(0)
if not item:
continue
ll.removeItem(item)
w = item.widget()
if w:
w.hide()
w.deleteLater()
continue
l = item.layout()

View File

@ -33,10 +33,10 @@ class proxysession(requests.Session):
super().__init__()
self.proxyconf = _key1, _key2
def request(self, *args, **kwargs) -> maybejson:
def request(self, *args, **kwargs):
kwargs["proxies"] = getproxy(self.proxyconf)
return maybejson(super().request(*args, **kwargs))
return super().request(*args, **kwargs)
class commonbase:

View File

@ -28,7 +28,10 @@ def grabwindow(app="PNG", callback_origin=None, tocliponly=False):
fname = ""
uid = None
elif callback_origin or tocliponly:
if callback_origin:
fname = gobject.gettempdir(tmsp)
else:
fname = ""
uid = None
else:

View File

@ -2,7 +2,7 @@ import windows
import os, time
import codecs, hashlib, shutil
import socket, gobject, uuid, subprocess, functools
import importlib, json
import importlib, json, requests
from qtsymbols import *
from string import Formatter
from ctypes import cast, c_char, POINTER
@ -340,7 +340,15 @@ def kanjitrans(k):
return k.translate(kanjichs2ja)
def stringfyerror(e):
def stringfyerror(e: Exception):
if e.args and isinstance(e.args[0], requests.Response):
from myutils.commonbase import maybejson
return "{} {}: {}".format(
e.args[0].status_code,
e.args[0].reason,
str(maybejson(e.args[0])).replace("\n", " ").replace("\r", ""),
)
return str(type(e))[8:-2] + " " + str(e).replace("\n", " ").replace("\r", "")
@ -699,15 +707,6 @@ def parsekeystringtomodvkcode(keystring, modes=False):
return mode, vkcode
def str2rgba(string, alpha100):
return "rgba(%s, %s, %s, %s)" % (
int(string[1:3], 16),
int(string[3:5], 16),
int(string[5:7], 16),
alpha100 / 100,
)
def get_time_stamp(ct=None, ms=True):
if ct is None:
ct = time.time()

View File

@ -1,11 +1,11 @@
from .libcurl import *
import threading, functools, queue
from ctypes import c_long, cast, pointer, POINTER, c_char
from requests import ResponseBase, Timeout, Requester_common
from requests import Response, Timeout, Requester_common
from traceback import print_exc
class Response(ResponseBase):
class Response(Response):
def __init__(self, stream=False):
super().__init__(stream)
self.keeprefs = []
@ -230,7 +230,7 @@ class Requester(Requester_common):
if not stream:
resp.content = b"".join(resp.queue)
resp.headers, resp.cookies, resp.status_text = self._parseheader2dict(header)
resp.headers, resp.cookies, resp.reason = self._parseheader2dict(header)
resp.status_code = self._getStatusCode(curl)
resp.url = url

View File

@ -1,5 +1,5 @@
from .winhttp import *
from requests import ResponseBase, Timeout, Requester_common
from requests import Response, Timeout, Requester_common
from traceback import print_exc
import windows
import gzip, zlib
@ -13,7 +13,7 @@ except:
print_exc()
class Response(ResponseBase):
class Response(Response):
def iter_content_impl(self, chunk_size=1):
availableSize = DWORD()
downloadedSize = DWORD()
@ -44,7 +44,7 @@ class Response(ResponseBase):
class Requester(Requester_common):
def request(self, *argc, **kwarg) -> ResponseBase:
def request(self, *argc, **kwarg) -> Response:
if kwarg["stream"]:
# winhttp流式时没办法判断解压边界
kwarg["headers"].pop("Accept-Encoding")

View File

@ -2,7 +2,6 @@ from ocrengines.baseocrclass import baseocr
import base64, requests
from myutils.utils import createurl, createenglishlangmap, urlpathjoin
from myutils.proxy import getproxy
from myutils.commonbase import maybejson
def list_models(typename, regist):
@ -19,7 +18,7 @@ def list_models(typename, regist):
try:
return sorted([_["id"] for _ in resp.json()["data"]])
except:
raise Exception(maybejson(resp))
raise Exception(resp)
class OCR(baseocr):

View File

@ -3,7 +3,6 @@ import requests
from ocrengines.baseocrclass import baseocr
from myutils.utils import createenglishlangmap, urlpathjoin
from myutils.proxy import getproxy
from myutils.commonbase import maybejson
def list_models(typename, regist):
@ -15,7 +14,7 @@ def list_models(typename, regist):
try:
models = resp.json()["models"]
except:
raise Exception(maybejson(resp))
raise Exception(resp)
mm = []
for m in models:
name: str = m["name"]

View File

@ -122,11 +122,12 @@ def dodownload(combo: QComboBox, allsupports: list):
)
def doinstall(self, combo: QComboBox, allsupports: list, parent, callback):
def doinstall(self, allsupports: list, parent, callback):
if not allsupports:
return
lang = allsupports[combo.currentIndex()]
f = QFileDialog.getOpenFileName(parent, filter=lang + ".zip")
f = QFileDialog.getOpenFileName(
parent, filter="model ({})".format(" ".join([_ + ".zip" for _ in allsupports]))
)
fn = f[0]
if not fn:
return
@ -166,7 +167,7 @@ def question():
btndownload.clicked.connect(functools.partial(dodownload, combo, allsupports))
btninstall = LPushButton("添加")
btninstall.clicked.connect(
functools.partial(doinstall, dialog, combo, allsupports, dialog, callback)
functools.partial(doinstall, combo, allsupports, dialog, callback)
)
formLayout.addRow(
"添加语言包",

View File

@ -1,6 +1,5 @@
import json
from collections import OrderedDict
from myutils.commonbase import maybejson
import requests
from urllib.parse import urlencode
from functools import reduce
@ -436,7 +435,7 @@ class Service(object):
if resp.status_code == 200:
return resp.text
else:
raise Exception(maybejson(resp))
raise Exception(resp)
def prepare_request(self, api_info, params, doseq=0):
for key in params:

View File

@ -67,7 +67,7 @@ class CaseInsensitiveDict(MutableMapping):
return str(dict(self.items()))
class ResponseBase:
class Response:
def __init__(self, stream):
self.headers = CaseInsensitiveDict()
self.stream = stream
@ -259,7 +259,7 @@ class Requester_common:
stream=None,
verify=False,
cert=None,
) -> ResponseBase:
) -> Response:
if auth and isinstance(auth, tuple) and len(auth) == 2:
headers["Authorization"] = (
@ -316,7 +316,7 @@ class Requester_common:
allow_redirects,
)
def request_impl(self, *argc) -> ResponseBase: ...
def request_impl(self, *argc) -> Response: ...
def _parseheader(self, headers: CaseInsensitiveDict, cookies: dict):
_x = []

View File

@ -2,7 +2,6 @@ import requests
import re
from translator.basetranslator import basetrans
import time, urllib
from myutils.commonbase import maybejson
class Tse:
@ -123,7 +122,7 @@ class BaiduV1(Tse):
try:
return "\n".join([item["dst"] for item in r.json()["data"]])
except:
raise Exception(maybejson(r))
raise Exception(r)
class TS(basetrans):

View File

@ -1,7 +1,6 @@
import re
import requests, time, urllib
from translator.basetranslator import basetrans
from myutils.commonbase import maybejson
class Tse:
@ -170,7 +169,7 @@ class Bing(Tse):
try:
return data[0] if is_detail_result else data[0]["translations"][0]["text"]
except:
raise Exception(maybejson(r))
raise Exception(r)
class TS(basetrans):

View File

@ -1,7 +1,23 @@
from traceback import print_exc
import json
import json, requests
from translator.basetranslator import basetrans
from myutils.utils import createenglishlangmap, checkv1, urlpathjoin
from myutils.proxy import getproxy
def list_models(typename, regist):
resp = requests.get(
urlpathjoin(checkv1(regist["BASE_URL"]().strip()), "models"),
headers={
"x-api-key": regist["API_KEY"]().split("|")[0].strip(),
"anthropic-version": "2023-06-01",
},
proxies=getproxy(("fanyi", typename)),
)
try:
return sorted([_["id"] for _ in resp.json()["data"]])
except:
raise Exception(resp)
class TS(basetrans):

View File

@ -130,9 +130,9 @@ def list_models(typename, regist):
"X-Client-Name": "my-cool-project",
},
proxies=getproxy(("fanyi", typename)),
).json()
)
try:
models = js["models"]
models = js.json()["models"]
except:
raise Exception(js)
mm = []

View File

@ -205,8 +205,8 @@ class TS(basetrans):
"Connection": "keep-alive",
},
data=postStr,
).json()
)
try:
return res["result"]["texts"][0]["text"]
return res.json()["result"]["texts"][0]["text"]
except:
raise Exception(res)

View File

@ -100,9 +100,9 @@ def list_models(typename, regist):
urlpathjoin(regist["BASE_URL"]().strip(), "v1beta/models"),
params={"key": regist["SECRET_KEY"]().split("|")[0].strip()},
proxies=getproxy(("fanyi", typename)),
).json()
)
try:
models = js["models"]
models = js.json()["models"]
except:
raise Exception(js)
mm = []

View File

@ -1,9 +1,8 @@
from translator.basetranslator import basetrans
import json, requests, time, hmac, hashlib
import json, requests, hmac, hashlib
from datetime import datetime, timezone
from myutils.utils import createurl, createenglishlangmap, urlpathjoin
from myutils.proxy import getproxy
from myutils.commonbase import maybejson
def list_models(typename, regist):
@ -20,7 +19,7 @@ def list_models(typename, regist):
try:
return sorted([_["id"] for _ in resp.json()["data"]])
except:
raise Exception(maybejson(resp))
raise Exception(resp)
class qianfanIAM:
@ -109,7 +108,7 @@ class gptcommon(basetrans):
_.update({"Authorization": "Bearer " + self.maybeuse[curkey]})
return _
def commonparseresponse(self, query, response: requests.ResponseBase, usingstream):
def commonparseresponse(self, query, response: requests.Response, usingstream):
if usingstream:
message = ""
if (
@ -117,13 +116,7 @@ class gptcommon(basetrans):
) and (response.status_code != 200):
# application/json
# text/html
raise Exception(
"{code} Error: {text} for url: {url}".format(
code=response.status_code,
text=response.reason,
url=response.url,
)
)
raise Exception(response)
for chunk in response.iter_lines():
response_data: str = chunk.decode("utf-8").strip()
if not response_data.startswith("data: "):

View File

@ -2,7 +2,6 @@ import requests
import re
import urllib
import time
from myutils.commonbase import maybejson
class Tse:
@ -125,7 +124,7 @@ class Itranslate(Tse):
try:
return r.json()["target"]["text"]
except:
raise Exception(maybejson(r))
raise Exception(r)
from traceback import print_exc

View File

@ -519,16 +519,14 @@
"fullscreenmethod_4": 0,
"tagNameRemap": {},
"dialog_savegame_layout": {
"itemw": 250,
"itemh": 350,
"margin": 10,
"textH": 50,
"backcolor1": "#ffffff",
"onselectcolor1": "#007fff",
"onfilenoexistscolor1": "#acacac",
"transparent": 25,
"transparentselect": 25,
"transparentnotexits": 25,
"itemw": 130,
"itemh": 190,
"margin": 8,
"margin2": 8,
"textH": 0,
"backcolor2": "#40ffffff",
"onselectcolor2": "#40007fff",
"onfilenoexistscolor2": "#40acacac",
"listitemheight": 30,
"listitemwidth_2": [
300,

View File

@ -523,10 +523,6 @@
{
"name": "manga-ocr",
"links": [
{
"name": "项目仓库",
"link": "https://github.com/kha-white/manga-ocr"
},
{
"name": "整合包_CPU",
"link": "{main_server}/Resource/IntegrationPack/manga_ocr/cpu"
@ -562,6 +558,10 @@
{
"name": "freemdict",
"link": "https://search.freemdict.com/"
},
{
"name": "Jitendex",
"link": "https://github.com/stephenmk/stephenmk.github.io/releases/latest/download/jitendex-mdict.zip"
}
]
}
@ -592,10 +592,6 @@
{
"name": "vits-simple-api",
"links": [
{
"name": "Github",
"link": "https://github.com/Artrajz/vits-simple-api/releases"
},
{
"name": "整合包_CPU",
"link": "{main_server}/Resource/IntegrationPack/vits-simple-api/cpu"

View File

@ -21,7 +21,7 @@
},
"deepl": {
"args": {
"usewhich": 0,
"usewhich": 2,
"github": "https://github.com/OwO-Network/DeepLX",
"api": "http://127.0.0.1:1188/translate",
"chromepath": "",
@ -377,6 +377,18 @@
"args": {
"BASE_URL": "https://api.anthropic.com",
"model": "claude-3-5-sonnet-latest",
"modellistcache": [
"claude-3-5-sonnet-latest",
"claude-3-5-sonnet-20241022",
"claude-3-5-sonnet-20240620",
"claude-3-opus-latest",
"claude-3-opus-20240229",
"claude-3-sonnet-20240229",
"claude-3-haiku-20240307",
"claude-2.1",
"claude-2.0",
"claude-instant-1.2"
],
"API_KEY": "",
"max_tokens": 2048,
"Temperature": 0.3,
@ -419,18 +431,8 @@
"model": {
"rank": 1,
"type": "lineedit_or_combo",
"list": [
"claude-3-5-sonnet-latest",
"claude-3-5-sonnet-20241022",
"claude-3-5-sonnet-20240620",
"claude-3-opus-latest",
"claude-3-opus-20240229",
"claude-3-sonnet-20240229",
"claude-3-haiku-20240307",
"claude-2.1",
"claude-2.0",
"claude-instant-1.2"
]
"list_function": "list_models",
"list_cache": "modellistcache"
},
"API_KEY": {
"name": "API Key",