Selaa lähdekoodia

select element

Falko Schindler 4 vuotta sitten
vanhempi
säilyke
c158cf4454
2 muutettua tiedostoa jossa 14 lisäystä ja 1 poistoa
  1. 10 1
      elements.py
  2. 4 0
      main.py

+ 10 - 1
elements.py

@@ -1,4 +1,5 @@
 import justpy as jp
 import justpy as jp
+from typing import List
 from contextlib import contextmanager
 from contextlib import contextmanager
 import asyncio
 import asyncio
 import time
 import time
@@ -25,7 +26,15 @@ class Group:
             jp.Div(text=text, a=d)
             jp.Div(text=text, a=d)
         if on_change is not None:
         if on_change is not None:
             c.on('change', handle_exceptions(provide_arguments(on_change, 'checked')))
             c.on('change', handle_exceptions(provide_arguments(on_change, 'checked')))
-        return c
+        return d
+    
+    def select(self, options: List[str], value=None, on_change=None) -> jp.Input:
+
+        s = jp.Select(classes='p-2 border rounded', a=self.view, value=value)
+        if on_change is not None:
+            s.on('change', handle_exceptions(provide_arguments(on_change, 'value')))
+        [ jp.Option(value=option, text=option, a=s) for option in options]
+        return s
 
 
     @contextmanager
     @contextmanager
     def plot(self):
     def plot(self):

+ 4 - 0
main.py

@@ -12,6 +12,10 @@ with ui.row() as row:
         right.label("Update itself:")
         right.label("Update itself:")
         right.button('Button 2', on_click=lambda e: setattr(e.sender, 'text', e.sender.text + ' :)'))
         right.button('Button 2', on_click=lambda e: setattr(e.sender, 'text', e.sender.text + ' :)'))
 
 
+ui.select(['one', 'two', 'three'], 'one', on_change=lambda e: output.label(e.value))
+with ui.row() as output:
+    pass
+
 with ui.card() as card:
 with ui.card() as card:
 
 
     with card.plot():
     with card.plot():