Debian Codegraph @

07p/python/auto/graphics/AUTOgui.py

raw symbols SCIP
1 #! /usr/bin/env python
2
3 from auto import AUTOCommands
4 import Tkinter
5 from auto.graphics import Pmw
6 from auto import runAUTO
7 from auto.graphics import plotter
8 import os
9 import tkSimpleDialog
10 import sys
11 from auto import AUTOclui
12 from auto import AUTOutil
13
14 class AUTOMessageBar(Pmw.MessageBar):
15 def printMessage(self,text):
16 self.helpmessage(text)
17
18 class AUTOGUIComponent:
19 def __init__(self,messageFunc=None,textFunc=None):
20 self.messageFunc = messageFunc
21 self.textFunc = textFunc
22
23 def create(self,messageFunc=None,textFunc=None,runner=None):
24 pass
25
26 def _getArgs(self,command):
27 args = tkSimpleDialog.askstring("Args for command","Args")
28 self._queueCommand(args,command)
29
30 def _queueCommand(self,args,command):
31 name = command.__name__
32 if args is not None:
33 sys.stdout.write(name+"("+args+")\n")
34 else:
35 sys.stdout.write(name+"()\n")
36 eval("command(%s)"%args)
37 sys.stdout.write(sys.ps1)
38 sys.stdout.flush()
39 if self.textFunc is not None:
40 self.textFunc(name+"("+args+")\n")
41 self.textFunc(str(output))
42 self.textFunc(sys.ps1)
43 self.messageFunc(name+"("+args+")\n")
44
45
46 class AUTOSimpleGUIComponent(Tkinter.Frame,AUTOGUIComponent):
47 def __init__(self,parent=None,messageFunc=None,textFunc=None,**kw):
48 Tkinter.Frame.__init__(self,parent,**kw)
49 AUTOGUIComponent.__init__(self,messageFunc,textFunc)
50 self.default = None
51 self.create()
52
53 def create(self,messageFunc=None,textFunc=None,runner=None):
54 keys = AUTOCommands.__dict__.keys()
55 self.simple()
56
57 def simple(self,keys):
58 self.addSimpleCommands([AUTOCommands])
59
60 def addSimpleCommands(self,moduleList):
61 self.defaultEntry = Pmw.EntryField(self,
62 labelpos = 'w',
63 label_text = 'Default name:',
64 validate = None,
65 command = self.__setDefault)
66 self.defaultEntry.grid(row=0,columnspan=2)
67 for module in moduleList:
68 keys = list(module.__dict__)
69 keys.sort()
70 i = 0
71 for key in keys:
72 # Check to see if it is a command
73 cmd = getattr(module,key)
74 if (hasattr(cmd,"fun") and hasattr(cmd,"type") and
75 cmd.type==AUTOCommands.SIMPLE):
76 button = Tkinter.Button(self,text=cmd.shortName,
77 command=lambda c=cmd.fun:
78 self._getArgs(c))
79 button.grid(row=i/2 + 1,column=i%2)
80 i = i + 1
81
82 def __setDefault(self):
83 self.default = self.defaultEntry.get()
84
85 def _getArgs(self,command):
86 if self.default is None:
87 self.default = tkSimpleDialog.askstring("Default Name","Name")
88 self.defaultEntry.setentry(self.default)
89 self._queueCommand(self.default,command)
90
91
92 class AUTOExpertGUIComponent(Pmw.MenuBar,AUTOGUIComponent):
93 def __init__(self,parent=None,messageFunc=None,textFunc=None,**kw):
94 Pmw.MenuBar.__init__(self,parent,**kw)
95 AUTOGUIComponent.__init__(self,messageFunc,textFunc)
96 self.create()
97
98 def create(self):
99 if self.textFunc is not None:
100 self.textFunc(sys.ps1)
101 keys = AUTOCommands.__dict__.keys()
102
103 self.expert(keys)
104
105 def expert(self,keys):
106 baseList = []
107 for key in keys:
108 # Check to see if it is a command
109 cmd = getattr(AUTOCommands,key)
110 if hasattr(cmd,"fun"):
111 bases = cmd.__bases__
112 for base in bases:
113 if base not in baseList:
114 baseList.append(base)
115
116 for base in baseList:
117 if len(base.__name__) > 7 and base.__name__[:7] == "command":
118 self.addmenu(base.__name__[7:],'Commands which inherit from %s'%base.__name__)
119 else:
120 self.addmenu(base.__name__,'Commands which inherit from %s'%base.__name__)
121 self.addExpertCommands([AUTOCommands])
122
123 def addExpertCommands(self,moduleList):
124 for module in moduleList:
125 keys = list(module.__dict__)
126 keys.sort()
127 for key in keys:
128 # Check to see if it is a command
129 cmd = getattr(module,key)
130 if hasattr(cmd,"fun"):
131 f = cmd.fun
132 name = cmd.__bases__[0].__name__
133 if len(name) > 7:
134 name = name[7:]
135 self.addmenuitem(name, 'command', key, label=key,
136 command=lambda c=f: self._getArgs(c))
137
138
139 class AUTOBody(Pmw.ScrolledText):
140 def printOutput(self,text):
141 self.insert("end",text)
142
143
144 class AUTOgui:
145 def __init__(self,type="simple"):
146 root=Tkinter.Toplevel()
147
148
149 # Create the message bar
150 messagebar = AUTOMessageBar(root,
151 entry_width = 40,
152 entry_relief='groove',
153 labelpos = 'w',
154 label_text = 'Status:')
155 messagebar.pack(fill = 'x', padx = 10, pady = 10,side="bottom")
156
157 # Create the body
158 #body = AUTOBody(root)
159 #body.pack(fill="both",expand=1)
160
161 if type=="simple":
162 self.interface = AUTOSimpleGUIComponent(root,messagebar.printMessage)
163 else:
164 balloon = Pmw.Balloon(root)
165 self.interface = AUTOExpertGUIComponent(root,messagebar.printMessage,
166 hull_relief = 'raised',
167 hull_borderwidth = 1,
168 balloon = balloon)
169 self.interface.pack(fill = 'x',side="top")
170
171
172 # def addCommands(self,moduleList):
173 # self.interface.addCommands(moduleList)
174
175
176
177
178
179
180
181