1 from Tkinter import *
2 import tkMessageBox
3 import Pmw
4 from tkFileDialog import askopenfilename
5 from teamwork.widgets.images import getImageDirectory,getImage
6
8 """Frame for managing general properties of an entity (e.g., image,
9 description, horizon, belief depth
10 """
11
13 optiondefs = (
14 ('balloon',None,Pmw.INITOPT),
15 ('generic',False,Pmw.INITOPT),
16 ('expert', False,None),
17 ('step',lambda : None,None),
18 ('policy',lambda entity: None,None),
19 ('society',{},None),
20 ('valueCmd', None,None),
21 )
22 self.entity = entity
23 self.defineoptions(kw, optiondefs)
24 Pmw.ScrolledFrame.__init__(self,parent)
25 self.interior().grid_columnconfigure(1,weight=1)
26
27 try:
28 image = PhotoImage(file=self.entity.attributes['imageName'])
29 except KeyError:
30 image = PhotoImage(file=getImage('nobody.gif'))
31 self.entity.attributes['image'] = image
32 widget = self.createcomponent('%s Image' % (self.entity.ancestry()),
33 (),None,Button,(self.interior(),))
34 widget.configure(command=self.selectImage)
35 widget.configure(image=self.entity.attributes['image'],
36 width=100,height=100)
37 widget.grid(row=0,column=0)
38
39
40
41
42
43
44
45
46
47
48
49
50
51 frame = Frame(self.interior())
52 if self['generic']:
53 if not self.entity.parent:
54 widget = Label(frame,text='Horizon:',justify='left')
55 widget.grid(row=0,column=0,sticky='w')
56 self.createcomponent('Horizon',(),None,Pmw.Counter,(frame,),
57 entryfield_modifiedcommand=self.getHorizon,
58 entryfield_value=self.entity.horizon,
59 entryfield_validate={'validator':'integer',
60 'min':1},
61 ).grid(row=0,column=1,sticky='w')
62 if self['balloon']:
63 self['balloon'].bind(widget,'The number of rounds into the future this agent considers when choosing an action.')
64 self['balloon'].bind(self.component('Horizon'),'The number of rounds into the future this agent considers when choosing an action.')
65 widget = Label(frame,text='Belief Depth:',justify='left')
66 widget.grid(row=1,column=0,sticky='w')
67 self.createcomponent('Depth',(),None,Pmw.Counter,(frame,),
68 entryfield_modifiedcommand=self.getDepth,
69 entryfield_value=self.entity.depth,
70 entryfield_validate={'validator':'integer',
71 'min':0},
72 ).grid(row=1,column=1,sticky='w')
73 if self['balloon']:
74 self['balloon'].bind(widget,'The number of levels of recursive beliefs that this agent will maintain of others.')
75 self['balloon'].bind(self.component('Depth'),'The number of levels of recursive beliefs that this agent will maintain of others.')
76 elif len(self.entity.actions.getOptions()) > 0:
77
78 widget = self.createcomponent('%s Run Box' % (self.entity.ancestry()),
79 (), None,Pmw.ButtonBox,(frame,),
80 orient='vertical')
81 if not self.entity.parent:
82
83 widget.add('real',text='Real Step',command=self.stepEntity)
84 widget.add('hypo',text='Hypothetical Step',command=self.applyPolicy)
85 if len(self.entity.getGoals()) > 0 and self['valueCmd']:
86
87 widget.add('value',text='Expected Value',
88 command = lambda s=self,e=self.entity:s.value(e))
89 widget.grid(row=0,column=1)
90 frame.grid(row=0,column=1,sticky='ewns')
91 self.initialiseoptions()
92
94 """Pops up a dialog to allow user to select image for an entity"""
95 filename = askopenfilename(parent=self._hull,
96 initialdir = getImageDirectory())
97 if filename:
98 try:
99 image = PhotoImage(file=filename)
100 except:
101 image = None
102 if image:
103 widget = self.component('%s Image' % (self.entity.ancestry()))
104 widget.configure(image=image)
105 self.entity.attributes['image'] = image
106 self.entity.attributes['imageName'] = filename
107
112
117
120
122 self['policy'](self.entity)
123