subscribe.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import os
  2. import os.path
  3. import tkinter as tk
  4. from tkinter import ttk
  5. import utils.constants as constants
  6. from utils.config import config
  7. from utils.tools import resource_path
  8. class SubscribeUI:
  9. def init_ui(self, root):
  10. """
  11. Init subscribe UI
  12. """
  13. frame_subscribe_open_subscribe = tk.Frame(root)
  14. frame_subscribe_open_subscribe.pack(fill=tk.X)
  15. self.open_subscribe_label = tk.Label(
  16. frame_subscribe_open_subscribe, text="开启订阅源:", width=9
  17. )
  18. self.open_subscribe_label.pack(side=tk.LEFT, padx=4, pady=8)
  19. self.open_subscribe_var = tk.BooleanVar(value=config.open_subscribe)
  20. self.open_subscribe_checkbutton = ttk.Checkbutton(
  21. frame_subscribe_open_subscribe,
  22. variable=self.open_subscribe_var,
  23. onvalue=True,
  24. offvalue=False,
  25. command=self.update_open_subscribe,
  26. )
  27. self.open_subscribe_checkbutton.pack(side=tk.LEFT, padx=4, pady=8)
  28. frame_subscribe_subscribe_urls = tk.Frame(root)
  29. frame_subscribe_subscribe_urls.pack(fill=tk.X)
  30. frame_subscribe_urls_column1 = tk.Frame(frame_subscribe_subscribe_urls)
  31. frame_subscribe_urls_column1.pack(side=tk.LEFT, fill=tk.Y)
  32. frame_subscribe_urls_column2 = tk.Frame(frame_subscribe_subscribe_urls)
  33. frame_subscribe_urls_column2.pack(side=tk.LEFT, fill=tk.Y)
  34. self.subscribe_urls_label = tk.Label(
  35. frame_subscribe_urls_column1, text="订阅源:", width=9
  36. )
  37. self.subscribe_urls_label.pack(side=tk.LEFT, padx=4, pady=8)
  38. self.subscribe_file_button = tk.ttk.Button(
  39. frame_subscribe_urls_column2,
  40. text="编辑",
  41. command=self.edit_subscribe_file,
  42. )
  43. self.subscribe_file_button.pack(side=tk.LEFT, padx=4, pady=0)
  44. def update_open_subscribe(self):
  45. config.set("Settings", "open_subscribe", str(self.open_subscribe_var.get()))
  46. def edit_subscribe_file(self):
  47. path = resource_path(constants.subscribe_path)
  48. if os.path.exists(path):
  49. os.system(f'notepad.exe {path}')
  50. def change_entry_state(self, state):
  51. for entry in [
  52. "open_subscribe_checkbutton",
  53. "subscribe_file_button",
  54. ]:
  55. getattr(self, entry).config(state=state)