[Dev] Re: [commits] (anthony) [6158] Added a few more built-ins to CPIA script:

John Anderson john at osafoundation.org
Tue Jul 26 07:10:23 PDT 2005


Hi Anthony:

That try you added has the unfortunate consequence of ignoring any 
attribute error that happens to get thrown inside ExecutableScript. 
Since attribute errors are common programming mistakes, we'll never seem 
any of them inside all of ExecutableScript. A better approach might be 
to either put the try around the smallest piece of code, i.e. accessing 
the name or using python getattr, which returns a specified default 
value when the atttribute doesn't exist.

John

commits at osafoundation.org wrote:

> Revision
>     6158 <http://viewcvs.osafoundation.org/chandler?view=rev&rev=6158>
> Author
>     anthony
> Date
>     2005-07-25 11:29:06 -0700 (Mon, 25 Jul 2005)
>
>
>       Log Message
>
>Added a few more built-ins to CPIA script:
>* function SideBarAdd(itemCollection) for adding collections to the sidebar
>* function GetWindow(label) for accessing a top level window (like the "About Chandler" dialog window)
>* variable __view__ that points to the current view
>I also added a try block around the hot key code since sometimes a note could have no name.
>
>
>       Modified Paths
>
>     * trunk/chandler/parcels/osaf/framework/scripting/CPIAScript.py
>       <#trunkchandlerparcelsosafframeworkscriptingCPIAScriptpy>
>     * trunk/chandler/parcels/osaf/framework/scripting/ScriptingGlobalFunctions.py
>       <#trunkchandlerparcelsosafframeworkscriptingScriptingGlobalFunctionspy>
>
>
>       Diff
>
>
>         Modified:
>         trunk/chandler/parcels/osaf/framework/scripting/CPIAScript.py
>         (6157 => 6158)
>
>--- trunk/chandler/parcels/osaf/framework/scripting/CPIAScript.py	2005-07-25 18:19:25 UTC (rev 6157)
>+++ trunk/chandler/parcels/osaf/framework/scripting/CPIAScript.py	2005-07-25 18:29:06 UTC (rev 6158)
>@@ -77,11 +77,14 @@
>         # try to find the corresponding Note
>         targetScriptName = "Script F%s" % str(keycode-wx.WXK_F1+1)
>         for aNote in Notes.Note.iterItems(view):
>-            if targetScriptName == aNote.about:
>-                scriptString = aNote.bodyString
>-                fKeyScript = ExecutableScript(scriptString, view=view)
>-                fKeyScript.execute()
>-                return True
>+            try:
>+                if targetScriptName == aNote.about:
>+                    scriptString = aNote.bodyString
>+                    fKeyScript = ExecutableScript(scriptString, view=view)
>+                    fKeyScript.execute()
>+                    return True
>+            except AttributeError:
>+                pass
> 
>         # maybe we have an existing script?
>         for aScript in Script.iterItems(view):
>@@ -196,6 +199,9 @@
> 
>         # add Globals
>         builtIns['Globals'] = Globals
>+        
>+        # add the current view      
>+        builtIns['__view__'] = self.itsView
> 
>         # now run that script in our predefined scope
>         try:
>
>
>         Modified:
>         trunk/chandler/parcels/osaf/framework/scripting/ScriptingGlobalFunctions.py
>         (6157 => 6158)
>
>--- trunk/chandler/parcels/osaf/framework/scripting/ScriptingGlobalFunctions.py	2005-07-25 18:19:25 UTC (rev 6157)
>+++ trunk/chandler/parcels/osaf/framework/scripting/ScriptingGlobalFunctions.py	2005-07-25 18:29:06 UTC (rev 6158)
>@@ -62,12 +62,20 @@
>         params = {'itemName':itemOrName}
>     Globals.mainViewRoot.postEventByName ('RequestSelectSidebarItem', params)
>     Focus(Sidebar())
>+
>+def SidebarAdd(itemCollection):
>+    """ Adds the given itemCollection to the sidebar """
>+    Globals.mainViewRoot.postEventByName ( 'AddToSidebarWithoutCopying', {'items' : [itemCollection]} )
> 
> def SummaryViewSelect(item):
>     # Tell the ActiveView to select our item
>     Globals.mainViewRoot.postEventByName ('SelectItemBroadcastInsideActiveView', {'item':item})
>-    Focus(SummaryView())
>-
>+    Focus(SummaryView())
>+
>+def GetWindow(label):
>+    """ Returns the window with the given label """
>+    return wx.FindWindowByLabel(label)
>+    
> """
> TO BE DONE
> * Type(<string>) function to take the string and tell wx
>
>  
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Commits mailing list
>Commits at osafoundation.org
>http://lists.osafoundation.org/mailman/listinfo/commits
>  
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.osafoundation.org/pipermail/dev/attachments/20050726/e43114aa/attachment.htm


More information about the Dev mailing list