wxPython using WebKit (or html2 module)

861 views
Skip to first unread message

edwin.nathaniel

unread,
Feb 9, 2012, 10:32:55 PM2/9/12
to wxPython-users
Hi guys,

I came across a few apps that apparently are using some sort of HTML
rendering for some part of their applications (Gwibber and Digsby
comes to mind) and am wondering why they chose that particular path/
route. Is it because HTML offers a more flexible layout?

A few more questions that I'd like to ask are:

1) How far these apps utilize the HTML rendering? just HTML (and CSS?)
or HTML and JavaScript?

2) For those who chose or have experienced using HTML renderer for UI/
layout purposes, mind to share your experience on using it? (i.e.:
difficulties, no-no, gotchas, etc)

I'd like to know a few patterns how people are using HTML renderer as
part of their apps.

Thanks!
Ed

Mike Driscoll

unread,
Feb 10, 2012, 10:11:31 AM2/10/12
to wxpytho...@googlegroups.com
Well, they are definitely using more than something like our HTMLWindow can provide. I suspect they're using a more fully fledged set of HTML and yes, CSS. The HTMLWindow doesn't support that. Fortunately, in wxPython 2.9, we now have the WebView widget, which has Webkit underneath on Linux and Mac. So we can probably do something very similar with that. Gwibber is using webkit and PyGtk, I think.

-------------------
Mike Driscoll
www.mousevspython.com

pyGrant

unread,
Feb 11, 2012, 11:56:39 PM2/11/12
to wxpytho...@googlegroups.com
Hi Ed,

I have used Webkit in a wxPython GUI for quite a while now in my SOFA Statistics project (www.sofastatistics.com) but it involved a hack to make it work in Linux. The module is here: http://bazaar.launchpad.net/~launchpad-p-s/sofastatistics/main/view/head:/full_html.py

In Windows, Mac, and Linux the html display widget has to handle complex Javascript in the form of the DOJO Javascript and SVG charting framework.


All the best, Grant

Edwin Nathaniel

unread,
Feb 12, 2012, 12:33:25 AM2/12/12
to wxpytho...@googlegroups.com
Hi Grant,

Thank you very much for showing me how to do this! 

What is your strategy for reading data from the database between Python code to the display using JS and HTML?

pyGrant

unread,
Feb 12, 2012, 2:31:57 PM2/12/12
to wxpytho...@googlegroups.com
Hi Ed,

The requirements of the different Dojo charts drove how I supplied the data to each. I made separate functions as required and they returned dictionaries with the specific data the chart type needed including labels etc. E.g for histograms:

histo_dic = {mg.CHART_CHART_BY_LBL: chart_by_lbl,
                  mg.CHART_XAXIS_DETS: xaxis_dets,
                  mg.CHART_Y_VALS: y_vals,
                  mg.CHART_NORMAL_Y_VALS: norm_ys,
                  mg.CHART_MINVAL: minval,
                  mg.CHART_MAXVAL: maxval,
                  mg.CHART_BIN_LBLS: bin_lbls}

were different from scatterplots:

scatterplot_dic = {mg.CHART_CHART_BY_LBL: chart_by_lbl,
                          mg.LIST_X: lst_x, mg.LIST_Y: lst_y,
                          mg.DATA_TUPS: data_tups,}

The code involved is mainly in one module of SOFA here: http://bazaar.launchpad.net/~launchpad-p-s/sofastatistics/main/view/head:/charting_output.py. Reading that should provide some ideas.

All the best, Grant

Kevin Ollivier

unread,
Feb 12, 2012, 3:18:18 PM2/12/12
to wxpytho...@googlegroups.com
Hi Ed,

On Feb 9, 2012, at 7:32 PM, edwin.nathaniel wrote:

> Hi guys,
>
> I came across a few apps that apparently are using some sort of HTML
> rendering for some part of their applications (Gwibber and Digsby
> comes to mind) and am wondering why they chose that particular path/
> route. Is it because HTML offers a more flexible layout?

Digsby is actually using wx, and wxWebKit for its HTML rendering. :)

There are a couple reasons to do this. One is that, if you want complex UIs with modern effects like semi-transparent controls, etc., then doing it in something like wx is far more painful. Windows in particular does not support transparent controls that differ from transparent windows, and most of the transparency seen in Windows is a result of some very convoluted hacks. Animations and such are often a lot easier done with CSS properties and a few JavaScript tweaks than hand-coding all the animation in control drawing routines. Plus, if you're doing all this stuff, browsers have been tweaked for high performance, but if you do it all by hand in something like wx, you will have to measure and debug all performance problems yourself.

Also, HTML layouts are easier to modify on the fly. Doing a complete UI redesign might take only a few hours depending on how you do it.

Lastly, you might want to make a desktop front end to a web interface stored on a server, so that you can share one UI between desktop, web, and maybe mobile apps.

> A few more questions that I'd like to ask are:
>
> 1) How far these apps utilize the HTML rendering? just HTML (and CSS?)
> or HTML and JavaScript?

You'd have to ask them that. :)

> 2) For those who chose or have experienced using HTML renderer for UI/
> layout purposes, mind to share your experience on using it? (i.e.:
> difficulties, no-no, gotchas, etc)

The main issue is that web embedding on wx is a bit of a mess right now. If you go the wx "native rendering engine" approach, you need to be ready to deal with differences in rendering engines from IE 6 to the latest Safari / WebKit release. That can be even more messy / problematic than dealing with cross-platform desktop issues in some cases, because the bugs can be more subtle and require more sophisticated workarounds.

Regards,

Kevin

> I'd like to know a few patterns how people are using HTML renderer as
> part of their apps.
>
> Thanks!
> Ed
>

Reply all
Reply to author
Forward
0 new messages