Loading a page into a HtmlWindow freezes the app

(resend because my mail server kicked the message back)

Hi guys,
I have an application with a wx.html.HtmlWindow element. When I click on a
button and make it load a page with LoadPage(url), the whole application
freezes until the page is loaded. The thing is that I'd like to be able to
e.g. browse menu while loading the page. I tried to put the LoadPage
method into a thread, but that freezes the app forever (as well as
LoadFile()), saying:

...

Am I doing something wrong when using threads?
Thanx for your help.

Generally speaking, wxPython does not like it when you indiscriminately
use anything other than the MainThread to create and/or manipulate
wxPython widgets. Some things will work on some platforms, and not on
others. If what you are doing is breaking on your platform, stop doing
it.

In regards to the HtmlWindow stuff...I don't know, I don't use it.

- Josiah

···

".: smilelover :." <smilelover@centrum.cz> wrote:

Hi,
I'm in the process of building a (structurally) simple CLI+GUI application. The GUI should be a simple WxFrame with a matplotlib plot inside it (using WxMpl for embedding), and at best a couple of buttons and a menu on top of the matplotlib plot. I'm a wxPython noob, but it looks very simple to do.

The CLI should be able to interact with the gui in both senses (printing events from the GUI and telling the GUI to plot something different).

I have seen that this kind of things requires threading. Yesterday I began experimenting with threads and it seems to me that the most straightforward thing is to have the CLI in the main thread. I would also build the GUI code in the main thread, but I would launch app.MainLoop() in the second thread.

As far as I have seen (not so much) it seems to work (at least in the cli-->gui sense).

However now I read on the ML:

Generally speaking, wxPython does not like it when you indiscriminately
use anything other than the MainThread to create and/or manipulate
wxPython widgets. Some things will work on some platforms, and not on
others. If what you are doing is breaking on your platform, stop doing
it.

>[...]
> - Josiah

Since my app should work at least on Linux and Windows, I am quite worried about it. Is there a better strategy to do what I want to do? In general, what's your advice for building such a simple, double-thread application?

m.

···

--
Massimo Sandal
University of Bologna
Department of Biochemistry "G.Moruzzi"

snail mail:
Via Irnerio 48, 40126 Bologna, Italy

email:
massimo.sandal@unibo.it

tel: +39-051-2094388
fax: +39-051-2094387

    wx.PostEvent(frame, ToGui(attr1=..., attr2=..., foo=...))

I just read the docs and oh, ok, this answers one of my questions...
So far, so good :slight_smile:
m.

···

--
Massimo Sandal
University of Bologna
Department of Biochemistry "G.Moruzzi"

snail mail:
Via Irnerio 48, 40126 Bologna, Italy

email:
massimo.sandal@unibo.it

tel: +39-051-2094388
fax: +39-051-2094387

Whoops. That gtk line shouldn't be in there...

···

On Mar 16, 2006, at 11:57 AM, Michael Taft wrote:

Hi,
At the risk of hijacking this thread, I want to ask a similar question for an app I'm working on. I think the issue is very similar.

I have a working version that currently consists of a back end that accepts observers.
I have a working front end in pygtk that receives events from the backend in an update function. In turn it also implements observable, and the backend observes it to receive input from the UI.
The two are linked through a short program that instantiates both and signs them up as observers to each other.
This works surprisingly well.

Except that it's in pygtk, which is pretty limited. And besides one of the points of keeping things so separate was so that I could slap whatever frontend on there I wanted to.

So I have been trying to do the same thing with wxPython. The UI again has an update method. It receives events from the observable. It functions for a while and then locks up. The update method is fairly simple:

def update (self, observable, **kwargs):
    info = observable.get_all_data()
    #blah blah blah - deal with kwargs, etc
    self. text_ctrl.WriteText(blah)

Currently, the short program that starts both frontend and backend looks like this:

----------------------------------------------------->8
#!/usr/bin/python
# author mwt
# Mar '06

import fahmodel, fah_mainframe, fahdata, time, gtk, os.path
import wxtest, wx

def main():
    gtk.gdk.threads_init()
    CUR_DIR = os.path.dirname(__file__)
    INI_DIR = os.path.join(CUR_DIR, 'fah.ini')
    fah = fahmodel.FAHModel(INI_DIR)
    app = wx.App()
    fah_m = wxtest.Main_Frame(None, title=" Monitor") #this is a test version of the wxPy UI
    #fah.addObserver(fah_m)
    fah.fahdata.addObserver(fah_m)
    #fah_m.addObserver(fah)
    #fah_m.main()
    fah_m.Show()
    app.MainLoop()

if __name__ == "__main__":
    main()

----------------------------------------------------->8

I'm sure I'm doing something basically messed up here. I would like to keep the two sections of the program completely separate from each other, however, and only have them communicate to each other through notification. Can anybody help me straighten this out?

Thanks.
M.

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

massimo sandal wrote:

One other option is to embed PyCrust,\

I'll look for it. However it seems that the event-driven approach suggested here in the mailing list is not so inelegant and works pretty well

Yes, it's quite elegant. The problem is keeping the standard command line alive, which I think means it's running the main thread, and all your GUI stuff needs to be in a secondary thread. I know the SciPy folks had built and interpreter like this (called gui_thread, or something like that), but it never seemed to be that robust.

IF you were to use PyCrust, you could still use the same event-driven approach, but the command shell would be written in wxPython, so it could share the same thread.

JMF seems to have it working, however, and maybe ipython could help.

who/what's JMF?

Jean-Michel Fauth (sorry if I spelled that wrong!), author of PSI, and other nice stuff. I think he posted a note in this thread already.

http://www.chez.com/spinecho/

As for MPL, you may be able to catch the event with regular old wxPython, then translate from pixel to axes coords with MPL calls. It's probably built in already, however, I'd delve into the source of wxMpl. Sorry I haven't had the need for that yet.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

.: smilelover :. wrote:

Hi,
I have a app, where I have TextCtrls that are updated by hand or by dragging a Slider and I need to differentiate between the two ways. Is it possible to do it programmaticaly? Is there a way how to get this info from the Event?

Set a flag before you call SetValue programatically, and then check that flag in the EVT_TEXT handler. In 2.8 there is a new ChangeValue method that is the same as SetValue except it doesn't send the event.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!