Re: Need to interrupt to check for mouse movement

2005-07-21 Thread Peter Hansen
Jp Calderone wrote:
 In the particular case of wxWidgets, it turns out that the *GUI* blocks 
 for long periods of time, preventing the *network* from getting 
 attention.  But I agree with your position for other toolkits, such as 
 Gtk, Qt, or Tk.

Are you simply showing that there are two points of view here, that one 
can look at the wx main loop as being blocking, waiting for I/O, even 
though it is simply doing asynchronous event-driven processing the same 
as Twisted?  Or am I missing something?  Allowing for the fact that wx 
blocks, not just for long periods of time, but *indefinitely* (as long 
as no events are arriving) I still don't see how that makes it different 
from Twisted or from any other typical GUI framework, which do exactly 
the same thing.  (And since there is even a wxPython main loop 
integrated with and provided in Twisted, surely you aren't arguing that 
what wx does is somehow unusual or bad.)

Or are you simply saying that parts of wx are slow and take a while to 
complete operations?  If that's all, I haven't seen such behaviour... 
what areas are of concern?

-Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need to interrupt to check for mouse movement

2005-07-21 Thread stringy
Cheers for the replies people, but I got it sorted by just whacking in
wx.YieldIfNeeded() in the code before it communicates over the socket.
It's kind of jerky, but it works, where as before I'd click and drag,
and the 3d view wouldn't move for about 20 seconds.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need to interrupt to check for mouse movement

2005-07-21 Thread Jp Calderone
On Thu, 21 Jul 2005 00:51:45 -0400, Christopher Subich [EMAIL PROTECTED] 
wrote:
Jp Calderone wrote:

 In the particular case of wxWidgets, it turns out that the *GUI* blocks
 for long periods of time, preventing the *network* from getting
 attention.  But I agree with your position for other toolkits, such as
 Gtk, Qt, or Tk.

Wow, I'm not familiar with wxWidgets; how's that work?

wxWidgets' event loop doesn't differentiate between two unrelated (but similar 
sounding) concepts: blocking arbitrary input from the user (as in the case of 
modal dialogs) and blocking execution of code.

When you pop up a modal dialog, your code will not get another chance to run 
until the user dismisses it.  Similarly, as long as a menu is open, your code 
will not get to run.

Jp
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need to interrupt to check for mouse movement

2005-07-21 Thread Jp Calderone
On 20 Jul 2005 22:06:31 -0700, Paul Rubin http://phr.cx@nospam.invalid 
wrote:
Christopher Subich [EMAIL PROTECTED] writes:
  In the particular case of wxWidgets, it turns out that the *GUI*
  blocks for long periods of time, preventing the *network* from
  getting attention.  But I agree with your position for other
  toolkits, such as Gtk, Qt, or Tk.

 Wow, I'm not familiar with wxWidgets; how's that work?

Huh?  It's pretty normal, the gui blocks while waiting for events
from the window system.  I expect that Qt and Tk work the same way.

But not Gtk? :)  I meant what I said: wxWidgets behaves differently in this 
regard than Gtk, Qt, and Tk.

Jp
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need to interrupt to check for mouse movement

2005-07-21 Thread Jp Calderone
On Thu, 21 Jul 2005 05:42:32 -, Donn Cave [EMAIL PROTECTED] wrote:
Quoth Paul Rubin http://[EMAIL PROTECTED]:
| Christopher Subich [EMAIL PROTECTED] writes:
|   In the particular case of wxWidgets, it turns out that the *GUI*
|   blocks for long periods of time, preventing the *network* from
|   getting attention.  But I agree with your position for other
|   toolkits, such as Gtk, Qt, or Tk.
| 
|  Wow, I'm not familiar with wxWidgets; how's that work?
|
| Huh?  It's pretty normal, the gui blocks while waiting for events
| from the window system.  I expect that Qt and Tk work the same way.

In fact anything works that way, that being the nature of I/O.
But usually there's a way to add your own I/O source to be
dispatched along with the UI events -- the toolkit will for
example use select() to wait for X11 socket I/O, so it can also
respond to incoming data on another socket, provided along with a
callback function by the application.

Am I hearing that wxWindows or other popular toolkits don't provide
any such feature, and need multiple threads for this reason?


Other popular toolkits do.  wxWindows doesn't.

Jp
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need to interrupt to check for mouse movement

2005-07-21 Thread Jp Calderone
On Thu, 21 Jul 2005 02:33:05 -0400, Peter Hansen [EMAIL PROTECTED] wrote:
Jp Calderone wrote:
 In the particular case of wxWidgets, it turns out that the *GUI* blocks
 for long periods of time, preventing the *network* from getting
 attention.  But I agree with your position for other toolkits, such as
 Gtk, Qt, or Tk.

Are you simply showing that there are two points of view here, that one
can look at the wx main loop as being blocking, waiting for I/O, even
though it is simply doing asynchronous event-driven processing the same
as Twisted?  Or am I missing something?  Allowing for the fact that wx
blocks, not just for long periods of time, but *indefinitely* (as long
as no events are arriving) I still don't see how that makes it different
from Twisted or from any other typical GUI framework, which do exactly
the same thing.  (And since there is even a wxPython main loop
integrated with and provided in Twisted, surely you aren't arguing that
what wx does is somehow unusual or bad.)

Providing wx support in Twisted has been orders of magnitude more difficult 
than providing Tk, Qt, or Gtk support has been.  And wxsupport and wxreactor 
are each broken in slightly different ways, so I wouldn't say we've been 
successful, either.

Blocking inside the mainloop while waiting for events is fine.  It's blocking 
elsewhere that is problematic.

Jp
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need to interrupt to check for mouse movement

2005-07-21 Thread Christopher Subich
Paul Rubin wrote:
 Huh?  It's pretty normal, the gui blocks while waiting for events
 from the window system.  I expect that Qt and Tk work the same way.

Which is why I recommended Twisted for the networking; it integrates 
with the toolkit event loops so it automagically works: 
http://twistedmatrix.com/projects/core/documentation/howto/choosing-reactor.html#auto15

I agree, though, that basic socket programming in the same thread as the 
gui's probably a bad idea.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need to interrupt to check for mouse movement

2005-07-21 Thread Peter Hansen
Jp Calderone wrote:
 On Thu, 21 Jul 2005 02:33:05 -0400, Peter Hansen [EMAIL PROTECTED] wrote:
 (And since there is even a wxPython main loop
 integrated with and provided in Twisted, surely you aren't arguing that
 what wx does is somehow unusual or bad.)
 
 Blocking inside the mainloop while waiting for events is fine.  It's 
 blocking elsewhere that is problematic.

Thanks for the clarification.  I can see how a wx modal dialog could 
cause trouble, though I didn't know holding a menu open had the same 
nasty behaviour.

For me, this is merely justification to continue using separate threads 
for wxPython's main loop and for anything else, which has worked well 
for me whether I've been using Twisted or not.

-Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Need to interrupt to check for mouse movement

2005-07-20 Thread stringy
I have a program that shows a 3d representation of a cell, depending on
some data that it receives from some C++. It runs with wx.timer(500),
and on wx.EVT_TIMER, it updates the the data, and receives it over the
socket.
In my program I also want to be able to rotate the 3d representation,
and can do so, and all the code works. However, I have a problem in
that while the program is updating itself (pretty much all the time
unless I tell it not to), it won't detect mouse motion, I'm guessing
because it doesn't have time to.

Is there any manual way to get a program to check for mouse movement,
that way I'd be able to check for mouse movement half way through my
updating the data over the socket, and then do the necessary rotations
before it finishes updating the data.

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need to interrupt to check for mouse movement

2005-07-20 Thread MooMaster
Have you tried binding EVT_MOTION(func) to your window?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need to interrupt to check for mouse movement

2005-07-20 Thread Peter Hansen
stringy wrote:
 I have a program that shows a 3d representation of a cell, depending on
 some data that it receives from some C++. It runs with wx.timer(500),
 and on wx.EVT_TIMER, it updates the the data, and receives it over the
 socket.

It's generally inappropriate to have a GUI program do network 
communications in the main GUI thread.  You should create a worker 
thread and communicate with it using Queues and possibly the 
AddPendingEvent() or PostEvent() methods in wx.  There should be many 
easily accessible examples of how to do such things.  Post again if you 
need help finding them.

-Peter
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need to interrupt to check for mouse movement

2005-07-20 Thread Christopher Subich
Peter Hansen wrote:
 stringy wrote:
 
 I have a program that shows a 3d representation of a cell, depending on
 some data that it receives from some C++. It runs with wx.timer(500),
 and on wx.EVT_TIMER, it updates the the data, and receives it over the
 socket.
 
 
 It's generally inappropriate to have a GUI program do network 
 communications in the main GUI thread.  You should create a worker 
 thread and communicate with it using Queues and possibly the 
 AddPendingEvent() or PostEvent() methods in wx.  There should be many 
 easily accessible examples of how to do such things.  Post again if you 
 need help finding them.

I'd argue that point; it's certainly inappropriate to do 
(long-)/blocking/ network communications in a main GUI thread, but 
that's just the same as any blocking IO.  If the main thread is blocked 
on IO, it can't respond to the user which is Bad.

However, instead of building threads (possibly needlessly) and dealing 
with synchronization issues, I'd argue that the solution is to use a 
nonblocking network IO package that integrates with the GUI event loop. 
  Something like Twisted is perfect for this task, although it might 
involve a significant application restructuring for the grandparent poster.

Since blocking network IO is generally slow, this should help the 
grandparent poster -- I am presuming that the program updating itself 
is an IO-bound, rather than processor-bound process.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need to interrupt to check for mouse movement

2005-07-20 Thread Jp Calderone
On Thu, 21 Jul 2005 00:18:58 -0400, Christopher Subich [EMAIL PROTECTED] 
wrote:
Peter Hansen wrote:
 stringy wrote:

 I have a program that shows a 3d representation of a cell, depending on
 some data that it receives from some C++. It runs with wx.timer(500),
 and on wx.EVT_TIMER, it updates the the data, and receives it over the
 socket.


 It's generally inappropriate to have a GUI program do network
 communications in the main GUI thread.  You should create a worker
 thread and communicate with it using Queues and possibly the
 AddPendingEvent() or PostEvent() methods in wx.  There should be many
 easily accessible examples of how to do such things.  Post again if you
 need help finding them.

I'd argue that point; it's certainly inappropriate to do
(long-)/blocking/ network communications in a main GUI thread, but
that's just the same as any blocking IO.  If the main thread is blocked
on IO, it can't respond to the user which is Bad.

However, instead of building threads (possibly needlessly) and dealing
with synchronization issues, I'd argue that the solution is to use a
nonblocking network IO package that integrates with the GUI event loop.
  Something like Twisted is perfect for this task, although it might
involve a significant application restructuring for the grandparent poster.

Since blocking network IO is generally slow, this should help the
grandparent poster -- I am presuming that the program updating itself
is an IO-bound, rather than processor-bound process.

In the particular case of wxWidgets, it turns out that the *GUI* blocks for 
long periods of time, preventing the *network* from getting attention.  But I 
agree with your position for other toolkits, such as Gtk, Qt, or Tk.

Jp
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need to interrupt to check for mouse movement

2005-07-20 Thread Christopher Subich
Jp Calderone wrote:

 In the particular case of wxWidgets, it turns out that the *GUI* blocks 
 for long periods of time, preventing the *network* from getting 
 attention.  But I agree with your position for other toolkits, such as 
 Gtk, Qt, or Tk.

Wow, I'm not familiar with wxWidgets; how's that work?
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need to interrupt to check for mouse movement

2005-07-20 Thread Paul Rubin
Christopher Subich [EMAIL PROTECTED] writes:
  In the particular case of wxWidgets, it turns out that the *GUI*
  blocks for long periods of time, preventing the *network* from
  getting attention.  But I agree with your position for other
  toolkits, such as Gtk, Qt, or Tk.
 
 Wow, I'm not familiar with wxWidgets; how's that work?

Huh?  It's pretty normal, the gui blocks while waiting for events
from the window system.  I expect that Qt and Tk work the same way.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Need to interrupt to check for mouse movement

2005-07-20 Thread Donn Cave
Quoth Paul Rubin http://[EMAIL PROTECTED]:
| Christopher Subich [EMAIL PROTECTED] writes:
|   In the particular case of wxWidgets, it turns out that the *GUI*
|   blocks for long periods of time, preventing the *network* from
|   getting attention.  But I agree with your position for other
|   toolkits, such as Gtk, Qt, or Tk.
|  
|  Wow, I'm not familiar with wxWidgets; how's that work?
|
| Huh?  It's pretty normal, the gui blocks while waiting for events
| from the window system.  I expect that Qt and Tk work the same way.

In fact anything works that way, that being the nature of I/O.
But usually there's a way to add your own I/O source to be
dispatched along with the UI events -- the toolkit will for
example use select() to wait for X11 socket I/O, so it can also
respond to incoming data on another socket, provided along with a
callback function by the application.

Am I hearing that wxWindows or other popular toolkits don't provide
any such feature, and need multiple threads for this reason?

Donn Cave, [EMAIL PROTECTED]
-- 
http://mail.python.org/mailman/listinfo/python-list