Kaynağa Gözat

Edited ServerModule1 and Form1

florian.residori@gmail.com 3 yıl önce
ebeveyn
işleme
d1217d2420

+ 14 - 2
client_code/Form1/__init__.py

@@ -24,11 +24,23 @@ class Form1(Form1Template):
 
   def check_json_click(self, **event_args):
     """This method is called when the button is clicked"""
-    status, parsed_data = anvil.server.call('parse_json',self.input.text)
+    status, parsed_data, lineno, colno = anvil.server.call('parse_json',self.input.text)
+    
+    if status == 0:
+      output_text = parsed_data
     if status==1:
+      output_text = ""
+      for line in self.input.text.splitlines():
+        output_text = output_text + line + '\n'
+        
       self.output.foreground = 'red'
     else:
       self.output.foreground = 'blue'
-    self.output.text = parsed_data
+      
+    self.output.text = output_text
+    
+    print(output_text)
+
+
 
 

+ 20 - 11
client_code/Form1/form_template.yaml

@@ -5,32 +5,41 @@ container:
     role: null, html: '@theme:standard-page.html'}
 components:
 - type: ColumnPanel
-  properties: {col_widths: '{}'}
+  properties: {role: null, tooltip: '', border: '', foreground: '', visible: true,
+    wrap_on: mobile, col_spacing: tiny, spacing_above: small, col_widths: '{}', spacing_below: small,
+    background: ''}
   name: content_panel
   layout_properties: {slot: default}
   components:
   - type: TextArea
-    properties: {height: 237.23329999999999}
+    properties: {role: null, align: left, height: 472.2333, tooltip: '', placeholder: '',
+      border: '', enabled: true, foreground: '', visible: true, text: '', font_size: null,
+      auto_expand: true, font: '', spacing_above: small, spacing_below: small, italic: false,
+      background: '', bold: false, underline: false}
     name: input
-    layout_properties: {slot: default, grid_position: 'QBAEHF,DZNSNI'}
+    layout_properties: {slot: default, grid_position: 'ZYPJLG,JVGICP', column: null}
+  - type: RichText
+    properties: {}
+    name: output
+    layout_properties: {grid_position: 'ZYPJLG,RAIGTL'}
   - type: Button
-    properties: {role: null, align: center, tooltip: '', border: '', enabled: true,
+    properties: {role: null, align: right, tooltip: '', border: '', enabled: true,
       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'}
+    layout_properties: {grid_position: 'FMPDIV,WJAISE'}
     event_bindings: {click: check_json_click}
   - type: Button
-    properties: {role: null, align: center, tooltip: '', border: '', enabled: true,
+    properties: {role: null, align: left, 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_yaml
-    layout_properties: {slot: default, grid_position: 'HOKUMP,WADNHD'}
+    layout_properties: {slot: default, grid_position: 'FMPDIV,SLPCJD'}
     event_bindings: {click: check_yaml_click}
-  - type: TextArea
-    properties: {height: 223.96662214355467}
-    name: output
-    layout_properties: {grid_position: 'VSVEIR,ESSUYK', slot: default}
+- type: Label
+  properties: {}
+  name: label_1
+  layout_properties: {slot: hero}

+ 7 - 6
server_code/ServerModule1.py

@@ -36,14 +36,15 @@ def parse_yaml(yaml_data):
 @anvil.server.callable
 def parse_json(json_data):
   try:
-    return (0,pprint.pformat(json.loads(json_data), indent=2))
+    return (0,pprint.pformat(json.loads(json_data), indent=2),0,0)
   except JSONDecodeError as exc:
+    
     error_message = ""
     if exc.lineno - 1 >= 0:
-      error_message = error_message.join(json_data.splitlines()[exc.lineno - 3])
+      error_message = error_message + json_data.splitlines()[exc.lineno - 3] + '\n'
     if exc.lineno >= 0:
-      error_message = error_message.join(json_data.splitlines()[exc.lineno - 2])
-    error_message = error_message.join(json_data.splitlines()[exc.lineno - 1])
+      error_message = error_message + json_data.splitlines()[exc.lineno - 2] + '\n'
+    error_message = error_message + json_data.splitlines()[exc.lineno - 1] + '\n'
     if len(json_data.splitlines()) != exc.lineno:
-      error_message = error_message.join(json_data.splitlines()[exc.lineno])
-    return (1,error_message)
+      error_message = error_message + json_data.splitlines()[exc.lineno] + '\n'
+    return (1,exc.msg, exc.lineno, exc.colno)