Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
HIllya51 committed Dec 4, 2024
1 parent 5db5643 commit 6e8ef2b
Show file tree
Hide file tree
Showing 45 changed files with 449 additions and 887 deletions.
4 changes: 2 additions & 2 deletions cpp/version.cmake
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

set(VERSION_MAJOR 6)
set(VERSION_MINOR 9)
set(VERSION_PATCH 7)
set(VERSION_MINOR 10)
set(VERSION_PATCH 0)
set(VERSION_REVISION 0)
set(LUNA_VERSION "{${VERSION_MAJOR},${VERSION_MINOR},${VERSION_PATCH},${VERSION_REVISION}}")
add_library(VERSION_DEF ${CMAKE_CURRENT_LIST_DIR}/version_def.cpp)
Expand Down
42 changes: 24 additions & 18 deletions py/LunaTranslator/gui/inputdialog.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
getspinbox,
SplitLine,
getIconButton,
VisLFormLayout,
)
from gui.dynalang import (
LFormLayout,
Expand Down Expand Up @@ -464,7 +465,7 @@ def __init__(
print_exc()
self.show()
return
formLayout = LFormLayout()
formLayout = VisLFormLayout()
self.setLayout(formLayout)
regist = {}

Expand Down Expand Up @@ -596,6 +597,9 @@ def __refresh(regist, line, combo: SuperCombo):
)
)
lineW.addWidget(combo)
_w = QWidget()
_w.setLayout(lineW)
lineW = _w
elif line["type"] == "okcancel":
lineW = QDialogButtonBox(
QDialogButtonBox.StandardButton.Ok
Expand Down Expand Up @@ -631,15 +635,19 @@ def __refresh(regist, line, combo: SuperCombo):
)

regist[key] = functools.partial(__temp.__getitem__, "k")

_ = QWidget()
_.setLayout(lineW)
lineW = _
elif line["type"] == "switch":
lineW = MySwitch(sign=dd[key])
regist[key] = lineW.isChecked
_ = QHBoxLayout()
_.addStretch()
_.addWidget(lineW)
_.addStretch()
lineW = _
_w = QWidget()
_w.setLayout(_)
lineW = _w
elif line["type"] in ["spin", "intspin"]:

__temp = {"k": dd[key]}
Expand All @@ -654,13 +662,6 @@ def __refresh(regist, line, combo: SuperCombo):
regist[key] = lineW.value
elif line["type"] == "split":
lineW = SplitLine()
formLayout.addRow(lineW)
continue
refcombo = line.get("refcombo")
if refcombo:
if refcombo not in cachehasref:
cachehasref[refcombo] = []
cachehasref[refcombo].append((lineW, line))

refswitch = line.get("refswitch", None)
if refswitch:
Expand All @@ -675,12 +676,19 @@ def __refresh(regist, line, combo: SuperCombo):
lineW.setEnabled(dd[key])
hbox.addWidget(switch)
hbox.addWidget(lineW)
lineW = hbox
if "name" in line:
formLayout.addRow(line["name"], lineW)
else:
_ = QWidget()
_.setLayout(hbox)
lineW = _
if ("name" not in line) or (line["type"] == "split"):
formLayout.addRow(lineW)
else:
formLayout.addRow(line["name"], lineW)

refcombo = line.get("refcombo")
if refcombo:
if refcombo not in cachehasref:
cachehasref[refcombo] = []
cachehasref[refcombo].append((lineW, line))
for comboname, refitems in cachehasref.items():

def refcombofunction(refitems, _i):
Expand All @@ -692,17 +700,15 @@ def refcombofunction(refitems, _i):
vis = linwinfo.get("refcombo_i_r") != _i
elif linwinfo.get("refcombo_l") is not None:
vis = _i in linwinfo.get("refcombo_l")
w.setVisible(vis)
formLayout.itemAt(formLayout.indexOf(w) - 1).widget().setVisible(
vis
)
formLayout.setRowVisible(w, vis)

cachecombo[comboname].currentIndexChanged.connect(
functools.partial(refcombofunction, refitems)
)
cachecombo[comboname].currentIndexChanged.emit(
cachecombo[comboname].currentIndex()
)

self.show()


Expand Down
2 changes: 1 addition & 1 deletion py/LunaTranslator/gui/setting_display_buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ def changerank(item, up, sortlist, savelist, savelay):

def createbuttonwidget(self, lay):
# return table
grids = [["显示", "", "", "对齐", "", "图标", "", "图标2", "", "说明"]]
grids = [["显示", "", "", "对齐", "", "图标", "", "图标_2", "", "说明"]]
sortlist = globalconfig["toolbutton"]["rank2"]
savelist = []
savelay = []
Expand Down
57 changes: 1 addition & 56 deletions py/LunaTranslator/gui/setting_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ def loadvisinternal(btnplus, copy):
is_gpt_likes, not_is_gpt_like = splitapillm(shoufei)
elif btnplus == "offline":
is_gpt_likes, not_is_gpt_like = splitapillm(lixians)
elif btnplus == "dev":
is_gpt_likes, not_is_gpt_like = splitapillm(develop)

for _ in is_gpt_likes:
if copy:
Expand Down Expand Up @@ -332,12 +330,6 @@ def createmanybtn(self, countnum, btnplus):
dynamiclink("{docs_server}/#/zh/guochandamoxing")
)
)
elif btnplus == "dev":
btn.clicked.connect(
lambda: gobject.baseobject.openlink(
dynamiclink("{docs_server}/#/zh/tiaoshiliulanqi")
)
)
hbox.addWidget(btn)
setattr(self, "btnmany" + btnplus, w)
return w
Expand Down Expand Up @@ -442,18 +434,6 @@ def initsome2(self, l, label=None, btnplus=None):
return grids


def statuslabelsettext(self, text):
try:
self.statuslabel.setText(text)
except:
pass


def createstatuslabel(self):

self.statuslabel = LLabel()
return self.statuslabel


def createbtnexport(self):

Expand Down Expand Up @@ -543,56 +523,21 @@ def setTabTwo_lazy(self, basel: QVBoxLayout):
{"type": "okcancel"},
]

developgrid = [
[
(
dict(
title="Chromium_设置",
type="grid",
grid=(
[
"路径",
D_getIconButton(
callback=functools.partial(
autoinitdialog,
self,
globalconfig,
"Chromium_路径",
800,
_items,
),
icon="fa.gear",
),
"",
"端口号",
D_getspinbox(0, 65535, globalconfig, "debugport"),
"",
],
[(functools.partial(createstatuslabel, self), 0)],
),
),
0,
"group",
)
],
]
lixians, pre, mianfei, develop, shoufei = splittranslatortypes()

offlinegrid = initsome2(self, lixians, btnplus="offline")
onlinegrid = initsome11(self, mianfei)
developgrid += initsome2(self, develop, btnplus="dev")
online_reg_grid += initsome2(self, shoufei, btnplus="api")
pretransgrid += initsome11(self, pre)

gridlayoutwidget, do = makegrid(grids, delay=True)
basel.addWidget(gridlayoutwidget)
tab, dotab = makesubtab_lazy(
["在线翻译", "注册在线翻译", "离线翻译", "调试浏览器", "预翻译"],
["在线翻译", "注册在线翻译", "离线翻译", "预翻译"],
[
functools.partial(makescrollgrid, onlinegrid),
functools.partial(makescrollgrid, online_reg_grid),
functools.partial(makescrollgrid, offlinegrid),
functools.partial(makescrollgrid, developgrid),
functools.partial(makescrollgrid, pretransgrid),
],
delay=True,
Expand Down
47 changes: 47 additions & 0 deletions py/LunaTranslator/gui/usefulwidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -2493,3 +2493,50 @@ def mouseReleaseEvent(self, ev: QMouseEvent) -> None:
if ev.button() == Qt.MouseButton.RightButton:
self.rightclick.emit()
return super().mouseReleaseEvent(ev)


class VisLFormLayout(LFormLayout):
# 简易实现
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._row_widgets = {}
self._reverse = {}
self._row_vis = {}

def addRow(self, label_or_field, field=None):
row_index = self.rowCount()
if field is None:
super().addRow(label_or_field)
field = label_or_field
label_or_field = None
else:
super().addRow(label_or_field, field)
self._row_widgets[row_index] = (label_or_field, field)
self._row_vis[row_index] = True
self._reverse[field] = row_index
return row_index

def setRowVisible(self, row_index, visible):
if isinstance(row_index, int):
pass
elif isinstance(row_index, QWidget):
row_index = self._reverse[row_index]
if self._row_vis[row_index] == visible:
return
insert_position = sum(1 for i in range(row_index) if self._row_vis[i])
if visible:
label, field = self._row_widgets[row_index]
if label is not None:
super().insertRow(insert_position, label, field)
else:
super().insertRow(insert_position, field)
if not field.isVisible():
field.setVisible(True)
else:
tres = self.takeRow(insert_position)
label = tres.labelItem
if label is not None:
self.removeItem(label)
label.widget().deleteLater()
tres.fieldItem.widget().hide()
self._row_vis[row_index] = visible
6 changes: 3 additions & 3 deletions py/LunaTranslator/myutils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -586,14 +586,14 @@ def loadlanguage():
def _TR(k: str):
if not k:
return ""
if isascii(k):
return k
loadlanguage()
if "_" in k:
splits = k.split("_")
return " ".join([_TR(_) for _ in splits])
if k.startswith("(") and k.endswith(")"):
return "(" + _TR(k[1:-1]) + ")"
if isascii(k):
return k
loadlanguage()
__ = languageshow.get(k)
if __:
return __
Expand Down
3 changes: 1 addition & 2 deletions py/LunaTranslator/myutils/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ def splittranslatortypes():
pre, offline, free, dev, api = [], [], [], [], []
for k in globalconfig["fanyi"]:
try:
{"pre": pre, "offline": offline, "free": free, "dev": dev, "api": api}[
{"pre": pre, "offline": offline, "free": free, "api": api}[
globalconfig["fanyi"][k].get("type", "free")
].append(k)
except:
Expand Down Expand Up @@ -1041,7 +1041,6 @@ def getannotatedapiname(x):
+ {
"free": "在线翻译",
"api": "注册在线翻译",
"dev": "调试浏览器",
"pre": "预翻译",
"offline": "离线翻译",
}.get(tp, "unknown type")
Expand Down
31 changes: 0 additions & 31 deletions py/LunaTranslator/translator/baidu_dev.py

This file was deleted.

16 changes: 0 additions & 16 deletions py/LunaTranslator/translator/bing_dev.py

This file was deleted.

Loading

0 comments on commit 6e8ef2b

Please sign in to comment.