Преглед изворни кода

Created ServerModule1 and Form1.RowTemplate1; Edited Form1

florian.residori@gmail.com пре 3 година
родитељ
комит
11070ab11f

+ 3 - 1
.anvil_editor.yaml

@@ -1,8 +1,10 @@
 unique_ids:
   forms:
     Form1: '1644127965059339743960149.557'
+    Form1.RowTemplate1: '1644129927900453114162459.66205'
   modules: {}
-  server_modules: {}
+  server_modules:
+    ServerModule1: '1644129300175719831956498.9198'
   assets:
     header.jpg: 7KSQKX6BX46N4HZVHNQ7B3PFT6UHIMAV
     splash.html: IT47CKLN7JIJXASU4Q7NHSNVLE6SJ6K6

+ 13 - 0
client_code/Form1/RowTemplate1/__init__.py

@@ -0,0 +1,13 @@
+from ._anvil_designer import RowTemplate1Template
+from anvil import *
+import anvil.server
+import anvil.tables as tables
+import anvil.tables.query as q
+from anvil.tables import app_tables
+
+class RowTemplate1(RowTemplate1Template):
+  def __init__(self, **properties):
+    # Set Form properties and Data Bindings.
+    self.init_components(**properties)
+
+    # Any code you write here will run when the form opens.

+ 3 - 0
client_code/Form1/RowTemplate1/form_template.yaml

@@ -0,0 +1,3 @@
+container: {type: DataRowPanel}
+components: []
+is_package: true

+ 11 - 3
client_code/Form1/__init__.py

@@ -1,9 +1,10 @@
 from ._anvil_designer import Form1Template
 from anvil import *
+import anvil.server
 import anvil.tables as tables
 import anvil.tables.query as q
 from anvil.tables import app_tables
-import yaml
+
 
 class Form1(Form1Template):
   def __init__(self, **properties):
@@ -12,7 +13,14 @@ class Form1(Form1Template):
 
     # Any code you write here will run when the form opens.
 
-  def check_click(self, **event_args):
+  def check_yaml_click(self, **event_args):
+    """This method is called when the button is clicked"""
+    parsed_data = anvil.server.call('parse_yaml',self.input.text)
+    self.output.text = parsed_data
+
+  def check_json_click(self, **event_args):
     """This method is called when the button is clicked"""
-    print(yaml.safe_load(self.yaml_input.text))
+    parsed_data = anvil.server.call('parse_json',self.input.text)
+    self.output.text = parsed_data
+
 

+ 16 - 8
client_code/Form1/form_template.yaml

@@ -10,19 +10,27 @@ components:
   layout_properties: {slot: default}
   components:
   - type: TextArea
-    properties: {}
-    name: yaml_input
-    layout_properties: {slot: default, grid_position: 'QBAEHF,LHVVNF'}
+    properties: {height: 237.23329999999999}
+    name: input
+    layout_properties: {slot: default, grid_position: 'QBAEHF,DZNSNI'}
   - type: Button
     properties: {role: null, align: center, tooltip: '', border: '', enabled: true,
-      foreground: '', visible: true, text: 'Check
+      foreground: '', visible: true, text: JSON, font_size: null, font: '', spacing_above: small,
+      icon_align: left, spacing_below: small, italic: false, background: '', bold: false,
+      underline: false, icon: ''}
+    name: check_json
+    layout_properties: {grid_position: 'JUZPYY,WEZPAN'}
+    event_bindings: {click: check_json_click}
+  - type: Button
+    properties: {role: null, align: center, tooltip: '', border: '', enabled: true,
+      foreground: '', visible: true, text: 'YAML
 
         ', font_size: null, font: '', spacing_above: small, icon_align: left, spacing_below: small,
       italic: false, background: '', bold: false, underline: false, icon: ''}
-    name: check
-    layout_properties: {slot: default, grid_position: 'VTVZAV,KZXXGI'}
-    event_bindings: {click: check_click}
+    name: check_yaml
+    layout_properties: {slot: default, grid_position: 'HOKUMP,WADNHD'}
+    event_bindings: {click: check_yaml_click}
   - type: TextArea
-    properties: {}
+    properties: {height: 223.96662214355467}
     name: output
     layout_properties: {grid_position: 'VSVEIR,ESSUYK', slot: default}

+ 22 - 0
server_code/ServerModule1.py

@@ -0,0 +1,22 @@
+import anvil.tables as tables
+import anvil.tables.query as q
+from anvil.tables import app_tables
+import anvil.server
+import yaml
+import json 
+
+# This is a server module. It runs on the Anvil server,
+# rather than in the user's browser.
+#
+# To allow anvil.server.call() to call functions here, we mark
+# them with @anvil.server.callable.
+# Here is an example - you can replace it with your own:
+#
+@anvil.server.callable
+def parse_yaml(text):
+  return yaml.safe_load(text)
+#
+
+@anvil.server.callable
+def parse_yaml(text):
+  return yaml.safe_load(text)