| John,
Actually, all those functions you're commenting on were there before Olivier's commit - so I'll take the action items to address the issues. BTW, the generic implementations that you suggest, like BlockNamed, are already there (it's called FindNamedBlock), so we don't *have* to add new access functions for each new block.
Why have both the generic and specific block lookup functions? When using the specific ones the scripter is insulated from the anticipated cleanup of block names that you're describing - we can just update the single function that all the scripts are calling. That may not be a compelling argument, since there's not a lot of script code written yet. :-) But I think the bigger issue is a matter of philosophy - should scripts use the end-user term for an item, or the internal term? I've been leaning towards supporting the end-user term, since people who know the internals can always use our standard python idioms to access the internal items as we're used to doing.
Phillipe (PJE) has been arguing that the internal terms should be the same as the end-user terms. It sounds like you agree. Now that we're exposing a lot more of the internals, it's time to review and update those terms. I'll take an action item to drive this process where the details of CPIA Script are concerned.
- Donn On Jul 29, 2005, at 2:00 PM, John Anderson wrote: Hi Oliver: I'd probably prefer a scripting function, e.g. BlockNamed (nameArgument), to hard coding methods for each name. If we did this instead, we wouldn't have to add a method each time we have a block with a new name, which makes it more extensible and gets rid of a bunch of code. If you're concerned that this wouldn't work because the current names are too confusing, I'd rename the blocks to use better names. Also, I'd probably change some of the functions to make them less Chandler specific and more general so they work with future Chandler extensions or non-Chandler CPIA apps, e.g. StampAsXXX, StampAsYYY, StampAsZZZ, should be StampAs (typeArgument). John [email protected] wrote: - Revision
- 6283
- Author
- olivier
- Date
- 2005-07-29 13:29:13 -0700 (Fri, 29 Jul 2005)
Log Message Some new block accessors for CPIA script Modified Paths Diff Modified: trunk/chandler/parcels/osaf/framework/scripting/CPIAScript.py (6282 => 6283) --- trunk/chandler/parcels/osaf/framework/scripting/CPIAScript.py 2005-07-29 20:22:03 UTC (rev 6282)
+++ trunk/chandler/parcels/osaf/framework/scripting/CPIAScript.py 2005-07-29 20:29:13 UTC (rev 6283)
@@ -13,6 +13,7 @@
import ScriptingGlobalFunctions
from application import schema
import wx
+import TestAppLib
logger = logging.getLogger('CPIA Script')
logger.setLevel(logging.INFO)
@@ -184,6 +185,7 @@
# @@@DLD TBD - remove
reload(ScriptingGlobalFunctions)
reload(KindShorthand)
+ reload(TestAppLib)
# add all the known BlockEvents as builtin functions
self._BindCPIAEvents(self.itsView, builtIns)
Modified: trunk/chandler/parcels/osaf/framework/scripting/ScriptingGlobalFunctions.py (6282 => 6283) --- trunk/chandler/parcels/osaf/framework/scripting/ScriptingGlobalFunctions.py 2005-07-29 20:22:03 UTC (rev 6282)
+++ trunk/chandler/parcels/osaf/framework/scripting/ScriptingGlobalFunctions.py 2005-07-29 20:29:13 UTC (rev 6283)
@@ -1,110 +1,130 @@
-__copyright__ = "Copyright (c) 2005 Open Source Applications Foundation"
-__license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
-
-""" Provide Scripting Global Functions """
-
-"""
- NOTE:
- ----
- All globals in this file become attributes of the user's script,
- unless the name starts with an underscore '_'.
- This includes things that you import here.
- Hence imports are done into the private name space.
-"""
-import wx as _wx
-import logging as _logging
-import osaf.framework.blocks.Block as _Block
-import application.Globals as _Globals
-from repository.item.Item import Item as _Item
-
-_logger = _logging.getLogger('CPIA Script')
-_logger.setLevel(_logging.INFO)
-
-# Functions that return a named block
-def FindNamedBlock(blockName):
- block = _Block.Block.findBlockByName(blockName)
- if not block:
- _logger.warning("Can't find block named %s" % blockName)
- return block
-
-def Sidebar():
- return FindNamedBlock("Sidebar")
-
-def SummaryView():
- return FindNamedBlock("TableSummaryView")
-
-def CalendarView():
- return FindNamedBlock("CalendarSummaryView")
-
-def DetailView():
- return FindNamedBlock("DetailView")
-
-def StartTime():
- # The Start time edit field of the Detail View
- return FindNamedBlock("EditCalendarStartTime")
-
-def EndTime():
- # The End time edit field of the Detail View
- return FindNamedBlock("EditCalendarEndTime")
-
-"""
-Special functions, including wxWidgets-related operations
-
-All attributes in this file get added to the builtin module
-for script execution, except for ones that start with "_".
-"""
-def Focus(block):
- # Set the input focus to the given block
- try:
- widget = block.widget
- except AttributeError:
- _logger.warning("Can't set focus to block %s" % block)
- else:
- widget.SetFocus()
-
-def SidebarSelect(itemOrName):
- """ Select the item in the Sidebar """
- # can pass in an item or a name
- if isinstance(itemOrName, Item):
- params = {'item':itemOrName}
- else:
- params = {'itemName':itemOrName}
- _Globals.mainViewRoot.postEventByName ('RequestSelectSidebarItem', params)
- Focus(Sidebar())
+__copyright__ = "Copyright (c) 2005 Open Source Applications Foundation"
+__license__ = "http://osafoundation.org/Chandler_0.1_license_terms.htm"
+""" Provide Scripting Global Functions """
+
+"""
+ NOTE:
+ ----
+ All globals in this file become attributes of the user's script,
+ unless the name starts with an underscore '_'.
+ This includes things that you import here.
+ Hence imports are done into the private name space.
+"""
+import wx as _wx
+import logging as _logging
+import osaf.framework.blocks.Block as _Block
+import application.Globals as _Globals
+from repository.item.Item import Item as _Item
+
+_logger = _logging.getLogger('CPIA Script')
+_logger.setLevel(_logging.INFO)
+
+# Functions that return a named block
+def FindNamedBlock(blockName):
+ block = _Block.Block.findBlockByName(blockName)
+ if not block:
+ _logger.warning("Can't find block named %s" % blockName)
+ return block
+
+def Sidebar():
+ return FindNamedBlock("Sidebar")
+
+def SummaryView():
+ return FindNamedBlock("TableSummaryView")
+
+def CalendarView():
+ return FindNamedBlock("CalendarSummaryView")
+
+def DetailView():
+ return FindNamedBlock("DetailView")
+
+def StartTime():
+ # The Start time edit field of the Detail View
+ return FindNamedBlock("EditCalendarStartTime")
+
+def EndTime():
+ # The End time edit field of the Detail View
+ return FindNamedBlock("EditCalendarEndTime")
+
+def DisplayName():
+ # The Display name block of the Detail View
+ return FindNamedBlock("HeadlineBlock")
+
+def Location():
+ # The Location block of the Detail View
+ return FindNamedBlock("AECalendarLocation")
+
+def StartDate():
+ # The Start date edit field of the Detail View
+ return FindNamedBlock("EditCalendarStartDate")
+
+def EndDate():
+ # The End date edit field of the Detail View
+ return FindNamedBlock("EditCalendarEndDate")
+
+def AllDay():
+ # The Allday block of the Detail View
+ return FindNamedBlock("EditAllDay")
+
+"""
+Special functions, including wxWidgets-related operations
+
+All attributes in this file get added to the builtin module
+for script execution, except for ones that start with "_".
+"""
+def Focus(block):
+ # Set the input focus to the given block
+ try:
+ widget = block.widget
+ except AttributeError:
+ _logger.warning("Can't set focus to block %s" % block)
+ else:
+ widget.SetFocus()
+
+def SidebarSelect(itemOrName):
+ """ Select the item in the Sidebar """
+ # can pass in an item or a name
+ if isinstance(itemOrName, Item):
+ params = {'item':itemOrName}
+ else:
+ 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())
-
-def StampAsMailMessage():
- PressStampButton('MailMessageButton')
-
-def StampAsTask():
- PressStampButton('TaskStamp')
-
-def StampAsCalendarEvent():
- PressStampButton('CalendarStamp')
-
-def PressStampButton(buttonName):
- """ Press a Stamp button in the markup bar, by firing its event"""
- uiView = _wx.GetApp().UIRepositoryView
- for block in _Block.Block.iterItems(uiView):
- # Find the live button, by name, and make sure its parent is live too"""
- try:
- blockName = block.blockName
- except AttributeError:
- continue
- if blockName == buttonName:
- if hasattr(block, 'widget') and hasattr(block.dynamicParent, 'widget'):
- block.post(block.event, {})
- break
-
+def SummaryViewSelect(item):
+ # Tell the ActiveView to select our item
+ _Globals.mainViewRoot.postEventByName ('SelectItemBroadcastInsideActiveView', {'item':item})
+ Focus(SummaryView())
+
+def StampAsMailMessage():
+ PressStampButton('MailMessageButton')
+
+def StampAsTask():
+ PressStampButton('TaskStamp')
+
+def StampAsCalendarEvent():
+ PressStampButton('CalendarStamp')
+
+def PressStampButton(buttonName):
+ """ Press a Stamp button in the markup bar, by firing its event"""
+ uiView = _wx.GetApp().UIRepositoryView
+ for block in _Block.Block.iterItems(uiView):
+ # Find the live button, by name, and make sure its parent is live too"""
+ try:
+ blockName = block.blockName
+ except AttributeError:
+ continue
+ if blockName == buttonName:
+ if hasattr(block, 'widget') and hasattr(block.dynamicParent, 'widget'):
+ block.post(block.event, {})
+ break
+
+
def GetWindow(label):
""" Returns the window with the given label """
return _wx.FindWindowByLabel(label)
@@ -128,15 +148,15 @@
stringSuccess = stringSuccess and charSuccess
return stringSuccess
-
-"""
-TO BE DONE
-* Type(<string>) function to take the string and tell wx
- to act like the user typed it in.
- (Could add modifier flags using optional parameters)
-* Look at Select(item) method on Block, for SummaryView,
- Sidebar, etc. I think Table.GotoItem() method or something
- like that might work.
-* RunScript(<script> | <scriptNameString>) - run a script
-* Click(<location>) should be possible.
-"""
+
+"""
+TO BE DONE
+* Type(<string>) function to take the string and tell wx
+ to act like the user typed it in.
+ (Could add modifier flags using optional parameters)
+* Look at Select(item) method on Block, for SummaryView,
+ Sidebar, etc. I think Table.GotoItem() method or something
+ like that might work.
+* RunScript(<script> | <scriptNameString>) - run a script
+* Click(<location>) should be possible.
+"""
_______________________________________________
Commits mailing list
[email protected]
http://lists.osafoundation.org/mailman/listinfo/commits
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Open Source Applications Foundation "Dev" mailing list
|