darklight

This commit is contained in:
恍兮惚兮 2024-04-01 03:17:27 +08:00
parent 9926236cf4
commit 62522ce915
25 changed files with 2411 additions and 91 deletions

View File

@ -566,7 +566,7 @@ class MAINUI() :
except:
print_exc()
def mainuiloadafter(self):
self.transhis=gui.transhist.transhist(self.translation_ui)
gobject.overridestdio()
self.loadvnrshareddict()
@ -575,11 +575,12 @@ class MAINUI() :
self.starthira()
self.settin_ui = Settin(self.translation_ui)
self.transhis=gui.transhist.transhist(self.settin_ui)
gobject.baseobject.Prompt=Prompt()
self.startreader()
self.edittextui=gui.edittext.edittext(self.translation_ui)
self.searchwordW=searchwordW(self.translation_ui)
self.edittextui=gui.edittext.edittext(self.settin_ui)
self.searchwordW=searchwordW(self.settin_ui)
self.hookselectdialog=gui.selecthook.hookselect(self.settin_ui)
self.showocrimage=showocrimage(self.settin_ui)
self.AttachProcessDialog=AttachProcessDialog(self.settin_ui,self.selectprocess,self.hookselectdialog)

View File

@ -0,0 +1,79 @@
from winreg import HKEY_CURRENT_USER as hkey, QueryValueEx as getSubkeyValue, OpenKey as getKey
import ctypes
import ctypes.wintypes
advapi32 = ctypes.windll.advapi32
# LSTATUS RegOpenKeyExA(
# HKEY hKey,
# LPCSTR lpSubKey,
# DWORD ulOptions,
# REGSAM samDesired,
# PHKEY phkResult
# );
advapi32.RegOpenKeyExA.argtypes = (
ctypes.wintypes.HKEY,
ctypes.wintypes.LPCSTR,
ctypes.wintypes.DWORD,
ctypes.wintypes.DWORD,
ctypes.POINTER(ctypes.wintypes.HKEY),
)
advapi32.RegOpenKeyExA.restype = ctypes.wintypes.LONG
# LSTATUS RegQueryValueExA(
# HKEY hKey,
# LPCSTR lpValueName,
# LPDWORD lpReserved,
# LPDWORD lpType,
# LPBYTE lpData,
# LPDWORD lpcbData
# );
advapi32.RegQueryValueExA.argtypes = (
ctypes.wintypes.HKEY,
ctypes.wintypes.LPCSTR,
ctypes.wintypes.LPDWORD,
ctypes.wintypes.LPDWORD,
ctypes.wintypes.LPBYTE,
ctypes.wintypes.LPDWORD,
)
advapi32.RegQueryValueExA.restype = ctypes.wintypes.LONG
# LSTATUS RegNotifyChangeKeyValue(
# HKEY hKey,
# WINBOOL bWatchSubtree,
# DWORD dwNotifyFilter,
# HANDLE hEvent,
# WINBOOL fAsynchronous
# );
advapi32.RegNotifyChangeKeyValue.argtypes = (
ctypes.wintypes.HKEY,
ctypes.wintypes.BOOL,
ctypes.wintypes.DWORD,
ctypes.wintypes.HANDLE,
ctypes.wintypes.BOOL,
)
advapi32.RegNotifyChangeKeyValue.restype = ctypes.wintypes.LONG
def theme():
""" Uses the Windows Registry to detect if the user is using Dark Mode """
# Registry will return 0 if Windows is in Dark Mode and 1 if Windows is in Light Mode. This dictionary converts that output into the text that the program is expecting.
valueMeaning = {0: "Dark", 1: "Light"}
# In HKEY_CURRENT_USER, get the Personalisation Key.
try:
key = getKey(hkey, "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize")
# In the Personalisation Key, get the AppsUseLightTheme subkey. This returns a tuple.
# The first item in the tuple is the result we want (0 or 1 indicating Dark Mode or Light Mode); the other value is the type of subkey e.g. DWORD, QWORD, String, etc.
subkey = getSubkeyValue(key, "AppsUseLightTheme")[0]
except FileNotFoundError:
# some headless Windows instances (e.g. GitHub Actions or Docker images) do not have this key
return None
return valueMeaning[subkey]
def isDark():
if theme() is not None:
return theme() == 'Dark'
def isLight():
if theme() is not None:
return theme() == 'Light'

View File

@ -1,7 +1,6 @@
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QApplication,QTextBrowser,QMainWindow,QFontDialog,QAction,QMenu,QHBoxLayout,QWidget,QPushButton,QVBoxLayout
from PyQt5.QtGui import QFont,QFontMetrics
from PyQt5.QtWidgets import QApplication,QTextBrowser,QAction,QMenu,QHBoxLayout,QWidget,QPushButton,QVBoxLayout
from PyQt5.QtCore import Qt,pyqtSignal ,QSize,QPoint
import qtawesome
import json,threading
@ -21,8 +20,7 @@ class edittext(closeashidewindow):
self.setWindowTitle(_TR('编辑'))
def setupUi(self):
self.setWindowIcon(qtawesome.icon("fa.edit" ))
font = QFont()
font.fromString(globalconfig['edit_fontstring'])
self.textOutput = QTextBrowser(self)
@ -60,14 +58,7 @@ class edittext(closeashidewindow):
self.hiding=True
self.setfonts()
def setfonts(self):
font = QFont()
font.fromString(globalconfig['sw_fontstring'])
fm=QFontMetrics(font)
self.bt1.setIconSize(QSize(fm.height(),fm.height() ))
self.bt2.setIconSize(QSize(fm.height(),fm.height() ))
self.textOutput.setFont(font)
def run(self):
threading.Thread(target=gobject.baseobject.textgetmethod,args=(self.textOutput.toPlainText(),False)).start()
def changestate(self):
@ -76,21 +67,11 @@ class edittext(closeashidewindow):
def showmenu(self,point:QPoint):
menu=QMenu(self.textOutput )
qingkong=QAction(_TR("清空"))
ziti=QAction(_TR("字体") )
menu.addAction(qingkong)
menu.addAction(ziti)
action=menu.exec(self.mapToGlobal(self.textOutput.pos())+point)
if action==qingkong:
self.textOutput.clear()
elif action==ziti :
font, ok = QFontDialog.getFont(self.textOutput.font(), parent=self)
if ok :
globalconfig['edit_fontstring']=font.toString()
self.setfonts()
def getnewsentence(self,sentence):
if self.sync:
self.textOutput.setCurrentCharFormat(self.charformat)

View File

@ -3,7 +3,7 @@ from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QLabel,QScrollArea,QWidget,QGridLayout,QVBoxLayout
from PyQt5.QtGui import QResizeEvent
from PyQt5.QtWidgets import QTabWidget
import qtawesome
import qtawesome,darkdetect
import functools
from traceback import print_exc
from myutils.config import globalconfig ,_TR
@ -151,7 +151,24 @@ class Settin(closeashidewindow) :
setTab_about(self)
self.isfirstshow=False
def setstylesheet(self):
self.setStyleSheet("font: %spt '"%(globalconfig['settingfontsize'])+(globalconfig['settingfonttype'] )+"' ; " )
dl=globalconfig['darklight']
if dl==0:
dark=False
elif dl==1:
dark=True
elif dl==2:
dark=darkdetect.isDark()
if dark:
try:
with open('./files/dark.qss','r') as ff:
style=ff.read()
except:
style=''
else:
style=''
style+="*{font: %spt '"%(globalconfig['settingfontsize'])+(globalconfig['settingfonttype'] )+"' ; }"
self.setStyleSheet(style)
def makevbox(self,wids):
q=QWidget()
v=QVBoxLayout()

View File

@ -164,7 +164,9 @@ def setTabThree_lazy(self) :
[('任务栏中显示',6),getsimpleswitch(globalconfig,'showintab' ,callback=__changeshowintab)],
[('子窗口任务栏中显示',6),getsimpleswitch(globalconfig,'showintab_sub')],
[('选择文本窗口中文本框只读',6),getsimpleswitch(globalconfig,'textboxreadonly',callback=lambda x:gobject.baseobject.hookselectdialog.textOutput.setReadOnly(x) )]
[('选择文本窗口中文本框只读',6),getsimpleswitch(globalconfig,'textboxreadonly',callback=lambda x:gobject.baseobject.hookselectdialog.textOutput.setReadOnly(x) )],
[],
[('明暗',6),(getsimplecombobox(_TRL(['明亮','黑暗','跟随系统']),globalconfig,'darklight',callback=lambda _: self.setstylesheet()),5)]
]
alleffect=['','Bicubic','Bilinear','Jinc','Lanczos','Nearest','SSimDownscaler']
downsname=magpie10_config.get('downscalingEffect',{'name':''}).get('name')

View File

@ -1,8 +1,7 @@
from re import search
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QWidget,QHBoxLayout,QMainWindow,QApplication,QVBoxLayout,QFontDialog,QTextBrowser,QLineEdit,QPushButton,QTabWidget,QMenu,QAction
from PyQt5.QtGui import QFont,QTextCursor,QFontMetrics
from PyQt5.QtWidgets import QWidget,QHBoxLayout,QVBoxLayout,QTextBrowser,QLineEdit,QPushButton,QTabWidget
from PyQt5.QtCore import Qt,pyqtSignal,QSize
import qtawesome,functools,json
import threading ,gobject
@ -96,39 +95,13 @@ class searchwordW(closeashidewindow):
textOutput.setContextMenuPolicy(Qt.CustomContextMenu)
textOutput.customContextMenuRequested.connect(functools.partial( self.showmenu ,i,textOutput) )
self.hiding=True
self.searchthreadsignal.connect(self.searchthread)
self.setfonts( )
def setfonts(self):
font = QFont()
font.fromString(globalconfig['sw_fontstring'])
fm=QFontMetrics(font)
self.searchbutton.setIconSize(QSize(fm.height(),fm.height() ))
self.soundbutton.setIconSize(QSize(fm.height(),fm.height() ))
self.setFont(font)
self.tab.setFont(font)
self.searchtext.setFont(font)
for _ in self.textbs:
self.textbs[_].setFont(font)
def langdu(self):
if gobject.baseobject.reader:
gobject.baseobject.reader.read(self.searchtext.text() )
def showmenu(self,ii,to:QTextBrowser,p):
menu=QMenu(self )
ziti=QAction(_TR("字体") )
menu.addAction(ziti)
action=menu.exec( to.mapToGlobal(p))
if action==ziti :
font, ok = QFontDialog.getFont(self.font(), parent=self)
if ok :
globalconfig['sw_fontstring']=font.toString()
self.setfonts()
def getnewsentence(self,sentence):
self.showNormal()
self.searchtext.setText(sentence )

View File

@ -1,7 +1,6 @@
from PyQt5.QtCore import Qt
from PyQt5.QtWidgets import QTabWidget,QTextBrowser,QMainWindow,QFontDialog,QAction,QMenu,QFileDialog
from PyQt5.QtGui import QFont,QTextCursor
from PyQt5.QtWidgets import QTabWidget,QTextBrowser,QAction,QMenu,QFileDialog
from PyQt5.QtCore import Qt,pyqtSignal
import qtawesome,functools
@ -26,9 +25,6 @@ class transhist(closeashidewindow):
self.setWindowTitle(_TR('历史翻译和调试输出'))
def setupUi(self):
self.setWindowIcon(qtawesome.icon("fa.rotate-left" ))
font = QFont()
font.fromString(globalconfig['hist_fontstring'])
self.setFont(font)
self.tabwidget=QTabWidget()
self.tabwidget.setTabPosition(QTabWidget.East)
self.setCentralWidget(self.tabwidget)
@ -52,7 +48,6 @@ class transhist(closeashidewindow):
menu=QMenu(self )
qingkong=QAction(_TR("清空"))
baocun=QAction(_TR("保存"))
ziti=QAction(_TR("字体") )
hideshowraw=QAction(_TR("显示原文" if self.hiderawflag else "不显示原文") )
hideshowapi=QAction(_TR("显示api" if self.hideapiflag else "不显示api") )
menu.addAction(qingkong)
@ -60,7 +55,6 @@ class transhist(closeashidewindow):
if flag==1:
menu.addAction(hideshowraw)
menu.addAction(hideshowapi)
menu.addAction(ziti)
action=menu.exec(self.mapToGlobal(p))
if action==qingkong:
@ -77,13 +71,7 @@ class transhist(closeashidewindow):
elif action==hideshowapi:
self.hideapiflag=not self.hideapiflag
elif action==ziti :
font, ok = QFontDialog.getFont(self.font(), parent=self)
if ok :
globalconfig['hist_fontstring']=font.toString()
self.setFont(font)
def debugprint(self,idx,sentence):
textbrowappendandmovetoend(self.debugoutputs[idx],sentence,False)
def getnewsentence(self,sentence):

File diff suppressed because it is too large Load Diff

View File

@ -40,9 +40,6 @@
"postprocess_rank": [],
"uselongtermcache": false,
"hist_split": false,
"hist_fontstring": "Arial,12,-1,5,50,0,0,0,0,0,Regular",
"sw_fontstring": "Arial,12,-1,5,50,0,0,0,0,0,Regular",
"edit_fontstring": "Arial,12,-1,5,50,0,0,0,0,0,Regular",
"fixedheight": false,
"showintab": true,
"remove_useless_hook": false,
@ -679,6 +676,7 @@
"name": "goo"
}
},
"darklight":0,
"usesearchword": false,
"usecopyword":false,
"outputtopasteboard": false,

View File

@ -1,5 +1,5 @@
{
"version":"v2.40.5",
"version":"v2.40.6",
"language_list_show":["简体中文","日本語","English","Русский язык","Español","한국어","Français","繁體中文","Tiếng Việt","Türkçe","Polski","Українська Мова","Italiano","اللغة العربية","ภาษาไทย","བོད་སྐད།"] ,
"language_list_translator":["简体中文","日文","英文","俄语","西班牙语","韩语","法语","繁体中文","越南语","土耳其语","波兰语","乌克兰语","意大利语","阿拉伯语","泰语","藏语"],
"language_list_translator_inner":["zh", "ja", "en","ru","es","ko","fr","cht","vi","tr","pl","uk","it","ar","th","bo"],

View File

@ -727,5 +727,9 @@
"相对地址": "العنوان النسبي",
"特征匹配": "ميزة مطابقة",
"函数对齐": "وظيفة المحاذاة",
"函数调用": "استدعاء الدالة"
"函数调用": "استدعاء الدالة",
"明亮": "مشرق",
"黑暗": "ظلام .",
"跟随系统": "متابعة النظام",
"明暗": "الضوء والظل"
}

View File

@ -727,5 +727,9 @@
"相对地址": "相對地址",
"特征匹配": "特徵匹配",
"函数对齐": "函數對齊",
"函数调用": "函數調用"
"函数调用": "函數調用",
"明亮": "明亮",
"黑暗": "黑暗",
"跟随系统": "跟隨系統",
"明暗": "明暗"
}

View File

@ -727,5 +727,9 @@
"相对地址": "Relative address",
"特征匹配": "Feature matching",
"函数对齐": "Function alignment",
"函数调用": "function call"
"函数调用": "function call",
"明亮": "bright",
"黑暗": "dark",
"跟随系统": "Follow system",
"明暗": "Brightness and darkness"
}

View File

@ -727,5 +727,9 @@
"相对地址": "Dirección relativa",
"特征匹配": "Coincidencia de características",
"函数对齐": "Alineación de funciones",
"函数调用": "Llamada a función"
"函数调用": "Llamada a función",
"明亮": "Brillante",
"黑暗": "Oscuridad",
"跟随系统": "Sistema de seguimiento",
"明暗": "Luz y oscuridad"
}

View File

@ -727,5 +727,9 @@
"相对地址": "Adresse relative",
"特征匹配": "Correspondance des caractéristiques",
"函数对齐": "Alignement des fonctions",
"函数调用": "Appel de fonction"
"函数调用": "Appel de fonction",
"明亮": "Lumineux",
"黑暗": "L'obscurité",
"跟随系统": "Suivre le système",
"明暗": "Lumière et obscurité"
}

View File

@ -727,5 +727,9 @@
"相对地址": "Indirizzo relativo",
"特征匹配": "Corrispondenza delle caratteristiche",
"函数对齐": "Allineamento delle funzioni",
"函数调用": "chiamata funzione"
"函数调用": "chiamata funzione",
"明亮": "luminoso",
"黑暗": "scuro",
"跟随系统": "Sistema di monitoraggio",
"明暗": "Luminosità e oscurità"
}

View File

@ -727,5 +727,9 @@
"相对地址": "そうたいアドレス",
"特征匹配": "フィーチャーマッチング",
"函数对齐": "関数の配置",
"函数调用": "関数呼び出し"
"函数调用": "関数呼び出し",
"明亮": "明るい",
"黑暗": "暗い",
"跟随系统": "フォローアップシステム",
"明暗": "明暗"
}

View File

@ -727,5 +727,9 @@
"相对地址": "상대 주소",
"特征匹配": "피쳐 일치",
"函数对齐": "함수 정렬",
"函数调用": "함수 호출"
"函数调用": "함수 호출",
"明亮": "밝기",
"黑暗": "어둠",
"跟随系统": "시스템 따르기",
"明暗": "명암"
}

View File

@ -727,5 +727,9 @@
"相对地址": "Adres względny",
"特征匹配": "Dopasowanie cech",
"函数对齐": "Wyrównanie funkcji",
"函数调用": "wywołanie funkcji"
"函数调用": "wywołanie funkcji",
"明亮": "jasne",
"黑暗": "ciemność",
"跟随系统": "System śledzenia",
"明暗": "Jasność i ciemność"
}

View File

@ -727,5 +727,9 @@
"相对地址": "Относительный адрес",
"特征匹配": "Соответствие характеристик",
"函数对齐": "Выравнивание функций",
"函数调用": "Вызов функции"
"函数调用": "Вызов функции",
"明亮": "Яркий",
"黑暗": "Тьма.",
"跟随系统": "Следующая система",
"明暗": "Свет и тьма"
}

View File

@ -727,5 +727,9 @@
"相对地址": "ที่อยู่ญาติ",
"特征匹配": "คุณสมบัติการจับคู่",
"函数对齐": "การจัดตำแหน่งฟังก์ชัน",
"函数调用": "เรียกฟังก์ชัน"
"函数调用": "เรียกฟังก์ชัน",
"明亮": "สดใส",
"黑暗": "ความมืด",
"跟随系统": "ติดตามระบบ",
"明暗": "ความสว่างและความมืด"
}

View File

@ -727,5 +727,9 @@
"相对地址": "Relatif adres",
"特征匹配": "Özellik eşleştirmesi",
"函数对齐": "Funksiyon hizalama",
"函数调用": "fonksiyon araması"
"函数调用": "fonksiyon araması",
"明亮": "bright",
"黑暗": "karanlık",
"跟随系统": "Sistemi takip et",
"明暗": "Parılık ve karanlık"
}

View File

@ -727,5 +727,9 @@
"相对地址": "Відносна адреса",
"特征匹配": "Порівнювання властивостей",
"函数对齐": "Вирівнювання функцій",
"函数调用": "виклик функції"
"函数调用": "виклик функції",
"明亮": "яскравий",
"黑暗": "темно",
"跟随系统": "Слідкувати за системою",
"明暗": "Яскравість і темрява"
}

View File

@ -727,5 +727,9 @@
"相对地址": "Địa chỉ tương đối",
"特征匹配": "Khớp tính năng",
"函数对齐": "Căn chỉnh chức năng",
"函数调用": "Gọi hàm"
"函数调用": "Gọi hàm",
"明亮": "Minh Lượng",
"黑暗": "Bóng tối",
"跟随系统": "Theo dõi hệ thống",
"明暗": "Ánh sáng và bóng tối"
}

View File

@ -727,5 +727,9 @@
"相对地址": "",
"特征匹配": "",
"函数对齐": "",
"函数调用": ""
"函数调用": "",
"明亮": "",
"黑暗": "",
"跟随系统": "",
"明暗": ""
}