Search code examples
pythonpysideweb2pyreusability

Writing for both PySide and web2py


Background: I have a desktop app that I've written in Python27x that uses wxPython for the UI and requests with xml.etree.ElementTree to retrieve open data from a RESTful service and present the data in meaningful ways to the user.

I am currently re-writing my app using PySide. I am fairly certain that I can present my data-candy in HTML5 and I would eventually like to provide a web-app using web2py and JavaScript.

The PySide and web2py versions both need to support:

  • aquiring a lock on a Throttle object that I've made to handle the fair-usage policy of the service.
  • presenting the analyzed data in tables with links or buttons for retrieving or donwloading more related data.
  • presenting lists of related data and highlighting groups of items on mouse-over of any member of the group.
  • presenting text documents and providing automatic searching / highlighting of keywords / part-of-speech tagging using NLTK.
  • providing basic graphs and charts of various stats on the data.

Question: Given what I've told you about my app, and assuming web2py and HTML5 can meet my user-interface / presentation needs, what steps can I take / widgets should I use in making my PySide desktop app to maximize re-use when porting over to web2py? What should I be sure to avoid when writing the desktop version?


Solution

  • You need to separate your data and data-processing from the user interface. Qt (and thus PySide) has a very strong focus on this Model-View approach (see e.g. http://qt-project.org/doc/qt-4.8/modelview.html), and provides models to organize your data, and views to present the data. Within Qt, this approach allows to easily use multiple views on the same data sets, without having to worry about how to get the data in the view.

    Admittedly, the Qt models take some time to get used to, but the aforementioned tutorial should give you some pointers and references to get you started. In your case, I would go for the following approach:

    • Find/extend a suitable Qt model to manage your data
    • Use this data with standard/custom views in your PySide application
    • Develop web2py-based view to present the data in your webapp

    I'm not familiar with web2py, so I can't assess how hard/easy this last step would be. However, I can recommend to invest some time (if you have it) in getting to know the Qt Model-View framework, as it can save you huge amounts of time in the future (at least, in my experience).