mirror of
https://github.com/HIllya51/LunaTranslator.git
synced 2024-12-29 00:24:13 +08:00
arc
This commit is contained in:
parent
8fca0bf4d9
commit
ccd47e6dc9
@ -32,6 +32,7 @@ from gui.setting_proxy import setTab_proxy
|
|||||||
from gui.settingpage7 import setTab7, settab7direct
|
from gui.settingpage7 import setTab7, settab7direct
|
||||||
from gui.settingpage_about import setTab_about, setTab_about_dicrect
|
from gui.settingpage_about import setTab_about, setTab_about_dicrect
|
||||||
from gui.usefulwidget import closeashidewindow, tabadd_lazy
|
from gui.usefulwidget import closeashidewindow, tabadd_lazy
|
||||||
|
from myutils.Acrylic import WindowEffect
|
||||||
|
|
||||||
|
|
||||||
class gridwidget(QWidget):
|
class gridwidget(QWidget):
|
||||||
@ -259,11 +260,16 @@ class Settin(closeashidewindow):
|
|||||||
|
|
||||||
for widget in QApplication.topLevelWidgets():
|
for widget in QApplication.topLevelWidgets():
|
||||||
if widget.testAttribute(Qt.WA_TranslucentBackground):
|
if widget.testAttribute(Qt.WA_TranslucentBackground):
|
||||||
|
if globalconfig["WindowEffect"] == 0:
|
||||||
|
WindowEffect().clear(int(widget.winId()))
|
||||||
|
elif globalconfig["WindowEffect"] == 1:
|
||||||
|
WindowEffect().setAcrylicEffect(int(widget.winId()))
|
||||||
|
elif globalconfig["WindowEffect"] == 2:
|
||||||
|
WindowEffect().setAeroEffect(int(widget.winId()))
|
||||||
continue
|
continue
|
||||||
winsharedutils.SetTheme(
|
winsharedutils.SetTheme(
|
||||||
int(widget.winId()), dark, globalconfig["WindowBackdrop"]
|
int(widget.winId()), dark, globalconfig["WindowBackdrop"]
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
idx = globalconfig[darklight + "theme"] - int(not dark)
|
idx = globalconfig[darklight + "theme"] - int(not dark)
|
||||||
if idx == -1:
|
if idx == -1:
|
||||||
|
@ -245,7 +245,8 @@ def setTabThree_lazy(self):
|
|||||||
functools.partial(changeHorizontal, self)
|
functools.partial(changeHorizontal, self)
|
||||||
)
|
)
|
||||||
self.horizontal_slider_label = QLabel()
|
self.horizontal_slider_label = QLabel()
|
||||||
self.horizontal_slider_label.setText("{}%".format(globalconfig["transparent_tool"]))
|
self.horizontal_slider_label.setText("{}%".format(globalconfig["transparent"]))
|
||||||
|
|
||||||
self.horizontal_slider_tool = QSlider()
|
self.horizontal_slider_tool = QSlider()
|
||||||
self.horizontal_slider_tool.setMaximum(100)
|
self.horizontal_slider_tool.setMaximum(100)
|
||||||
self.horizontal_slider_tool.setMinimum(1)
|
self.horizontal_slider_tool.setMinimum(1)
|
||||||
@ -259,6 +260,7 @@ def setTabThree_lazy(self):
|
|||||||
self.horizontal_slider_tool_label.setText(
|
self.horizontal_slider_tool_label.setText(
|
||||||
"{}%".format(globalconfig["transparent_tool"])
|
"{}%".format(globalconfig["transparent_tool"])
|
||||||
)
|
)
|
||||||
|
|
||||||
self.font_comboBox = QFontComboBox()
|
self.font_comboBox = QFontComboBox()
|
||||||
self.font_comboBox.activated[str].connect(
|
self.font_comboBox.activated[str].connect(
|
||||||
lambda x: globalconfig.__setitem__("fonttype", x)
|
lambda x: globalconfig.__setitem__("fonttype", x)
|
||||||
@ -644,6 +646,21 @@ def setTabThree_lazy(self):
|
|||||||
5,
|
5,
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
[
|
||||||
|
("WindowEffect", 6),
|
||||||
|
(
|
||||||
|
getsimplecombobox(
|
||||||
|
["Disable", "Acrylic", "Aero"],
|
||||||
|
globalconfig,
|
||||||
|
"WindowEffect",
|
||||||
|
callback=lambda _: [
|
||||||
|
self.setstylesheet(),
|
||||||
|
gobject.baseobject.translation_ui.set_color_transparency(),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
5,
|
||||||
|
),
|
||||||
|
],
|
||||||
[
|
[
|
||||||
("WindowBackdrop", 6),
|
("WindowBackdrop", 6),
|
||||||
(
|
(
|
||||||
|
@ -669,7 +669,7 @@ class QUnFrameWindow(resizableframeless):
|
|||||||
return "border-radius:%spx" % r
|
return "border-radius:%spx" % r
|
||||||
|
|
||||||
def set_color_transparency(self):
|
def set_color_transparency(self):
|
||||||
|
rate = int(globalconfig["WindowEffect"] == 0)
|
||||||
use_r1 = min(
|
use_r1 = min(
|
||||||
self.translate_text.height() // 2,
|
self.translate_text.height() // 2,
|
||||||
self.translate_text.width() // 2,
|
self.translate_text.width() // 2,
|
||||||
@ -681,13 +681,13 @@ class QUnFrameWindow(resizableframeless):
|
|||||||
globalconfig["yuanjiao_r"],
|
globalconfig["yuanjiao_r"],
|
||||||
)
|
)
|
||||||
topr = self.createborderradiusstring(
|
topr = self.createborderradiusstring(
|
||||||
use_r1,
|
rate * use_r1,
|
||||||
globalconfig["yuanjiao_merge"] and self._TitleLabel.isVisible(),
|
globalconfig["yuanjiao_merge"] and self._TitleLabel.isVisible(),
|
||||||
False,
|
False,
|
||||||
)
|
)
|
||||||
bottomr2 = self.createborderradiusstring(use_r2, False)
|
bottomr3 = self.createborderradiusstring(use_r2, False)
|
||||||
bottomr = self.createborderradiusstring(
|
bottomr = self.createborderradiusstring(
|
||||||
use_r2, globalconfig["yuanjiao_merge"], True
|
rate * use_r2, globalconfig["yuanjiao_merge"], True
|
||||||
)
|
)
|
||||||
|
|
||||||
self.translate_text.setStyleSheet(
|
self.translate_text.setStyleSheet(
|
||||||
@ -724,12 +724,12 @@ class QUnFrameWindow(resizableframeless):
|
|||||||
font: 100 10pt;
|
font: 100 10pt;
|
||||||
}
|
}
|
||||||
""" % (
|
""" % (
|
||||||
bottomr2,
|
bottomr3,
|
||||||
(
|
(
|
||||||
globalconfig["button_color_normal"],
|
globalconfig["button_color_normal"],
|
||||||
globalconfig["button_color_close"],
|
globalconfig["button_color_close"],
|
||||||
)[_type - 1],
|
)[_type - 1],
|
||||||
bottomr2,
|
bottomr3,
|
||||||
)
|
)
|
||||||
|
|
||||||
for btn in self.stylebuttons[_type]:
|
for btn in self.stylebuttons[_type]:
|
||||||
|
151
LunaTranslator/LunaTranslator/myutils/Acrylic.py
Normal file
151
LunaTranslator/LunaTranslator/myutils/Acrylic.py
Normal file
@ -0,0 +1,151 @@
|
|||||||
|
# coding:utf-8
|
||||||
|
|
||||||
|
from ctypes import POINTER, Structure
|
||||||
|
from ctypes.wintypes import DWORD, HWND, ULONG
|
||||||
|
from enum import Enum
|
||||||
|
|
||||||
|
# coding:utf-8
|
||||||
|
|
||||||
|
from ctypes import POINTER, c_bool, sizeof, windll, pointer, c_int
|
||||||
|
from ctypes.wintypes import DWORD, HWND, ULONG
|
||||||
|
|
||||||
|
|
||||||
|
class WINDOWCOMPOSITIONATTRIB(Enum):
|
||||||
|
WCA_UNDEFINED = (0,)
|
||||||
|
WCA_NCRENDERING_ENABLED = (1,)
|
||||||
|
WCA_NCRENDERING_POLICY = (2,)
|
||||||
|
WCA_TRANSITIONS_FORCEDISABLED = (3,)
|
||||||
|
WCA_ALLOW_NCPAINT = (4,)
|
||||||
|
WCA_CAPTION_BUTTON_BOUNDS = (5,)
|
||||||
|
WCA_NONCLIENT_RTL_LAYOUT = (6,)
|
||||||
|
WCA_FORCE_ICONIC_REPRESENTATION = (7,)
|
||||||
|
WCA_EXTENDED_FRAME_BOUNDS = (8,)
|
||||||
|
WCA_HAS_ICONIC_BITMAP = (9,)
|
||||||
|
WCA_THEME_ATTRIBUTES = (10,)
|
||||||
|
WCA_NCRENDERING_EXILED = (11,)
|
||||||
|
WCA_NCADORNMENTINFO = (12,)
|
||||||
|
WCA_EXCLUDED_FROM_LIVEPREVIEW = (13,)
|
||||||
|
WCA_VIDEO_OVERLAY_ACTIVE = (14,)
|
||||||
|
WCA_FORCE_ACTIVEWINDOW_APPEARANCE = (15,)
|
||||||
|
WCA_DISALLOW_PEEK = (16,)
|
||||||
|
WCA_CLOAK = (17,)
|
||||||
|
WCA_CLOAKED = (18,)
|
||||||
|
WCA_ACCENT_POLICY = (19,)
|
||||||
|
WCA_FREEZE_REPRESENTATION = (20,)
|
||||||
|
WCA_EVER_UNCLOAKED = (21,)
|
||||||
|
WCA_VISUAL_OWNER = (22,)
|
||||||
|
WCA_LAST = 23
|
||||||
|
|
||||||
|
|
||||||
|
class ACCENT_STATE(Enum):
|
||||||
|
"""客户区状态枚举类"""
|
||||||
|
|
||||||
|
ACCENT_DISABLED = (0,)
|
||||||
|
ACCENT_ENABLE_GRADIENT = (1,)
|
||||||
|
ACCENT_ENABLE_TRANSPARENTGRADIENT = (2,)
|
||||||
|
ACCENT_ENABLE_BLURBEHIND = (3,) # Aero效果
|
||||||
|
ACCENT_ENABLE_ACRYLICBLURBEHIND = (4,) # 亚克力效果
|
||||||
|
ACCENT_INVALID_STATE = 5
|
||||||
|
|
||||||
|
|
||||||
|
class ACCENT_POLICY(Structure):
|
||||||
|
"""设置客户区的具体属性"""
|
||||||
|
|
||||||
|
_fields_ = [
|
||||||
|
("AccentState", DWORD),
|
||||||
|
("AccentFlags", DWORD),
|
||||||
|
("GradientColor", DWORD),
|
||||||
|
("AnimationId", DWORD),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class WINDOWCOMPOSITIONATTRIBDATA(Structure):
|
||||||
|
_fields_ = [
|
||||||
|
("Attribute", DWORD),
|
||||||
|
(
|
||||||
|
"Data",
|
||||||
|
POINTER(ACCENT_POLICY),
|
||||||
|
), # POINTER()接收任何ctypes类型,并返回一个指针类型
|
||||||
|
("SizeOfData", ULONG),
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
class WindowEffect:
|
||||||
|
"""调用windows api实现窗口效果"""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
# 调用api
|
||||||
|
self.SetWindowCompositionAttribute = windll.user32.SetWindowCompositionAttribute
|
||||||
|
self.SetWindowCompositionAttribute.restype = c_bool
|
||||||
|
self.SetWindowCompositionAttribute.argtypes = [
|
||||||
|
c_int,
|
||||||
|
POINTER(WINDOWCOMPOSITIONATTRIBDATA),
|
||||||
|
]
|
||||||
|
# 初始化结构体
|
||||||
|
self.accentPolicy = ACCENT_POLICY()
|
||||||
|
self.winCompAttrData = WINDOWCOMPOSITIONATTRIBDATA()
|
||||||
|
self.winCompAttrData.Attribute = (
|
||||||
|
WINDOWCOMPOSITIONATTRIB.WCA_ACCENT_POLICY.value[0]
|
||||||
|
)
|
||||||
|
self.winCompAttrData.SizeOfData = sizeof(self.accentPolicy)
|
||||||
|
self.winCompAttrData.Data = pointer(self.accentPolicy)
|
||||||
|
|
||||||
|
def clear(self, hWnd):
|
||||||
|
self.accentPolicy.AccentState = ACCENT_STATE.ACCENT_DISABLED.value[0]
|
||||||
|
self.SetWindowCompositionAttribute(hWnd, pointer(self.winCompAttrData))
|
||||||
|
|
||||||
|
def setAcrylicEffect(
|
||||||
|
self,
|
||||||
|
hWnd: int,
|
||||||
|
gradientColor: str = "F2F2F230",
|
||||||
|
isEnableShadow: bool = True,
|
||||||
|
animationId: int = 0,
|
||||||
|
):
|
||||||
|
"""开启亚克力效果
|
||||||
|
|
||||||
|
Parameters
|
||||||
|
----------
|
||||||
|
hWnd: int
|
||||||
|
窗口句柄
|
||||||
|
|
||||||
|
gradientColor: str
|
||||||
|
十六进制亚克力混合色,对应 RGBA 四个分量
|
||||||
|
|
||||||
|
isEnableShadow: bool
|
||||||
|
是否启用窗口阴影
|
||||||
|
|
||||||
|
animationId: int
|
||||||
|
控制磨砂动画
|
||||||
|
"""
|
||||||
|
# 亚克力混合色
|
||||||
|
gradientColor = (
|
||||||
|
gradientColor[6:]
|
||||||
|
+ gradientColor[4:6]
|
||||||
|
+ gradientColor[2:4]
|
||||||
|
+ gradientColor[:2]
|
||||||
|
)
|
||||||
|
gradientColor = DWORD(int(gradientColor, base=16))
|
||||||
|
# 磨砂动画
|
||||||
|
animationId = DWORD(animationId)
|
||||||
|
# 窗口阴影
|
||||||
|
accentFlags = DWORD(0x20 | 0x40 | 0x80 | 0x100) if isEnableShadow else DWORD(0)
|
||||||
|
self.accentPolicy.AccentState = (
|
||||||
|
ACCENT_STATE.ACCENT_ENABLE_ACRYLICBLURBEHIND.value[0]
|
||||||
|
)
|
||||||
|
self.accentPolicy.GradientColor = gradientColor
|
||||||
|
self.accentPolicy.AccentFlags = accentFlags
|
||||||
|
self.accentPolicy.AnimationId = animationId
|
||||||
|
# 开启亚克力
|
||||||
|
self.SetWindowCompositionAttribute(hWnd, pointer(self.winCompAttrData))
|
||||||
|
|
||||||
|
def setAeroEffect(self, hWnd: int):
|
||||||
|
"""开启 Aero 效果
|
||||||
|
|
||||||
|
Parameter
|
||||||
|
----------
|
||||||
|
hWnd: int
|
||||||
|
窗口句柄
|
||||||
|
"""
|
||||||
|
self.accentPolicy.AccentState = ACCENT_STATE.ACCENT_ENABLE_BLURBEHIND.value[0]
|
||||||
|
# 开启Aero
|
||||||
|
self.SetWindowCompositionAttribute(hWnd, pointer(self.winCompAttrData))
|
@ -8,6 +8,7 @@
|
|||||||
"showrangeafterrangeselect": true,
|
"showrangeafterrangeselect": true,
|
||||||
"autodisappear": false,
|
"autodisappear": false,
|
||||||
"WindowBackdrop": 0,
|
"WindowBackdrop": 0,
|
||||||
|
"WindowEffect": 0,
|
||||||
"read_raw": true,
|
"read_raw": true,
|
||||||
"read_trans": false,
|
"read_trans": false,
|
||||||
"read_translator": 0,
|
"read_translator": 0,
|
||||||
|
@ -29,7 +29,7 @@ include(generate_product_version)
|
|||||||
|
|
||||||
set(VERSION_MAJOR 2)
|
set(VERSION_MAJOR 2)
|
||||||
set(VERSION_MINOR 53)
|
set(VERSION_MINOR 53)
|
||||||
set(VERSION_PATCH 0)
|
set(VERSION_PATCH 1)
|
||||||
|
|
||||||
add_library(pch pch.cpp)
|
add_library(pch pch.cpp)
|
||||||
target_precompile_headers(pch PUBLIC pch.h)
|
target_precompile_headers(pch PUBLIC pch.h)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user