Hi Jeffrey,
I see what you mean...I had all of that on one line the same as you did,
and I didn't notice that the paste into email bit me also.
Here's where I went next (for those who might be interested)...this
should suit for a bit my desire to have simple rapidly available prints
of collections, for example, errand lists. I'm sure I'm violating a few
standard practices and such, but that was fun, and it works. :)
Please pardon my having left in my specific naming. A minor thing I'm
not able to solve right now is how to get the menu item title to read
something other than "Some action" from your original template. I've
replaced that string in my version, but the menu item title hasn't
changed.
Cheers, Andre
#----------
#AndrePlugin/setup.py
#----------
from setuptools import setup
setup(
name = "AndrePlugin",
version = "0.1",
packages = ["andre_plugin"],
entry_points = {
"chandler.parcels": ["AndrePlugin package = andre_plugin"],
},
)
#---------- End of setup.py
#----------
#AndrePlugin/andre_plugin/__init__.py
#printtofiles
#----------
from application import schema
from osaf.framework.blocks import BlockEvent, MenuItem
from osaf.framework.blocks.Block import Block
from i18n import MessageFactory
# using _ for unicode that will be displayed to users enables localizers
to
# change the unicode
_ = MessageFactory("AndrePlugin")
def installParcel(parcel, oldVersion=None):
# find the parent menu for your new menu item
parentMenu = schema.ns('osaf.views.main', parcel).FileMenu
# the code that should handle events when your menu item is chosen
handler = AndrePluginMenuBlock.update(parcel, None,
blockName='AndrePluginMenuHandler')
# the event that's sent when your menu item is chosen
addAndrePluginEvent = BlockEvent.update(parcel, None,
blockName='ActionOnAndrePlugin',
dispatchEnum='SendToBlockByReference',
destinationBlockReference=handler)
# create the menu item
MenuItem.update(parcel, None, blockName='AndrePluginMenu',
title=_(u"Print items to file"),
accel = _(u'Ctrl+Shift+Y'),
helpString=_(u"This does something"),
event=addAndrePluginEvent,
parentBlock=parentMenu)
class AndrePluginMenuBlock(Block):
# the method name has to be the blockName of the BlockEvent above
# sandwiched with "on" and "Event"
def onActionOnAndrePluginEvent(self, event):
filename = "itemlist.txt"
# Append to existing file or create new file
file = open(filename, 'a')
print "Writing to file: %s" % filename
for item in
Block.findBlockByName("MainView").getSidebarSelectedCollection():
# Get triageStatus of item in selection collection
item_triageStatus = item._triageStatus
# Get title of item in selection collection
item_title = item.displayName
# Get body of item in selection collection
item_body = item.body
# Python's print can't print unicode, encode as utf-8
# encoded_triageStatus = item_triageStatus.encode('utf-8')
encoded_title = item_title.encode('utf-8')
encoded_body = item_body.encode('utf-8')
# Print to the console
# print "\n-------------------------------------------\n"
# print item_triageStatus
# print encoded_title
# print encoded_body
# Print to file
print >> file, "-------------------------------------------"
print >> file, "%s \n" % item_triageStatus
print >> file, "%s \n" % encoded_title
print >> file, "%s \n" % encoded_body
print >> file, "End of Item List"
file.close()
print "Done writing to file"
#---------- End of __init__.py
On Wed, 28 Nov 2007 14:51:10 -0800, "Jeffrey Harris"
<[EMAIL PROTECTED]> said:
> Hi Andre,
>
> > I believe I'm (now) installing my plugin without error.
> >
> > Q1. I made one change to the init.py script in response to a runtime
> > syntax error that halted Chandler in (my line 42) "for item in". Is my
> > fix correct?
> >
> > class AndrePluginMenuBlock(Block):
> > # the method name has to be the blockName of the BlockEvent above
> > # sandwiched with "on" and "Event"
> > def onActionOnAndrePluginEvent(self, event):
> > for item in
> > Block.findBlockByName("MainView").getSidebarSelectedCollection():
>
> "for item in" and the following "Block. ..." line ought to be on the
> same line, your code ought to give a syntax error when run :)
>
> The line I wrote will get wrapped by most mail clients. Mostly Python's
> whitespace sensitivity doesn't bother me, but it's a problem when
> emailing Python code... I should've made that line shorter.
>
> Sincerely,
> Jeffrey
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
> Open Source Applications Foundation "chandler-dev" mailing list
> http://lists.osafoundation.org/mailman/listinfo/chandler-dev
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
Open Source Applications Foundation "chandler-dev" mailing list
http://lists.osafoundation.org/mailman/listinfo/chandler-dev