Results 1 to 5 of 5

Thread: Lianja 5 and Python

  1. #1
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    5,770

    Lianja 5 and Python

    There are some significant improvements to Python integration in Lianja 5.

    You can now write server-side python pages that execute in both the desktop and web.

    I have also integrated package management using pip (from https://pypi.org). You can type pip commands in the Python tab of the console to install and/or manage python packages that you want to use in your Apps.

    A picture says a thousand words.

    Name:  Screen Shot 2019-03-29 at 5.50.15 PM.jpg
Views: 232
Size:  48.1 KB

    You can now choose to develop a WebView renderer in Lianja/VFP, JavaScript, Python or PHP.

    Name:  Screen Shot 2019-03-29 at 5.52.17 PM.jpg
Views: 232
Size:  127.2 KB

    One click editing of WebView renderer code.

    Name:  Screen Shot 2019-03-29 at 5.57.11 PM.jpg
Views: 227
Size:  108.6 KB

    Name:  Screen Shot 2019-03-31 at 12.19.11 PM.jpg
Views: 232
Size:  103.9 KB

    And here is the Python code. Note how you have full access to the Lianja data access classes.

    Code:
    <%@ Language=Python %>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset='utf-8'>
    <meta name='viewport' content='width=device-width, initial-scale=1.0'>
    <link rel='stylesheet' href='../../library/bootstrap/css/bootstrap.min.css' type='text/css'/>
    <link rel='stylesheet' href='../../library/bootstrap-3.3.4/css/bootstrap.min.css'>
    <script src='../../library/jquery-1.10.2/jquery-1.10.2.min.js' type='text/javascript'></script>
    <script src='../../library/bootstrap-3.3.4/js/bootstrap.min.js' type='text/javascript'></script>
    <style>
    .tablecaption { background: gray; font-weight: bold; color: white; text-align:center; }
    </style>
    
    </head>
    <body style="margin:10px;"> 
    <%
    import Lianja
    
    # open the southwind database
    db = Lianja.openDatabase("southwind") 
    
    # open a recordset
    rs = db.openRecordSet("select * from example")
    
    # main table
    print "<table class='table'>"
    print "<caption class=\"tablecaption\"> Example Python Report using bootstrap</caption>"
    
    # column headings
    rs.movefirst()
    print "<tr bgcolor=\"lightgray\" class=\"smallfont\">"
    for j in range( rs.fcount() ):
        print "<th><font color=\"white\">" + rs.fields(j).name + "</font></th>"
    print "</tr>"
    
    # Traverse the recordset and write the output into the Webview section.
    for i in range( rs.reccount() ):
        if ((i%2) == 0):
      rowcolor = "#f1f6fe"
      altcolor = "#FFFFFF"
        else:
      rowcolor = "#FFFFFF"        
      altcolor = "#f1f6fe"
      print "<tr bgcolor=\"" + rowcolor + "\" color=\"darkgray\" class=\"smallfont\" valign=top>"
        for j in range( rs.fcount() ):
      if rs.fields(j).name in [ "LIMIT", "BALANCE", "AVAILABLE" ]:
       print "<td align=right>$%.2f</td>" % rs.fields(j).value
      else:
       print "<td>%s</td>" % rs.fields(j).value
       print "</tr>"
       rs.movenext()
    
    # end of table
    print "</table>"
    
    # Close the RecordSet    
    rs.close() 
    
    %>
    </body>
    </html>
    Let's run that in the Web and see how it looks.

    Name:  Screen Shot 2019-03-30 at 4.39.49 PM.jpg
Views: 224
Size:  78.3 KB

    So as you can see Python can now be used in Web/Mobile Apps.

    Enjoy.
    Last edited by barrymavin; 2019-03-31 at 00:38.
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  2. #2
    Senior Member
    Join Date
    Feb 2012
    Posts
    1,214
    Wow - this has incredible possibilities.

    I can already think of several ways I can use this.

    Thanks Barry!

  3. #3
    Senior Member
    Join Date
    Feb 2012
    Posts
    1,214
    Hi Barry,

    I can't overstate how fantastic this is!

    If was going to create an installer that included all the python files, would I need to set any type of environment settings?

    Thanks

    Herb

  4. #4
    Lianja Development Team barrymavin's Avatar
    Join Date
    Feb 2012
    Location
    UK, USA, Thailand
    Posts
    5,770
    When you use pip from inside the python console Lianja knows where to run pip from. So no path needed.

    Are you talking about desktop distribution?
    Principal developer of Lianja, Recital and other products

    Follow me on:

    Twitter: http://twitter.com/lianjaInc
    Facebook: http://www.facebook.com/LianjaInc
    LinkedIn: http://www.linkedin.com/in/barrymavin

  5. #5
    Senior Member
    Join Date
    Feb 2012
    Posts
    1,214
    Hi Barry,

    yes. I am talking about installing the app on a new clean machine.

    Thanks

    Herb

Bookmarks

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Journey into the Cloud
Join us