Skip to content

Commit

Permalink
✨ Add change festival source
Browse files Browse the repository at this point in the history
  • Loading branch information
kinegratii committed Jan 18, 2024
1 parent 9e359fe commit b6ba25e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 8 deletions.
9 changes: 7 additions & 2 deletions borax/calendars/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ class FestivalTableFrame(ttk.Frame):
"""A table frame displaying festivals with CURD feature."""

def __init__(self, master=None, columns: Sequence = None, festival_source: Union[str, FestivalLibrary] = 'empty',
**kwargs):
countdown_ordered: bool = False, **kwargs):
super().__init__(master=master, **kwargs)
self._adapter = FestivalItemAdapter(columns)
if isinstance(festival_source, FestivalLibrary):
Expand All @@ -198,6 +198,7 @@ def __init__(self, master=None, columns: Sequence = None, festival_source: Union
for i, name in enumerate(self._adapter.displays, start=1):
self._tree.column(f"# {i}", anchor=tk.CENTER, width=self._adapter.widths[i - 1])
self._tree.heading(f"# {i}", text=name)
self._countdown_ordered = countdown_ordered

self.notify_data_changed()

Expand All @@ -213,11 +214,15 @@ def festival_library(self) -> FestivalLibrary:
def row_count(self):
return len(self._tree.get_children())

def change_festival_source(self, source: str):
self._library = FestivalLibrary.load_builtin(source)
self.notify_data_changed()

def notify_data_changed(self):
item_iids = self._tree.get_children()
if len(item_iids):
self._tree.delete(*item_iids)
for ndays, wd, festival in self._library.list_days_in_countdown(countdown_ordered=False):
for ndays, wd, festival in self._library.list_days_in_countdown(countdown_ordered=self._countdown_ordered):
values = self._adapter.object2values(festival, wd, ndays)
self._tree.insert('', 'end', text="1", values=values)

Expand Down
20 changes: 14 additions & 6 deletions borax/capp/borax_calendar_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ def __init__(self, master=None, **kwargs):
gz_grid_frame = ttk.Frame(self)
for offset in range(60):
row, col = offset // 10, offset % 10
btn = tk.Button(gz_grid_frame, text=TextUtils.get_gz_cn(offset), width=3, height=1,
btn_text = '{} {}'.format(TextUtils.offset2gz(offset), offset + 1)
btn = tk.Button(gz_grid_frame, text=btn_text, width=5, height=1,
command=lambda go=offset: self._show_years(go), relief=tk.GROOVE)
btn.grid(row=row, column=col, ipadx=5, ipady=5)
gz_grid_frame.pack(side='left')
Expand Down Expand Up @@ -237,12 +238,14 @@ def __init__(self, master=None):
self.cal_panel.bind_date_selected(self.on_show_date_detail)

ttk.Separator(self, orient=tk.VERTICAL).pack(side='left', fill=tk.Y, expand=True)
self._table_festival_libray = library
columns = (("name", 100), ("description", 180), ("code", 80), ("next_day", 150), ("countdown", 60))
cs = FestivalTableFrame(self, columns=columns, festival_source=library)
cs.pack(side='right', expand=True, fill=tk.BOTH, padx=10, pady=10)
self._cs = FestivalTableFrame(self, columns=columns, festival_source=library, countdown_ordered=True)
self._cs.pack(side='right', expand=True, fill=tk.BOTH, padx=10, pady=10)

# cs.update_data()
self._style_var = tk.StringVar()
self._table_festival_source_var = tk.StringVar(value='basic')
self.create_top_menu()
self._tool_dlg = None
self._gz_dlg = None
Expand All @@ -262,9 +265,11 @@ def create_top_menu(self):
menu_bar.add_command(label='日期计算', command=self.start_tool_dlg)
menu_bar.add_command(label='干支节气', command=self.start_gz_dlg)
menu_bar.add_command(label='创建节日', command=self.start_festival_dlg)
settings_menu = tk.Menu(menu_bar)
settings_menu.add_command(label='节日源')
menu_bar.add_cascade(label='设置', menu=settings_menu)
source_menu = tk.Menu(menu_bar)
for source in ('basic', 'ext1'):
source_menu.add_radiobutton(label=source, variable=self._table_festival_source_var,
command=self._change_source)
menu_bar.add_cascade(label='节日源', menu=source_menu)
about_menu = tk.Menu(menu_bar)
about_menu.add_command(label='项目主页', command=lambda: webbrowser.open(PROJECT_URLS['home']))
about_menu.add_command(label='关于软件', command=self.show_about_info)
Expand All @@ -274,6 +279,9 @@ def _change_theme(self):
global style
style.theme_use(self._style_var.get())

def _change_source(self):
self._cs.change_festival_source(self._table_festival_source_var.get())

def on_show_date_detail(self, wd: WrappedDate):
self.detail_frame.set_selected_date(wd)

Expand Down

0 comments on commit b6ba25e

Please sign in to comment.