Analytics

Using Python and QML to build native apps

Python is a highly efficient and intuitive language that is pervasive throughout the ArcGIS Platform, as well as the larger scientific community. I personally love writing Python code because you can build sophisticated scripts that accomplish a wide array of tasks with relatively little effort or lines of code. Many ArcGIS users have picked up the scripting language in recent years and have found it to be invaluable in maximizing their productivity. However, one thing that I think most Python coders would agree with me on is that it isn’t very easy to make great looking UIs with Python. There are options, such as TkInter, that allow you to build up UIs from Python, but I would argue that the power of Python is in scripting procedural workflows, not in building beautiful UIs. There are, however, other languages and frameworks for building great UIs that integrate well with Python, and one of those is Qt.

Qt is a cross platform SDK that is similar in functionality to .NET, and provides APIs in both C++ and QML. For those that are not already familiar, QML is a declarative JavaScript based language that looks similar to JSON with nested JavaScript functions within it. QML is a newcomer to the ArcGIS stack, and recently emerged as one of the languages used in the ArcGIS Runtime SDK for Qt, as well as AppStudio for ArcGIS. QML is great for building user interfaces, and through a plugin called PyOtherSide, integrates very well with Python. This plugin allows you to call Python scripts directly from QML. This is powerful for a few reasons:

Building off of these different use cases, I put together a GitHub repo that shows some samples of how to integrate QML, Python, and ArcGIS through PyOtherSide. The examples include:

Here is a snippet that shows how a Python function can be executed from QML. Note how a list of parameters can be passed in, and a callback JavaScript function is passed in. This will be executed on completion of the Python script.
Here is the Python script that is executed by the above QML code. It converts an Excel spreadsheet to CSV and returns the output path.

These samples only scratch the surface of possible applications for this technology. However, I think they serve as a good starting point to understand how QML works (if you don’t already know) and how to call Python functions from QML. Whether you are a Python dev looking to build UIs or an ArcGIS Runtime dev looking to utilize your Python skills in your native apps, PyOtherSide is a powerful and intuitive plugin that opens the doors for many ArcGIS users. Please note that specific issues relating to integrating ArcGIS and PyOtherSide is not supported by Esri technical support (but don’t let that stop you from seeing what you can create!).

About the author

Lucas is a Product Engineering Lead on the ArcGIS Runtime SDK team. He is the Product Owner of the ArcGIS Runtime SDK for Qt and also leads the ArcGIS Runtime Toolkit team. In his free time, he likes spending time outdoors, traveling, and cooking.

Connect:
0 Comments
Inline Feedbacks
View all comments

Next Article

Basemap Releases Include Over 300 New and Updated Communities

Read this article