Browse Source

Created Parser and ParserServer; Edited settings; Deleted ServerModule1, Form1.RowTemplate1 and Form1

florian.residori@gmail.com 3 years ago
parent
commit
8840759c1e

+ 2 - 3
.anvil_editor.yaml

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

+ 4 - 3
anvil.yaml

@@ -1,7 +1,8 @@
 allow_embedding: false
-package_name: Hello_San_Francisco_1
-name: Hello San Francisco 1
-startup_form: Form1
+package_name: onlineParser
+startup: {type: form, module: Parser}
+name: onlineParser
+startup_form: null
 runtime_options: {version: 2, client_version: '3', server_version: python3-sandbox}
 services:
 - source: /runtime/services/tables.yml

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

@@ -1,13 +0,0 @@
-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.

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

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

+ 0 - 46
client_code/Form1/__init__.py

@@ -1,46 +0,0 @@
-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
-
-
-class Form1(Form1Template):
-  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.
-
-  def check_yaml_click(self, **event_args):
-    """This method is called when the button is clicked"""
-    status, parsed_data = anvil.server.call('parse_yaml',self.input.text)
-    if status==1:
-      self.output.foreground = 'red'
-    else:
-      self.output.foreground = 'blue'
-    self.output.text = parsed_data
-
-  def check_json_click(self, **event_args):
-    """This method is called when the button is clicked"""
-    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 = output_text
-    
-    print(output_text)
-
-
-
-

+ 60 - 0
client_code/Parser/__init__.py

@@ -0,0 +1,60 @@
+from ._anvil_designer import ParserTemplate
+from anvil import *
+import anvil.server
+import anvil.tables as tables
+import anvil.tables.query as q
+from anvil.tables import app_tables
+
+class Parser(ParserTemplate):
+  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.
+
+  def check_yaml_click(self, **event_args):
+    """This method is called when the button is clicked"""
+    status, parsed_data, msg, lineno, colno = anvil.server.call('parse_yaml',self.input.text)
+    
+    output_text = parsed_data
+    self.output.foreground = 'green'
+    
+    if status==1:
+      self.output.foreground = 'red'
+      output_text = ""
+      index = 1
+      for line in self.input.text.splitlines():
+        output_text = output_text + line + '\n'
+        index+= 1
+        if index == lineno:
+          output_text = output_text + ' '*colno + '^' '\n'
+          output_text = output_text + ' '*colno + 'MESSAGE: ' + msg + '\n'
+      
+    self.output.text = output_text
+
+  def check_json_click(self, **event_args):
+    """This method is called when the button is clicked"""
+    status, parsed_data, msg, lineno, colno = anvil.server.call('parse_json',self.input.text)
+    
+    output_text = parsed_data
+    self.output.foreground = 'green'
+    
+    if status==1:
+      self.output.foreground = 'red'
+      output_text = ""
+      index = 1
+      for line in self.input.text.splitlines():
+        output_text = output_text + line + '\n'
+        index+= 1
+        if index == lineno:
+          output_text = output_text + ' '*colno + '^' '\n'
+          output_text = output_text + ' '*colno + 'MESSAGE: ' + msg + '\n'
+      
+    self.output.text = output_text
+
+
+
+
+
+
+

+ 37 - 29
client_code/Form1/form_template.yaml → client_code/Parser/form_template.yaml

@@ -4,32 +4,19 @@ container:
   properties: {tooltip: '', background: '', foreground: '', border: '', visible: true,
     role: null, html: '@theme:standard-page.html'}
 components:
-- type: ColumnPanel
-  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}
+- type: Label
+  properties: {}
+  name: label_1
+  layout_properties: {slot: hero}
+- type: FlowPanel
+  properties: {}
+  name: flow_panel_1
+  layout_properties: {grid_position: 'CPLQVZ,XTXCAG', slot: default}
   components:
-  - type: TextArea
-    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: 'ZYPJLG,JVGICP', column: null}
-  - type: RichText
+  - type: ColumnPanel
     properties: {}
-    name: output
-    layout_properties: {grid_position: 'ZYPJLG,RAIGTL'}
-  - type: Button
-    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: 'FMPDIV,WJAISE'}
-    event_bindings: {click: check_json_click}
+    name: column_panel_1
+    layout_properties: {}
   - type: Button
     properties: {role: null, align: left, tooltip: '', border: '', enabled: true,
       foreground: '', visible: true, text: 'YAML
@@ -37,9 +24,30 @@ components:
         ', 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: 'FMPDIV,SLPCJD'}
+    layout_properties: {slot: default, grid_position: 'IVHSBH,EPWHFD'}
     event_bindings: {click: check_yaml_click}
-- type: Label
-  properties: {}
-  name: label_1
-  layout_properties: {slot: hero}
+  - type: Button
+    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: 'IVHSBH,AKJSSX'}
+    event_bindings: {click: check_json_click}
+  - type: TextArea
+    properties: {role: null, align: left, height: 812.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: 'IVHSBH,EPWHFD ZAELRL,ZLIOFD',
+      column: null, width: 737.567}
+    event_bindings: {}
+  - type: TextArea
+    properties: {role: null, align: left, height: 810.9666221435547, 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: output
+    layout_properties: {width: 802.567}
+    event_bindings: {}

+ 31 - 0
server_code/ParserServer.py

@@ -0,0 +1,31 @@
+import anvil.tables as tables
+import anvil.tables.query as q
+from anvil.tables import app_tables
+import anvil.server
+
+import yaml
+import json 
+import pprint
+
+# 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(yaml_data):
+  try:
+    return (0,pprint.pformat(yaml.safe_load(yaml_data), indent=2),"",0,0)
+  except yaml.YAMLError as exc:
+    return (1,pprint.pformat(yaml_data, indent=2), exc.msg, exc.lineno, exc.colno)
+
+
+@anvil.server.callable
+def parse_json(json_data):
+  try:
+    return (0,pprint.pformat(json.loads(json_data), indent=2),"",0,0)
+  except json.JSONDecodeError as exc:
+    return (1,pprint.pformat(json_data, indent=2), exc.msg, exc.lineno, exc.colno)
+  

+ 0 - 50
server_code/ServerModule1.py

@@ -1,50 +0,0 @@
-import anvil.tables as tables
-import anvil.tables.query as q
-from anvil.tables import app_tables
-import anvil.server
-import yaml
-import json 
-import pprint
-from json.decoder import JSONDecodeError
-
-# 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(yaml_data):
-  try:
-    return (0,pprint.pformat(yaml.safe_load(yaml_data), indent=2))
-  except yaml.YAMLError as exc:
-    if hasattr(exc, 'problem_mark'):
-        if exc.context != None:
-            error_message = ('Error while parsing YAML file:\n'+
-                              'parser says\n' + str(exc.problem_mark) + '\n  ' +
-                str(exc.problem) + ' ' + str(exc.context) +
-                '\nPlease correct data and retry.')
-        else:
-            error_message = ('Error while parsing YAML file:\n'+'  parser says\n' + str(exc.problem_mark) + '\n  ' +
-                str(exc.problem) + '\nPlease correct data and retry.')
-    else:
-        error_message =  ("Something went wrong while parsing yaml file")
-    return (1,error_message)
-#
-
-@anvil.server.callable
-def parse_json(json_data):
-  try:
-    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 + json_data.splitlines()[exc.lineno - 3] + '\n'
-    if exc.lineno >= 0:
-      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 + json_data.splitlines()[exc.lineno] + '\n'
-    return (1,exc.msg, exc.lineno, exc.colno)