1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
|
#!/usr/bin/env python3
# This is a Python/Tk toolbar to run the Python demos. Perhpas
# eventually we will be able to have plframe in a Python/Tk context.
from Tkinter import *
import string
class PyDemo(Frame):
def __init__(self, master=None):
Frame.__init__(self,master)
self.create_demo_bar()
self.pack()
def create_demo_bar(s):
# Build a button for each PLplot python example program.
s.x01 = Button( s, {
"text" : "Example 1",
"command" : s.x01m
} )
s.x02 = Button( s, {
"text" : "Example 2",
"command" : s.x02m
} )
s.x03 = Button( s, {
"text" : "Example 3",
"command" : s.x03m
} )
s.x04 = Button( s, {
"text" : "Example 4",
"command" : s.x04m
} )
s.x05 = Button( s, {
"text" : "Example 5",
"command" : s.x05m
} )
s.x06 = Button( s, {
"text" : "Example 6",
"command" : s.x06m
} )
s.x07 = Button( s, {
"text" : "Example 7",
"command" : s.x07m
} )
s.x08 = Button( s, {
"text" : "Example 8",
"command" : s.x08m
} )
s.x09 = Button( s, {
"text" : "Example 9",
"command" : s.x09m
} )
s.x10 = Button( s, {
"text" : "Example 10",
"command" : s.x10m
} )
s.x11 = Button( s, {
"text" : "Example 11",
"command" : s.x11m
} )
s.x12 = Button( s, {
"text" : "Example 12",
"command" : s.x12m
} )
s.x13 = Button( s, {
"text" : "Example 13",
"command" : s.x13m
} )
s.x14 = Button( s, {
"text" : "Example 14",
"command" : s.x14m
} )
s.x15 = Button( s, {
"text" : "Example 15",
"command" : s.x15m
} )
s.x16 = Button( s, {
"text" : "Example 16",
"command" : s.x16m
} )
s.x17 = Button( s, {
"text" : "Example 17",
"command" : s.x17m
} )
s.x18 = Button( s, {
"text" : "Example 18",
"command" : s.x18m
} )
s.x19 = Button( s, {
"text" : "Example 19",
"command" : s.x19m
} )
# Now pack them all.
s.x01.pack()
s.x02.pack()
s.x03.pack()
s.x04.pack()
s.x05.pack()
s.x06.pack()
s.x07.pack()
s.x08.pack()
s.x09.pack()
s.x10.pack()
s.x11.pack()
s.x12.pack()
s.x13.pack()
s.x14.pack()
s.x15.pack()
s.x16.pack()
s.x17.pack()
s.x18.pack()
s.x19.pack()
# It sure seems to me that it ought to have been possible to do this
# dynamically, but I couldn't get it to work. The following was my
# feeble effort, but it failed b/c I could never figure out how to get
# the command action to bind to the method I was trying to define in
# this class. Very annoying.
## for i in range(2,5):
## n = string.zfill( `i`, 2 )
## print i, "fn will be x" + n + "m"
## exec( "def x"+n+"m(s): import x"+n+"; x"+n+".main()",
## globals(), locals() )
##
#### exec( """
#### def x""" + n + """m(s):
#### print "xxx" """ )
##
## exec( "s.x" + n + " = Button( s, {" +
## "'text' : 'Example " + `i` + "'," +
## "'command' : s.x" + n + "m" +
## "} )", globals(), locals() )
## exec( "s.x"+ n +".pack()" )
##
#### exec( "s.x"+`i`+" = Button(s, {" +
#### "'text' : 'Example " + `i` + "'," +
#### "'command' : s.x"+`i` + "m" +
#### "} )" )
##
#### exec( "def x" + `i` +"m(s):
#### import x" +
# Don't forget the quit button!
s.quit = Button( s, {
"text" : "Quit",
"command" : s.quit
} )
s.quit.pack()
# Build some methods for all the button actions, which run the
# corresponding demo. Unfortunately, this isn't really doing what I
# want. What I want si to run the demo. If I use execfile, there si
# some nonsense about it not running in the right namespace or
# something. I can't understand. If I use import, they work, but on
# second invocations nothing is done. If I add an explicit call to
# x01.main() here, then it runs twice the first time, once
# thereafter. Can't win. Obviously there is something I don't
# understand about the Python execution model. Probably the
# difficulties with dynamically defining the methods are all bundled
# up in the same problem here.
def x01m(s): import x01
def x02m(s): import x02
def x03m(s): import x03
def x04m(s): import x04
def x05m(s): import x05
def x06m(s): import x06
def x07m(s): import x07
def x08m(s): import x08
def x09m(s): import x09
def x10m(s): import x10
def x11m(s): import x11
def x12m(s): import x12
def x13m(s): import x13
def x14m(s): import x14
def x15m(s): import x15
def x16m(s): import x16
def x17m(s): import x17
def x18m(s): import x18
def x19m(s): import x19
demoapp = PyDemo()
demoapp.mainloop()
|