Question

I have a small python program to help my colleagues to analyse some tsv data. The data is not big, usually below 20MB. I developed the GUI with PyQT. I want to change this desktop program to a web app so my colleagues don't have to upgrade the program every time I change it or fix a bug. They can just go to a website and use Chrome as the GUI. So how do I do this? I spend most of my time developing desktop program and just know some basic web developing knowledges. I have read some framework such as flask and web2py, and know how to use HTML and Javascript to make buttons but no clue to achieve my purpose.

Can someone give me a practical way to do this? It'd be better if the user don't have to upload the local data to the server. Maybe just download the python code from server then execute in Chrome. Is this possible?

Thanks.

Was it helpful?

Solution 2

The whole point of a web application is that the GUI is written in HTML, CSS, and JavaScript, not Python. However, it talks to a web service, which can be written in Python.

For a well-written desktop app, the transition should be pretty easy. If you've already got a clean separation between the GUI part and the engine part of your code, the engine part will only need minor changes (and maybe stick it behind, e.g., a WSGI server). You will have to rewrite the GUI part for the web, but in a complex app, that should be the easy part.

However, many desktop GUI apps don't have such a clean separation. For example, if you have button handlers that directly do stuff to your model, there's really no way to make that work without duplicating the model on both sides (the Python web service and the JS client app) and synchronizing the two, which is a lot of work and leads to a bad experience. In that case, you have to decide between rewriting most of your app from scratch, or refactoring it to the point where you can web-service-ify it.

If you do choose to go the refactoring route, I'd consider adding a second local interface (maybe using the cmd module to build a CLI, or tkinter for an alternate GUI), because that's much easier to do. Once the same backend code can support your PyQt GUI and your cmd GUI, adding a web interface is much easier.

OTHER TIPS

No, you cannot run Python code in a web browser.[1] You'd have to port the core of your application to JavaScript to do it all locally.

Just do the upload. 20MB isn't all that much data, and if it's stored on the server then they can all look at each others' results, too.


[1] There are some tools that try to transpile Python to JavaScript: pyjs compiles directly, and Emscripten is an entire LLVM interpreter in JS that can run CPython itself. I wouldn't really recommend relying on these.

If I get your point correctly, you want

  1. Web connection, so your python program updated on server, client get it before using it.
  2. Data store on local to avoid upload big file.

You can write a python program to check a server location to get your latest program if needed. You need a url / server file for program version / created date/time information to determine if you need to update or not. After get latest python program, then start this python program to run locally.

With this said, What you need is to update your program to add below features:

  • Access your server, to get latest version information
  • Check against current version to see if you need to download latest program
  • Download latest version and use that to run locally.

Does this solve your problem?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top