forked from FADEDTUMI/PartyFish
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPartyFish.py
More file actions
8552 lines (7322 loc) · 302 KB
/
PartyFish.py
File metadata and controls
8552 lines (7322 loc) · 302 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import time
import os
import webbrowser
import warnings
import cv2
import numpy as np
from PIL import Image
import threading # 用于在独立线程中运行脚本
import ctypes
from pynput import keyboard, mouse # 用于监听键盘和鼠标事件,支持热键和鼠标侧键操作
# 初始化键盘和鼠标控制器
keyboard_controller = keyboard.Controller()
mouse_controller = mouse.Controller()
import datetime
import re
import queue # 用于线程安全通信
import random # 添加随机模块用于时间抖动
import getpass # 用于获取电脑账号
# 尝试导入硬件信息相关库
try:
import wmi
WMI_AVAILABLE = True
except ImportError:
WMI_AVAILABLE = False
print("⚠️ [警告] 无法导入wmi,硬件信息获取可能受限")
try:
import psutil
PSUTIL_AVAILABLE = True
except ImportError:
PSUTIL_AVAILABLE = False
print("⚠️ [警告] 无法导入psutil,硬件信息获取可能受限")
try:
import winsound
WINSOUND_AVAILABLE = True
except ImportError:
WINSOUND_AVAILABLE = False
print("⚠️ [警告] 无法导入winsound,部分音效可能不可用")
# 过滤libpng的iCCP警告(图片ICC配置文件问题)
warnings.filterwarnings("ignore", message=".*iCCP.*")
# 设置OpenCV不显示libpng警告
os.environ["OPENCV_IO_ENABLE_JASPER"] = "0"
import tkinter as tk # 保留用于兼容性
from tkinter import ttk # 保留用于兼容性
from tkinter import messagebox
import ttkbootstrap as ttkb
from ttkbootstrap.constants import *
import json # 用于保存和加载参数
import mss
# =========================
# 卡密验证相关
# =========================
# 硬编码卡密
VALID_CARD_KEY = "免费软件倒卖全家死光光"
# 卡密信息保存键名
CARD_KEY_SAVE_KEY = "card_key"
HARDWARE_INFO_SAVE_KEY = "hardware_info"
def verify_card_key():
"""
验证卡密,绑定硬件信息
每次启动时调用,硬件信息不一致则需要重新输入卡密
"""
# 先加载参数,获取保存的卡密和硬件信息
load_parameters()
# 获取当前硬件信息
current_hardware = get_hardware_info()
# 读取保存的卡密和硬件信息
saved_card_key = None
saved_hardware = None
try:
with open(PARAMETER_FILE, "r", encoding="utf-8") as f:
params = json.load(f)
saved_card_key = params.get(CARD_KEY_SAVE_KEY, None)
saved_hardware = params.get(HARDWARE_INFO_SAVE_KEY, None)
except Exception as e:
print(f"⚠️ [警告] 读取卡密信息失败: {e}")
# 检查是否需要重新输入卡密
need_reinput = False
if not saved_card_key:
need_reinput = True
print("🔑 [卡密] 首次启动,需要输入卡密")
elif saved_hardware != current_hardware:
need_reinput = True
print("🔄 [卡密] 硬件信息已变更,需要重新输入卡密")
# 需要重新输入卡密
if need_reinput:
# 导入必要的模块
import tkinter as tk
from tkinter import messagebox
# 创建卡密输入窗口
def create_card_key_window():
"""创建卡密输入窗口"""
# 创建临时根窗口
temp_root = tk.Tk()
temp_root.withdraw() # 隐藏主窗口
# 创建卡密输入对话框
card_key = tk.StringVar()
result = [False] # 使用列表存储结果,以便在内部函数中修改
def on_submit():
"""提交卡密"""
input_card_key = card_key_entry.get().strip()
if input_card_key == VALID_CARD_KEY:
result[0] = True
temp_root.quit() # 退出对话框
else:
messagebox.showerror("错误", "卡密错误,请重新输入!")
def on_cancel():
"""取消输入"""
temp_root.quit() # 退出对话框
exit() # 退出程序
# 创建对话框
dialog = tk.Toplevel(temp_root)
dialog.title("🔑 卡密验证")
dialog.geometry("400x200")
dialog.minsize(350, 180)
dialog.resizable(False, False) # 不允许调整大小
# 设置窗口居中
dialog.update_idletasks()
width = dialog.winfo_width()
height = dialog.winfo_height()
x = (dialog.winfo_screenwidth() // 2) - (width // 2)
y = (dialog.winfo_screenheight() // 2) - (height // 2)
dialog.geometry(f"{width}x{height}+{x}+{y}")
# 设置窗口图标
set_window_icon(dialog)
# 创建对话框内容
frame = tk.Frame(dialog, padx=20, pady=20)
frame.pack(fill=tk.BOTH, expand=True)
# 标题
title_label = tk.Label(frame, text="请输入卡密", font=("Segoe UI", 14, "bold"))
title_label.pack(pady=(0, 20))
# 卡密输入框
card_key_entry = tk.Entry(frame, textvariable=card_key, font=("Segoe UI", 12), width=30)
card_key_entry.pack(pady=(0, 20))
card_key_entry.focus_set() # 设置焦点
# 绑定回车键提交
card_key_entry.bind("<Return>", lambda event: on_submit())
# 按钮框架
button_frame = tk.Frame(frame)
button_frame.pack(fill=tk.X, pady=(0, 10))
# 取消按钮
cancel_btn = tk.Button(button_frame, text="取消", command=on_cancel, width=12)
cancel_btn.pack(side=tk.LEFT, padx=(0, 10))
# 确定按钮
submit_btn = tk.Button(button_frame, text="确定", command=on_submit, width=12)
submit_btn.pack(side=tk.RIGHT)
# 禁用关闭按钮
def on_close():
exit() # 退出程序
dialog.protocol("WM_DELETE_WINDOW", on_close)
# 运行对话框
temp_root.mainloop()
# 销毁临时窗口
temp_root.destroy()
return card_key.get().strip() if result[0] else None
# 运行卡密输入对话框
input_card_key = create_card_key_window()
if input_card_key:
# 保存卡密和硬件信息
try:
# 读取现有参数
with open(PARAMETER_FILE, "r", encoding="utf-8") as f:
params = json.load(f)
except Exception:
params = {}
# 更新卡密和硬件信息
params[CARD_KEY_SAVE_KEY] = input_card_key
params[HARDWARE_INFO_SAVE_KEY] = current_hardware
# 保存更新后的参数
with open(PARAMETER_FILE, "w", encoding="utf-8") as f:
json.dump(params, f)
print("✅ [卡密] 验证成功!")
print("💾 [卡密] 卡密和硬件信息已保存")
else:
print("❌ [卡密] 卡密验证失败,程序退出")
exit()
else:
# 验证通过
print("✅ [卡密] 卡密验证通过")
# =========================
# 硬件信息获取
# =========================
def get_hardware_info():
"""
获取硬件信息,包括CPU型号、CPU序列号、GPU型号和电脑账号
返回格式化的硬件信息字符串
"""
hardware_info = {}
# 获取电脑账号
try:
hardware_info['username'] = getpass.getuser()
except Exception as e:
hardware_info['username'] = f"获取失败: {e}"
# 获取CPU信息
try:
if WMI_AVAILABLE:
w = wmi.WMI()
for processor in w.Win32_Processor():
hardware_info['cpu_model'] = processor.Name.strip()
break
else:
hardware_info['cpu_model'] = "获取失败: wmi不可用"
except Exception as e:
hardware_info['cpu_model'] = f"获取失败: {e}"
# 获取CPU序列号
try:
if WMI_AVAILABLE:
w = wmi.WMI()
for processor in w.Win32_Processor():
hardware_info['cpu_serial'] = processor.ProcessorId.strip()
break
else:
hardware_info['cpu_serial'] = "获取失败: wmi不可用"
except Exception as e:
hardware_info['cpu_serial'] = f"获取失败: {e}"
# 获取内存信息
try:
if PSUTIL_AVAILABLE:
total_memory = psutil.virtual_memory().total
# 转换为GB
total_memory_gb = round(total_memory / (1024 ** 3), 2)
hardware_info['memory'] = f"{total_memory_gb} GB"
else:
hardware_info['memory'] = "获取失败: psutil不可用"
except Exception as e:
hardware_info['memory'] = f"获取失败: {e}"
# 获取GPU信息
try:
if WMI_AVAILABLE:
w = wmi.WMI()
gpu_info = []
for gpu in w.Win32_VideoController():
if gpu.Name:
gpu_info.append(gpu.Name.strip())
hardware_info['gpu_model'] = ", ".join(gpu_info) if gpu_info else "未知"
else:
hardware_info['gpu_model'] = "获取失败: wmi不可用"
except Exception as e:
hardware_info['gpu_model'] = f"获取失败: {e}"
# 格式化硬件信息字符串,按照顺序:cpu|内存|硬盘|网卡|gpu型号
# 保留username和cpu_serial作为前两个字段,保持与现有逻辑兼容
hardware_str = f"{hardware_info['username']}|{hardware_info['cpu_model']}|{hardware_info['memory']}|{hardware_info['gpu_model']}"
return hardware_str
# =========================
# 简化版音效管理器
# =========================
class SimpleSoundManager:
"""简化版音效管理器,只使用winsound和控制台铃声"""
def __init__(self):
self.enabled = True
self.can_use_winsound = False
self._playing = False # 防止重复播放
self._lock = threading.Lock() # 线程锁
try:
import winsound
self.can_use_winsound = True
print("🔊 [音效] 使用winsound播放音效")
except ImportError:
print("🔊 [音效] 使用控制台铃声")
def _safe_beep(self, frequency, duration):
"""安全的蜂鸣函数"""
if not self.enabled:
return
try:
if self.can_use_winsound:
import winsound
winsound.Beep(frequency, duration)
else:
print("\a", end="", flush=True)
except:
# 音效失败时静默处理
pass
def play_start(self):
"""播放启动音效"""
with self._lock:
if not self.enabled or self._playing:
return
self._playing = True
# 在独立线程中播放,避免阻塞
def _play():
try:
self._safe_beep(1000, 200)
time.sleep(0.05)
self._safe_beep(1200, 150)
finally:
with self._lock:
self._playing = False
threading.Thread(target=_play, daemon=True).start()
def play_pause(self):
"""播放暂停音效"""
with self._lock:
if not self.enabled or self._playing:
return
self._playing = True
def _play():
try:
self._safe_beep(600, 200)
time.sleep(0.05)
self._safe_beep(500, 150)
finally:
with self._lock:
self._playing = False
threading.Thread(target=_play, daemon=True).start()
def play_resume(self):
"""播放恢复音效"""
with self._lock:
if not self.enabled or self._playing:
return
self._playing = True
def _play():
try:
self._safe_beep(800, 200)
time.sleep(0.05)
self._safe_beep(900, 150)
finally:
with self._lock:
self._playing = False
threading.Thread(target=_play, daemon=True).start()
# 使用简化版
sound_manager = SimpleSoundManager()
# =========================
# 全局资源路径管理
# =========================
def get_icon_path():
"""获取logo.ico图标的路径,处理不同环境下的路径问题
Returns:
str: logo.ico图标的完整路径
"""
import sys
import os
if hasattr(sys, "_MEIPASS"):
# 打包后直接在MEIPASS下查找
icon_path = os.path.join(sys._MEIPASS, "logo.ico")
else:
# 开发环境下直接使用当前目录
icon_path = "logo.ico"
return icon_path
def get_resources_path():
"""获取resources目录的路径,处理不同环境下的路径问题
Returns:
str: resources目录的完整路径
"""
import sys
import os
if hasattr(sys, "_MEIPASS"):
# 打包后resources目录在MEIPASS下
resources_path = os.path.join(sys._MEIPASS, "resources")
else:
# 开发环境下直接使用当前目录下的resources
resources_path = os.path.join(".", "resources")
return resources_path
def set_window_icon(window):
"""设置窗口图标,同时支持窗口和任务栏
Args:
window: 要设置图标的窗口对象
"""
try:
import tkinter as tk
# 获取图标路径
icon_path = get_icon_path()
# 尝试使用iconphoto方法设置图标(同时支持窗口和任务栏)
try:
icon = tk.PhotoImage(file=icon_path)
window.iconphoto(True, icon)
except Exception as e1:
# 如果iconphoto失败,尝试回退到iconbitmap
try:
window.iconbitmap(icon_path)
except Exception as e2:
print(f"⚠️ [警告] 设置窗口图标失败: {e2}")
except Exception as e:
print(f"⚠️ [警告] 设置窗口图标时发生错误: {e}")
# =========================
# OCR引擎初始化(使用rapidocr,速度快)
# =========================
try:
from rapidocr_onnxruntime import RapidOCR
ocr_engine = RapidOCR()
OCR_AVAILABLE = True
print("✅ [OCR] RapidOCR 引擎加载成功")
except ImportError:
OCR_AVAILABLE = False
ocr_engine = None
print("⚠️ [OCR] RapidOCR 未安装,钓鱼记录功能将不可用")
# =========================
# 鱼桶满检测设置
# =========================
FISH_BUCKET_FULL_TEXT = "鱼桶满了,无法钓鱼"
fish_bucket_full_detected = False
fish_bucket_sound_enabled = True # 是否启用鱼桶满/没鱼饵警告!音效
# 鱼桶满/没鱼饵!检测模式
# mode1: 自动暂停
# mode2: 按下一次F键然后一直鼠标左键,但检测到键盘活动时自动停止
# mode3: 不会自动暂停,只会按下一次F键
bucket_detection_mode = "mode1" # 默认模式
# 抛竿间隔检测相关设置
casting_timestamps = [] # 存储最近的抛竿时间戳
casting_interval_lock = threading.Lock() # 保护抛竿时间戳的线程锁
CASTING_INTERVAL_THRESHOLD = 1.0 # 抛竿间隔阈值(秒)
REQUIRED_CONSECUTIVE_MATCHES = 4 # 需要连续匹配的次数
bucket_full_by_interval = False # 标记是否通过间隔检测到鱼桶满/没鱼饵!
# 操作状态标志,用于协调抛杆和放生操作
is_casting = False # 当前是否正在抛杆
is_releasing = False # 当前是否正在放生
operation_lock = threading.Lock() # 保护操作状态的线程锁
# =========================
# 调试信息管理函数
# =========================
def add_debug_info(info):
"""添加调试信息到队列和历史记录"""
if not debug_mode:
return
# 添加到队列(用于实时通知)
try:
debug_info_queue.put_nowait(info)
except queue.Full:
try:
debug_info_queue.get_nowait()
debug_info_queue.put_nowait(info)
except:
pass
# 添加到历史记录(用于保留历史信息)
with debug_history_lock:
debug_info_history.append(info)
# 保持历史记录不超过200条
if len(debug_info_history) > 200:
debug_info_history.pop(0) # 移除最旧的记录
# =========================
# 运行日志系统
# =========================
# 运行日志队列,用于存储所有控制台输出信息
log_queue = queue.Queue(maxsize=1000)
log_history = [] # 日志历史记录
log_history_max = 500 # 最大保存500条日志
log_history_lock = threading.Lock() # 保护日志历史记录的线程锁
# 重定向标准输出到日志系统
import sys
import io
class LogRedirector:
"""重定向标准输出到日志系统"""
def __init__(self, original_stream):
self.original_stream = original_stream
self.buffer = io.StringIO()
def write(self, text):
# 写入到原始流,只有当original_stream不为None时才写入
if self.original_stream is not None:
self.original_stream.write(text)
# 如果文本不为空,添加到日志队列
if text.strip():
timestamp = datetime.datetime.now().strftime("%H:%M:%S")
log_entry = f"[{timestamp}] {text.rstrip()}"
# 添加到队列
try:
log_queue.put_nowait(log_entry)
except queue.Full:
# 队列满时移除最旧的条目
try:
log_queue.get_nowait()
log_queue.put_nowait(log_entry)
except:
pass
# 添加到历史记录
with log_history_lock:
log_history.append(log_entry)
# 保持历史记录不超过最大限制
if len(log_history) > log_history_max:
log_history.pop(0)
# 写入到缓冲区(如果需要)
self.buffer.write(text)
def flush(self):
if self.original_stream is not None:
self.original_stream.flush()
self.buffer.flush()
# 重定向标准输出和标准错误
sys.stdout = LogRedirector(sys.stdout)
sys.stderr = LogRedirector(sys.stderr)
# =========================
# 线程锁 - 保护共享变量
# =========================
param_lock = threading.Lock() # 参数读写锁
# =========================
# 钓鱼记录开关
# =========================
record_fish_enabled = True # 默认启用钓鱼记录
legendary_screenshot_enabled = True # 默认关闭传奇鱼自动截屏
first_capture_screenshot_enabled = True # 默认启用首次捕获自动截屏
# =========================
# 放生功能设置
# =========================
release_fish_enabled = False # 是否启用放生功能
release_standard_enabled = False # 是否放生标准鱼
release_uncommon_enabled = False # 是否放生非凡鱼
release_rare_enabled = False # 是否放生稀有鱼
release_epic_enabled = False # 是否放生史诗鱼
release_legendary_enabled = False # 是否放生传奇鱼
release_phantom_rare_enabled = False # 是否放生幻神稀有鱼
# =========================
# 字体大小设置
# =========================
font_size = 100 # 默认字体大小
input_entries = [] # 保存所有输入框引用,用于后续字体更新
combo_boxes = [] # 保存所有组合框引用,用于后续字体更新
fish_tree_ref = None # 保存钓鱼记录Treeview引用,用于动态调整列宽
# =========================
# 调试功能设置
# =========================
debug_mode = True # 调试模式开关,默认开启
debug_info_queue = queue.Queue(maxsize=200) # 调试信息队列,用于线程间通信
debug_info_history = [] # 调试信息历史记录,最多保存200条
debug_history_lock = threading.Lock() # 保护调试历史记录的线程锁
debug_window = None # 调试窗口引用
debug_auto_refresh = True # 是否自动刷新调试信息
# =========================
# 时间抖动配置
# =========================
JITTER_RANGE = 0 # 时间抖动范围 ±0%
# 保存上次操作的时间戳
last_operation_time = None
last_operation_type = None
def add_jitter(base_time):
"""为给定的基础时间添加随机抖动
Args:
base_time: 基础时间(秒)
Returns:
float: 添加抖动后的时间(秒)
"""
if base_time <= 0:
return base_time
# 计算抖动范围(±JITTER_RANGE%)
jitter_factor = random.uniform(1 - JITTER_RANGE / 100, 1 + JITTER_RANGE / 100)
jittered_time = base_time * jitter_factor
# 确保时间不为负数且保持精度
return max(0.01, round(jittered_time, 3))
def print_timing_info(operation_type, base_time, actual_time, previous_interval=None):
"""打印时间抖动信息
Args:
operation_type: 操作类型字符串
base_time: 基础时间(秒)
actual_time: 实际执行时间(秒)
previous_interval: 与上次操作的时间间隔(秒)
"""
global last_operation_time, last_operation_type
current_time = time.time()
# 计算与基础时间的偏差百分比
deviation = ((actual_time - base_time) / base_time) * 100 if base_time > 0 else 0
deviation_str = f"{deviation:+.1f}%"
# 直接使用偏差字符串,不添加颜色
deviation_display = deviation_str
# 计算与上次操作的时间间隔
interval_info = ""
if last_operation_time is not None:
interval = current_time - last_operation_time
expected_interval = base_time if last_operation_type == operation_type else None
if expected_interval is not None and expected_interval > 0:
interval_deviation = (
(interval - expected_interval) / expected_interval
) * 100
interval_str = f"{interval:.3f}s ({interval_deviation:+.1f}%)"
# 直接使用间隔字符串,不添加颜色
interval_info = f" | 间隔: {interval_str}"
# 更新最后操作信息
last_operation_time = current_time
last_operation_type = operation_type
# 打印信息
print(
f"⏱️ [时间] {operation_type}: 基础={base_time:.3f}s, 实际={actual_time:.3f}s ({deviation_display}){interval_info}"
)
# =========================
# 参数文件路径
# =========================
PARAMETER_FILE = "./parameters.json"
# =========================
# 配置管理
# =========================
# 配置只管理5个核心钓鱼参数:t, leftclickdown, leftclickup, times, paogantime
# 其他参数保持全局设置,不受配置切换影响
# 配置数量限制
MAX_CONFIGS = 4
# 当前配置索引(0-3)
current_config_index = 0
# 配置名称
config_names = ["配置1", "配置2", "配置3", "配置4"]
# 配置参数,保存5个核心钓鱼参数
config_params = [
# 配置1
{"t": 0.9, "leftclickdown": 1, "leftclickup": 0.7, "times": 25, "paogantime": 2},
# 配置2
{
"t": 0.5,
"leftclickdown": 0.9,
"leftclickup": 0.5,
"times": 25,
"paogantime": 3,
},
# 配置3
{
"t": 0.2,
"leftclickdown": 0.4,
"leftclickup": 0.2,
"times": 25,
"paogantime": 0.1,
},
# 配置4
{
"t": 0.2,
"leftclickdown": 1.5,
"leftclickup": 1.0,
"times": 25,
"paogantime": 0.1,
},
]
# =========================
# 初始化字体样式
# =========================
def init_font_styles(style, font_size_percent):
"""初始化所有字体样式
Args:
style: ttkbootstrap.Style对象
font_size_percent: 字体大小百分比(50-200)
"""
# 缩放因子
scale_factor = font_size_percent / 100.0
# 基础字体设置
base_font = "Segoe UI"
# 定义不同控件的字体大小
font_sizes = {
"Title": int(14 * scale_factor), # 标题字体大小
"Subtitle": int(8 * scale_factor), # 副标题字体大小
"Label": int(9 * scale_factor), # 普通标签字体大小
"Entry": int(9 * scale_factor), # 输入框字体大小
"Button": int(9 * scale_factor), # 按钮字体大小
"Treeview": int(9 * scale_factor), # 树视图字体大小
"Combobox": int(9 * scale_factor), # 组合框字体大小
"Small": int(7 * scale_factor), # 小号字体大小
"Stats": int(10 * scale_factor), # 统计信息字体大小
"StatsTotal": int(11 * scale_factor), # 总计统计字体大小
"LogText": int(8 * scale_factor), # 日志文本字体大小
}
# 确保字体大小在合理范围内
for key in font_sizes:
font_sizes[key] = max(5, min(30, font_sizes[key]))
# 更新各种控件的字体样式
try:
# 1. 更新标签样式
label_font = (base_font, font_sizes["Label"])
label_styles = ["TLabel", "TLabelframe.Label", "Status.TLabel", "Stats.TLabel"]
for style_name in label_styles:
style.configure(style_name, font=label_font)
# 2. 更新输入框样式
entry_font = (base_font, font_sizes["Entry"])
entry_styles = ["TEntry", "Entry"]
for style_name in entry_styles:
style.configure(style_name, font=entry_font)
# 3. 更新组合框样式(包括下拉列表)
combobox_font = (base_font, font_sizes["Combobox"])
combobox_styles = [
"TCombobox",
"Combobox",
"TCombobox.Listbox",
"Combobox.Listbox",
]
for style_name in combobox_styles:
style.configure(style_name, font=combobox_font)
# 4. 更新复选框样式
style.configure("TCheckbutton", font=label_font)
# 5. 更新树视图样式
treeview_font = (base_font, font_sizes["Treeview"])
treeview_rowheight = int(font_sizes["Treeview"] * 2.2)
treeview_styles = [
("Treeview", treeview_font, treeview_rowheight),
("CustomTreeview.Treeview", treeview_font, treeview_rowheight),
]
for style_name, font, rowheight in treeview_styles:
style.configure(style_name, font=font, rowheight=rowheight)
style.configure(
f"{style_name}.Heading", font=(base_font, font_sizes["Label"], "bold")
)
# 6. 更新滑块样式
scale_styles = ["Horizontal.TScale", "Vertical.TScale"]
for style_name in scale_styles:
style.configure(style_name, font=label_font)
# 7. 更新单选按钮样式
radiobutton_styles = {
"TRadiobutton": label_font,
"Toolbutton.TRadiobutton": label_font,
"InfoOutline.TRadiobutton": label_font,
"SuccessOutline.TRadiobutton": label_font,
"DangerOutline.TRadiobutton": label_font,
"InfoOutline.Toolbutton.TRadiobutton": label_font,
"SuccessOutline.Toolbutton.TRadiobutton": label_font,
"DangerOutline.Toolbutton.TRadiobutton": label_font,
"WarningOutline.Toolbutton.TRadiobutton": label_font,
"SecondaryOutline.Toolbutton.TRadiobutton": label_font,
}
for style_name, font in radiobutton_styles.items():
style.configure(style_name, font=font)
# 8. 更新按钮样式
button_font = (base_font, font_sizes["Button"])
# 基础按钮样式
base_button_styles = [
"TButton",
"Button",
"Toolbutton",
"Outline.TButton",
"Toolbutton.TButton",
"Outline.Toolbutton.TButton",
]
for style_name in base_button_styles:
style.configure(style_name, font=button_font)
# 特定按钮样式变体
specific_button_styles = [
"InfoOutline.TButton",
"SuccessOutline.TButton",
"DangerOutline.TButton",
"WarningOutline.TButton",
"SecondaryOutline.TButton",
"InfoOutline.Toolbutton.TButton",
"SuccessOutline.Toolbutton.TButton",
"DangerOutline.Toolbutton.TButton",
"WarningOutline.Toolbutton.TButton",
"SecondaryOutline.Toolbutton.TButton",
"SuccessOutline.Toolbutton",
"DangerOutline.Toolbutton",
"InfoOutline.Toolbutton",
"WarningOutline.Toolbutton",
"SecondaryOutline.Toolbutton",
]
for style_name in specific_button_styles:
style.configure(style_name, font=button_font)
# 颜色变体按钮样式
color_variants = [
"Primary",
"Secondary",
"Success",
"Info",
"Warning",
"Danger",
"Light",
"Dark",
]
color_button_templates = [
f"{{}}.TButton",
f"{{}}Outline.TButton",
f"{{}}.Toolbutton.TButton",
f"{{}}Outline.Toolbutton.TButton",
]
bootstyle_templates = [f"{{}}-toolbutton", f"{{}}-outline-toolbutton"]
for color in color_variants:
# 颜色按钮样式
for template in color_button_templates:
style_name = template.format(color)
style.configure(style_name, font=button_font)
# 直接使用bootstyle名称作为样式
for template in bootstyle_templates:
style_name = template.format(color.lower())
style.configure(style_name, font=button_font)
# 9. 更新日志文本样式
log_font = (base_font, font_sizes["LogText"])
style.configure("LogText.TText", font=log_font)
except Exception as e:
print(f"Error initializing font styles: {e}")
# =========================
# 更新所有控件的字体
# =========================
def update_all_widget_fonts(widget, style, font_size_percent):
"""更新所有控件的字体大小
Args:
widget: 根控件
style: ttkbootstrap.Style对象
font_size_percent: 字体大小百分比(50-200)
"""
# 初始化字体样式 - 这会更新所有控件的样式字体
init_font_styles(style, font_size_percent)
# 缩放因子
scale_factor = font_size_percent / 100.0
base_font = "Segoe UI"
# 定义默认字体大小
default_sizes = {
"Label": 9,
"Button": 9,
"Entry": 9,
"Combobox": 9,
"Radiobutton": 9,
"Checkbutton": 9,
"Treeview": 9,
"LogText": 8,
}
# 递归更新所有控件的字体
def update_widget_font(w):
try:
widget_type = type(w).__name__
# 确定默认字体大小
if widget_type in ["Label", "TLabel", "TTKLabel"] or "Label" in widget_type:
default_size = default_sizes["Label"]
elif (
widget_type in ["Button", "TButton", "TTKButton"]
or "Button" in widget_type
):
default_size = default_sizes["Button"]
elif (
widget_type in ["Entry", "TEntry", "TTKEntry"] or "Entry" in widget_type
):
default_size = default_sizes["Entry"]
elif (
widget_type in ["Combobox", "TCombobox", "TTKCombobox"]
or "Combobox" in widget_type
):
default_size = default_sizes["Combobox"]
elif (
widget_type in ["Radiobutton", "TRadiobutton", "TTKRadiobutton"]
or "Radiobutton" in widget_type
):
default_size = default_sizes["Radiobutton"]
elif (
widget_type in ["Checkbutton", "TCheckbutton", "TTKCheckbutton"]
or "Checkbutton" in widget_type
):
default_size = default_sizes["Checkbutton"]
elif (
widget_type in ["Treeview", "TTKTreeview"] or "Treeview" in widget_type
):
default_size = default_sizes["Treeview"]
elif widget_type in ["Text", "TKText", "TTKText"] or "Text" in widget_type:
default_size = default_sizes["LogText"]
elif (
widget_type in ["Frame", "TFrame", "TTKFrame"] or "Frame" in widget_type
):
# 跳过框架,只处理其内部控件
pass
else:
# 对于其他控件类型,尝试将其作为按钮处理,特别是ttkbootstrap按钮
# 检查控件是否有configure方法,尝试获取其样式
try:
style_name = w.cget("style")
if "Button" in style_name or "Toolbutton" in style_name:
default_size = default_sizes["Button"]