123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- import tkinter as tk
- from tkinter import ttk
- from utils.config import config
- class SpeedUI:
- def init_ui(self, root=None):
- """
- Init speed UI
- """
- frame_default_sort = tk.Frame(root)
- frame_default_sort.pack(fill=tk.X)
- 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)
- self.open_sort_label = tk.Label(
- frame_default_sort_column1, text="测速排序:", width=12
- )
- self.open_sort_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_sort_var = tk.BooleanVar(value=config.open_sort)
- self.open_sort_checkbutton = ttk.Checkbutton(
- frame_default_sort_column1,
- variable=self.open_sort_var,
- onvalue=True,
- offvalue=False,
- command=self.update_open_sort,
- )
- self.open_sort_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
- self.sort_timeout_label = tk.Label(
- frame_default_sort_column2, text="响应超时(s):", width=12
- )
- self.sort_timeout_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.sort_timeout_entry = tk.Entry(frame_default_sort_column2, width=10)
- self.sort_timeout_entry.pack(side=tk.LEFT, padx=4, pady=8)
- self.sort_timeout_entry.insert(0, config.sort_timeout)
- 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)
- frame_default_sort_mode_column1.pack(side=tk.LEFT, fill=tk.Y)
- frame_default_sort_mode_column2 = tk.Frame(frame_default_sort_mode)
- frame_default_sort_mode_column2.pack(side=tk.RIGHT, fill=tk.Y)
- frame_default_speed_params = tk.Frame(root)
- frame_default_speed_params.pack(fill=tk.X)
- frame_default_speed_params_column1 = tk.Frame(
- frame_default_speed_params
- )
- frame_default_speed_params_column1.pack(side=tk.LEFT, fill=tk.Y)
- frame_default_speed_params_column2 = tk.Frame(
- frame_default_speed_params
- )
- frame_default_speed_params_column2.pack(side=tk.RIGHT, fill=tk.Y)
- self.open_filter_speed_label = tk.Label(
- frame_default_speed_params_column1, text="速率过滤:", width=12
- )
- self.open_filter_speed_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_filter_speed_var = tk.BooleanVar(
- value=config.open_filter_speed
- )
- self.open_filter_speed_checkbutton = ttk.Checkbutton(
- frame_default_speed_params_column1,
- variable=self.open_filter_speed_var,
- onvalue=True,
- offvalue=False,
- command=self.update_open_filter_speed
- )
- self.open_filter_speed_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
- self.min_speed_label = tk.Label(
- frame_default_speed_params_column2, text="最小速率(M/s):", width=12
- )
- self.min_speed_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.min_speed_entry = tk.Entry(
- frame_default_speed_params_column2, width=10
- )
- self.min_speed_entry.pack(side=tk.LEFT, padx=4, pady=8)
- self.min_speed_entry.insert(0, config.min_speed)
- self.min_speed_entry.bind("<KeyRelease>", self.update_min_speed)
- frame_default_resolution_params = tk.Frame(root)
- frame_default_resolution_params.pack(fill=tk.X)
- frame_default_resolution_params_column1 = tk.Frame(
- frame_default_resolution_params
- )
- frame_default_resolution_params_column1.pack(side=tk.LEFT, fill=tk.Y)
- frame_default_resolution_params_column2 = tk.Frame(
- frame_default_resolution_params
- )
- frame_default_resolution_params_column2.pack(side=tk.RIGHT, fill=tk.Y)
- self.open_filter_resolution_label = tk.Label(
- frame_default_resolution_params_column1, text="分辨率过滤:", width=12
- )
- self.open_filter_resolution_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.open_filter_resolution_var = tk.BooleanVar(
- value=config.open_filter_resolution
- )
- self.open_filter_resolution_checkbutton = ttk.Checkbutton(
- frame_default_resolution_params_column1,
- variable=self.open_filter_resolution_var,
- onvalue=True,
- offvalue=False,
- command=self.update_open_filter_resolution
- )
- self.open_filter_resolution_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
- self.min_resolution_label = tk.Label(
- frame_default_resolution_params_column2, text="最小分辨率:", width=12
- )
- self.min_resolution_label.pack(side=tk.LEFT, padx=4, pady=8)
- self.min_resolution_entry = tk.Entry(
- frame_default_resolution_params_column2, width=10
- )
- self.min_resolution_entry.pack(side=tk.LEFT, padx=4, pady=8)
- self.min_resolution_entry.insert(0, config.min_resolution)
- self.min_resolution_entry.bind("<KeyRelease>", self.update_min_resolution)
- frame_default_sort_params = tk.Frame(root)
- frame_default_sort_params.pack(fill=tk.X)
- frame_default_sort_params_column1 = tk.Frame(frame_default_sort_params)
- frame_default_sort_params_column1.pack(side=tk.LEFT, fill=tk.Y)
- frame_default_sort_params_column2 = tk.Frame(frame_default_sort_params)
- frame_default_sort_params_column2.pack(side=tk.RIGHT, fill=tk.Y)
- 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_filter_speed(self):
- config.set(
- "Settings",
- "open_filter_speed",
- str(self.open_filter_speed_var.get()),
- )
- def update_min_speed(self, event):
- config.set("Settings", "min_speed", self.min_speed_entry.get())
- def update_open_filter_resolution(self):
- config.set(
- "Settings",
- "open_filter_resolution",
- str(self.open_filter_resolution_var.get()),
- )
- def update_min_resolution(self, event):
- config.set("Settings", "min_resolution", self.min_resolution_entry.get())
- def change_entry_state(self, state):
- for entry in [
- "open_sort_checkbutton",
- "sort_timeout_entry",
- "open_filter_speed_checkbutton",
- "min_speed_entry",
- "open_filter_resolution_checkbutton",
- "min_resolution_entry"
- ]:
- getattr(self, entry).config(state=state)
|