1+ from typing import Callable
2+
13import emoji
24
35import pythonnative as pn
46from pythonnative .navigation import NavigationContainer , create_tab_navigator
57
8+ print ("[hello-world] main_page module imported" )
9+
610MEDALS = [":1st_place_medal:" , ":2nd_place_medal:" , ":3rd_place_medal:" ]
711
812Tab = create_tab_navigator ()
@@ -28,12 +32,22 @@ def counter_badge(initial: int = 0) -> pn.Element:
2832 count , set_count = pn .use_state (initial )
2933 medal = emoji .emojize (MEDALS [count ] if count < len (MEDALS ) else ":star:" )
3034
35+ print (f"[counter_badge] render count={ count } " )
36+
37+ def handle_tap () -> None :
38+ print (f"[counter_badge] Tap me clicked; { count } -> { count + 1 } " )
39+ set_count (count + 1 )
40+
41+ def handle_reset () -> None :
42+ print (f"[counter_badge] Reset clicked from count={ count } " )
43+ set_count (0 )
44+
3145 return pn .View (
3246 pn .Text (f"Tapped { count } times" , style = styles ["subtitle" ]),
3347 pn .Text (medal , style = styles ["medal" ]),
3448 pn .Row (
35- pn .Button ("Tap me" , on_click = lambda : set_count ( count + 1 ) ),
36- pn .Button ("Reset" , on_click = lambda : set_count ( 0 ) ),
49+ pn .Button ("Tap me" , on_click = handle_tap ),
50+ pn .Button ("Reset" , on_click = handle_reset ),
3751 style = styles ["button_row" ],
3852 ),
3953 style = styles ["card" ],
@@ -44,17 +58,25 @@ def counter_badge(initial: int = 0) -> pn.Element:
4458def HomeTab () -> pn .Element :
4559 """Home tab — counter demo and push-navigation to other pages."""
4660 nav = pn .use_navigation ()
61+
62+ def _on_mount () -> Callable [[], None ]:
63+ print ("[HomeTab] mounted" )
64+ return lambda : print ("[HomeTab] unmounted" )
65+
66+ pn .use_effect (_on_mount , [])
67+
68+ def go_to_second () -> None :
69+ print ("[HomeTab] navigating to SecondPage" )
70+ nav .navigate (
71+ "app.second_page.SecondPage" ,
72+ params = {"message" : "Greetings from MainPage" },
73+ )
74+
4775 return pn .ScrollView (
4876 pn .Column (
4977 pn .Text ("Hello from PythonNative Demo!" , style = styles ["title" ]),
5078 counter_badge (),
51- pn .Button (
52- "Go to Second Page" ,
53- on_click = lambda : nav .navigate (
54- "app.second_page.SecondPage" ,
55- params = {"message" : "Greetings from MainPage" },
56- ),
57- ),
79+ pn .Button ("Go to Second Page" , on_click = go_to_second ),
5880 style = styles ["section" ],
5981 )
6082 )
0 commit comments