473,378 Members | 1,312 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

GUI Wizard: flow control?

Hi,

I'm trying to use python to create GUI wizards, i.e. sequences of dialog
boxes with <BACK and NEXT> buttons. Since I want to re-use some of the
dialog boxes in different wizards, I want to have a main function which
calls each dialog box, much like this:

def select_item():
"""runs GUI wizard to select item"""

client = show_client_dialog()
job = show_job_dialog(client)
invoice, rate = show_invoice_dialog(job)
item = choose_item_dialog(invoice, rate)
return item

This works fine until you want to implement the <BACK button, which should
return to the previous dialog. Theoretically, what I'd really like is to be
able to jump backwards through the control flow, like this:

class GoBack(Exception): pass
def select_item():
"""runs GUI wizard to select item - can go <BACK"""
back = HERE
client = show_client_dialog()

try: job = show_job_dialog(client)
except GoBack: back.goto()
back = HERE

try: invoice, rate = show_invoice_dialog(job)
except GoBack: back.goto()
back = HERE

try: item = show_item_dialog(invoice, rate)
except GoBack: back.goto()

return item

But I couldn't find a way of doing anything like that. You could do
something almost as unhorrible with nested breaks:'

class GoBack(Exception): pass
def select_item():
"""runs GUI wizard to select item - can go <BACK"""
CLIENT: while 1:
client = show_client_dialog()

JOB: while 1:
try: job = show_job_dialog(client)
except GoBack: continue CLIENT

INVOICE: while 1:
try: invoice, rate = show_invoice_dialog(job)
except GoBack: continue JOB

try: item = show_item_dialog(invoice, rate)
except GoBack: continue INVOICE
break CLIENT

Or you could do all the flow control manually in a "do_wizard" function and
make the caller create a horrible data structure instead of writing readable
code:

calls = [
{'meth': show_client_dialog, 'args': [], 'ret': ['client']},
{'meth': show_job_dialog, 'args': ['client'], 'ret': ['job']},
{'meth': show_invoice_dialog, 'args': ['job'], 'ret': ['invoice', 'rate']},
{'meth': show_item_dialog, 'args': ['invoice', 'rate'], 'ret': ['item']},
] # this just says: "client = show_client_dialog()", etc.
do_wizard(calls, locals())
But this is too hideous to deploy, because I might have to remember what it
does in six months :-)

Can anyone suggest something better, or should I abandon my goal of having a
main function which calls each dialog box?

Many thanks,
--
David Chan
Clockwork Software Systems

intY has scanned this email for all known viruses (www.inty.com)

Jul 18 '05 #1
1 2835
David Chan wrote:
Hi,

I'm trying to use python to create GUI wizards, i.e. sequences of dialog
boxes with <BACK and NEXT> buttons. Since I want to re-use some of the
dialog boxes in different wizards, I want to have a main function which
calls each dialog box, much like this:

def select_item():
"""runs GUI wizard to select item"""

client = show_client_dialog()
job = show_job_dialog(client)
invoice, rate = show_invoice_dialog(job)
item = choose_item_dialog(invoice, rate)
return item

This works fine until you want to implement the <BACK button, which should
return to the previous dialog. Theoretically, what I'd really like is to be
able to jump backwards through the control flow, like this:

class GoBack(Exception): pass
def select_item():
"""runs GUI wizard to select item - can go <BACK"""
back = HERE
client = show_client_dialog()

try: job = show_job_dialog(client)
except GoBack: back.goto()
back = HERE

try: invoice, rate = show_invoice_dialog(job)
except GoBack: back.goto()
back = HERE

try: item = show_item_dialog(invoice, rate)
except GoBack: back.goto()

return item

But I couldn't find a way of doing anything like that. You could do
something almost as unhorrible with nested breaks:'

class GoBack(Exception): pass
def select_item():
"""runs GUI wizard to select item - can go <BACK"""
CLIENT: while 1:
client = show_client_dialog()

JOB: while 1:
try: job = show_job_dialog(client)
except GoBack: continue CLIENT

INVOICE: while 1:
try: invoice, rate = show_invoice_dialog(job)
except GoBack: continue JOB

try: item = show_item_dialog(invoice, rate)
except GoBack: continue INVOICE
break CLIENT

Or you could do all the flow control manually in a "do_wizard" function and
make the caller create a horrible data structure instead of writing readable
code:

calls = [
{'meth': show_client_dialog, 'args': [], 'ret': ['client']},
{'meth': show_job_dialog, 'args': ['client'], 'ret': ['job']},
{'meth': show_invoice_dialog, 'args': ['job'], 'ret': ['invoice', 'rate']},
{'meth': show_item_dialog, 'args': ['invoice', 'rate'], 'ret': ['item']},
] # this just says: "client = show_client_dialog()", etc.
do_wizard(calls, locals())
But this is too hideous to deploy, because I might have to remember what it
does in six months :-)

Can anyone suggest something better, or should I abandon my goal of having a
main function which calls each dialog box?

Many thanks,


Caveat: I am assuming that your chosen GUI allows you to easily choose
which of a number of panels is displayed inside a dialog. This is
typically most easily done with the component usually known as a notebook.

You create a list a panels, each of which you have constructed using
your chosen GUI. You then associate the "Next" button with a function
that displays the next panel in the sequence, and the "Back" button with
a function that displays the preceding panel in the sequence.

The dialog then becomes just a list of the panels, plus a counter to
tell you which in the sequence is currently being displayed.

You *don't* want to try and control flow through the sequence in the way
you have attempted. Typically windows are actually just data structures,
and so data-driven methods will work best.

Naturally, each of the panels in the notebook will have callbacks
associated with the various widgets, and interaction with those widgets
will change the data that your program eventually sees when the user
clicks the "Finish" button.

If you want to reuse the panels then make sure they are properly
modularized so their creators can be called used in different programs.

regards
Steve
Jul 18 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Miyra | last post by:
Hi. I'm working with an app that uses exceptions for control flow. These are code blocks where exceptions are thrown/caught regularly. A couple hundred exceptions occur per hour and they're caught...
9
by: Alvin Bruney [MVP] | last post by:
Exceptions must not be used to control program flow. I intend to show that this statement is flawed. In some instances, exceptions may be used to control program flow in ways that can lead to...
2
by: Nick | last post by:
Is there anyway to get a javascript confirm button on the wizard control so that when a user clicks "cancel" it can prompt something like... "Are you sure you want to cancel? Your changes will...
2
by: John R. Lewis | last post by:
I posted this yesterday with a different email address. I am reposting with my fake-address as given to me by Microsoft so that I can be guraranteed a response from a support representative. Sorry...
6
by: Douglas J. Badin | last post by:
Earlier this month, there was a posting about this without a definitive answer. If you place a Wizard inside a FormView's EditItemTemplate the bound fields contained within the View will display...
2
by: brianlum | last post by:
Hi, I have been looking for a good way to convert python code into a control flow graph. I know of Python functions that will convert an expression into an abstract syntax tree (i.e. ast =...
4
by: Dabbler | last post by:
I have a Wizard control with each step using a user control. It seems the page_load of each user control is called everytime a postback event occurs in any step. Is there away to communicate to a...
12
by: raghav | last post by:
Hi I am working on ASP.NET 2.0. I am developing a website using Wizard control. Based on number of steps added, next, previous, finish buttons generate automatically. After running the...
8
by: GaryDean | last post by:
I have a Wizard page and need to affect the next and previous buttons from my code-behind. I've googled around and found two solutions, and neither appear to work. I can access the SideBarList...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.