[Tutor] [tutor] threading problem in GUI
Pierre Barbier de Reuille
pierre.barbier at cirad.fr
Thu Sep 8 09:43:14 CEST 2005
Great :)
Just to be clear about that: you can see the "connect" line as a dynamic
registration process (with the symetric disconnect operation available
via ... "disconnect"). The only thing you need is to connect (at
runtime) the even before it's called (obvious isn't it ? ;) ), but you
have no other constraint. You can even choose to connect/disconnect
events when they are used/unused ... You can also connect a single event
many times (to different functions) or you can connect many events to
the same function. This is the "power" of this system :) Like now if you
want to log your strings on a file, you just define the function writing
in the file and connect the event to this function: you'll have both the
GUI and the log-file outputs !
This is, AFAIK, the best existing implementation for user interfaces !
Pierre
nephish a écrit :
> Pierre Barbier de Reuille wrote:
>
>> nephish a écrit :
>>
>>
>>> one more thing.
>>> if i uncomment the lines
>>> gtk.threads_enter()
>>> and
>>> gtk.threads_leave()
>>> the whole thing locks up when the function is called.
>>> the gui, and the thread both lock up.
>>>
>>
>>
>> Well, that's just normal. However, what you should do is to send a
>> signal from your thread with the text to append in your textbuffer.
>> Then, you catch the signal in your main widget to show it !
>>
>> To emit a signal use :
>>
>> gtk.gdk.threads_enter()
>> self.emit("writing", str)
>> gtk.gdk.threads_leave()
>>
>> To catch it:
>>
>>
>> emitting_object.connect("writing", self.method_handling_to_signal)
>>
>> Well, I used that and it just work ! Using the signal does not solve any
>> threading problem but allow you to separate between the event and the
>> answer to the event, which is a good habit to take !
>>
>> Pierre
>>
>>
>>
>>
> I finally got it working !!
> thanks so much for all your help
> i would not have gotten it working without you,
> (or this mailing list)
>
> God bless
> shawn
>
--
Pierre Barbier de Reuille
INRA - UMR Cirad/Inra/Cnrs/Univ.MontpellierII AMAP
Botanique et Bio-informatique de l'Architecture des Plantes
TA40/PSII, Boulevard de la Lironde
34398 MONTPELLIER CEDEX 5, France
tel : (33) 4 67 61 65 77 fax : (33) 4 67 61 56 68
More information about the Tutor
mailing list