multicast.py 4.9 KB

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