Re: Correct abstraction for TK

2007-07-03 Thread Laurent Pointal
[EMAIL PROTECTED] a écrit :
 I'm looking for a good example of how to correctly abstract TK code
 from the rest of my program. I want to just get some user info and
 then get 4 values from the GUI. Right now I've written it OOP per the
 examples on python.org but it doesn't seem to be meshing very well
 with the rest of my project.
 
 Can anyone suggest some examples so that I can get more ideas?
 
 Thanks,
 Luke
 

Maybe try with easygui [1]. The multenterbox [2] seem to be right to 
enter 4 values [3]... Its really a nice tool to have a quick and clean 
user input solution with GUI in a function.

A+

Laurent.

[1] http://www.ferg.org/easygui/
[2] http://www.ferg.org/easygui/screenshot-multenterbox.png
[3] From the doc:
MULTENTERBOX AND MULTPASSWORDBOX --
GETTING INFORMATION FROM THE USER ABOUT MULTIPLE FIELDS
===

Multenterbox is a simple way of showing multiple enterboxes on a single
screen.  Multpasswordbox has the same interface as multenterbox, but
when it is displayed, the last of the fields is assumed to be a
password, and is masked with asterisks.

def multenterbox(message=Fill in values for the fields.
 , title=
 , argListOfFieldNames  = []
 , argListOfFieldValues = []
 ):
 Show screen with multiple data entry fields.
 The third argument is a list of fieldnames.
 The the forth argument is a list of field values.

 If there are fewer values than names, the list of values is padded
 with empty strings until the number of values is the same as the
 number of names.

 If there are more values than names, the list of values
 is truncated so that there are as many values as names.

 Returns a list of the values of the fields,
 or None if the user cancels the operation.

 Here is some example code, that shows how values returned from
 multenterbox can be checked for validity before they are accepted.
 --
 msg = Enter your personal information
 title = Credit Card Application
 fieldNames = [Name,Street Address,City,State,ZipCode]
 fieldValues = []  # we start with blanks for the values
 fieldValues = multenterbox(msg,title, fieldNames)

 # make sure that none of the fields was left blank
 while 1:
 if fieldValues == None: break
 errmsg = 
 for i in range(len(fieldNames)):
if fieldValues[i].strip() == :
errmsg = errmsg + ('%s is a required field.\n\n' %
fieldNames[i])
 if errmsg == : break # no problems found
 fieldValues = multenterbox(errmsg, title, fieldNames,
 fieldValues)

 print Reply was:, fieldValues
 
 
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Correct abstraction for TK

2007-07-03 Thread Paul Rubin
[EMAIL PROTECTED] writes:
 I'm looking for a good example of how to correctly abstract TK code
 from the rest of my program. I want to just get some user info and
 then get 4 values from the GUI. Right now I've written it OOP per the
 examples on python.org but it doesn't seem to be meshing very well
 with the rest of my project.

Simplest: just have gui operations call the application code.  The
application main loop is just the gui event loop.  Example (first tk
program I ever wrote, and one of my first python programs):

   http://www.nightsong.com/phr/python/calc.py

That might be enough for what you're doing.

Fancier: put gui in separate thread.  Be careful, it's not reentrant;
all communication with the application has to be through queues, sort
of like writing a miniature web server.  Most straightforward is to
pass tuples like (function, args, **kwargs) through the queues, where
the opposite end invokes the function on the arg list.  There are some
recipes in the Python cookbook for triggering the event loop on a
periodic timeout from inside tkinter.

See also model-view-controller for a more complex design approach
intended to separate the interface from the application logic.

Finally, consider total separation by embedding an http server in the
application, so the gui is a web browser and you write a web app.
It's often easier to code a simple html interface than to mess with
the damn Tk widgets and trying to get them to look decent on the
screen, plus it lets you easily put the client on a remote machine,
support multiple clients simultaneously, etc.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Correct abstraction for TK

2007-07-03 Thread Luke Hoersten
Thanks for all the suggestions guys. I'm realizing that I need to
chose more of a specific paradigm. With closures, I was able to stay
away from unneeded classes before but Tk brings it to a whole other
level.

Thanks again,
Luke

On Jul 3, 2:50 am, Paul Rubin http://[EMAIL PROTECTED] wrote:
 [EMAIL PROTECTED] writes:
  I'm looking for a good example of how to correctly abstract TK code
  from the rest of my program. I want to just get some user info and
  then get 4 values from the GUI. Right now I've written it OOP per the
  examples on python.org but it doesn't seem to be meshing very well
  with the rest of my project.

 Simplest: just have gui operations call the application code.  The
 application main loop is just the gui event loop.  Example (first tk
 program I ever wrote, and one of my first python programs):

http://www.nightsong.com/phr/python/calc.py

 That might be enough for what you're doing.

 Fancier: put gui in separate thread.  Be careful, it's not reentrant;
 all communication with the application has to be through queues, sort
 of like writing a miniature web server.  Most straightforward is to
 pass tuples like (function, args, **kwargs) through the queues, where
 the opposite end invokes the function on the arg list.  There are some
 recipes in the Python cookbook for triggering the event loop on a
 periodic timeout from inside tkinter.

 See also model-view-controller for a more complex design approach
 intended to separate the interface from the application logic.

 Finally, consider total separation by embedding an http server in the
 application, so the gui is a web browser and you write a web app.
 It's often easier to code a simple html interface than to mess with
 the damn Tk widgets and trying to get them to look decent on the
 screen, plus it lets you easily put the client on a remote machine,
 support multiple clients simultaneously, etc.


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


Correct abstraction for TK

2007-07-02 Thread luke . hoersten
I'm looking for a good example of how to correctly abstract TK code
from the rest of my program. I want to just get some user info and
then get 4 values from the GUI. Right now I've written it OOP per the
examples on python.org but it doesn't seem to be meshing very well
with the rest of my project.

Can anyone suggest some examples so that I can get more ideas?

Thanks,
Luke

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


Re: Correct abstraction for TK

2007-07-02 Thread Adonis Vargas
[EMAIL PROTECTED] wrote:
 I'm looking for a good example of how to correctly abstract TK code
 from the rest of my program. I want to just get some user info and
 then get 4 values from the GUI. Right now I've written it OOP per the
 examples on python.org but it doesn't seem to be meshing very well
 with the rest of my project.
 
 Can anyone suggest some examples so that I can get more ideas?
 
 Thanks,
 Luke
 

I would not consider this to be 'correct' as many have different 
philosophies on how to tackle certain projects. My way of doing 
programming with GUI is writing it in 'tiers' (using this word loosely).

i.e.

import Tkinter as tk

class UsersInfo:

 pass

class Events(UserInfo):

 pass

class GUI(Events):

 pass

This way your GUI class sends events to the Events class to act upon the 
UserInfo class. For the GUI class here all you do is code the actual 
display and the callbacks only. Then in the Events class you code the 
actions you want to happen when you interact the the GUI. Since the GUI 
class inherits the Events class, in the GUI class you would simply call 
a method found in the Events class when an event is triggered. Now the 
Events class which inherits the UserInfo class, you can start using the 
class to store/modify the user data you desire. Now your code is 
separated into more comprehensible, and easier to manage sections. In 
this example I am using inheritance, but if you prefer delegation, then 
that too can be done here. Also, by doing this it will simplify the 
moving to more robust graphic toolkits with little modification.

Hope this helps.

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