Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified __pycache__/conf_ui.cpython-311.pyc
Binary file not shown.
Binary file modified __pycache__/updater_gui.cpython-311.pyc
Binary file not shown.
1 change: 1 addition & 0 deletions _version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__version__ = "1.3.0"
25 changes: 6 additions & 19 deletions conf_ui.py
Original file line number Diff line number Diff line change
@@ -1,65 +1,52 @@
"""设置界面(Qt)相关逻辑。

通过 `paths.resource` 加载 UI 文件,读取/写入配置并处理开机自启选项。
"""
"""设置界面(Qt)相关逻辑"""

from PyQt6.QtWidgets import QDialog, QLineEdit, QPushButton, QComboBox, QCheckBox
from PyQt6 import uic
from PyQt6.QtCore import Qt
import paths
from pathlib import Path
import conf_file as config
import shortcut as a

_UI_FILE = Path(__file__).with_name('settings.ui')

class FramelessWindow(QDialog):
"""无边框设置窗口,绑定 UI 控件并保存配置。"""

class FramelessWindow(QDialog):
def __init__(self):
super().__init__()
# 使用 paths.resource 加载 UI 文件(兼容打包与源码)
uic.loadUi(paths.resource('settings.ui'), self)
uic.loadUi(_UI_FILE, self)

# 绑定 DPI 组合框
self.opt1_Combo = self.findChild(QComboBox, 'opt1_Combo')
self.opt1_Combo.setCurrentIndex(int(config.read_conf('General', 'DPI') or 0))
self.opt1_Combo.currentIndexChanged.connect(self.opt1_Save)

# 绑定 PPT 标题输入框
self.opt2_LineEdit = self.findChild(QLineEdit, 'opt2_LineEdit')
self.opt2_LineEdit.setText(config.read_conf('General', 'PPT_Title') or 'PowerPoint 幻灯片放映')
self.opt2_LineEdit.textChanged.connect(self.opt2_Save)

# 绑定开机自启复选框
self.opt3_checkBox = self.findChild(QCheckBox, 'opt3_checkBox')
self.opt3_checkBox.setChecked(int(config.read_conf('General', 'auto_startup') or 0))
self.opt3_checkBox.stateChanged.connect(self.opt3_Save)

# 重置按钮
self.opt2_Reset = self.findChild(QPushButton, 'opt2Reset')
self.opt2_Reset.clicked.connect(self.opt2_ResetToDefault)

# ---------- 配置保存相关方法 ----------

def opt1_Save(self, idx):
"""保存 DPI 设置索引."""
config.write_conf('General', 'DPI', str(idx))

def opt2_Save(self, txt):
"""保存 PPT 标题配置."""
config.write_conf('General', 'PPT_Title', txt)

def opt2_ResetToDefault(self):
"""将 PPT 标题恢复为默认并更新输入框."""
config.write_conf('General', 'PPT_Title', 'PowerPoint 幻灯片放映')
self.opt2_LineEdit.setText('PowerPoint 幻灯片放映')

def opt3_Save(self, state):
"""保存开机自启选项并根据选中状态添加或移除自启."""
checked = state == Qt.CheckState.Checked.value
config.write_conf('General', 'auto_startup', str(int(checked)))
(a.add_to_startup if checked else a.remove_from_startup)('PowerPoint_TouchAssist.exe')


def main():
"""显示设置对话框并阻塞直到关闭."""
dlg = FramelessWindow()
dlg.exec()
3 changes: 0 additions & 3 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,3 @@ auto_startup = 0
[Miscellaneous]
initialstartup = 0
ver = 1.1

[About]
version = 1.3.0
28 changes: 2 additions & 26 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import conf_ui
from configparser import ConfigParser

from _version import __version__ as versi
# --------------------------------------------------
# ① 更新窗口模块(同级目录)
# --------------------------------------------------
Expand All @@ -39,33 +40,8 @@
「钟表的指针周而复始,就像人的困惑、烦恼、软弱…摇摆不停。但最终,人们依旧要前进,就像你的指针,永远落在前方。」

""")
try:
conf = ConfigParser()
conf.read('config.ini', encoding='utf-8')
version = conf['About']['version']
except KeyError as e:
logger.bug(f"读取 config.ini 出错(缺少 {e}),重新创建")
conf = ConfigParser()

conf['General'] = {
'dpi': '0',
'ppt_title': 'PowerPoint 幻灯片放映',
'auto_startup': '0'
}

conf['Miscellaneous'] = {
'initialstartup': '0',
'ver': '1.1'
}

conf['About'] = {
'version': '1.2.0'
}

with open('config.ini', 'w', encoding='utf-8') as f:
conf.write(f)


version = versi
# --------------------------------------------------
# ③ PathManager & 日志
# --------------------------------------------------
Expand Down