August'24: Kamaelia is in maintenance mode and will recieve periodic updates, about twice a year, primarily targeted around Python 3 and ecosystem compatibility. PRs are always welcome. Latest Release: 1.14.32 (2024/3/24)
The Chooser component iterates (steps) forwards and backwards through a list of items. Request the next or previous item and Chooser will return it.
The ForwardIteratingChooser component only steps forwards, but can therefore handle more than just lists - for example: infinite sequences.
A simple slideshow:
items=[ "image1.png", "image2.png", "image3.png", ... ]
Graphline( CHOOSER = Chooser(items=imagefiles),
FORWARD = Button(position=(300,16), msg="NEXT", caption="Next"),
BACKWARD = Button(position=(16,16), msg="PREV", caption="Previous"),
DISPLAY = Image(position=(16,64), size=(640,480)),
linkages = { ("FORWARD" ,"outbox") : ("CHOOSER","inbox"),
("BACKWARD","outbox") : ("CHOOSER","inbox"),
("CHOOSER" ,"outbox") : ("DISPLAY","inbox"),
}
).run()
The chooser is driven by the 'next' and 'previous' Button components. Chooser then sends filenames to an Image component to display them.
Another example: a forever looping carousel of files, read at 1MBit/s:
def filenames():
while 1:
yield "file 1"
yield "file 2"
yield "file 3"
JoinChooserToCarousel( chooser = InfiniteChooser(items=filenames),
carousel = FixedRateControlledReusableFilereader("byte",rate=131072,chunksize=1024),
)
When creating it, pass the component a set of items for it to iterate over.
Chooser will only accept finite length datasets. InfiniteChooser will accept any interable sequence, even one that never ends from a generator.
Once activated, the component will emit the first item from the list from its "outbox" outbox.
If the list/sequence is empty, then nothing is emitted, even in response to messages sent to the "inbox" inbox described now.
Send commands to the "inbox" inbox to move onto another item of data and cause it to be emitted. This behaviour is very much like a database cursor or file pointer - you are issuing commands to step through a dataset.
Send "SAME" and the component will emit the same item of data that was last emitted last time. Both Chooser and InfiniteChooser respond to this request.
Send "NEXT" and the component will emit the next item from the list or sequence. If there is no 'next' item (becuase we are already at the end of the list/sequence) then nothing is emitted. Both Chooser and InfiniteChooser respond to this request.
With InfiniteChooser, if there is not 'next' item then, additionally, a producerFinished message will be sent out of its "signal" outbox to signal that the end of the sequence has been reached. The component will then terminate.
All requests described from now are only supported by the Chooser component. InfiniteChooser will ignore them.
Send "PREV" and the previous item from the list or sequence will be emitted. If there is no previous item (because we are already at the front of the list/sequence) then nothing is emitted.
Send "FIRST" or "LAST" and the first or last item from the list or sequence will be emitted, respectively. The item will be emitted even if we are already at the first/last item.
If Chooser or InfiniteChooser receive a shutdownMicroprocess message on the "control" inbox, they will pass it on out of the "signal" outbox. The component will then terminate.
Chooser([items]) -> new Chooser component.
Iterates through a finite list of items. Step by sending "NEXT", "PREV", "FIRST" or "LAST" messages to its "inbox" inbox.
Keyword arguments:
Warning!
You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Return the current choice to the outbox
Goto the first item in the set. Returns True.
Goto the last item in the set. Returns True.
Advance the choice forwards one.
Returns True if successful or False if unable to (eg. already at end).
Backstep the choice backwards one.
Returns True if successful or False if unable to (eg. already at start).
Main loop.
Returns True if a shutdownMicroprocess message was received.
Chooser([items]) -> new Chooser component.
Iterates through an iterable set of items. Step by sending "NEXT" messages to its "inbox" inbox.
Keyword arguments: - items -- iterable source of items to be chosen from (default=[])
Warning!
You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
Return the current choice
Advance the choice forwards one.
Returns True if successful or False if unable to (eg. already at end).
Main loop.
Returns True if a shutdownMicroprocess message was received.
Got a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording!
Please leave you feedback here in reply to the documentation thread in the Kamaelia blog.
-- Automatic documentation generator, 05 Jun 2009 at 03:01:38 UTC/GMT