Results 1 to 3 of 3

Thread: [Answers] Python

  1. #1
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135

    [Answers] Python

    Did you copy the the pyglet folder - i.e. the folder under pyglet-1.1.4 - into C:\lianja\scriptinglanguages\python\Lib\site-packages\?




    From Python, you can use:
    Lianja.execute('Lianja.showdocument("page:name_of_ page")')
    to select a particular Page. Lianja.activePage returns an object reference for the currently active Page. If you get the chance, can you submit a ticket with an App that displays the 'white flash' - I haven't seen that.



    Q:
    I have some VFP global variables declared in App Init() event. What would be the best way to access those in a python event delegate?
    A:
    For example I have an App, myapp, with the myapp_init.prg (App init()):

    Code:
    public m_var = "Hello World"
    Then a Python Custom Section:

    Code:
    import Lianja
    
    print "<html>"
    print "<head>"
    print "</head>"
    print "<body>"
    m_pub = Lianja.evaluate("m_var")
    print m_pub
    # Or, if all I want to do is print the value
    # print Lianja.evaluate("m_var")
    print "</body>"
    print "</html>"


    With the modules installed in the Lianja Python path under C:\lianja\scriptinglanguages\python\Lib\ (default installation) you should be able to import as in your existing Python code. Check out http://www.lianja.com/community/show...Python-modules for information on Registry tweaks that may be required.
    Remember that you can also use the Python tab in the Console Workspace to test out imports (and see any error messages if the modules aren't found) before running your complete script.



    It looks like you don't yet have pywin32 installed and wmi sits on top of it. Once you have pywin32 installed, copy the dlls from C:\Lianja\scriptinglanguages\python\Lib\site-packages\pywin32_system32 into your Windows System folder and you should be up and running.



    Q:
    for num in range(5):
    Lianja.writeLog(num)
    A.
    Lianja.writeLog() takes a string.




    ​All topics in [Answers] alphabetically:http://www.lianja.com/community/show...ll=1#post12352
    Last edited by josipradnik; 2017-01-06 at 05:49.

  2. #2
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135
    Q:
    I have the module in that deployment folder (.py in the Lib folder and .pyd in the DLLs folder) yet the app still breaks on the "import xyz" line in my app when not run through the app builder.
    A:
    check that any modules required by your xyz module are also installed on the deployment target machine.



    Q:
    where to put python DLLs (.pyd) that are called in python modules we want to import? I've tried putting them in both .../Lianja/scriptinglanguages/python/DLLs and in .../Lianja/scriptinglanguages/python/Lib. In the "Using Python Modules" thread on here it mentions registry key editing and I've followed those instructions as well. What is happening now is:


    • I have a python DLL "mydll.pyd" in the 2 folders mentioned above
    • I have a script "myscript.py" in .../Lianja/scriptinglanguages/python/Lib which has at the top:


    Code:
    import mydll
    When I runCode:
    Code:
    import myscript
    in the Lianja Python console, it pops out:

    Code:
    **** Lianja Python error ****
    Traceback (most recent call last):
      File "Console" at line 1, in <module>
      File "C:\lianja\scriptinglanguages\python\lib\myscript.py" at line 7, in <module>
        import mydll
    ImportError: DLL load failed: The specified module could not be found.
    A:
    If the python DLL has been built against the version of Python supported in Lianja (which is 2.7 on windows) it works by just placing the DLL in the DLL directory.
    You can verify this from the Python console.

    Code:
    import sqlite3
    where sqlite3.dll exists in C:\lianja\scriptinglanguages\python\DLLs
    If you exit Lianja and rename the sqllite3.dll to xxx_sqlite3.dll and then run Lianja again and do the same sequence of steps the DLL will not be found.
    So...
    The DLL must be a 32-bit DLL not a 64-bit version, and it must be compatible with Python 2.7.



    Q:
    how python imports work when deploying desktop apps? I assume I have to put the imported .py and .pyd files somewhere on the client system in a similar place to where I have them on the dev system. I've tried putting them in the same place (lianja/scriptinglanguages/python) and in cloudserver/scriptingilanguages/python.
    A:
    The deployment path for Python modules is:
    C:\lianja\cloudserver\scriptinglanguages\python\
    The development path for Python modules is:

    C:\lianja\scriptinglanguages\python\
    The drive letter where the exe is run from is prefixed onto it and replaces C:
    After deploying look in file explorer and make sure the files are indeed in the place you expect them to be.



    Q:
    it told me I had the wrong version of python installed. So I uninstalled my Python 3.5 and installed Python 2.7, the same version Lianja uses.
    it seems to be an issue with the way node.js structures its directories. I had a look through the phonegap directory tree on the computer we have with phonegap working and it doesn't seem to have "node_modules\bufferutil" or "node_modules\utf-8-validate", it goes straight from "ws" to "build". Without those folders the entire path is just barely under the Windows character limit for a folder name, with them it's just barely over.
    Do you know how to get around this or why it's putting those two folders in?
    A:
    Lianja is not using those folders. It seems you installed visual studio with PhoneGap tools and it has basically messed up any ability to install PhoneGap and node.js for use with Lianja.
    It's the path that visual studio has setup for node.js. It's too long as stated in the error messages
    It's highly likely that visual studio has custom versions of PhoneGap and node.js installed that prevent it being used by other products.
    A2:
    Yep that was it, I uninstalled Visual Studio and reinstalled Lianja and now everything works



    Q:
    I have problem about Lianja App Builder.
    Sometimes to often my App Builder stop working immediately after changing my python file a switching from Apps to Pages.
    I'm using Windows 7 32 bit and Lianja full download with all services, but Trial.
    I'm going to add some code below to check if my code isn't bad.
    Before my Lianja stopped working, I had the following code:

    Code:
    #
    # Lianja custom Python section "page1_section1"
    #
    import Lianja
    #--------------------------------------------------------------------------
    # Step 1: Define the classes we need
    # Note that all Lianja UI Framework classes can be subclassed in Python
    class mySection(Lianja.Section):
        def add(self):
            Lianja.showMessage("add() was called")
     
        def delete(self):
            Lianja.showMessage("delete() was called")
     
        def first(self):
            Lianja.showMessage("first() was called")
     
        def previous(self):
            Lianja.showMessage("previous() was called")
     
        def next(self):
            Lianja.showMessage("next() was called")
     
        def last(self):
            Lianja.showMessage("last() was called")
            
        def refresh(self):
            pass
     
        def search(self):
            pass
             
        def watch(self):
            Lianja.showMessage("watch() was called")
     
        def edit(self):
            Lianja.showMessage("edit() was called")
     
        def save(self):
            Lianja.showMessage("save() was called")
     
        def cancel(self):
            Lianja.showMessage("cancel() was called")
     
    #--------------------------------------------------------------------------
    # Note how the click() event handler for the ListBox is defined in Python
    class myListbox(Lianja.Listbox):
        def click(self):
            ui_grid.clear( )
            # Note how the AddItems method of Grid, ListBox and ComboBox can take 
            # a SQL SELECT statement as an argument
            if ui_listbox.text == "All":
                ui_grid.additems('select * from southwind!example where last_name != " "')
            else: 
                ui_grid.additems('select * from southwind!example where upper(left(last_name,1)) \
                = "' + ui_listbox.text + '"')
            ui_grid.refresh( )
    This works when I changed from Apps to Pages.
    But when I added following lines of code, my Lianja stop working, and after restart I cannot access my App, It stop working again and again..

    Code:
    # Step 2: Create the Section object
    # Note that the CreateObject() method needs two args: objectname, classname
    oSection = Lianja.createObject("oSection", "mySection")
    oSection.backcolor = "lightgreen"
    oSection.caption = "This is a custom Python section
    Stop working means Windows pop-up dialog stop working, and just one way is to close the app.
    A:
    The reason I asked you to cut and paste the code is that Python syntax is all based on whitespace indentation.
    1. oSection.caption = "This is a custom Python section

    This is missing a closing quote.

    2. This is not a valid custom section as you have removed this code that was generated for you and is required.

    Code:
    oSection = Lianja.createObject("oSection", "mySection")
    returnvalue = oSection


    you will see some Python sections and gadgets in the pages menu. Select the python section, then click the little keyboard icon in the section header to edit/view the code.

    The developers guide on the Lianja website has documentation on how to use Python to build custom sections and custom gadgets.
    http://www.lianja.com/doc/index.php/...velopers_Guide



    Q:
    I have problem about debugging in Python. When I click Open file in debugger, it says: "You cannot run the debugger on this type of file."
    It is possible to debug in python?
    A:
    No the debugger is for Lianja/VFP code only.



    Q:
    I have a file in my application called convert.py.
    I would like to call it from a Custom VFP section.
    I have tried execPython("convert.py"), but that is not calling it.
    A:
    once I loaded the file using loadlibrary(), all of my python functions are working using execPython("functionName()").



    in Lianja 3.1 the execPython( expr ), execPHP( expr ) and execJavaScript( expr ) Lianja/VFP functions return the result of the executed code. This makes it simple to integrate Lianja/VFP with Python/PHP/JavaScript. If expr is a filename it it loaded and executed.

    And also just to remind you.

    1. In Python, PHP and JavaScript you can call Lianja.evaluate( expr ) to call back into Lianja/VFP.
    2. The Lianja/VFP loadLibrary( filename ) function can load Python (.py), PHP (.php) and JavaScript (.js) libraries too.



    Q:
    This works fine in my application.
    Code:
    for i in range(1,20):
            <one tab Here>Lianja.console(str(i))
    But it looks like the it is not picking up both lines when I try to test it in the app inspector or console.
    A:
    You can only issue single-line commands in the Console/App Inspector Command Windows.



    Q:
    I have a migration process to Lianja occurring in stages.
    But the data will be live I Lianja from Day 1.
    I need the rest of the applications to be able to read the data from python until they are all moved over.
    I am testing out how best to access the Lianja databases from outside Python code.
    To test, I have configured the Lianja ODBC connection "Lianja_Soutwind" and successfully tested the connection.
    However, I am unable to connect using pyodbc.
    Is there a different, recommended way I should be connecting to Lianja?




    We have an internal team at the Fund that uses Python a lot. I am trying to show them the light of Lianja
    So for now, I do need to test both the code in Lianja and from the current external install.
    A:
    You would appear to be using your own Python installation which is probably x64 rather than the python we provide that is also embedded in Lianja.
    As per the error message you have a x64 and x86 mismatch of drivers.



    You dont need QT to build full database interactive openCV applications.
    By usings Lianja python and native database support, you can extend opencv easier than you ever thought possible.
    Lianja openCV threshold part 1 - https://youtu.be/bF1096tC8pk

    Taking the C++ threshold example, building it in python, then extending it as a web application using Lianja.
    Lianja openCV threshold part 2 - https://youtu.be/CAkz1kb_7D4



    Using the robust Lianja framework with python/OpenCV, we build an application that converts any image to a pencil sketch.
    openCVLIanja - https://youtu.be/RQhRXzl-b8k



    Just did a quick and dirty demo of Python with newest Data Aware IDE/Platform on the Market called Lianja.
    I have been developing apps for over 20 years and just started with Python.
    I have used the Lianja product for a couple years now building desktop, web and mobile apps.
    It's fairly new, but makes developing data aware applications simple.
    Python LIanja Intro - https://youtu.be/g5R9BrhduY4



    ​All topics in [Answers] alphabetically:http://www.lianja.com/community/showthread.php?2717-Answers

  3. #3
    Lianja MVP
    Join Date
    Dec 2012
    Location
    Croatia, Zagreb
    Posts
    1,135
    Q:
    I have a python library called
    pythonfunctions.py
    I want to load that library in a prg called via lianjaruntim.exe
    I have an install on c:\lianja and I am testing this locally.
    The app is called mbcore.
    So the files are sitting for now in "c:\lianja\apps\mbcore\"
    What setting would I need to set in order to use loadlibrary() correctly.
    I have tried --runtimedir and --tenancy.

    A:
    Put pythonfunctions.py in the library and reference it using the 'lib:/' prefix.

    Q2:
    I have copied the file to the library.
    In my proc, I am now calling
    Code:
    isloaded = loadlibrary("lib:/pythonFunctions.py")
    I am calling it like this in the command line.
    Code:
    c:\lianja\bin\lianjaruntime.exe c:\lianja\apps\mbcore\convert2cropgifremote.dbo --runtime --runtimedir c:\lianja\apps\mbcore\ --args "'BYS2EP20_1_000001.jpg','BYS2EP20_1_000301.jpg',5 0,'R:\bys2ep20\bys2ep20_ROLL1',1,'bys2ep20'"
    The library is not getting loaded.
    If I hard code the path to the library, it does load, but then doesnt call the python function.

    A2:
    in the deployed cloudserver path library



    Q:
    This is the code of the gadget who crash the IDE with any kind of code:

    pythonfunctions.py
    Code:
    define class Seleccion as Commandbutton
    procedure click(id)
     //a=messagebox("Hola Mundo")
     select employees
     browse
     endproc
     endclass
    A:
    In Lianja, you would use define and endDefine for classes, not endclass.




    All topics in [Answers] alphabetically: https://www.lianja.com/community/sho...ll=1#post13748

    These answers are also systematized on the site "Lianja developer": https://lianjadeveloper.wordpress.com/category/python/

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