speed.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import tkinter as tk
  2. from tkinter import ttk
  3. from utils.config import config
  4. class SpeedUI:
  5. def init_ui(self, root=None):
  6. """
  7. Init speed UI
  8. """
  9. frame_default_sort = tk.Frame(root)
  10. frame_default_sort.pack(fill=tk.X)
  11. frame_default_sort_column1 = tk.Frame(frame_default_sort)
  12. frame_default_sort_column1.pack(side=tk.LEFT, fill=tk.Y)
  13. frame_default_sort_column2 = tk.Frame(frame_default_sort)
  14. frame_default_sort_column2.pack(side=tk.RIGHT, fill=tk.Y)
  15. self.open_sort_label = tk.Label(
  16. frame_default_sort_column1, text="测速排序:", width=12
  17. )
  18. self.open_sort_label.pack(side=tk.LEFT, padx=4, pady=8)
  19. self.open_sort_var = tk.BooleanVar(value=config.open_sort)
  20. self.open_sort_checkbutton = ttk.Checkbutton(
  21. frame_default_sort_column1,
  22. variable=self.open_sort_var,
  23. onvalue=True,
  24. offvalue=False,
  25. command=self.update_open_sort,
  26. )
  27. self.open_sort_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
  28. self.sort_timeout_label = tk.Label(
  29. frame_default_sort_column2, text="响应超时(s):", width=12
  30. )
  31. self.sort_timeout_label.pack(side=tk.LEFT, padx=4, pady=8)
  32. self.sort_timeout_entry = tk.Entry(frame_default_sort_column2, width=10)
  33. self.sort_timeout_entry.pack(side=tk.LEFT, padx=4, pady=8)
  34. self.sort_timeout_entry.insert(0, config.sort_timeout)
  35. self.sort_timeout_entry.bind("<KeyRelease>", self.update_sort_timeout)
  36. frame_default_sort_mode = tk.Frame(root)
  37. frame_default_sort_mode.pack(fill=tk.X)
  38. frame_default_sort_mode_column1 = tk.Frame(frame_default_sort_mode)
  39. frame_default_sort_mode_column1.pack(side=tk.LEFT, fill=tk.Y)
  40. frame_default_sort_mode_column2 = tk.Frame(frame_default_sort_mode)
  41. frame_default_sort_mode_column2.pack(side=tk.RIGHT, fill=tk.Y)
  42. frame_default_speed_params = tk.Frame(root)
  43. frame_default_speed_params.pack(fill=tk.X)
  44. frame_default_speed_params_column1 = tk.Frame(
  45. frame_default_speed_params
  46. )
  47. frame_default_speed_params_column1.pack(side=tk.LEFT, fill=tk.Y)
  48. frame_default_speed_params_column2 = tk.Frame(
  49. frame_default_speed_params
  50. )
  51. frame_default_speed_params_column2.pack(side=tk.RIGHT, fill=tk.Y)
  52. self.open_filter_speed_label = tk.Label(
  53. frame_default_speed_params_column1, text="速率过滤:", width=12
  54. )
  55. self.open_filter_speed_label.pack(side=tk.LEFT, padx=4, pady=8)
  56. self.open_filter_speed_var = tk.BooleanVar(
  57. value=config.open_filter_speed
  58. )
  59. self.open_filter_speed_checkbutton = ttk.Checkbutton(
  60. frame_default_speed_params_column1,
  61. variable=self.open_filter_speed_var,
  62. onvalue=True,
  63. offvalue=False,
  64. command=self.update_open_filter_speed
  65. )
  66. self.open_filter_speed_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
  67. self.min_speed_label = tk.Label(
  68. frame_default_speed_params_column2, text="最小速率(M/s):", width=12
  69. )
  70. self.min_speed_label.pack(side=tk.LEFT, padx=4, pady=8)
  71. self.min_speed_entry = tk.Entry(
  72. frame_default_speed_params_column2, width=10
  73. )
  74. self.min_speed_entry.pack(side=tk.LEFT, padx=4, pady=8)
  75. self.min_speed_entry.insert(0, config.min_speed)
  76. self.min_speed_entry.bind("<KeyRelease>", self.update_min_speed)
  77. frame_default_resolution_params = tk.Frame(root)
  78. frame_default_resolution_params.pack(fill=tk.X)
  79. frame_default_resolution_params_column1 = tk.Frame(
  80. frame_default_resolution_params
  81. )
  82. frame_default_resolution_params_column1.pack(side=tk.LEFT, fill=tk.Y)
  83. frame_default_resolution_params_column2 = tk.Frame(
  84. frame_default_resolution_params
  85. )
  86. frame_default_resolution_params_column2.pack(side=tk.RIGHT, fill=tk.Y)
  87. self.open_filter_resolution_label = tk.Label(
  88. frame_default_resolution_params_column1, text="分辨率过滤:", width=12
  89. )
  90. self.open_filter_resolution_label.pack(side=tk.LEFT, padx=4, pady=8)
  91. self.open_filter_resolution_var = tk.BooleanVar(
  92. value=config.open_filter_resolution
  93. )
  94. self.open_filter_resolution_checkbutton = ttk.Checkbutton(
  95. frame_default_resolution_params_column1,
  96. variable=self.open_filter_resolution_var,
  97. onvalue=True,
  98. offvalue=False,
  99. command=self.update_open_filter_resolution
  100. )
  101. self.open_filter_resolution_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
  102. self.min_resolution_label = tk.Label(
  103. frame_default_resolution_params_column2, text="最小分辨率:", width=12
  104. )
  105. self.min_resolution_label.pack(side=tk.LEFT, padx=4, pady=8)
  106. self.min_resolution_entry = tk.Entry(
  107. frame_default_resolution_params_column2, width=10
  108. )
  109. self.min_resolution_entry.pack(side=tk.LEFT, padx=4, pady=8)
  110. self.min_resolution_entry.insert(0, config.min_resolution)
  111. self.min_resolution_entry.bind("<KeyRelease>", self.update_min_resolution)
  112. frame_default_sort_params = tk.Frame(root)
  113. frame_default_sort_params.pack(fill=tk.X)
  114. frame_default_sort_params_column1 = tk.Frame(frame_default_sort_params)
  115. frame_default_sort_params_column1.pack(side=tk.LEFT, fill=tk.Y)
  116. frame_default_sort_params_column2 = tk.Frame(frame_default_sort_params)
  117. frame_default_sort_params_column2.pack(side=tk.RIGHT, fill=tk.Y)
  118. def update_open_sort(self):
  119. config.set("Settings", "open_sort", str(self.open_sort_var.get()))
  120. def update_sort_timeout(self):
  121. config.set("Settings", "sort_timeout", self.sort_timeout_entry.get())
  122. def update_open_filter_speed(self):
  123. config.set(
  124. "Settings",
  125. "open_filter_speed",
  126. str(self.open_filter_speed_var.get()),
  127. )
  128. def update_min_speed(self, event):
  129. config.set("Settings", "min_speed", self.min_speed_entry.get())
  130. def update_open_filter_resolution(self):
  131. config.set(
  132. "Settings",
  133. "open_filter_resolution",
  134. str(self.open_filter_resolution_var.get()),
  135. )
  136. def update_min_resolution(self, event):
  137. config.set("Settings", "min_resolution", self.min_resolution_entry.get())
  138. def change_entry_state(self, state):
  139. for entry in [
  140. "open_sort_checkbutton",
  141. "sort_timeout_entry",
  142. "open_filter_speed_checkbutton",
  143. "min_speed_entry",
  144. "open_filter_resolution_checkbutton",
  145. "min_resolution_entry"
  146. ]:
  147. getattr(self, entry).config(state=state)