multicast.py 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. import tkinter as tk
  2. from tkinter import ttk
  3. from utils.config import config, resource_path
  4. from select_combobox import SelectCombobox
  5. import os
  6. class MulticastUI:
  7. def init_ui(self, root):
  8. """
  9. Init multicast UI
  10. """
  11. frame_multicast_multicast = tk.Frame(root)
  12. frame_multicast_multicast.pack(fill=tk.X)
  13. self.open_multicast_label = tk.Label(
  14. frame_multicast_multicast, text="开启组播源:", width=9
  15. )
  16. self.open_multicast_label.pack(side=tk.LEFT, padx=4, pady=8)
  17. self.open_multicast_var = tk.BooleanVar(
  18. value=config.getboolean("Settings", "open_multicast", fallback=True)
  19. )
  20. self.open_multicast_checkbutton = ttk.Checkbutton(
  21. frame_multicast_multicast,
  22. variable=self.open_multicast_var,
  23. onvalue=True,
  24. offvalue=False,
  25. command=self.update_open_multicast,
  26. )
  27. self.open_multicast_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
  28. frame_multicast_mode = tk.Frame(root)
  29. frame_multicast_mode.pack(fill=tk.X)
  30. self.open_multicast_mode_label = tk.Label(
  31. frame_multicast_mode, text="工作模式:", width=9
  32. )
  33. self.open_multicast_mode_label.pack(side=tk.LEFT, padx=4, pady=8)
  34. self.open_multicast_tonkiang_var = tk.BooleanVar(
  35. value=config.getboolean(
  36. "Settings", "open_multicast_tonkiang", fallback=True
  37. )
  38. )
  39. self.open_multicast_tonkiang_checkbutton = ttk.Checkbutton(
  40. frame_multicast_mode,
  41. variable=self.open_multicast_tonkiang_var,
  42. onvalue=True,
  43. offvalue=False,
  44. command=self.update_open_multicast_tonkiang,
  45. text="Tonkiang",
  46. )
  47. self.open_multicast_tonkiang_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
  48. self.open_multicast_fofa_var = tk.BooleanVar(
  49. value=config.getboolean("Settings", "open_multicast_fofa", fallback=True)
  50. )
  51. self.open_multicast_fofa_checkbutton = ttk.Checkbutton(
  52. frame_multicast_mode,
  53. variable=self.open_multicast_fofa_var,
  54. onvalue=True,
  55. offvalue=False,
  56. command=self.update_open_multicast_fofa,
  57. text="FOFA",
  58. )
  59. self.open_multicast_fofa_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
  60. frame_multicast_region_list = tk.Frame(root)
  61. frame_multicast_region_list.pack(fill=tk.X)
  62. frame_multicast_region_list = tk.Frame(root)
  63. frame_multicast_region_list.pack(fill=tk.X)
  64. self.region_list_label = tk.Label(
  65. frame_multicast_region_list, text="组播地区:", width=9
  66. )
  67. self.region_list_label.pack(side=tk.LEFT, padx=4, pady=8)
  68. rtp_path = resource_path("config/rtp")
  69. regions = list(
  70. {"全部"}.union(
  71. filename.rsplit(".", 1)[0].split("_", 1)[0]
  72. for filename in os.listdir(rtp_path)
  73. if filename.endswith(".txt") and "_" in filename
  74. )
  75. )
  76. if "全部" in regions:
  77. regions.remove("全部")
  78. regions.insert(0, "全部")
  79. region_selected_values = [
  80. value.strip()
  81. for value in config.get(
  82. "Settings", "multicast_region_list", fallback="全部"
  83. ).split(",")
  84. if value.strip()
  85. ]
  86. self.region_list_combo = SelectCombobox(
  87. frame_multicast_region_list,
  88. values=regions,
  89. selected_values=region_selected_values,
  90. height=10,
  91. command=self.update_region_list,
  92. )
  93. self.region_list_combo.pack(
  94. side=tk.LEFT, padx=4, pady=8, expand=True, fill=tk.BOTH
  95. )
  96. frame_multicast_page_num = tk.Frame(root)
  97. frame_multicast_page_num.pack(fill=tk.X)
  98. self.page_num_label = tk.Label(
  99. frame_multicast_page_num, text="获取页数:", width=9
  100. )
  101. self.page_num_label.pack(side=tk.LEFT, padx=4, pady=8)
  102. self.page_num_entry = tk.Entry(frame_multicast_page_num)
  103. self.page_num_entry.pack(side=tk.LEFT, padx=4, pady=8)
  104. self.page_num_entry.insert(
  105. 0, config.getint("Settings", "multicast_page_num", fallback=3)
  106. )
  107. self.page_num_entry.bind("<KeyRelease>", self.update_page_num)
  108. def update_open_multicast(self):
  109. config.set("Settings", "open_multicast", str(self.open_multicast_var.get()))
  110. def update_open_multicast_tonkiang(self):
  111. config.set(
  112. "Settings",
  113. "open_multicast_tonkiang",
  114. str(self.open_multicast_tonkiang_var.get()),
  115. )
  116. def update_open_multicast_fofa(self):
  117. config.set(
  118. "Settings", "open_multicast_fofa", str(self.open_multicast_fofa_var.get())
  119. )
  120. def update_region_list(self, event):
  121. config.set(
  122. "Settings",
  123. "multicast_region_list",
  124. ",".join(self.region_list_combo.selected_values),
  125. )
  126. def update_page_num(self, event):
  127. config.set("Settings", "multicast_page_num", self.page_num_entry.get())
  128. def change_entry_state(self, state):
  129. for entry in [
  130. "open_multicast_checkbutton",
  131. "open_multicast_tonkiang_checkbutton",
  132. "open_multicast_fofa_checkbutton",
  133. "region_list_combo",
  134. "page_num_entry",
  135. ]:
  136. getattr(self, entry).config(state=state)