123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490 |
- import os
- import tkinter as tk
- from tkinter import filedialog
- from tkinter import ttk
- import utils.constants as constants
- from utils.config import config
- from utils.tools import resource_path
- class DefaultUI:
- def init_ui(self, root):
- """
- Init default UI
- """
- frame_default_source_file = tk.Frame(root)
- frame_default_source_file.pack(fill=tk.X)
- frame_default_source_file_column1 = tk.Frame(frame_default_source_file)
- frame_default_source_file_column1.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
- frame_default_source_file_column2 = tk.Frame(frame_default_source_file)
- frame_default_source_file_column2.pack(side=tk.RIGHT, fill=tk.Y)
- self.source_file_label = tk.Label(
- frame_default_source_file_column1, text="模板文件:", width=8
- )
- self.source_file_entry = tk.Entry(frame_default_source_file_column1)
- self.source_file_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.source_file_entry.pack(fill=tk.X, padx=4, expand=True)
- self.source_file_entry.insert(0, config.source_file)
- self.source_file_button = tk.ttk.Button(
- frame_default_source_file_column2,
- text="选择文件",
- command=self.select_source_file,
- )
- self.source_file_button.pack(side=tk.LEFT, padx=4, pady=0)
- frame_default_final_file = tk.Frame(root)
- frame_default_final_file.pack(fill=tk.X)
- frame_default_final_file_column1 = tk.Frame(frame_default_final_file)
- frame_default_final_file_column1.pack(side=tk.LEFT, fill=tk.BOTH, expand=True)
- frame_default_final_file_column2 = tk.Frame(frame_default_final_file)
- frame_default_final_file_column2.pack(side=tk.RIGHT, fill=tk.Y)
- self.final_file_label = tk.Label(
- frame_default_final_file_column1, text="结果文件:", width=8
- )
- self.final_file_entry = tk.Entry(frame_default_final_file_column1)
- self.final_file_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.final_file_entry.pack(fill=tk.X, padx=4, expand=True)
- self.final_file_entry.insert(0, config.final_file)
- self.final_file_button = tk.ttk.Button(
- frame_default_final_file_column2,
- text="选择文件",
- command=self.select_final_file,
- )
- self.final_file_button.pack(side=tk.LEFT, padx=4, pady=0)
- frame_default_open_update = tk.Frame(root)
- frame_default_open_update.pack(fill=tk.X)
- frame_default_open_update_column1 = tk.Frame(frame_default_open_update)
- frame_default_open_update_column1.pack(side=tk.LEFT, fill=tk.Y)
- frame_default_open_update_column2 = tk.Frame(frame_default_open_update)
- frame_default_open_update_column2.pack(side=tk.RIGHT, fill=tk.Y)
- self.open_update_label = tk.Label(
- frame_default_open_update_column1, text="开启更新:", width=12
- )
- self.open_update_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_update_var = tk.BooleanVar(value=config.open_update)
- self.open_update_checkbutton = ttk.Checkbutton(
- frame_default_open_update_column1,
- variable=self.open_update_var,
- onvalue=True,
- offvalue=False,
- command=self.update_open_update
- )
- self.open_update_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_service_label = tk.Label(
- frame_default_open_update_column2, text="开启服务:", width=8
- )
- self.open_service_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_service_var = tk.BooleanVar(value=config.open_service)
- self.open_service_checkbutton = ttk.Checkbutton(
- frame_default_open_update_column2,
- variable=self.open_service_var,
- onvalue=True,
- offvalue=False,
- command=self.update_open_service
- )
- self.open_service_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
- self.app_port_label = tk.Label(
- frame_default_open_update_column2, text="端口:", width=3
- )
- self.app_port_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.app_port_entry = tk.Entry(frame_default_open_update_column2, width=8)
- self.app_port_entry.pack(side=tk.LEFT, padx=4, pady=8)
- self.app_port_entry.insert(0, config.app_port)
- self.app_port_entry.bind("<KeyRelease>", self.update_app_port)
- frame_default_open_cache = tk.Frame(root)
- frame_default_open_cache.pack(fill=tk.X)
- frame_default_open_cache_column1 = tk.Frame(frame_default_open_cache)
- frame_default_open_cache_column1.pack(side=tk.LEFT, fill=tk.Y)
- frame_default_open_cache_column2 = tk.Frame(frame_default_open_cache)
- frame_default_open_cache_column2.pack(side=tk.RIGHT, fill=tk.Y)
- self.open_use_old_result_label = tk.Label(
- frame_default_open_cache_column1, text="使用历史结果:", width=12
- )
- self.open_use_old_result_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_use_old_result_var = tk.BooleanVar(value=config.open_use_old_result)
- self.open_use_old_result_checkbutton = ttk.Checkbutton(
- frame_default_open_cache_column1,
- variable=self.open_use_old_result_var,
- onvalue=True,
- offvalue=False,
- command=self.update_open_use_old_result,
- )
- self.open_use_old_result_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_use_cache_label = tk.Label(
- frame_default_open_cache_column2, text="使用离线数据:", width=12
- )
- self.open_use_cache_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_use_cache_var = tk.BooleanVar(value=config.open_use_cache)
- self.open_use_cache_checkbutton = ttk.Checkbutton(
- frame_default_open_cache_column2,
- variable=self.open_use_cache_var,
- onvalue=True,
- offvalue=False,
- command=self.update_open_use_cache,
- )
- self.open_use_cache_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
- frame_default_mode = tk.Frame(root)
- frame_default_mode.pack(fill=tk.X)
- frame_default_mode_params_column1 = tk.Frame(frame_default_mode)
- frame_default_mode_params_column1.pack(side=tk.LEFT, fill=tk.Y)
- frame_default_mode_params_column2 = tk.Frame(frame_default_mode)
- frame_default_mode_params_column2.pack(side=tk.RIGHT, fill=tk.Y)
- self.open_request_label = tk.Label(
- frame_default_mode_params_column1, text="开启网络请求:", width=12
- )
- self.open_request_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_request_var = tk.BooleanVar(value=config.open_request)
- self.open_request_checkbutton = ttk.Checkbutton(
- frame_default_mode_params_column1,
- variable=self.open_request_var,
- onvalue=True,
- offvalue=False,
- command=self.update_open_request
- )
- self.open_request_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
- self.request_timeout_label = tk.Label(
- frame_default_mode_params_column2, text="请求超时(s):", width=12
- )
- self.request_timeout_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.request_timeout_entry = tk.Entry(frame_default_mode_params_column2, width=8)
- self.request_timeout_entry.pack(side=tk.LEFT, padx=4, pady=8)
- self.request_timeout_entry.insert(0, config.request_timeout)
- self.request_timeout_entry.bind("<KeyRelease>", self.update_request_timeout)
- frame_default_channel = tk.Frame(root)
- frame_default_channel.pack(fill=tk.X)
- frame_default_channel_column1 = tk.Frame(frame_default_channel)
- frame_default_channel_column1.pack(side=tk.LEFT, fill=tk.Y)
- frame_default_channel_column2 = tk.Frame(frame_default_channel)
- frame_default_channel_column2.pack(side=tk.RIGHT, fill=tk.Y)
- self.urls_limit_label = tk.Label(
- frame_default_channel_column1, text="频道接口数量:", width=12
- )
- self.urls_limit_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.urls_limit_entry = tk.Entry(frame_default_channel_column1, width=8)
- self.urls_limit_entry.pack(side=tk.LEFT, padx=4, pady=8)
- self.urls_limit_entry.insert(0, config.urls_limit)
- self.urls_limit_entry.bind("<KeyRelease>", self.update_urls_limit)
- self.ipv_type_label = tk.Label(
- frame_default_channel_column2, text="接口协议类型:", width=12
- )
- self.ipv_type_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.ipv_type_combo = ttk.Combobox(frame_default_channel_column2, width=5)
- self.ipv_type_combo.pack(side=tk.LEFT, padx=4, pady=8)
- self.ipv_type_combo["values"] = ("IPv4", "IPv6", "全部")
- if config.ipv_type == "ipv4":
- self.ipv_type_combo.current(0)
- elif config.ipv_type == "ipv6":
- self.ipv_type_combo.current(1)
- else:
- self.ipv_type_combo.current(2)
- self.ipv_type_combo.bind("<<ComboboxSelected>>", self.update_ipv_type)
- frame_proxy_mode = tk.Frame(root)
- frame_proxy_mode.pack(fill=tk.X)
- frame_proxy_mode_params_column1 = tk.Frame(frame_proxy_mode)
- frame_proxy_mode_params_column1.pack(side=tk.LEFT, fill=tk.Y)
- frame_proxy_mode_params_column2 = tk.Frame(frame_proxy_mode)
- frame_proxy_mode_params_column2.pack(side=tk.RIGHT, fill=tk.Y)
- self.open_proxy_label = tk.Label(
- frame_proxy_mode_params_column1, text="开启代理查询:", width=12
- )
- self.open_proxy_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_proxy_var = tk.BooleanVar(value=config.open_proxy)
- self.open_proxy_checkbutton = ttk.Checkbutton(
- frame_proxy_mode_params_column1,
- variable=self.open_proxy_var,
- onvalue=True,
- offvalue=False,
- command=self.update_open_proxy
- )
- self.open_proxy_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_keep_all_label = tk.Label(
- frame_proxy_mode_params_column2, text="完整记录:", width=12
- )
- self.open_keep_all_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_keep_all_var = tk.BooleanVar(value=config.open_keep_all)
- self.open_keep_all_checkbutton = ttk.Checkbutton(
- frame_proxy_mode_params_column2,
- variable=self.open_keep_all_var,
- onvalue=True,
- offvalue=False,
- command=self.update_open_keep_all
- )
- self.open_keep_all_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
- frame_m3u = tk.Frame(root)
- frame_m3u.pack(fill=tk.X)
- frame_proxy_m3u_column1 = tk.Frame(frame_m3u)
- frame_proxy_m3u_column1.pack(side=tk.LEFT, fill=tk.Y)
- frame_proxy_m3u_column2 = tk.Frame(frame_m3u)
- frame_proxy_m3u_column2.pack(side=tk.RIGHT, fill=tk.Y)
- self.open_m3u_result_label = tk.Label(
- frame_proxy_m3u_column1, text="M3U转换:", width=12
- )
- self.open_m3u_result_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_m3u_result_var = tk.BooleanVar(value=config.open_m3u_result)
- self.open_m3u_result_checkbutton = ttk.Checkbutton(
- frame_proxy_m3u_column1,
- variable=self.open_m3u_result_var,
- onvalue=True,
- offvalue=False,
- command=self.update_open_m3u_result
- )
- self.open_m3u_result_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_driver_label = tk.Label(
- frame_proxy_m3u_column2, text="浏览器模式:", width=12
- )
- self.open_driver_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_driver_var = tk.BooleanVar(value=config.open_driver)
- self.open_driver_checkbutton = ttk.Checkbutton(
- frame_proxy_m3u_column2,
- variable=self.open_driver_var,
- onvalue=True,
- offvalue=False,
- command=self.update_open_driver
- )
- self.open_driver_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
- frame_default_open_update_info = tk.Frame(root)
- frame_default_open_update_info.pack(fill=tk.X)
- frame_default_open_update_info_column1 = tk.Frame(
- frame_default_open_update_info
- )
- frame_default_open_update_info_column1.pack(side=tk.LEFT, fill=tk.Y)
- frame_default_open_update_info_column2 = tk.Frame(
- frame_default_open_update_info
- )
- frame_default_open_update_info_column2.pack(side=tk.RIGHT, fill=tk.Y)
- self.open_update_time_label = tk.Label(
- frame_default_open_update_info_column1, text="显示更新时间:", width=12
- )
- self.open_update_time_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_update_time_var = tk.BooleanVar(value=config.open_update_time)
- self.open_update_time_checkbutton = ttk.Checkbutton(
- frame_default_open_update_info_column1,
- variable=self.open_update_time_var,
- onvalue=True,
- offvalue=False,
- command=self.update_open_update_time,
- )
- self.open_update_time_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_url_info_label = tk.Label(
- frame_default_open_update_info_column2, text="显示接口信息:", width=12
- )
- self.open_url_info_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_url_info_var = tk.BooleanVar(value=config.open_url_info)
- self.open_url_info_checkbutton = ttk.Checkbutton(
- frame_default_open_update_info_column2,
- variable=self.open_url_info_var,
- onvalue=True,
- offvalue=False,
- command=self.update_open_url_info,
- )
- self.open_url_info_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
- frame_default_open_empty_category = tk.Frame(root)
- frame_default_open_empty_category.pack(fill=tk.X)
- frame_default_open_empty_category_column1 = tk.Frame(
- frame_default_open_empty_category
- )
- frame_default_open_empty_category_column1.pack(side=tk.LEFT, fill=tk.Y)
- frame_default_open_empty_category_column2 = tk.Frame(
- frame_default_open_empty_category
- )
- frame_default_open_empty_category_column2.pack(side=tk.RIGHT, fill=tk.Y)
- self.open_empty_category_label = tk.Label(
- frame_default_open_empty_category_column1, text="显示无结果分类:", width=12
- )
- self.open_empty_category_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_empty_category_var = tk.BooleanVar(value=config.open_empty_category)
- self.open_empty_category_checkbutton = ttk.Checkbutton(
- frame_default_open_empty_category_column1,
- variable=self.open_empty_category_var,
- onvalue=True,
- offvalue=False,
- command=self.update_open_empty_category,
- )
- self.open_empty_category_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
- self.ipv6_support_label = tk.Label(
- frame_default_open_empty_category_column2, text="跳过IPv6检测:", width=12
- )
- self.ipv6_support_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.ipv6_support_var = tk.BooleanVar(value=config.ipv6_support)
- self.ipv6_support_checkbutton = ttk.Checkbutton(
- frame_default_open_empty_category_column2,
- variable=self.ipv6_support_var,
- onvalue=True,
- offvalue=False,
- command=self.update_ipv6_support,
- )
- self.ipv6_support_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
- frame_default_url_keywords = tk.Frame(root)
- frame_default_url_keywords.pack(fill=tk.X)
- frame_default_url_keywords_column1 = tk.Frame(frame_default_url_keywords)
- frame_default_url_keywords_column1.pack(side=tk.LEFT, fill=tk.Y)
- frame_default_url_keywords_column2 = tk.Frame(frame_default_url_keywords)
- frame_default_url_keywords_column2.pack(side=tk.RIGHT, fill=tk.Y)
- self.url_keywords_whitelist_label = tk.Label(
- frame_default_url_keywords_column1, text="白名单:", width=12
- )
- self.url_keywords_whitelist_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.whitelist_file_button = tk.ttk.Button(
- frame_default_url_keywords_column1,
- text="编辑",
- command=self.edit_whitelist_file,
- )
- self.whitelist_file_button.pack(side=tk.LEFT, padx=4, pady=0)
- self.url_keywords_blacklist_label = tk.Label(
- frame_default_url_keywords_column2, text="黑名单:", width=12
- )
- self.url_keywords_blacklist_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.blacklist_file_button = tk.ttk.Button(
- frame_default_url_keywords_column2,
- text="编辑",
- command=self.edit_blacklist_file,
- )
- self.blacklist_file_button.pack(side=tk.LEFT, padx=4, pady=0)
- def update_open_update(self):
- config.set("Settings", "open_update", str(self.open_update_var.get()))
- def update_open_service(self):
- config.set("Settings", "open_service", str(self.open_update_var.get()))
- def update_app_port(self, event):
- config.set("Settings", "app_port", self.app_port_entry.get())
- def update_open_use_old_result(self):
- config.set(
- "Settings", "open_use_old_result", str(self.open_use_old_result_var.get())
- )
- def update_open_use_cache(self):
- config.set(
- "Settings", "open_use_cache", str(self.open_use_cache_var.get())
- )
- def select_source_file(self):
- filepath = filedialog.askopenfilename(
- initialdir=os.getcwd(), title="选择模板文件", filetypes=[("txt", "*.txt")]
- )
- if filepath:
- self.source_file_entry.delete(0, tk.END)
- self.source_file_entry.insert(0, filepath)
- config.set("Settings", "source_file", filepath)
- def select_final_file(self):
- filepath = filedialog.askopenfilename(
- initialdir=os.getcwd(), title="选择结果文件", filetypes=[("txt", "*.txt")]
- )
- if filepath:
- self.final_file_entry.delete(0, tk.END)
- self.final_file_entry.insert(0, filepath)
- config.set("Settings", "final_file", filepath)
- def update_open_request(self):
- config.set("Settings", "open_requests", str(self.open_request_var.get()))
- def update_open_driver(self):
- config.set("Settings", "open_driver", str(self.open_driver_var.get()))
- def update_open_proxy(self):
- config.set("Settings", "open_proxy", str(self.open_proxy_var.get()))
- def update_open_keep_all(self):
- config.set("Settings", "open_keep_all", str(self.open_keep_all_var.get()))
- def update_open_m3u_result(self):
- config.set("Settings", "open_m3u_result", str(self.open_m3u_result_var.get()))
- def update_request_timeout(self, event):
- config.set("Settings", "request_timeout", self.request_timeout_entry.get())
- def update_urls_limit(self, event):
- config.set("Settings", "urls_limit", self.urls_limit_entry.get())
- def update_open_update_time(self):
- config.set("Settings", "open_update_time", str(self.open_update_time_var.get()))
- def update_open_url_info(self):
- config.set("Settings", "open_url_info", str(self.open_url_info_var.get()))
- def update_open_empty_category(self):
- config.set(
- "Settings", "open_empty_category", str(self.open_empty_category_var.get())
- )
- def update_ipv6_support(self):
- config.set(
- "Settings", "ipv6_support", str(self.ipv6_support_var.get())
- )
- def update_ipv_type(self, event):
- config.set("Settings", "ipv_type", self.ipv_type_combo.get())
- def edit_whitelist_file(self):
- path = resource_path(constants.whitelist_path)
- if os.path.exists(path):
- os.system(f'notepad.exe {path}')
- def edit_blacklist_file(self):
- path = resource_path(constants.blacklist_path)
- if os.path.exists(path):
- os.system(f'notepad.exe {path}')
- def change_entry_state(self, state):
- for entry in [
- "open_update_checkbutton",
- "open_service_checkbutton",
- "app_port_entry",
- "open_use_old_result_checkbutton",
- "open_use_cache_checkbutton",
- "open_request_checkbutton",
- "open_driver_checkbutton",
- "open_proxy_checkbutton",
- "request_timeout_entry",
- "source_file_entry",
- "source_file_button",
- "final_file_entry",
- "final_file_button",
- "open_keep_all_checkbutton",
- "open_m3u_result_checkbutton",
- "urls_limit_entry",
- "open_update_time_checkbutton",
- "open_url_info_checkbutton",
- "open_empty_category_checkbutton",
- "ipv_type_combo",
- "ipv6_support_checkbutton",
- "whitelist_file_button",
- "blacklist_file_button",
- ]:
- getattr(self, entry).config(state=state)
|