Need Dynamic Menu Code 
Author Message
 Need Dynamic Menu Code

How can you create dynamic menus in Python?  Imagine 2 pull-down
menus, one for Country, the other for Language.  Your selection of
Country establishes the choices/values on the Languages menu
(consisting of either native language of selected country or English).

We can do this easily in ASP.  But how can we do it in Python?  Advice
and input would be greatly appreciated...

Thanks



Tue, 22 Jun 2004 01:52:12 GMT  
 Need Dynamic Menu Code

Quote:
>How can you create dynamic menus in Python?  Imagine 2 pull-down
>menus, one for Country, the other for Language.  Your selection of
>Country establishes the choices/values on the Languages menu
>(consisting of either native language of selected country or English).

>We can do this easily in ASP.  But how can we do it in Python?  Advice
>and input would be greatly appreciated...

Disclaimer: I'm not much of an ASP fan.

ASP is just HTML with special VB Script between <% and %>. So you're
probably talking about (D)HTML menus and not "GUI" menus. ASP is a
server-side technique, which allows you to use a language that makes
perl shine syntaxwise to generate HTML. Whatever the client sees is
only HTML, therefor you can generate it in any language you like. [You
could do server-side scripting in Brain{*filter*} if so you desired (see
http://www.*-*-*.com/ {*filter*}/utils/mod_bf-0.2/) and have the
most annoying proprietary tags be generated by programs that look like
this: http://www.*-*-*.com/ {*filter*}/bf-source/prog/HELLOBF2.BF)

If you generate a Menu in ASP, you generate HTML tags. The HTML tags
are just strings. So, if the user chooses one thing, some strings are
printed, if the user chooses another string, something else gets
printed. Its not only simple in ASP, its simple in most programming
languages (but not in Brain{*filter*}). What you need to know is

a) The choice the user has made
b) What HTML tags to display depending upon the choice of the user.

The thing about webprogramming is that there are so many alternatives
use. I don't know if you use

- a python CGI
- a mod_python script
- a python script that just generates static HTML for khttpd ;)
- Client-Side Scripting with Python (IE only)
- Server-Side Scripting with Python (IIS only)
- your homegrown webserver based on the SocketServer class
- a java applet that embedds jython
- a java applet that embedds jython which runs a python-powered
brain{*filter*} interpreter ( http://www.*-*-*.com/ )
- a python interpreter written in mod_bf
etc...

All mechanisms differ in

- how data is transfered from the user (the webbrowser) to the
application (the webserver / the client in case d)
- how HTML tags are generated.

They do NOT differ in the fact that "a dynamic menu" is just a string
that gets generated based on user choice. If you can detail which one
of the methods above you want to use, I can perhaps give you an
example of generating different HTML tags based on user choice.

Here is a very elaborate CGI for dynamic menus in python:
-------------------------------------------------------------
#!/usr/bin/python -u

# print "language menu"
print '''Content-type: text/html

<html><p>The users choice is either
<a href="/cgi-bin/dynamic_menu.py?cmd=english">english</a> or
<a href="/cgi-bin/dynamic_menu.py?cmd=german">german</a>.</p>
'''

import cgi
form = cgi.FieldStorage()

# get the users choice
cmd = None
if form.has_key('cmd'):
    cmd = form['cmd'].value

# display the various "menus"
if cmd == 'english':
    print '<p>This is the fancy english menu</p>'
elif cmd == 'german':
    print '<p>Das ist das alberne Deutschmenue</p>'
else:
    print '<p>The user has not decided on a language yet.</p>'
--------------------------------------------------------------



Tue, 22 Jun 2004 02:48:57 GMT  
 Need Dynamic Menu Code
THANK YOU for your detailed reply.  We are using server-side scripting
with Python on IIS.  Would you still recommend the "elaborate CGI for
dynamic menus in python" code you so kindly provided us, or would you
recommend something else?

Thanks again for all your help.

Quote:


> >How can you create dynamic menus in Python?  Imagine 2 pull-down
> >menus, one for Country, the other for Language.  Your selection of
> >Country establishes the choices/values on the Languages menu
> >(consisting of either native language of selected country or English).

> >We can do this easily in ASP.  But how can we do it in Python?  Advice
> >and input would be greatly appreciated...

> Disclaimer: I'm not much of an ASP fan.

> ASP is just HTML with special VB Script between <% and %>. So you're
> probably talking about (D)HTML menus and not "GUI" menus. ASP is a
> server-side technique, which allows you to use a language that makes
> perl shine syntaxwise to generate HTML. Whatever the client sees is
> only HTML, therefor you can generate it in any language you like. [You
> could do server-side scripting in Brain{*filter*} if so you desired (see
> http://www.*-*-*.com/ {*filter*}/utils/mod_bf-0.2/) and have the
> most annoying proprietary tags be generated by programs that look like
> this: http://www.*-*-*.com/ {*filter*}/bf-source/prog/HELLOBF2.BF)

> If you generate a Menu in ASP, you generate HTML tags. The HTML tags
> are just strings. So, if the user chooses one thing, some strings are
> printed, if the user chooses another string, something else gets
> printed. Its not only simple in ASP, its simple in most programming
> languages (but not in Brain{*filter*}). What you need to know is

> a) The choice the user has made
> b) What HTML tags to display depending upon the choice of the user.

> The thing about webprogramming is that there are so many alternatives
> use. I don't know if you use

> - a python CGI
> - a mod_python script
> - a python script that just generates static HTML for khttpd ;)
> - Client-Side Scripting with Python (IE only)
> - Server-Side Scripting with Python (IIS only)
> - your homegrown webserver based on the SocketServer class
> - a java applet that embedds jython
> - a java applet that embedds jython which runs a python-powered
> brain{*filter*} interpreter ( http://www.*-*-*.com/ )
> - a python interpreter written in mod_bf
> etc...

> All mechanisms differ in

> - how data is transfered from the user (the webbrowser) to the
> application (the webserver / the client in case d)
> - how HTML tags are generated.

> They do NOT differ in the fact that "a dynamic menu" is just a string
> that gets generated based on user choice. If you can detail which one
> of the methods above you want to use, I can perhaps give you an
> example of generating different HTML tags based on user choice.

> Here is a very elaborate CGI for dynamic menus in python:
> -------------------------------------------------------------
> #!/usr/bin/python -u

> # print "language menu"
> print '''Content-type: text/html

> <html><p>The users choice is either
> <a href="/cgi-bin/dynamic_menu.py?cmd=english">english</a> or
> <a href="/cgi-bin/dynamic_menu.py?cmd=german">german</a>.</p>
> '''

> import cgi
> form = cgi.FieldStorage()

> # get the users choice
> cmd = None
> if form.has_key('cmd'):
>     cmd = form['cmd'].value

> # display the various "menus"
> if cmd == 'english':
>     print '<p>This is the fancy english menu</p>'
> elif cmd == 'german':
>     print '<p>Das ist das alberne Deutschmenue</p>'
> else:
>     print '<p>The user has not decided on a language yet.</p>'
> --------------------------------------------------------------



Wed, 23 Jun 2004 00:15:32 GMT  
 Need Dynamic Menu Code


Quote:
> THANK YOU for your detailed reply.  We are using server-side scripting
> with Python on IIS.  Would you still recommend the "elaborate CGI for
> dynamic menus in python" code you so kindly provided us, or would you
> recommend something else?

> Thanks again for all your help.

If you're forced to use IIS (such as I am), glad to see you went with
Python!

You should be aware of how to jump between pages with information, a simple
form post.

But, if you want a DHTML solution, here's a simple ex.

(Careful of newsreader wrapping)


<%
menu1 = ('stooges', 'colors', 'langs')

submenus = {
        'stooges': ('moe', 'larry', 'curly'),
        'colors': ('blue', 'green', 'red'),
        'langs': ('python', 'ruby', 'scheme')

Quote:
}

%>
<form name=theForm>
<select name=first size=1 onChange='jsfunc()'>
<%
for item in menu1:
        Response.Write('<option>%s' % item)
%>
</select>

<br><br>

<select name=second size=1>
<%
for item in submenus['stooges']:
        Response.Write('<option>%s' % item)
%>
</select>
</form>

<script language='javascript'>
<!--
function jsfunc() {
<%
# have Python generate DHTML
for i in range(len(menu1)):
        Response.Write("  if (document.theForm.first.selectedIndex == %s)
{\n" % i)
        subitems = submenus[menu1[i]]
        for j in range(len(submenus)):
                Response.Write("   document.theForm.second.options[%s].text =
'%s';\n" % (j, subitems[j]))
        Response.Write("  }\n")
%>

Quote:
}

//-->
</script>

===============



Wed, 23 Jun 2004 03:25:06 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Dynamic menu-rights/Enable and Disable menu-items

2. Dynamic Menu's

3. Dynamic Menu Problems

4. Dynamic Menus in VA Smalltalk

5. Dynamic creation of menu separator

6. Dynamic menus in Windows

7. Dynamic add menu items

8. Dynamic menu question

9. VO - dynamic changes to menu - problem

10. dynamic menu list problem

11. Tk Dynamic Menus problem

12. WPY: dynamic menu items

 

 
Powered by phpBB® Forum Software