@@ -1462,12 +1462,12 @@ class lvh_spinner : lvh_arc
1462
1462
# obj: (opt) LVGL object if it already exists and was created prior to init()
1463
1463
# parent_lvh: HASPmota parent object defined by `parentid`
1464
1464
#====================================================================
1465
- def init ( parent, page, jline)
1465
+ def init ( parent, page, jline, lv_instance, parent_obj )
1466
1466
var angle = jline.find ( "angle" , 60 )
1467
1467
var speed = jline.find ( "speed" , 1000 )
1468
1468
self ._lv_obj = lv.spinner ( parent)
1469
1469
self ._lv_obj.set_anim_params ( speed, angle)
1470
- super ( self ) .init ( parent, page, jline, self ._lv_obj )
1470
+ super ( self ) .init ( parent, page, jline, self ._lv_obj , parent_obj )
1471
1471
end
1472
1472
1473
1473
def set_angle ( t) end
@@ -1735,7 +1735,7 @@ class lvh_dropdown_list : lvh_obj
1735
1735
if isinstance ( self ._parent_lvh , self ._page._hm.lvh_dropdown )
1736
1736
self ._lv_obj = lv.list ( self ._parent_lvh._lv_obj.get_list () ._p )
1737
1737
else
1738
- print ( "HSP: '_dropdown_list ' should have a parent of type 'dropdown'" )
1738
+ print ( "HSP: 'dropdown_list ' should have a parent of type 'dropdown'" )
1739
1739
end
1740
1740
super ( self ) .post_init ()
1741
1741
end
@@ -2056,6 +2056,8 @@ class lvh_span : lvh_root
2056
2056
# print(">>> GOOD")
2057
2057
self ._lv_obj = self ._parent_lvh._lv_obj.new_span ()
2058
2058
self ._style = self ._lv_obj.get_style ()
2059
+ else
2060
+ print ( "HSP: 'span' should have a parent of type 'spangroup'" )
2059
2061
end
2060
2062
# super(self).post_init() # call super - not needed for lvh_root
2061
2063
end
@@ -2160,6 +2162,182 @@ class lvh_span : lvh_root
2160
2162
2161
2163
end
2162
2164
2165
+ #====================================================================
2166
+ # tabview
2167
+ #====================================================================
2168
+ #@ solidify:lvh_tabview,weak
2169
+ class lvh_tabview : lvh_obj
2170
+ static var _lv_class = lv.tabview
2171
+ var _tab_list # list of tabs
2172
+
2173
+ # label do not need a sub-label
2174
+ def post_init ()
2175
+ self ._tab_list = []
2176
+ super ( self ) .post_init () # call super -- not needed
2177
+ end
2178
+
2179
+ #====================================================================
2180
+ # direction for buttons
2181
+ #====================================================================
2182
+ static var _direction = [
2183
+ lv.DIR_NONE , # 0 = none
2184
+ lv.DIR_TOP , # 1 = top
2185
+ lv.DIR_BOTTOM , # 2 = bottom
2186
+ lv.DIR_LEFT , # 3 = left
2187
+ lv.DIR_RIGHT , # 4 = right
2188
+ ]
2189
+ def set_btn_pos ( v)
2190
+ v = int ( v)
2191
+ if ( v == nil ) || ( v < 0 ) || ( v >= size ( self ._direction ))
2192
+ v = 0
2193
+ end
2194
+ var direction = self ._direction [ v]
2195
+ self ._lv_obj.set_tab_bar_position ( direction)
2196
+ end
2197
+
2198
+ #====================================================================
2199
+ # management of `_tab_list` list
2200
+ #====================================================================
2201
+ # add lvh_tab instance as they are created
2202
+ def push_tab ( t)
2203
+ self ._tab_list.push ( t)
2204
+ end
2205
+ # returns the index of the tab instance, or `nil` if not found
2206
+ def find_tab ( t)
2207
+ return self ._tab_list.find ( t)
2208
+ end
2209
+
2210
+ #====================================================================
2211
+ # count read-only attribute, returns number of tabs
2212
+ #====================================================================
2213
+ def get_count ()
2214
+ return self ._lv_obj.get_tab_count ()
2215
+ end
2216
+ def get_val ()
2217
+ return self ._lv_obj.get_tab_active ()
2218
+ end
2219
+ # change current tab
2220
+ # v: value of new tab
2221
+ # stop: (opt) if true, don't defer again to avoid infinite loop
2222
+ def set_val ( v, stop)
2223
+ var v_max = self .get_count ()
2224
+ if ( v_max == 0 )
2225
+ # probably not constructed yet
2226
+ if (! stop)
2227
+ tasmota.set_timer ( 0 , def () self .set_val ( v, true #-stop propagation-# ) end )
2228
+ end
2229
+ else
2230
+ if ( v == nil ) v = 0 end
2231
+ if ( v < 0 ) v = 0 end
2232
+ if ( v >= v_max) v = v_max - 1 end
2233
+
2234
+ self ._lv_obj.set_active ( v, lv.ANIM_OFF )
2235
+ end
2236
+ end
2237
+ def get_text ()
2238
+ var val = self .get_val ()
2239
+ if ( val >= 0 ) && ( val < self .get_count ())
2240
+ return self ._tab_list [ val] .get_text ()
2241
+ else
2242
+ return nil
2243
+ end
2244
+ end
2245
+ end
2246
+
2247
+ #====================================================================
2248
+ # tab
2249
+ #====================================================================
2250
+ #@ solidify:lvh_tab.lvh_btn_tab,weak
2251
+ #@ solidify:lvh_tab,weak
2252
+ class lvh_tab : lvh_obj
2253
+ static var _lv_class = nil
2254
+ # label do not need a sub-label
2255
+ var _text # text label of the tab
2256
+ var _btn # btn lvh object
2257
+
2258
+ static class lvh_btn_tab : lvh_obj
2259
+ static var _lv_class = lv.button
2260
+ #====================================================================
2261
+ # specific post-init wihtout events
2262
+ #====================================================================
2263
+ def post_init ()
2264
+ self ._lv_obj.set_style_radius ( 0 , 0 ) # set default radius to `0` for rectangle tabs
2265
+ # self.register_event_cb()
2266
+ end
2267
+ end
2268
+
2269
+ #====================================================================
2270
+ # init
2271
+ #
2272
+ # parent: LVGL parent object (used to create a sub-object)
2273
+ # page: HASPmota page object
2274
+ # jline: JSONL definition of the object from HASPmota template (used in sub-classes)
2275
+ # obj: (opt) LVGL object if it already exists and was created prior to init()
2276
+ # parent_lvh: HASPmota parent object defined by `parentid`
2277
+ #====================================================================
2278
+ def init ( parent, page, jline, lv_instance, parent_obj)
2279
+ self .set_text ( jline.find ( "text" )) # anticipate reading 'text' for creation
2280
+ super ( self ) .init ( parent, page, jline, lv_instance, parent_obj)
2281
+ end
2282
+
2283
+ def post_init ()
2284
+ self ._lv_obj = nil # default to nil object, whatever it was initialized with
2285
+ # check if it is the parent is a spangroup
2286
+ if isinstance ( self ._parent_lvh , self ._page._hm.lvh_tabview )
2287
+ if ( self ._text != nil )
2288
+ self ._lv_obj = self ._parent_lvh._lv_obj.add_tab ( self ._text )
2289
+
2290
+ # get the last button object of the tab bar and create an instance of simplified btn
2291
+ var tab_bar = self ._parent_lvh._lv_obj.get_tab_bar ()
2292
+ var btn_class = lv.obj_class ( lv.button._class )
2293
+ var btn_count = tab_bar.get_child_count_by_type ( btn_class)
2294
+ var btn_obj = tab_bar.get_child_by_type ( btn_count - 1 , btn_class) # get last button
2295
+ self ._btn = self .lvh_btn_tab ( nil , self ._page , {}, btn_obj, self ) # instanciate a local lvh object
2296
+
2297
+ # add to parent list
2298
+ self ._parent_lvh.push_tab ( self )
2299
+ else
2300
+ print ( "HSP: 'tab' requires 'text' attribute" )
2301
+ end
2302
+ else
2303
+ print ( "HSP: 'tab' should have a parent of type 'tabview'" )
2304
+ end
2305
+ # super(self).post_init() # call super - not needed for lvh_root
2306
+ end
2307
+
2308
+ #====================================================================
2309
+ def set_text ( t)
2310
+ self ._text = str ( t)
2311
+ end
2312
+ def get_text ()
2313
+ return self ._text
2314
+ end
2315
+
2316
+ #- ------------------------------------------------------------#
2317
+ # `setmember` virtual setter
2318
+ #
2319
+ # If the key starts with `bar_`
2320
+ # send to the corresponding object
2321
+ #- ------------------------------------------------------------#
2322
+ def setmember ( k, v)
2323
+ import string
2324
+ if string.startswith ( k, 'tab_' )
2325
+ self ._btn.setmember ( k[ 4 ..] , v)
2326
+ else
2327
+ super ( self ) .setmember ( k, v)
2328
+ end
2329
+ end
2330
+ def member ( k)
2331
+ import string
2332
+ if string.startswith ( k, 'tab_' )
2333
+ return self ._btn.member ( k[ 4 ..])
2334
+ else
2335
+ return super ( self ) .member ( k)
2336
+ end
2337
+ end
2338
+
2339
+ end
2340
+
2163
2341
#################################################################################
2164
2342
# Special case for lv.chart
2165
2343
# Adapted to getting values one after the other
@@ -2621,6 +2799,8 @@ class HASPmota
2621
2799
static lvh_scale_line = lvh_scale_line
2622
2800
static lvh_spangroup = lvh_spangroup
2623
2801
static lvh_span = lvh_span
2802
+ static lvh_tabview = lvh_tabview
2803
+ static lvh_tab = lvh_tab
2624
2804
static lvh_qrcode = lvh_qrcode
2625
2805
# special cases
2626
2806
static lvh_chart = lvh_chart
0 commit comments