[Sugar-devel] Object Chooser (selecting user-created audio objects from the Journal)
abhunkin at uncg.edu
Thu Dec 23 20:56:15 EST 2010
Aleksey: Thanks so much for your suggestions/corrections. And Walter: thanks
equally for posting these ideas to the wiki.
Aleksey: Please take a look at this further refinement of the Chooser
def choose(self, widget):
chooser = ObjectChooser(parent=self, what_filter=mime.GENERIC_TYPE_AUDIO)
result = chooser.run()
if result == gtk.RESPONSE_ACCEPT:
self.jobject = chooser.get_selected_object()
self.path = str(self.jobject.get_file_path())
self.jobject = None
self.path = "0"
It is essential that if the Journal is closed without a selection, that the
default values (for self.jobject and self.path) be reset.
Also, the user needs to be able to change his mind - to make a second
selection, as well as to revert to the default.
Is the above code a fairly good way of achieving this?
Also, I'd like to find a way to limit the selected Journal object to an
*audio* file, one included in mime.GENERIC_TYPE_AUDIO - and (likewise) to
revert to default values if such a selection is not made.
Do you see a fairly simple way of making such a "filter"? I'd rather not get
into specifying all specific file types (except, if feasible, to rule out
Once again, thanks for your insights.
----- Original Message -----
From: "Aleksey Lim" <alsroot at member.fsf.org>
To: "Art Hunkins" <abhunkin at uncg.edu>
Cc: <Sugar-devel at lists.sugarlabs.org>
Sent: Wednesday, December 22, 2010 1:22 AM
Subject: Re: [Sugar-devel] Object Chooser (selecting user-created audio
objects from the Journal)
> On Tue, Dec 21, 2010 at 09:54:24PM -0500, Art Hunkins wrote:
>> I'd like to thank all those who helped me get Object Chooser in the
>> up and running in my FileMix activity. I'd also like to share my results,
>> case the code could be helpful to others.
>> Excerpts follow:
>> from sugar.graphics.objectchooser import ObjectChooser
>> from sugar import mime
>> self.jname1 = "0"
>> self.jobject1 = 0
>> if os.path.exists("/etc/fedora-release"):
>> release = open("/etc/fedora-release").read()
>> if release.find("OLPC release 9 ") == -1:
>> # Insert here code relevent to Sugar 0.84 and higher
>> # I use this to only display Object Chooser callback buttons only for >=
>> # Clicking one of the displayed buttons calls the choose1 method
>> def choose1(self, widget):
>> chooser = ObjectChooser(parent=self,
>> result = chooser.run()
>> if result == gtk.RESPONSE_ACCEPT:
>> jobject = chooser.get_selected_object()
>> if jobject and jobject.file_path:
>> self.jobject1 = jobject
>> self.jname1 = str(jobject.get_file_path())
>> self.jname1 = "0"
>> Random observations:
>> 1) I exclude Sugar 0.82 for two reasons (which means, unfortunately, "no
>> user soundfiles for 0.82"):
> Another useful way to check sugar version is:
> from jarabe import config
> version = [int(i) for i in config.version.split('.')][:2]
> except ImportError:
> version = [0, 82]
> if version >= [0, 84]:
>> a) its version of Object Chooser does not allow filtering for the audio
>> mime type;
>> b) Sugar 0.82's Csound (5.08) - or more specifically its version of
>> libsndfile - does not handle ogg vorbis soundfiles, the type that the
>> activity creates. Record is the most likely/accessible means that
>> would use to create their own soundfiles. (The whole idea behind using
>> Object Chooser here is to select user files that have been placed in the
>> Journal [as Record does by default] for performance in FileMix.)
>> c) In addition, earlier versions of Record (<v64 or so) create ogg SPEEX
>> soundfiles; even the recent versions of Csound (actually, libsndfile) do
>> handle this (lo-fi) format.
>> I found that a search for "OLPC release 9 " in /etc/fedora-release
>> identifies all current 0.82 incarnations of Sugar of which I'm aware.
>> 2) jname1 stores the soundfile name (complete path); jobject1 stores the
>> object itself. This is key to being able (in Csound) to locate and load
>> selected soundfile. jname1 is then a channel opened to send the named
>> soundfile to Csound.
> You can make code more elegant by using only jobject1
> (and None initializer):
> self.jobject1 = None
> if result == gtk.RESPONSE_ACCEPT:
> self.jobject1 = jobject
> if self.jobject1 is not None:
> path = str(self.jobject1.get_file_path())
>> 3) If the user closes the Object Chooser box instead of clicking on a
>> object, the result is not accepted, and jname1 reverts to "0" - which is
>> flag (in Csound) to revert to the default soundfile included in FileMix.
>> 4) The str() cast for self.jname1 converts the filename to the usual path
>> format readable by Csound (this too is required).
> Yeah, I guess it is dbus string object... maybe we need to this type
> cast in sugar-toolkit code (though in most cases this casting should
> happen implicitly).
>> Art Hunkins
>> Sugar-devel mailing list
>> Sugar-devel at lists.sugarlabs.org
More information about the Sugar-devel