1 '''
2 Defines a GTK dialog for buffering L{AEEvent}s and how L{AEScript}s and tasks
3 handle them.
4
5 @author: Peter Parente
6 @organization: IBM Corporation
7 @copyright: Copyright (c) 2005, 2007 IBM Corporation
8 @license: The BSD License
9
10 @author: Frank Zenker
11 @author: Ramona Bunk
12 @organization: IT Science Center Ruegen gGmbH, Germany
13 @copyright: Copyright (c) 2007, 2008 ITSC Ruegen
14
15 @license: I{The BSD License}
16 All rights reserved. This program and the accompanying materials are made
17 available under the terms of the BSD license which accompanies
18 this distribution, and is available at
19 U{http://www.opensource.org/licenses/bsd-license.php}
20 '''
21 import pygtk
22 pygtk.require('2.0')
23 import gtk
24 from AccessEngine import AEEvent
25 from AccessEngine import AEConstants
26 from GTKEventDialog import GTKEventDialog
27 from Tools.i18n import _
28 import time, datetime
29 import pango
30
31 __uie__ = dict(kind='monitor', profiles=['developer'])
32
34 '''
35 Logs information about Tasks running in SUE Scripts to a GUI window.
36
37 @ivar filter_tasks: Should logging information about tasks be inhibited?
38 @type filter_tasks: boolean
39 @ivar tabs: Stack of tab characters indenting logged events and tasks to
40 appropriate levels
41 @type tabs: string
42 '''
55
57 '''
58 Gets the localized name of this monitor.
59
60 @return: Monitor name
61 @rtype: string
62 '''
63 return _('Task monitor')
64
66 '''
67 Gets the event categories to be displayed in the View menu for filtering.
68
69 @return: Event categories
70 @rtype: list of string
71 '''
72 return AEEvent.getNames()
73
75 '''
76 Gets the default event categories to check in the View menu.
77
78 @return: Event categories
79 @rtype: list of string
80 '''
81 return AEEvent.getDefaults()
82
84 '''
85 Gets the L{AEEvent.Base.AEEvent} base class to indicate the type
86 of events this monitor wants to buffer.
87
88 @return: Base type of the event this monitor should buffer
89 @rtype: L{AEEvent.Base.AEEvent} class
90 '''
91 return AEEvent.Base.AEEvent
92
93 - def show(self, event=None, task_name=None, chain_type=None, propagate=None,
94 **kwargs):
95 '''
96 Buffers additional details about how the L{AEEvent} was handled by various
97 L{AEScript}s and tasks.
98
99 @param event: Event to filter on
100 @type event: object
101 @param task_name: name of the task executing
102 @type task_name: string
103 @param chain_type: One of the L{AEConstants} CHAIN_* constants
104 @type chain_type: integer
105 @param propagate: Is the event allowed to propagate to other script tasks?
106 @type propagate: boolean
107 @raise IOError: When the monitor is no longer accepting data to buffer
108 '''
109 if not self.isInitialized():
110 raise IOError
111
112
113 if ((event is None and self.filter_tasks) or
114 (event is not None and not self._isShown(event.__class__.__name__))):
115
116
117
118 self.filter_tasks = True
119 return
120
121 self.filter_tasks = False
122 if propagate is not None:
123
124 self._showReturn(propagate)
125 elif chain_type is not None:
126
127 self._showChain(chain_type, **kwargs)
128 elif task_name is not None:
129
130 self._showTask(task_name, **kwargs)
131 else:
132
133 self._showEvent(event, **kwargs)
134
136 '''
137 Adds menu items to menu.
138
139 @param menu: Menu on which to append
140 @type menu: gtk.Menu
141 '''
142 menu.append(gtk.SeparatorMenuItem())
143 item = gtk.CheckMenuItem(_('Timestamp'))
144 menu.append(item)
145 item.connect('activate', self._onTimeStamp, _('Timestamp'))
146
148 '''
149 Buffer information about the current event.
150
151 @param event: Event to filter on
152 @type event: object
153 @param tier_name: Name of the L{AETier} that handled the event
154 @type tier_name: string
155 '''
156 eventstr = str(event)
157 split = eventstr.find('\n')
158 self._queueText(eventstr[:split], tags=['bold', 'small'])
159 self._queueText(eventstr[split:]+'\n', tags=['small'])
160 self._queueText('%stier: %s\n' % (self.tabs, tier_name),
161 tags=['small'])
162 if self.timestamp:
163 self._queueText('%s%s\n' % (self.tabs,
164 datetime.datetime.fromtimestamp(time.time())),
165 tags=['small'])
166
168 '''
169 Buffer information about a script task chained to an anchor.
170
171 @param chain_type: One of the L{AEConstants} CHAIN_* constants
172 @type chain_type: integer
173 @param anchor_ident: Identifier of the anchor task
174 @type anchor_ident: string
175 '''
176
177 if chain_type is AEConstants.CHAIN_BEFORE:
178 template = '%s(before: %s)\n'
179 tags = ['blue_foreground']
180 elif chain_type is AEConstants.CHAIN_AFTER:
181 template = '%s(after: %s)\n'
182 tags = ['red_foreground']
183 elif chain_type is AEConstants.CHAIN_AROUND:
184 template = '%s(around: %s)\n'
185 tags = ['green_foreground']
186 tags.append('small')
187 self._queueText(template % (self.tabs, anchor_ident), tags=tags)
188
190 '''
191 Buffer information about a script task executing.
192
193 @param task_name: name of the executing Task
194 @type task_name: string
195 @param script: Script in which the task resides
196 @type script: L{AEScript}
197 '''
198
199 tags=['small']
200
201 if len(self.tabs) == 1:
202 tags.append('bold')
203 template = '%s%s in %s\n'
204 self._queueText(template % (self.tabs,
205 task_name,
206 script.getClassName()), tags=tags)
207
208 self.tabs += '\t'
209
211 '''
212 Buffer information about the return value of a script task.
213
214 @param propagate: Are tasks later in a chain or deeper in the L{AEScript}
215 stack allowed to execute (True) or update (False)?
216 @type propagate: boolean
217 '''
218
219 self._queueText('%spropagate: %s\n' % (self.tabs, str(propagate)),
220 tags=['small'])
221
222 self.tabs = self.tabs[:-1]
223
225 '''
226 '''
227 if widget.get_active():
228 self.timestamp = True
229 else:
230 self.timestamp = False
231