Переглянути джерело

ensure components get an id by setting temp=False

Falko Schindler 3 роки тому
батько
коміт
91312ffec2

+ 1 - 1
nicegui/elements/button.py

@@ -19,7 +19,7 @@ class Button(Element):
         :param on_click: callback which is invoked when button is pressed
         :param on_click: callback which is invoked when button is pressed
         """
         """
 
 
-        view = jp.QButton(label=text, color='primary')
+        view = jp.QButton(label=text, color='primary', temp=False)
         super().__init__(view)
         super().__init__(view)
 
 
         self.text = text
         self.text = text

+ 2 - 2
nicegui/elements/card.py

@@ -8,11 +8,11 @@ class Card(Group):
 
 
         Provides a container with a dropped shadow.
         Provides a container with a dropped shadow.
         """
         """
-        view = jp.QCard(classes='column items-start q-pa-md', style='gap: 1em', delete_flag=False)
+        view = jp.QCard(classes='column items-start q-pa-md', style='gap: 1em', delete_flag=False, temp=False)
         super().__init__(view)
         super().__init__(view)
 
 
 class CardSection(Group):
 class CardSection(Group):
 
 
     def __init__(self):
     def __init__(self):
-        view = jp.QCardSection(delete_flag=False)
+        view = jp.QCardSection(delete_flag=False, temp=False)
         super().__init__(view)
         super().__init__(view)

+ 1 - 1
nicegui/elements/chart.py

@@ -11,6 +11,6 @@ class Chart(Element):
 
 
         :param options: dictionary of highcharts options
         :param options: dictionary of highcharts options
         """
         """
-        view = jp.HighCharts()
+        view = jp.HighCharts(temp=False)
         view.options = self.options = jp.Dict(**options)
         view.options = self.options = jp.Dict(**options)
         super().__init__(view)
         super().__init__(view)

+ 1 - 1
nicegui/elements/checkbox.py

@@ -16,6 +16,6 @@ class Checkbox(BoolElement):
         :param value: whether it should be checked initally (default: `False`)
         :param value: whether it should be checked initally (default: `False`)
         :param on_change: callback to execute when value changes
         :param on_change: callback to execute when value changes
         """
         """
-        view = jp.QCheckbox(text=text, input=self.handle_change)
+        view = jp.QCheckbox(text=text, input=self.handle_change, temp=False)
 
 
         super().__init__(view, value=value, on_change=on_change)
         super().__init__(view, value=value, on_change=on_change)

+ 1 - 1
nicegui/elements/column.py

@@ -8,5 +8,5 @@ class Column(Group):
 
 
         Provides a container which arranges its child in a row.
         Provides a container which arranges its child in a row.
         '''
         '''
-        view = jp.QDiv(classes='column items-start', style='gap: 1em', delete_flag=False)
+        view = jp.QDiv(classes='column items-start', style='gap: 1em', delete_flag=False, temp=False)
         super().__init__(view)
         super().__init__(view)

+ 1 - 0
nicegui/elements/dialog.py

@@ -17,6 +17,7 @@ class Dialog(Group):
             value=value,
             value=value,
             classes='row items-start bg-red-400',
             classes='row items-start bg-red-400',
             style='gap: 1em',
             style='gap: 1em',
+            temp=False,
         )
         )
 
 
         super().__init__(view)
         super().__init__(view)

+ 1 - 1
nicegui/elements/html.py

@@ -12,7 +12,7 @@ class Html(Element):
 
 
         :param content: the HTML code to be displayed
         :param content: the HTML code to be displayed
         """
         """
-        view = jp.QDiv()
+        view = jp.QDiv(temp=False)
         super().__init__(view)
         super().__init__(view)
         self.content = content
         self.content = content
 
 

+ 1 - 1
nicegui/elements/icon.py

@@ -6,6 +6,6 @@ class Icon(Element):
     def __init__(self,
     def __init__(self,
                  name: str,
                  name: str,
                  ):
                  ):
-        view = jp.QIcon(name=name, classes=f'q-pt-xs', size='20px')
+        view = jp.QIcon(name=name, classes=f'q-pt-xs', size='20px', temp=False)
 
 
         super().__init__(view)
         super().__init__(view)

+ 1 - 1
nicegui/elements/image.py

@@ -15,7 +15,7 @@ class Image(Group):
 
 
         :param source: the source of the image; can be an URL or a base64 string
         :param source: the source of the image; can be an URL or a base64 string
         """
         """
-        view = jp.QImg(src=source)
+        view = jp.QImg(src=source, temp=False)
         super().__init__(view)
         super().__init__(view)
 
 
         self.source = source
         self.source = source

+ 1 - 0
nicegui/elements/input.py

@@ -23,6 +23,7 @@ class Input(StringElement):
             placeholder=placeholder,
             placeholder=placeholder,
             value=value,
             value=value,
             change=self.handle_change,
             change=self.handle_change,
+            temp=False,
         )
         )
 
 
         super().__init__(view, value=value, on_change=on_change)
         super().__init__(view, value=value, on_change=on_change)

+ 1 - 1
nicegui/elements/label.py

@@ -15,7 +15,7 @@ class Label(Element):
 
 
         :param text: the content of the label
         :param text: the content of the label
         """
         """
-        view = jp.Div(text=text)
+        view = jp.Div(text=text, temp=False)
         super().__init__(view)
         super().__init__(view)
 
 
         self.text = text
         self.text = text

+ 1 - 1
nicegui/elements/link.py

@@ -17,6 +17,6 @@ class Link(Element):
         :param target: link target (either a string or a page object)
         :param target: link target (either a string or a page object)
         """
         """
         href = target if isinstance(target, str) else target.route
         href = target if isinstance(target, str) else target.route
-        view = jp.A(text=text, href=href, classes='underline text-blue')
+        view = jp.A(text=text, href=href, classes='underline text-blue', temp=False)
 
 
         super().__init__(view)
         super().__init__(view)

+ 1 - 1
nicegui/elements/menu.py

@@ -13,7 +13,7 @@ class Menu(Group):
 
 
         :param value: whether the menu is already opened (default: `False`)
         :param value: whether the menu is already opened (default: `False`)
         """
         """
-        view = jp.QMenu(value=value)
+        view = jp.QMenu(value=value, temp=False)
 
 
         super().__init__(view)
         super().__init__(view)
 
 

+ 1 - 1
nicegui/elements/menu_item.py

@@ -21,7 +21,7 @@ class MenuItem(Element):
         :param on_click: callback to be executed when selecting the menu item
         :param on_click: callback to be executed when selecting the menu item
         :param auto_close: whether the menu should be closed after a click event (default: `True`)
         :param auto_close: whether the menu should be closed after a click event (default: `True`)
         """
         """
-        view = jp.QItem(text=text, clickable=True)
+        view = jp.QItem(text=text, clickable=True, temp=False)
 
 
         def handle_click(*_):
         def handle_click(*_):
             handle_event(on_click, ClickEventArguments(sender=self), update=self.parent_view)
             handle_event(on_click, ClickEventArguments(sender=self), update=self.parent_view)

+ 1 - 1
nicegui/elements/menu_separator.py

@@ -10,5 +10,5 @@ class MenuSeparator(Element):
 
 
         A separator for menus.
         A separator for menus.
         """
         """
-        view = jp.QSeparator()
+        view = jp.QSeparator(temp=False)
         super().__init__(view)
         super().__init__(view)

+ 1 - 1
nicegui/elements/notify.py

@@ -19,7 +19,7 @@ class Notify(Element):
         :param position: position on the screen ("top-left", "top-right", "bottom-left","bottom-right, "top", "bottom", "left", "right" or "center", default: "bottom")
         :param position: position on the screen ("top-left", "top-right", "bottom-left","bottom-right, "top", "bottom", "left", "right" or "center", default: "bottom")
         :param close_button: optional label of a button to dismiss the notification (default: `None`)
         :param close_button: optional label of a button to dismiss the notification (default: `None`)
         """
         """
-        view = jp.QNotify(message=message, position=position, closeBtn=close_button)
+        view = jp.QNotify(message=message, position=position, closeBtn=close_button, temp=False)
 
 
         super().__init__(view)
         super().__init__(view)
         create_task(self.notify_async(), name='notify_async')
         create_task(self.notify_async(), name='notify_async')

+ 1 - 0
nicegui/elements/number.py

@@ -25,6 +25,7 @@ class Number(FloatElement):
             label=label,
             label=label,
             placeholder=placeholder,
             placeholder=placeholder,
             change=self.handle_change,
             change=self.handle_change,
+            temp=False,
         )
         )
 
 
         super().__init__(view, value=value, format=format, on_change=on_change)
         super().__init__(view, value=value, format=format, on_change=on_change)

+ 1 - 1
nicegui/elements/page.py

@@ -43,7 +43,7 @@ class Page(jp.QuasarPage):
             </script>
             </script>
         '''  # avoid confirmation dialog for reload
         '''  # avoid confirmation dialog for reload
 
 
-        self.view = jp.Div(a=self, classes=classes, style='row-gap: 1em')
+        self.view = jp.Div(a=self, classes=classes, style='row-gap: 1em', temp=False)
         self.view.add_page(self)
         self.view.add_page(self)
 
 
         self.route = route
         self.route = route

+ 1 - 1
nicegui/elements/plot.py

@@ -19,7 +19,7 @@ class Plot(Element):
         self.close = close
         self.close = close
         self.fig = plt.figure(**kwargs)
         self.fig = plt.figure(**kwargs)
 
 
-        view = jp.Matplotlib()
+        view = jp.Matplotlib(temp=False)
         view.set_figure(self.fig)
         view.set_figure(self.fig)
 
 
         super().__init__(view)
         super().__init__(view)

+ 1 - 1
nicegui/elements/radio.py

@@ -16,6 +16,6 @@ class Radio(ChoiceElement):
         :param value: the inital value
         :param value: the inital value
         :param on_change: callback to execute when selection changes
         :param on_change: callback to execute when selection changes
         """
         """
-        view = jp.QOptionGroup(options=options, input=self.handle_change)
+        view = jp.QOptionGroup(options=options, input=self.handle_change, temp=False)
 
 
         super().__init__(view, options, value=value, on_change=on_change)
         super().__init__(view, options, value=value, on_change=on_change)

+ 1 - 1
nicegui/elements/row.py

@@ -8,5 +8,5 @@ class Row(Group):
 
 
         Provides a container which arranges its child in a row.
         Provides a container which arranges its child in a row.
         '''
         '''
-        view = jp.QDiv(classes='row items-start', style='gap: 1em', delete_flag=False)
+        view = jp.QDiv(classes='row items-start', style='gap: 1em', delete_flag=False, temp=False)
         super().__init__(view)
         super().__init__(view)

+ 1 - 1
nicegui/elements/select.py

@@ -16,7 +16,7 @@ class Select(ChoiceElement):
         :param value: the inital value
         :param value: the inital value
         :param on_change: callback to execute when selection changes
         :param on_change: callback to execute when selection changes
         """
         """
-        view = jp.QSelect(options=options, input=self.handle_change)
+        view = jp.QSelect(options=options, input=self.handle_change, temp=False)
 
 
         super().__init__(view, options, value=value, on_change=on_change)
         super().__init__(view, options, value=value, on_change=on_change)
 
 

+ 1 - 1
nicegui/elements/slider.py

@@ -20,6 +20,6 @@ class Slider(FloatElement):
         :param value: inital value to set position of the slider
         :param value: inital value to set position of the slider
         :param on_change: callback which is invoked when the user releases the slider
         :param on_change: callback which is invoked when the user releases the slider
         """
         """
-        view = jp.QSlider(min=min, max=max, step=step, change=self.handle_change)
+        view = jp.QSlider(min=min, max=max, step=step, change=self.handle_change, temp=False)
 
 
         super().__init__(view, value=value, on_change=on_change)
         super().__init__(view, value=value, on_change=on_change)

+ 1 - 1
nicegui/elements/svg.py

@@ -13,7 +13,7 @@ class Svg(Element):
 
 
         :param content: the svg definition
         :param content: the svg definition
         """
         """
-        view = jp.Div(style="padding:0;width:100%;height:100%")
+        view = jp.Div(style='padding:0;width:100%;height:100%', temp=False)
         super().__init__(view)
         super().__init__(view)
         self.content = content
         self.content = content
 
 

+ 1 - 1
nicegui/elements/switch.py

@@ -16,6 +16,6 @@ class Switch(BoolElement):
         :param value: whether it should be active initally (default: `False`)
         :param value: whether it should be active initally (default: `False`)
         :param on_click: callback which is invoked when state is changed by the user
         :param on_click: callback which is invoked when state is changed by the user
         """
         """
-        view = jp.QToggle(text=text, input=self.handle_change)
+        view = jp.QToggle(text=text, input=self.handle_change, temp=False)
 
 
         super().__init__(view, value=value, on_change=on_change)
         super().__init__(view, value=value, on_change=on_change)

+ 1 - 1
nicegui/elements/toggle.py

@@ -16,6 +16,6 @@ class Toggle(ChoiceElement):
         :param value: the inital value
         :param value: the inital value
         :param on_change: callback to execute when selection changes
         :param on_change: callback to execute when selection changes
         """
         """
-        view = jp.QBtnToggle(input=self.handle_change)
+        view = jp.QBtnToggle(input=self.handle_change, temp=False)
 
 
         super().__init__(view, options, value=value, on_change=on_change)
         super().__init__(view, options, value=value, on_change=on_change)

+ 8 - 4
nicegui/elements/upload.py

@@ -19,10 +19,14 @@ class Upload(Element):
         :param on_upload: callback to execute when a file is uploaded (list of bytearrays)
         :param on_upload: callback to execute when a file is uploaded (list of bytearrays)
         """
         """
         self.upload_handler = on_upload
         self.upload_handler = on_upload
-        view = jp.Form(enctype='multipart/form-data', classes='flex gap-4 items-center',
-                       submit=lambda s, m: self.submit(s, m))
-        jp.Input(type='file', multiple=multiple, a=view)
-        jp.QButton(type='submit', text='Upload', color='primary', a=view)
+        view = jp.Form(
+            enctype='multipart/form-data',
+            classes='flex gap-4 items-center',
+            submit=lambda sender, msg: self.submit(sender, msg),
+            temp=False,
+        )
+        jp.Input(type='file', multiple=multiple, a=view, temp=False)
+        jp.QBtn(type='submit', text='Upload', color='primary', a=view, temp=False)
 
 
         super().__init__(view)
         super().__init__(view)