66import tkinter as tk
77import ttkbootstrap as ttk
88
9+ from ttkbootstrap import tableview
10+
911from .ui import *
1012from ..utility import get_ui_image
1113
@@ -98,6 +100,92 @@ def __init__(self, wrapper, main=False):
98100
99101 self ._updateform ()
100102
103+ def __init2__ (self , wrapper , main = False ):
104+
105+ # the main tree view has an increased row size
106+ style = ttk .Style ()
107+ style .configure ("History.Treeview" , rowheight = 24 )
108+
109+ size = AppConfig .get ("SIZE_HISTORY_FORM" )
110+ assert isinstance (size , tuple )
111+ bbox = (BBOX_RELOAD , BBOX_CLOSE )
112+ super ().__init__ (UI_TITLE_HISTORY , size , None , bbox , main )
113+
114+ # list box icons
115+ self ._icon_ok = get_ui_image (OK_ICON )
116+ self ._icon_fail = get_ui_image (FAIL_ICON )
117+ self ._icon_unknown = get_ui_image (UNK_ICON )
118+
119+ # form data
120+ self ._wrapper = wrapper
121+ self ._history = []
122+ self .set_history (self ._wrapper .get_history ())
123+
124+ # build the UI: build widgets, arrange them in the box, bind data
125+
126+ # client area
127+ area = ttk .Frame (self .contents )
128+ area .grid (row = 0 , column = 0 , sticky = tk .NSEW )
129+ PAD = WIDGET_PADDING_PIXELS
130+
131+ # history list section
132+ l_history = ttk .Label (area , text = UI_FORM_HISTORYITEMS_SC )
133+
134+ cols = (
135+ "#0" ,
136+ UI_FORM_HS_TIME ,
137+ UI_FORM_HS_TASK ,
138+ UI_FORM_HS_TRIGGER ,
139+ UI_FORM_HS_DURATION ,
140+ UI_FORM_HS_SUCCESS ,
141+ UI_FORM_HS_MESSAGE ,
142+ )
143+
144+ tab_history = tableview .Tableview (
145+ area ,
146+ coldata = cols ,
147+ paginated = False ,
148+ yscrollbar = True ,
149+ )
150+
151+ # build a scrolled frame for the treeview
152+ tab_history .pack (side = tk .LEFT , fill = tk .BOTH , expand = True )
153+
154+ # tab_history.column("#0", anchor=tk.CENTER, width=30, stretch=tk.NO)
155+ # tab_history.heading("#0", anchor=tk.CENTER, text="")
156+
157+ # NOTE: widths are empirically determined, should be tested on
158+ # other platform to verify that they are suitable anyway
159+ # tab_history.column("time", anchor=tk.CENTER, width=15)
160+ # tab_history.column("task", anchor=tk.W, width=16)
161+ # tab_history.column("trigger", anchor=tk.W, width=16)
162+ # tab_history.column("duration", anchor=tk.W, width=7)
163+ # tab_history.column("success", anchor=tk.CENTER, width=4)
164+ # tab_history.column("message", anchor=tk.W, width=38)
165+
166+ # tab_history.heading("time", anchor=tk.CENTER, text=UI_FORM_HS_TIME)
167+ # tab_history.heading("task", anchor=tk.W, text=UI_FORM_HS_TASK)
168+ # tab_history.heading("trigger", anchor=tk.W, text=UI_FORM_HS_TRIGGER)
169+ # tab_history.heading("duration", anchor=tk.W, text=UI_FORM_HS_DURATION)
170+ # tab_history.heading("success", anchor=tk.CENTER, text=UI_FORM_HS_SUCCESS)
171+ # tab_history.heading("message", anchor=tk.W, text=UI_FORM_HS_MESSAGE)
172+
173+ # arrange items in the grid
174+ l_history .grid (row = 0 , column = 0 , sticky = tk .W , padx = PAD , pady = PAD )
175+ tab_history .grid (row = 1 , column = 0 , sticky = tk .NSEW , padx = PAD , pady = PAD )
176+
177+ # expand appropriate sections
178+ area .rowconfigure (1 , weight = 1 )
179+ area .columnconfigure (0 , weight = 1 )
180+
181+ # bind data to widgets
182+ # NOTE: no data to bind
183+
184+ # propagate widgets that need to be accessed
185+ self ._tv_history = tab_history
186+
187+ self ._updateform2 ()
188+
101189 def set_history (self , history ) -> None :
102190 h = list (
103191 (
@@ -106,7 +194,7 @@ def set_history(self, history) -> None:
106194 x ["task" ],
107195 x ["trigger" ],
108196 ("%.2fs" % x ["duration" ].total_seconds ()).ljust (7 ),
109- (
197+ (\
110198 SYM_OK
111199 if x ["success" ] == "OK"
112200 else SYM_UNKNOWN if x ["success" ] == "IND" else SYM_FAIL
@@ -130,6 +218,16 @@ def _updateform(self) -> None:
130218 )
131219 self ._tv_history .insert ("" , values = entry , index = tk .END , image = icon )
132220
221+ def _updateform2 (self ) -> None :
222+ self ._tv_history .delete_rows ()
223+ for entry , outcome in self ._history :
224+ icon = (
225+ self ._icon_ok
226+ if outcome == "OK"
227+ else self ._icon_unknown if outcome == "IND" else self ._icon_fail
228+ )
229+ self ._tv_history .insert_row ("" , values = entry )
230+
133231 # reload history data when the `reload` button is clicked
134232 def reload (self ) -> None :
135233 self .set_history (self ._wrapper .get_history ())
0 commit comments