Skip to content

Commit

Permalink
Merge pull request Guovin#441 from Guovin/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
Guovin authored Oct 23, 2024
2 parents ec0b170 + dfa747b commit 606b528
Show file tree
Hide file tree
Showing 9 changed files with 357 additions and 107 deletions.
2 changes: 1 addition & 1 deletion config/config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -43,5 +43,5 @@ origin_type_prefer = hotel,multicast,subscribe,online_search
hotel_num = 10
multicast_num = 10
subscribe_num = 10
online_search_num = 10
online_search_num = 0
open_url_info = True
94 changes: 47 additions & 47 deletions docs/config.md

Large diffs are not rendered by default.

94 changes: 47 additions & 47 deletions docs/config_en.md

Large diffs are not rendered by default.

Binary file added static/images/prefer_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
67 changes: 57 additions & 10 deletions tkinter_ui/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,8 +166,8 @@ def init_ui(self, root):
self.ipv_type_label.pack(side=tk.LEFT, padx=4, pady=8)
self.ipv_type_combo = ttk.Combobox(frame_default_channel_column2)
self.ipv_type_combo.pack(side=tk.LEFT, padx=4, pady=8)
self.ipv_type_combo["values"] = ("ipv4", "ipv6", "全部")
ipv_type = config.get("Settings", "ipv_type", fallback="全部")
self.ipv_type_combo["values"] = ("IPv4", "IPv6", "全部")
ipv_type = config.get("Settings", "ipv_type", fallback="全部").lower()
if ipv_type == "ipv4":
self.ipv_type_combo.current(0)
elif ipv_type == "ipv6":
Expand All @@ -181,7 +181,9 @@ def init_ui(self, root):
frame_default_sort_column1 = tk.Frame(frame_default_sort)
frame_default_sort_column1.pack(side=tk.LEFT, fill=tk.Y)
frame_default_sort_column2 = tk.Frame(frame_default_sort)
frame_default_sort_column2.pack(side=tk.RIGHT, fill=tk.Y)
frame_default_sort_column2.pack(side=tk.LEFT, fill=tk.Y)
frame_default_sort_column3 = tk.Frame(frame_default_sort)
frame_default_sort_column3.pack(side=tk.RIGHT, fill=tk.Y)

self.open_keep_all_label = tk.Label(
frame_default_sort_column1, text="保留模式:", width=12
Expand All @@ -196,12 +198,12 @@ def init_ui(self, root):
onvalue=True,
offvalue=False,
command=self.update_open_keep_all,
text="(保留所有检索结果,建议手动维护时开启)",
text="(非严格匹配)",
)
self.open_keep_all_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)

self.open_sort_label = tk.Label(
frame_default_sort_column2, text="开启测速排序:", width=12
frame_default_sort_column2, text="测速排序:", width=12
)
self.open_sort_label.pack(side=tk.LEFT, padx=4, pady=8)
self.open_sort_var = tk.BooleanVar(
Expand All @@ -216,6 +218,17 @@ def init_ui(self, root):
)
self.open_sort_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)

self.sort_timeout_label = tk.Label(
frame_default_sort_column3, text="测速超时:", width=12
)
self.sort_timeout_label.pack(side=tk.LEFT, padx=4, pady=8)
self.sort_timeout_entry = tk.Entry(frame_default_sort_column3)
self.sort_timeout_entry.pack(side=tk.LEFT, padx=4, pady=8)
self.sort_timeout_entry.insert(
0, config.getint("Settings", "sort_timeout", fallback=5)
)
self.sort_timeout_entry.bind("<KeyRelease>", self.update_sort_timeout)

frame_default_sort_mode = tk.Frame(root)
frame_default_sort_mode.pack(fill=tk.X)
frame_default_sort_mode_column1 = tk.Frame(frame_default_sort_mode)
Expand Down Expand Up @@ -337,25 +350,51 @@ def init_ui(self, root):
config.getfloat("Settings", "resolution_weight", fallback=0.5)
)

frame_default_open_update_time = tk.Frame(root)
frame_default_open_update_time.pack(fill=tk.X)
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_time, text="显示更新时间:", width=12
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.getboolean("Settings", "open_update_time", fallback=True)
)
self.open_update_time_checkbutton = ttk.Checkbutton(
frame_default_open_update_time,
frame_default_open_update_info_column1,
variable=self.open_update_time_var,
onvalue=True,
offvalue=False,
command=self.update_open_update_time,
text="(显示于结果文件首行, 作为首个频道分类显示)",
text="(结果顶部显示)",
)
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.getboolean("Settings", "open_url_info", fallback=True)
)
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,
text="(需要播放器支持)",
)
self.open_url_info_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)

frame_default_domain_blacklist = tk.Frame(root)
frame_default_domain_blacklist.pack(fill=tk.X)

Expand Down Expand Up @@ -432,6 +471,9 @@ def update_open_keep_all(self):
def update_open_sort(self):
config.set("Settings", "open_sort", str(self.open_sort_var.get()))

def update_sort_timeout(self):
config.set("Settings", "sort_timeout", self.sort_timeout_entry.get())

def update_open_ffmpeg(self):
config.set("Settings", "open_ffmpeg", str(self.open_ffmpeg_var.get()))

Expand Down Expand Up @@ -468,6 +510,9 @@ def update_resolution_weight(self, event):
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_ipv_type(self, event):
config.set("Settings", "ipv_type", self.ipv_type_combo.get())

Expand Down Expand Up @@ -504,6 +549,7 @@ def change_entry_state(self, state):
"final_file_button",
"open_keep_all_checkbutton",
"open_sort_checkbutton",
"sort_timeout_entry",
"open_ffmpeg_checkbutton",
"open_m3u_result_checkbutton",
"open_filter_resolution_checkbutton",
Expand All @@ -512,6 +558,7 @@ def change_entry_state(self, state):
"response_time_weight_scale",
"resolution_weight_scale",
"open_update_time_checkbutton",
"open_url_info_checkbutton",
"ipv_type_combo",
"domain_blacklist_text",
"url_keywords_blacklist_text",
Expand Down
185 changes: 185 additions & 0 deletions tkinter_ui/prefer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,185 @@
import tkinter as tk
from tkinter import ttk
from utils.config import config


class PreferUI:
def init_ui(self, root=None):
"""
Init prefer UI
"""
origin_type_prefer = [
item.lower()
for item in config.get(
"Settings",
"origin_type_prefer",
fallback="hotel,multicast,subscribe,online_search",
).split(",")
]
config_options = [
{"label_text": f"结果来源优先{i+1}:", "combo_box_value": i}
for i in range(len(origin_type_prefer))
]
self.origin_type_prefer_options = []
for config_option in config_options:
option = ConfigOption(root, **config_option)
option.combo_box.bind(
"<<ComboboxSelected>>",
option.update_select,
)
option.entry.bind("<KeyRelease>", option.update_input)
self.origin_type_prefer_options.append(option)

frame_prefer_ipv_type = tk.Frame(root)
frame_prefer_ipv_type.pack(fill=tk.X)
self.prefer_ipv_type_label = tk.Label(
frame_prefer_ipv_type, text="结果协议优先:", width=12
)
self.prefer_ipv_type_label.pack(side=tk.LEFT, padx=4, pady=8)
self.prefer_ipv_type_combo = ttk.Combobox(frame_prefer_ipv_type)
self.prefer_ipv_type_combo.pack(side=tk.LEFT, padx=4, pady=8)
self.prefer_ipv_type_combo["values"] = ("IPv4", "IPv6", "随机")
ipv_type_prefer = config.get(
"Settings", "ipv_type_prefer", fallback="IPv4"
).lower()
if ipv_type_prefer == "ipv4":
self.prefer_ipv_type_combo.current(0)
elif ipv_type_prefer == "ipv6":
self.prefer_ipv_type_combo.current(1)
else:
self.prefer_ipv_type_combo.current(2)
self.prefer_ipv_type_combo.bind(
"<<ComboboxSelected>>", self.update_ipv_type_prefer
)
self.ipv_type_input = []
for ipv_type in ["ipv4", "ipv6"]:
input = IpvNumInput(root, ipv_type)
input.entry.bind("<KeyRelease>", input.update_input)
self.ipv_type_input.append(input)

def update_ipv_type_prefer(self, event):
config.set(
"Settings",
"ipv_type_prefer",
self.prefer_ipv_type_combo.get(),
)

def change_entry_state(self, state):
for option in self.origin_type_prefer_options:
option.change_state(state)
self.prefer_ipv_type_combo.config(state=state)
for input in self.ipv_type_input:
input.change_state(state)


class IpvNumInput:
def __init__(self, master, ipv_type):
self.master = master
self.ipv_type = ipv_type
self.frame = tk.Frame(master)
self.frame.pack(fill=tk.X)
self.frame_column1 = tk.Frame(self.frame)
self.frame_column1.pack(side=tk.LEFT, fill=tk.Y)
self.frame_column2 = tk.Frame(self.frame)
self.frame_column2.pack(side=tk.RIGHT, fill=tk.Y)

ipv_type_text = "IPv4" if ipv_type == "ipv4" else "IPv6"
self.entry_label = tk.Label(
self.frame_column1, text=f"{ipv_type_text}数量:", width=12
)
self.entry_label.pack(side=tk.LEFT, padx=4, pady=8)

self.entry = tk.Entry(self.frame_column1)
self.entry.insert(
0,
config.getint(
"Settings",
f"{ipv_type}_num",
fallback=15,
),
)
self.entry.pack(side=tk.LEFT, padx=4, pady=8)

def update_input(self, event):
config.set(
"Settings",
f"{ self.ipv_type}_num",
self.entry.get(),
)

def change_state(self, state):
self.entry.config(state=state)


class ConfigOption:
def __init__(self, master, label_text, combo_box_value):
self.master = master
self.label_text = label_text
self.combo_box_value = combo_box_value

self.frame = tk.Frame(master)
self.frame.pack(fill=tk.X)

self.column1 = tk.Frame(self.frame)
self.column1.pack(side=tk.LEFT, fill=tk.Y)

self.column2 = tk.Frame(self.frame)
self.column2.pack(side=tk.RIGHT, fill=tk.Y)

self.label = tk.Label(self.column1, text=label_text, width=12)
self.label.pack(side=tk.LEFT, padx=4, pady=8)

self.combo_box = ttk.Combobox(self.column1)
self.origin_type_prefer_obj = {
"酒店源": "hotel",
"组播源": "multicast",
"订阅源": "subscribe",
"在线搜索": "online_search",
}
combo_box_values_name = list(self.origin_type_prefer_obj.keys())
self.combo_box["values"] = combo_box_values_name
self.combo_box.pack(side=tk.LEFT, padx=4, pady=8)
self.combo_box.current(combo_box_value)

self.entry_label = tk.Label(self.column2, text="数量:", width=12)
self.entry_label.pack(side=tk.LEFT, padx=4, pady=8)

self.entry = tk.Entry(self.column2)
self.entry.insert(
0,
config.getint(
"Settings",
f"{self.origin_type_prefer_obj[self.combo_box.get()]}_num",
fallback=10,
),
)
self.entry.pack(side=tk.LEFT, padx=4, pady=8)

def update_select(self, key):
origin_type_prefer_list = [
item.lower()
for item in config.get(
"Settings",
"origin_type_prefer",
fallback="hotel,multicast,subscribe,online_search",
).split(",")
]
origin_type_prefer_list[self.combo_box_value] = self.origin_type_prefer_obj[
self.combo_box.get()
]
config.set(
"Settings",
"origin_type_prefer",
(",").join(origin_type_prefer_list),
)

def update_input(self, event):
config.set(
"Settings",
f"{ self.origin_type_prefer_obj[self.combo_box.get()]}_num",
self.entry.get(),
)

def change_state(self, state):
self.combo_box.config(state=state)
self.entry.config(state=state)
Loading

0 comments on commit 606b528

Please sign in to comment.