Package teamwork :: Package widgets :: Package PsychGUI :: Package AgentWindow :: Module ActionEditor
[hide private]
[frames] | no frames]

Source Code for Module teamwork.widgets.PsychGUI.AgentWindow.ActionEditor

  1  import string 
  2  from Tkinter import * 
  3  import Pmw 
  4  from teamwork.widgets.TreeEditor import TreeEditor 
  5   
6 -class ActionEditor(TreeEditor):
7
8 - def __init__(self,parent,**kw):
9 optiondefs = ( 10 ('entity', None, Pmw.INITOPT), 11 ) 12 self.defineoptions(kw, optiondefs) 13 TreeEditor.__init__(self,parent) 14 widget = self.createcomponent('Entry',(),None, 15 Pmw.EntryField, 16 (self.pane('editorPane'),), 17 ) 18 widget.pack_forget() 19 self.component('box').add('Test...',command=self.generate) 20 self.configure(tree=self['entity'].actions) 21 self.initialiseoptions()
22
23 - def setLeaf(self,leafType):
24 tree = self.selectedTree() 25 if leafType == 'relationship': 26 widget = self.component('feature0') 27 widget.setitems(self['entity'].getRelationships()) 28 widget.pack(fill='x') 29 widget.configure(menubutton_state='normal') 30 if tree.split == leafType: 31 widget.invoke(tree._children[0]) 32 widget = self.component('feature1') 33 widget.setitems(['object']) 34 widget.pack(fill='x') 35 widget.configure(menubutton_state='normal') 36 if tree.split == leafType: 37 widget.invoke(tree.key) 38 self.component('Entry').pack_forget() 39 elif leafType == 'generic': 40 widget = self.component('feature0') 41 itemList = self['entity'].hierarchy.keys() 42 itemList.sort() 43 widget.setitems(itemList) 44 widget.pack(fill='x') 45 widget.configure(menubutton_state='normal') 46 if tree.split == leafType: 47 widget.invoke(tree._children[0]) 48 widget = self.component('feature1') 49 widget.setitems(['object']) 50 widget.pack(fill='x') 51 widget.configure(menubutton_state='normal') 52 if tree.split == leafType: 53 widget.invoke(tree.key) 54 self.component('Entry').pack_forget() 55 elif leafType == 'literal': 56 self.component('feature1').pack_forget() 57 widget = self.component('feature0') 58 widget.setitems(['object','type']) 59 widget.pack(fill='x') 60 widget.configure(menubutton_state='normal') 61 if tree.split == leafType: 62 widget.invoke(tree.key) 63 widget = self.component('Entry') 64 widget.pack(after=self.component('feature0'),side='top', 65 fill='x',expand='yes') 66 if tree.split == leafType: 67 widget.setvalue(tree._children[0]) 68 else: 69 raise NotImplementedError,'Unable to edit leaves of type %s' % \ 70 (leafType)
71
72 - def setBranch(self,rowType):
73 self.component('feature0').pack_forget() 74 self.component('feature1').pack_forget() 75 self.component('Entry').pack_forget()
76
77 - def selectLeaf(self):
78 names = ['generic','literal','relationship'] 79 self.component('type').setitems(names) 80 tree = self.selectedTree() 81 self.component('type').invoke(tree.split)
82
83 - def selectBranch(self):
84 self.component('type').setitems(['AND','OR','XOR']) 85 tree = self.selectedTree() 86 self.component('type').invoke(tree.split)
87
88 - def apply(self):
89 tree = self.selectedTree() 90 if tree.isLeaf(): 91 tree.split = self.component('type').getvalue() 92 if tree.split == 'literal': 93 tree.key = self.component('feature0').getvalue() 94 tree._children[0] = self.component('Entry').getvalue() 95 else: 96 tree.key = self.component('feature1').getvalue() 97 tree._children[0] = self.component('feature0').getvalue() 98 print tree 99 name = self.displayLeaf(tree.getValue()) 100 self.selection().var.set(name) 101 else: 102 tree.split = self.component('type').getvalue() 103 name = self.displayPlane(tree.split) 104 self.selection().var.set(name)
105
106 - def generate(self):
107 tree = self.selectedTree() 108 if tree: 109 tree.generateOptions(debug=True) 110 actions = tree.getOptions() 111 else: 112 actions = self['entity'].actions.getOptions() 113 if len(actions) == 0: 114 msg = 'No actions.' 115 else: 116 msg = string.join(map(lambda a:str(a),actions),'\n') 117 dialog = Pmw.MessageDialog(self.component('hull'), 118 title='Actions for %s' % \ 119 (self['entity'].ancestry()), 120 message_text=msg) 121 dialog.activate()
122
123 - def addBranch(self):
124 tree = self.selectedTree() 125 node = self.selection() 126 if tree.isLeaf(): 127 pass 128 else: 129 pass
130
131 - def deleteNode(self):
132 tkMessageBox.showerror('Delete Node','Not implemented')
133