- Revision
- 11273
- Author
- john
- Date
- 2006-07-27 17:13:45 -0700 (Thu, 27 Jul 2006)
Log Message
First pass of implementing a dispatchEvent hook for Ashkan's event logger
Modified Paths
- trunk/chandler/WingWindowsRelease.wpr
- trunk/chandler/application/Utility.py
- trunk/chandler/parcels/osaf/framework/blocks/Block.py
- trunk/chandler/parcels/osaf/framework/blocks/MenusAndToolbars.py
- trunk/chandler/parcels/osaf/framework/blocks/__init__.py
Added Paths
- trunk/chandler/parcels/eventLogger/
- trunk/chandler/parcels/eventLogger/__init__.py
Diff
Modified: trunk/chandler/WingWindowsRelease.wpr (11272 => 11273)
--- trunk/chandler/WingWindowsRelease.wpr 2006-07-27 16:53:53 UTC (rev 11272) +++ trunk/chandler/WingWindowsRelease.wpr 2006-07-28 00:13:45 UTC (rev 11273) @@ -4,7 +4,7 @@ # Wing IDE project file # ################################################################## [project attributes] -debug.run-args = {loc('Chandler.py'): '--nocatch'} +debug.run-args = {loc('Chandler.py'): '--nocatch --create'} proj.env-vars = {None: ('custom', ['PATH=release/bin']), loc('Chandler.py'): ('project', @@ -116,6 +116,7 @@ loc('parcels/evdb/evdb.py'), loc('parcels/evdb/EVDBDialog.py'), loc('parcels/evdb/__init__.py'), + loc('parcels/eventLogger/__init__.py'), loc('parcels/flickr/flickr.py'), loc('parcels/flickr/tests/TestI18nFlickr.py'), loc('parcels/flickr/tests/__init__.py'),
Modified: trunk/chandler/application/Utility.py (11272 => 11273)
--- trunk/chandler/application/Utility.py 2006-07-27 16:53:53 UTC (rev 11272) +++ trunk/chandler/application/Utility.py 2006-07-28 00:13:45 UTC (rev 11273) @@ -33,7 +33,7 @@ # with your name (and some helpful text). The comment's really there just to # cause Subversion to warn you of a conflict when you update, in case someone # else changes it at the same time you do (that's why it's on the same line). -SCHEMA_VERSION = "226" #john: remove more displayNames +SCHEMA_VERSION = "227" #john: added dispatchEevent hook logger = None # initialized in initLogging()
Added: trunk/chandler/parcels/eventLogger/__init__.py (11272 => 11273)
--- trunk/chandler/parcels/eventLogger/__init__.py 2006-07-27 16:53:53 UTC (rev 11272) +++ trunk/chandler/parcels/eventLogger/__init__.py 2006-07-28 00:13:45 UTC (rev 11273) @@ -0,0 +1,73 @@ +# Copyright (c) 2003-2006 Open Source Applications Foundation +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + + +__parcel__ = "eventLogger" + +from application import schema +from osaf.framework.blocks import DispatchHook, BlockEvent +from osaf.framework.blocks.MenusAndToolbars import MenuItem +from i18n import OSAFMessageFactory as _ + +class EventLoggingDispatchHook (DispatchHook): + logging = schema.One(schema.Boolean, initialValue=False) + + def dispatchEvent (self, event, depth): + print event, depth + + def onToggleLoggingEvent (self, event): + self.logging = not self.logging + + hooksListItem = schema.ns ('osaf.framework.blocks', self.itsView).BlockDispatchHookList + dispatchHook = schema.ns (__name__, self.itsView).EventLoggingHook + if self.logging: + hooksListItem.hooks.insertItem (dispatchHook, None) + else: + hooksListItem.hooks.remove (dispatchHook) + + + def onToggleLoggingEventUpdateUI (self, event): + event.arguments['Check'] = self.logging + + +def installParcel(parcel, old_version=None): + mainView = schema.ns('osaf.views.main', parcel.itsView) + + dispatchHook = EventLoggingDispatchHook.update( + parcel, 'EventLoggingHook', + blockName = 'EventLoggingHook') + + # Event to toggle logging + ToggleLogging = BlockEvent.update( + parcel, 'ToggleLogging', + blockName = 'ToggleLogging', + dispatchEnum = 'SendToBlockByReference', + destinationBlockReference = dispatchHook) + + # Add menu item to Chandler + MenuItem.update( + parcel, 'StartLogging', + blockName = 'StartLoggingMenuItem', + menuItemKind = 'Check', + title = _(u'Start Logging'), + helpString = _(u'Turn on logging and send result to OSAF'), + event = ToggleLogging, + eventsForNamedLookup = [ToggleLogging], + # Recent changes have broken the menu location code + #location = "TestMenu", + #itemLocation = "RepositoryTestMenu", + #parentBlock = mainView.MainView + parentBlock = mainView.TestMenu) + + Property changes on: trunk/chandler/parcels/eventLogger/__init__.py ___________________________________________________________________ Name: svn:eol-style + native
Modified: trunk/chandler/parcels/osaf/framework/blocks/Block.py (11272 => 11273)
--- trunk/chandler/parcels/osaf/framework/blocks/Block.py 2006-07-27 16:53:53 UTC (rev 11272) +++ trunk/chandler/parcels/osaf/framework/blocks/Block.py 2006-07-28 00:13:45 UTC (rev 11273) @@ -80,7 +80,6 @@ app.ignoreSynchronizeWidget = oldIgnoreSynchronizeWidget return result - class Block(schema.Item): @@ -156,6 +155,13 @@ #See Bug #5219 wxId = schema.One (schema.Integer, defaultValue=0) + # event profiler (class attributes) + profileEvents = False # Make "True" to profile events + __profilerActive = False # to prevent reentrancy, if the profiler is currently active + __profiler = None # The hotshot profiler + + depth = 0 # Recursive post depth + @classmethod def post (self, event, arguments, sender=None): """ @@ -171,14 +177,20 @@ @return: the value returned by the event handler """ try: + Block.depth += 1 stackedArguments = getattr (event, "arguments", None) arguments ['sender'] = sender arguments ['results'] = None event.arguments = arguments - self.dispatchEvent (event) + + hookListItem = schema.ns (__name__, wx.GetApp().UIRepositoryView).BlockDispatchHookList + for hookItem in hookListItem.hooks: + hookItem.dispatchEvent (event, Block.depth) + results = event.arguments ['results'] return results # return after the finally clause finally: + Block.depth -= 1 if stackedArguments is None: delattr (event, 'arguments') else: @@ -873,8 +885,24 @@ block = block.parentBlock return block.frame - @classmethod - def dispatchEvent (theClass, event): + +class DispatchHook (Block): + """ + Override dispatchEvent and assign hookList to get called each + time an event is disspatched + """ + hookList = schema.One("DispatcHookList", otherName='hooks') + + def dispatchEvent (self, event, depth): + pass + + +class DispatcHookList (schema.Item): + hooks = schema.Sequence("DispatchHook", otherName='hookList', defaultValue = []) + + +class BlockDispatchHook (DispatchHook): + def dispatchEvent (self, event, depth): def callProfiledMethod(blockOrWidget, methodName, event): """ @@ -1051,10 +1079,6 @@ if commitAfterDispatch: wx.GetApp().UIRepositoryView.commit() - # event profiler (class attributes) - profileEvents = False # Make "True" to profile events - __profilerActive = False # to prevent reentrancy, if the profiler is currently active - __profiler = None # The hotshot profiler def debugName(thing): """
Modified: trunk/chandler/parcels/osaf/framework/blocks/MenusAndToolbars.py (11272 => 11273)
--- trunk/chandler/parcels/osaf/framework/blocks/MenusAndToolbars.py 2006-07-27 16:53:53 UTC (rev 11272) +++ trunk/chandler/parcels/osaf/framework/blocks/MenusAndToolbars.py 2006-07-28 00:13:45 UTC (rev 11273) @@ -31,24 +31,24 @@ The attribute that contains the reference collection is determined through attribute indirection using the collectionSpecifier attribute. - The "itsName" property of the items in the reference collection + The "blockName" property of the items in the reference collection is used for the dictionary lookup by default. You can override the name accessor if you want to use something other than - itsName to key the items in the collection. + blockName to key the items in the collection. """ def itemNameAccessor(self, item): """ Name accessor used for RefCollectionDictionary subclasses can override this method if they want to - use something other than the itsName property to + use something other than the blockName property to determine item names. @param item: The item whose name we want. @type item: C{item} @return: A C{immutable} for the key into the collection """ - return item.itsName or item.itsUUID.str64() + return item.blockName or item.itsUUID.str64() def getCollectionSpecifier(self): """ @@ -175,11 +175,18 @@ """ # coll = self.getAttributeValue(self.getCollectionSpecifier()) - coll.append(item, alias=self.itemNameAccessor(item)) - if index is not None: - prevItem = coll.previous(index) - coll.placeItem(item, prevItem) # place after the previous item + if index is None: + afterItem = coll.last() + else: + afterItem = coll.previous(index) + if item not in coll: + coll.append(item, alias=self.itemNameAccessor(item)) + if index is not None: + coll.placeItem(item, afterItem) # place after the previous item + else: + coll.placeItem(item, afterItem) # place item at end + def __delitem__(self, key): """ Delete the keyed item from our ref collection. @@ -293,9 +300,8 @@ Use 'MenuBar' for the Menu Bar. """ - try: - locationName = child.location - except AttributeError: + locationName = getattr (child, 'location', None) + if locationName is None: locationName = child.parentBlock.blockName bar = containers [locationName]
Modified: trunk/chandler/parcels/osaf/framework/blocks/__init__.py (11272 => 11273)
--- trunk/chandler/parcels/osaf/framework/blocks/__init__.py 2006-07-27 16:53:53 UTC (rev 11272) +++ trunk/chandler/parcels/osaf/framework/blocks/__init__.py 2006-07-28 00:13:45 UTC (rev 11273) @@ -23,7 +23,7 @@ RectangularChild, BlockEvent, NewItemEvent, ChoiceEvent, ColorEvent, KindParameterizedEvent, AddToSidebarEvent, NewBlockWindowEvent, EventList, debugName, getProxiedItem, WithoutSynchronizeWidget, - IgnoreSynchronizeWidget + IgnoreSynchronizeWidget, DispatchHook, DispatcHookList, BlockDispatchHook ) from ContainerBlocks import ( @@ -143,3 +143,9 @@ CharacterStyle.update(parcel, "SummaryRowStyle", fontFamily="DefaultUIFont") CharacterStyle.update(parcel, "SidebarRowStyle", fontFamily="DefaultUIFont", fontSize=12) + + defaultDispatchHook = BlockDispatchHook.update(parcel, "DefaultDispatchHook") + + DispatcHookList.update(parcel, "BlockDispatchHookList", + hooks = [defaultDispatchHook] + ) \ No newline at end of file
_______________________________________________ Commits mailing list [email protected] http://lists.osafoundation.org/mailman/listinfo/commits
