[Sugar-devel] ObjectChooser() Issue?
Bert Freudenberg
bert at freudenbergs.de
Mon Nov 15 06:12:54 EST 2010
On 15.11.2010, at 00:00, Sascha Silbe wrote:
> Excerpts from Art Hunkins's message of Sun Nov 14 23:20:49 +0100 2010:
>
>> The jobject is being selected just fine; the problem is, it is still being
>> deleted, even though I'm trying to store its path.
>
> That's exactly the problem: You need to store the _DSObject_ instance,
> not just the path to the file.
Here is what likely happens:
1. User chooses object.
2. You create a DSObject instance, put it in the jobject temp var
3. You store the path of the DSObject instance.
4. The jobject temp var goes "out of scope", automatically deletes the file.
5. You try to access the file path, but the file is gone.
In your code:
if result == gtk.RESPONSE_ACCEPT:
jobject = chooser.get_selected_object() <== jobject created
if jobject and jobject.file_path: <== file created
self.file[0] = jobject.get_file_path()
open(self.file[0], "r")
self.fileflag[0] = "1"
else:
self.fileflag[0] = "0"
close(self.file[0])
<== jobject destroyed
<== file deleted
# Later, variables sent to my Csound code via:
self.w.set_channel("fileflag1", self.fileflag[0])
self.w.set_filechannel("file1", str(self.file[0]))
So, as Sascha wrote, keep the jobject, not just the file path, until you do need the file anymore. The files you check out from the Journal are considered temporary. The DSObject mechanism ensures those temp files are cleaned up automatically.
- Bert -
More information about the Sugar-devel
mailing list