Organization of GUIs

2009-12-03 Thread Michael Mossey
I have a question about typical organization of GUIs. I will be using
PyQt.

I have mostly used Python and C++ in my professional life, but I just
took an 8 month detour into using a functional programming language
called Haskell. Haskell is pure meaning that for the most part data
is not mutable, or if it is mutable, access to it is controlled very
carefully. This got me thinking about how mutable data can make
program behavior complicated and difficult to understood/prove-
correct.  I am returning to Python and PyQt for my next project, but I
come away inspired to do things a little differently.

For example, in GUIs I've written in the past, typically there are a
lot of GUI objects (windows, data repositories, etc.) that talk to
each other. One object might send messages about a change in its state
to other objects that are watching it.

I am now wondering if I should write a GUI so that everything is in a
true hierarchy, rather than a tangle of objects with democratic
relationships---and more specifically, that messages (which may cause
state to be changed in the receiver of the message) should first go up
the hierarchy until they reach the right level, and then down to the
ultimate receiver of the message. This way a parent object in the
hierarchy has complete visibility and control of messages passing
between its children, leading to the possibility of consolidating the
code and documentation about the children's mutability in one place
(the parent).

But honestly, I have never really studied how good existing GUI
programs are organized. Always flew by the seat of my pants. So I'm
interested in someone has thoughts about this, maybe can point me to a
good book, etc.
Thanks,
Mike
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Organization of GUIs

2009-12-03 Thread Michael Mossey
On Dec 3, 6:38 am, Lie Ryan lie.1...@gmail.com wrote:
 On 12/4/2009 12:44 AM, Michael Mossey wrote:

  I have a question about typical organization of GUIs. I will be using
  PyQt.

 Model-View-Controller (MVC) pattern.

 Model - all the business logic lives in the model.
 View - your GUI
 Controller - Takes input

 Controller notifies Model if there is user input; Model notifies View if
 there is an update in the model; View notifies user if there is an
 update in the model; User notifies controller of the changes wanted.

 http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93controller

I'm aware of Model-View-Controller, but my question is broader than
that for a couple reasons:

View can be fine-grained. Often the View consists of a number of GUI
objects. Some people write this in a democratic arrangement---they all
talk to each other. This can make analyzing system behavior
complicated. Hence my proposal for a hierarchy.

Also, often different parts of the Model talk to different parts of
the View. The question, then, is whether both the Model and View
should be structured hierarchically so that all messages pass through
a master or root object before going to the other Model/View, and
messages within a Model or View should only move along the hierarchy.

In other words, you can easily make a complete mess of MVC.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help with threads

2009-08-08 Thread Michael Mossey
On Aug 7, 5:03 pm, Piet van Oostrum p...@cs.uu.nl wrote:
  Michael Mossey michaelmos...@gmail.com (MM) wrote:
 MM Ah yes, that explains it. Some of these long computations are done in
 MM pure C, so I'm sure the GIL is not being released.

 Is that C code under your own control? Or at least the glue from Python
 to C? In that case, and if the C code is not manipulating Python objects
 or something in the Python interpreter, it could be changed to release
 the GIL during the computation. That's also how Numpy does it, IIRC.
 --
 Piet van Oostrum p...@cs.uu.nl
 URL:http://pietvanoostrum.com[PGP 8DAE142BE17999C4]
 Private email: p...@vanoostrum.org

I don't have any control over this code, and it's easier to solve my
problem in other ways. I just put a sleep() call between calls to the
C library, and that gives the network thread enough responsiveness for
my particular task. I am grateful, anyway, to understand why this kind
of thing happens.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: help with threads

2009-08-07 Thread Michael Mossey
Ah yes, that explains it. Some of these long computations are done in
pure C, so I'm sure the GIL is not being released.
Thanks.
-- 
http://mail.python.org/mailman/listinfo/python-list


help with threads

2009-08-06 Thread Michael Mossey
Hello,

I have a simple application that needs one thread to manage networking
in addition to the main thread that does the main job. It's not
working right. I know hardly anything about threads, so I was hoping
someone could point me in the right direction to research this.

Basically, I have a program that does some computational work, and
also conveys its status to a monitor program elsewhere on the network
via sockets. I wanted to use a thread to manage the networking so that
the main program can run without regard to networking (i.e. they would
be asynchronous). So the network thread loops and calls select.

My problem is that in some cases, the network thread appears to stop,
while the main thread is doing a long computation.

I'm hoping someone can give me a general idea what to read about. For
example, under what conditions does a thread stop running? Can other
threads take priority? Are there certain operations that block other
threads (such as disk access)?

Thanks,
Mike
-- 
http://mail.python.org/mailman/listinfo/python-list


Catching control-C

2009-07-06 Thread Michael Mossey
What is required in a python program to make sure it catches a control-
c on the command-line? Do some i/o? The OS here is Linux.

Thanks,
Mike
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Catching control-C

2009-07-06 Thread Michael Mossey
On Jul 6, 2:47 pm, Philip Semanchuk phi...@semanchuk.com wrote:
 On Jul 6, 2009, at 5:37 PM, Michael Mossey wrote:

  What is required in a python program to make sure it catches a  
  control-
  c on the command-line? Do some i/o? The OS here is Linux.

 You can use a try/except to catch a KeyboardInterrupt exception, or  
 you can trap it using the signal 
 module:http://docs.python.org/library/signal.html

 You want to trap SIGINT.

 HTH
 Philip

Thanks to both of you. However, my question is also about whether I
need to be doing i/o or some similar operation for my program to
notice in any shape or form that Control-C has been pressed. In the
past, I've written Python programs that go about their business
ignoring Ctrl-C. Other programs respond to it immediately by exiting.
I think the difference is that the latter programs are doing i/o. But
I want to understand better what the secret is to responding to a
ctrl-C in any shape or form.

For example, does trapping SIGINT always work, regardless of what my
process is doing?

Thanks,
Mike
-- 
http://mail.python.org/mailman/listinfo/python-list