[Sugar-devel] ObjectChooser() Issue?

James Simmons nicestep at gmail.com
Tue Nov 9 13:37:01 EST 2010


I sent this answer to Art yesterday, but I didn't send it to the
group.  I think this may be the answer to his problem.

James Simmons


On Mon, Nov 8, 2010 at 4:56 PM, James Simmons <nicestep at gmail.com> wrote:
> Art,
>
> One thing I noted when I tried to read paths from Journal entries is
> that they don't stay valid forever.  I think they are symbolic links
> to the actual file.  If you read through a list of Journal objects
> only the current one will have a valid path, and the others get
> disconnected.  Hard coding a value that worked before isn't going to
> work.
>
> I would guess that the object chooser will give you a valid jobject.
>
> Maybe try this:
>
> jobject.get_file_path()
>
> instead of jobject.file_path.  It may be that using get_file_path()
> makes the datastore create the symbolic link, whereas just using
> .file_path just give the current value in the field, which might be
> stale.  I use .get_file_path() in Sugar Commander and it seems to work
> OK.
>
> James Simmons
>
>
> On Mon, Nov 8, 2010 at 4:36 PM, Art Hunkins <abhunkin at uncg.edu> wrote:
>> James,
>>
>> I tried the following variations of my "open" line:
>> open(jobject.file_path, "r").read()
>>
>> open(jobject.file_path, "r")
>>
>> self.read_file = open(jobject.file_path, "r")
>> self.read_file = open(jobject.file_path, "r").read()
>>
>> open(self.filename[0], "r").read()
>>
>> open(self.filename[0], "r")
>>
>> self.read_file = open(self.filename[0], "r")
>> self.read_file = open(self.filename[0], "r").read()
>>
>> Same result: Csound can't open the file.
>>
>> Strangely, as well, I hardcoded the filepath of the file I was selecting
>> from the Journal into Csound - to see if one of the above would at least
>> enable the (same) file to be read. No luck; still can't open the file.
>>
>> Passing the name works fine; Csound just can't open the file. And the only
>> files I seem to be able to *open* are the ones I place in the activity's
>> folder and hardcode in Csound.
>>
>> Thanks so much for your help. Do you have any idea whether using *your*
>> Journal (and USB) methods (from your Using the Journal chapter) I'd have any
>> better luck opening soundfiles to play in Csound?
>>
>> Art Hunkins
>>
>>
>> ----- Original Message ----- From: "James Simmons" <nicestep at gmail.com>
>> To: "Art Hunkins" <abhunkin at uncg.edu>
>> Sent: Monday, November 08, 2010 1:45 PM
>> Subject: Re: [Sugar-devel] ObjectChooser() Issue?
>>
>>
>> Art,
>>
>> You probably want to put the "r" argument in your open statement like this:
>>
>>       self.read_file = open(fileName,"r")
>>
>> What may be happening is that you are by default opening the file
>> read/write, which Sugar will not allow.
>>
>> James Simmons
>>
>>
>> On Mon, Nov 8, 2010 at 12:01 PM, Art Hunkins <abhunkin at uncg.edu> wrote:
>>>
>>> At Sasha's suggestion, I've arrived at the following code to send the
>>> filepath of a soundfile to Csound via its reference in the Journal. The
>>> filename (self.filename[0]) is being correctly passed:
>>>
>>> def choose1(self, widget):
>>> chooser = ObjectChooser(parent=self, what_filter=mime.GENERIC_TYPE_AUDIO)
>>> result = chooser.run()
>>> if result == gtk.RESPONSE_ACCEPT:
>>> jobject = chooser.get_selected_object()
>>> if jobject and jobject.file_path:
>>> self.filename[0] = str(jobject.file_path)
>>> # open(jobject.file_path).read()
>>> # open(self.filename[0]).read()
>>> else:
>>> self.filename[0] = "0"
>>>
>>> The problem is that the file cannot be opened by Csound - either via the
>>> above function as it stands, or by the addition of either line that is
>>> commented out.
>>>
>>> I receive this error message (from Csound):
>>> diskinfo can't open
>>> /home/olpc/.sugar/default/data/f70f03b1-fe40-44e6-9d75-5ef274cf0ad2.wav
>>> The filepath and name are correct, and the file can be played fine with
>>> either Browse or Jukebox.
>>>
>>> What must I do to make the referenced soundfile readable?
>>>
>>> Art Hunkins
>>>
>>> _______________________________________________
>>> Sugar-devel mailing list
>>> Sugar-devel at lists.sugarlabs.org
>>> http://lists.sugarlabs.org/listinfo/sugar-devel
>>>
>>
>>
>


More information about the Sugar-devel mailing list