<br><br><div><span class="gmail_quote">On 2/29/08, <b class="gmail_sendername">Erik Blankinship</b> <<a href="mailto:erikb@mediamods.com">erikb@mediamods.com</a>> wrote:</span><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
Is there a way to filter the mime types of the objects presented with an object chooser (e.g., only png)? Here is some sample code I am using:<br><br><font size="1"><span style="font-family: courier new,monospace;">import gtk</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">import shutil</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">from sugar.graphics.objectchooser import ObjectChooser</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">class FilePicker:</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> def __init__(self):</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> pass</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> def show(self):</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> title = None</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> parent = None</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> file = None</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> chooser = ObjectChooser(title, parent, gtk.DIALOG_MODAL | gtk.DIALOG_DESTROY_WITH_PARENT)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> try:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> result = chooser.run()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> if result == gtk.RESPONSE_ACCEPT:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> jobject = chooser.get_selected_object()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> if jobject and jobject.file_path:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> ext = os.path.splitext(jobject.file_path)[1]</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> f, new_temp = tempfile.mkstemp(ext)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> del f</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> global _temp_files_to_clean</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> _temp_files_to_clean.append(new_temp)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> shutil.copy(jobject.file_path, new_temp)</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> file = new_temp</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> finally:</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> chooser.destroy()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;"> del chooser</span><br style="font-family: courier new,monospace;"><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"> return file</span></font><br>
</blockquote></div><br><br>Unfortunately, this code (and the identical code in the Browse activity) when run in jhbuild always returns this path: "."<br><br>Is this expected behavior? Is this problem unique to jhbuild? Is there something I should to differently?<br>
<br><br>