How to load SWF content into a Python application on Linux? - python

I have an application that uses Flash for the GUI and Python for the core logic. This combination is awesome. Unfortunately my current approach only works on Windows, as it uses the wxPython comtypes library to embed the Flash ActiveX player. Every other aspect of the app is platform-agnostic, so I'm thinking there must be some way on Linux to have Python talk to Flash.
The SWF need not require AVM2/AS3, though ideally I could use the most current Flash player available. I am using wxPython (wxWidgets) and would prefer to keep using it. Worst case I could jerry-rig something that loads the SWF in a separate process and talks over a socket connection to the Python, but I see no simple way to have the Flash display inside my application's window rather than a player window with its own menus and decorations.
Any suggestions appreciated. I'm very open to hacking at a solution if there's reason to believe it will work :)

Flash Professional has support to Adobe Air, so you could use it as front-end, usually a flash project can be released as an AIR application without major changes to its code. The communication could be done using Native Process Api (see links bellow). Then you can run it on Mac, Win e Lin.
http://www.kirupa.com/forum/showthread.php?349728-Air2-NativeProcess-launching-Python-scripts.
http://mykola.bilokonsky.net/2010/11/adobe-air-nativeprocess-and-python-introduction/

Related

Is there any way to integrate an OS native window in a browser dialog?

I'm building a prototype for a bin packing app.
The front-end runs on the browser. Where it takes a picture and sends it to the back-end to extract the "board outline" from the image and then responds to front-end with a svg of it.
To finally add some shapes and pack in the bin.
I'm working with rust both back-end and front-end through wasm.
The back-end is polyglot, I use rust-ffi to encrust some java and pyhton code. I'm reciclyng the bin packing algorithm from a java code. And the image conversion is being done by the owners of the project with python.
The point is that the whole front-end runs in the browser and these guys at some point in their process need the user to click on the image and for that they display a dialog with the native windows of the operating system.
Initially this prototype will not be deployed in a network, but everything will be deployed on the same host as the client, so ultimately it will not be a catastrophic problem.
The question is that it totally impairs the usability of the project so I want to know if it is possible to somehow integrate the popup window of the python process in a browser dialog?
Note:
The python program was made with opencv

How to control a Windows application from Python

I have the application installed on my windows PC, I want to launch that application using python and select dropdown options and do some other activities in that application.
I was able to launch the application using the os.system command, but I am not able to proceed further.
I want my program to do things like:
* select from a dropdown menu
* click on a button
How can my application control the user interface of another application?
Normally, an application exposes a user interface (UI) for users, and an application programming interface (API) for programming.
A human being uses keyboard and mouse to work with the user interface (UI)
An application uses programming to work with the application programming interface (API)
The UI is designed for humans, and the API is designed for computers.
It is sometimes possible to use programming to control the user interface of another program -- so your program acts as if it were using the keyboard and mouse. This technique is often called "UI automation", and programs that do it are sometimes called "robots".
It's a big topic, and it can be quite complex. It's almost always better to use an API instead if you can: it's faster, simpler, more reliable.
If you do need to use UI automation, there are a few different tools that can help.
You are asking about Python, so here are a few UI automation tools that work with Python:
AutoIT is a standalone product, but you can use Python to script it.
PyWinAuto is designed for use from Python.
Sikuli uses computer vision to find parts of the screen. I believe it comes with a recording tool as well.
Just to repeat: UI automation is weird and hard. If you can possibly use an API instead, your life will be much easier.
You need to install pywinauto package
Try the following code to run the .exe file
from pywinauto import application
app = application.Application()
app.start("Notepad.exe")
here you are:
(with os ^_-)
import os
os.startfile('your exe file address')

Python: How to create a simple frame in Kivy?

How can I create a simple frame in Kivy (Python for mobile), which will include a simple TextBox ?
Thanks guys
The biggest name I know of that uses (or used) wxPython is probably Dropbox:
How does Dropbox use Python on Windows and OS X?
This web page implies that NASA also uses wxPython:
https://modelingguru.nasa.gov/docs/DOC-2424/diff?secondVersionNumber=4
Google uses Python itself for all kinds of things and has been a big supporter of Python. They provide Python bindings to many of their product's APIs for example.
You might also check out the following for less well-known projects:
http://freecode.com/tags/wxpython
Whyteboard was getting popular for a while too.
There is significant movement away from desktop development to web and mobile development. For mobile, one of the best Python projects out there is Kivy. For the web, you have a lot of choices:
django
flask
pyramid
Plone / Zope
web2py
I have seen some pretty impressive desktop GUIs created using PyQt and IronPython, so I can't say that desktop GUI development is totally dead.

How to control an outside executable application?

I have my own application on python 2.7. I want to control an outside .exe application.
I'm able to launch such an application, klm.exe as:
from win32com.client import *
ExtApp = Dispatch("Wscript.Shell")
ExtApp.Run("E:\XYZ\ABC\klm")
But I want to have full control of this outside .exe application as it has tabs, radio buttons, push buttons, etc.
Is there a way to do so?
But I want to have full control of this outside .exe application as it has tabs, radio buttons, push buttons, etc.
Is there a way to do so?
Yes, multiple ways, depending on the application.
Since you're already using COM (although I'm not sure why you're using it just to launch apps)… does the app have a COM automation (IDispatch) interface? If so, there will probably be documentation showing how to use it from VB# (or VBScript or C# or …), which you can easily adapt to Python and win32com. (For an example of such an application, see the Outlook automation docs.)
If there's no COM automation interface, there may still be a lower-level COM interface, which is almost as easy to use via win32com, but it usually won't provide any access to the GUI controls; instead, you'll be talking to the same lower-level functionality that the GUI uses. (For a good example, see Apple's iTunes COM Interface.)
If there's no COM support at all, the simplest thing to do is to automate it via Windows WM_* events. There are some examples of doing that in the pywin32 documentation, but there are also a lot of higher-level wrappers, like AutoPy and pywinauto/swapy, and so on that will make things a whole lot easier. There are dozens of these, free and commercial, and even more if you're willing to step outside of Python and use a different scripting system, and SO is not a good place to discuss the pros and cons of each.
Finally, you can always ignore the app's windows and just automate the system mouse… but this is almost always a silly thing to do.

What are some successful methods for deploying a Django application on the desktop?

I have a Django application that I would like to deploy to the desktop. I have read a little on this and see that one way is to use freeze. I have used this with varying success in the past for Python applications, but am not convinced it is the best approach for a Django application.
My questions are: what are some successful methods you have used for deploying Django applications? Is there a de facto standard method? Have you hit any dead ends? I need a cross platform solution.
I did this a couple years ago for a Django app running as a local daemon. It was launched by Twisted and wrapped by py2app for Mac and py2exe for Windows. There was both a browser as well as an Air front-end hitting it. It worked pretty well for the most part but I didn't get to deploy it out in the wild because the larger project got postponed. It's been a while and I'm a bit rusty on the details, but here are a few tips:
IIRC, the most problematic thing was Python loading C extensions. I had an Intel assembler module written with C "asm" commands that I needed to load to get low-level system data. That took a while to get working across both platforms. If you can, try to avoid C extensions.
You'll definitely need an installer. Most likely the app will end up running in the background, so you'll need to mark it as a Windows service, Unix daemon, or Mac launchd application.
In your installer you'll want to provide a way to locate a free local TCP port. You may have to write a little stub routine that the installer runs or use the installer's built-in scripting facility to find a port that hasn't been taken and save it to a config file. You then load the config file inside your settings.py and whatever front-end you're going to deploy. That's the shared port. Or you could just pick a random number and hope no other service on the desktop steps on your toes :-)
If your front-end and back-end are separate apps then you'll need to design an API for them to talk to each other. Make sure you provide a flag to return the data in both raw and human-readable form. It really helps in debugging.
If you want Django to be able to send notifications to the user, you'll want to integrate with something like Growl or get Python for Windows extensions so you can bring up toaster pop-up notifications.
You'll probably want to stick with SQLite for database in which case you'll want to make sure you use semaphores to tackle multiple requests vying for the database (or any other shared resource). If your app is accessed via a browser users can have multiple windows open and hit the app at the same time. If using a custom front-end (native, Air, etc...) then you can control how many instances are running at a given time so it won't be as much of an issue.
You'll also want some sort of access to local system logging facilities since the app will be running in the background and make sure you trap all your exceptions and route it into the syslog. A big hassle was debugging Windows service startup issues. It would have been impossible without system logging.
Be careful about hardcoded paths if you want to stay cross-platform. You may have to rely on the installer to write a config file entry with the actual installation path which you'll have to load up at startup.
Test actual deployment especially across a variety of firewalls. Some of the desktop firewalls get pretty aggressive about blocking access to network services that accept incoming requests.
That's all I can think of. Hope it helps.
If you want a good solution, you should give up on making it cross platform. Your code should all be portable, but your deployment - almost by definition - needs to be platform-specific.
I would recommend using py2exe on Windows, py2app on MacOS X, and building deb packages for Ubuntu with a .desktop file in the right place in the package for an entry to show up in the user's menu. Unfortunately for the last option there's no convenient 'py2deb' or 'py2xdg', but it's pretty easy to make the relevant text file by hand.
And of course, I'd recommend bundling in Twisted as your web server for making the application easily self-contained :).

Categories