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
9 @license: I{The BSD License}
10 All rights reserved. This program and the accompanying materials are made
11 available under the terms of the BSD license which accompanies
12 this distribution, and is available at
13 U{http://www.opensource.org/licenses/bsd-license.php}
14 '''
15 from AccessEngine.AEConstants import LAYER_NAMES, SEMANTIC_NAMES
16 from AccessEngine import InputEvent, OutputEvent, AEDeviceEvent, AEOutput, AEInput
17 from GTKEventDialog import GTKEventDialog
18 from AccessEngine import AEConstants
19 from Tools.i18n import _
20 import pango
21
22 __uie__ = dict(kind='monitor', profiles=['developer'])
23
25 '''
26 Logs information about input and output to a GUI window.
27
28 @ivar last_dev: Name of the last device to which output was sent
29 @type last_dev: string
30 '''
32 '''
33 Initialize the monitor instance variables.
34 '''
35 super(IOMonitor, self).init()
36 self.last_dev = None
37
38 self._insert_one_tag_into_buffer('gray_fg', {'foreground':'#A5A5A5'})
39 self._insert_one_tag_into_buffer('red_fg', {'foreground':'red'})
40 '''
41 Gets the localized name of this monitor.
42
43 @return: Monitor name
44 @rtype: string
45 '''
46 return _('I/O monitor')
47
49 '''
50 Gets the event categories to be displayed in the View menu for filtering.
51
52 @return: Event categories
53 @rtype: list of string
54 '''
55 return AEInput.getNames() + AEOutput.getNames()
56
58 '''
59 Gets the default event categories to check in the View menu.
60
61 @return: Event categories
62 @rtype: list of string
63 '''
64 return AEInput.getDefaults() + AEOutput.getDefaults()
65
67 '''
68 Gets the L{AEDevice.AEDeviceEvent} base class to indicate the type
69 of events this monitor wants to buffer.
70
71 @return: Base type of the event this monitor should buffer
72 @rtype: L{AEDevice.AEDeviceEvent} class
73 '''
74 return AEDeviceEvent
75
76 - def show(self, event, value=None, dev=None, sem=None, layer=None):
77 '''
78 Buffers additional details about how the L{AEEvent} was handled by various
79 L{AEScript}s and tasks. The event is only provided as a means of filtering
80 information.
81
82 @param event: Wrapper giving the direction of a command (input/output) and
83 the command name
84 @type event: L{AEDevice.AEDeviceEvent}
85 @param value: Value of the command sent to/from a device
86 @type value: object
87 @param dev: Device on which the event occurred
88 @type dev: L{AEInput} or L{AccessEngine.AEDevice.AEOutput}
89 @param sem: Semantic constant indicating the kind of output
90 @type sem: integer
91 @param layer: Layer constant indicating from where the event came
92 @type layer: integer
93 @raise IOError: When the monitor is no longer accepting data to buffer
94 '''
95 if not self.isInitialized():
96 raise IOError
97 elif not self._isShown(event.getName()):
98 return
99
100 if dev and dev.getName() != self.last_dev:
101
102 name = dev.getName()
103 self.last_dev = name
104 self._queueText('\n\n{device: %s}\n' % name, tags=['red_fg'])
105
106 if event.cmd == AEConstants.CMD_TALK:
107 self._queueText(' {%s: %s} ' %(event.getName(), SEMANTIC_NAMES.get(sem)),
108 tags=['gray_fg'])
109 elif event.cmd == AEConstants.CMD_STOP:
110 self._queueText('{%s}\n' % event.getName(), tags=['gray_fg'])
111 elif event.cmd == AEConstants.CMD_STRING:
112 self._queueText(str(value))
113 elif event == AEConstants.CMD_FILENAME:
114 self._queueText('{%s: %s}' % (event.getName(), str(value)),
115 tags=['gray_fg'])
116 else:
117 self._queueText('{%s: %s}\n' % (event.getName(), str(value)),
118 tags=['gray_fg'])
119