hotel.py 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. import tkinter as tk
  2. from tkinter import ttk
  3. from utils.config import config
  4. from select_combobox import SelectCombobox
  5. import updates.fofa.fofa_map as fofa_map
  6. class HotelUI:
  7. def init_ui(self, root):
  8. """
  9. Init hotel UI
  10. """
  11. frame_hotel_open_hotel = tk.Frame(root)
  12. frame_hotel_open_hotel.pack(fill=tk.X)
  13. self.open_hotel_label = tk.Label(
  14. frame_hotel_open_hotel, text="开启酒店源:", width=9
  15. )
  16. self.open_hotel_label.pack(side=tk.LEFT, padx=4, pady=8)
  17. self.open_hotel_var = tk.BooleanVar(value=config.open_hotel)
  18. self.open_hotel_checkbutton = ttk.Checkbutton(
  19. frame_hotel_open_hotel,
  20. variable=self.open_hotel_var,
  21. onvalue=True,
  22. offvalue=False,
  23. command=self.update_open_hotel,
  24. )
  25. self.open_hotel_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
  26. frame_hotel_mode = tk.Frame(root)
  27. frame_hotel_mode.pack(fill=tk.X)
  28. self.open_hotel_mode_label = tk.Label(
  29. frame_hotel_mode, text="工作模式:", width=9
  30. )
  31. self.open_hotel_mode_label.pack(side=tk.LEFT, padx=4, pady=8)
  32. self.open_hotel_foodie_var = tk.BooleanVar(value=config.open_hotel_foodie)
  33. self.open_hotel_foodie_checkbutton = ttk.Checkbutton(
  34. frame_hotel_mode,
  35. variable=self.open_hotel_foodie_var,
  36. onvalue=True,
  37. offvalue=False,
  38. command=self.update_open_hotel_foodie,
  39. text="Foodie",
  40. )
  41. self.open_hotel_foodie_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
  42. self.open_hotel_fofa_var = tk.BooleanVar(value=config.open_hotel_fofa)
  43. self.open_hotel_fofa_checkbutton = ttk.Checkbutton(
  44. frame_hotel_mode,
  45. variable=self.open_hotel_fofa_var,
  46. onvalue=True,
  47. offvalue=False,
  48. command=self.update_open_hotel_fofa,
  49. text="FOFA",
  50. )
  51. self.open_hotel_fofa_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
  52. frame_hotel_region_list = tk.Frame(root)
  53. frame_hotel_region_list.pack(fill=tk.X)
  54. self.region_list_label = tk.Label(
  55. frame_hotel_region_list, text="酒店地区:", width=9
  56. )
  57. self.region_list_label.pack(side=tk.LEFT, padx=4, pady=8)
  58. regions = ["全部"] + list(getattr(fofa_map, "region_url").keys())
  59. self.region_list_combo = SelectCombobox(
  60. frame_hotel_region_list,
  61. values=regions,
  62. selected_values=config.hotel_region_list,
  63. height=10,
  64. command=self.update_region_list,
  65. )
  66. self.region_list_combo.pack(
  67. side=tk.LEFT, padx=4, pady=8, expand=True, fill=tk.BOTH
  68. )
  69. frame_hotel_page_num = tk.Frame(root)
  70. frame_hotel_page_num.pack(fill=tk.X)
  71. self.page_num_label = tk.Label(frame_hotel_page_num, text="获取页数:", width=9)
  72. self.page_num_label.pack(side=tk.LEFT, padx=4, pady=8)
  73. self.page_num_entry = tk.Entry(frame_hotel_page_num)
  74. self.page_num_entry.pack(side=tk.LEFT, padx=4, pady=8)
  75. self.page_num_entry.insert(0, config.hotel_page_num)
  76. self.page_num_entry.bind("<KeyRelease>", self.update_page_num)
  77. def update_open_hotel(self):
  78. config.set("Settings", "open_hotel", str(self.open_hotel_var.get()))
  79. def update_open_hotel_foodie(self):
  80. config.set(
  81. "Settings", "open_hotel_foodie", str(self.open_hotel_foodie_var.get())
  82. )
  83. def update_open_hotel_fofa(self):
  84. config.set("Settings", "open_hotel_fofa", str(self.open_hotel_fofa_var.get()))
  85. def update_region_list(self, event):
  86. config.set(
  87. "Settings",
  88. "hotel_region_list",
  89. ",".join(self.region_list_combo.selected_values),
  90. )
  91. def update_page_num(self, event):
  92. config.set("Settings", "hotel_page_num", self.page_num_entry.get())
  93. def change_entry_state(self, state):
  94. for entry in [
  95. "open_hotel_checkbutton",
  96. "open_hotel_foodie_checkbutton",
  97. "open_hotel_fofa_checkbutton",
  98. "region_list_combo",
  99. "page_num_entry",
  100. ]:
  101. getattr(self, entry).config(state=state)