python - Add filter on executable files in filechooser dialog using pygtk when OS is Ubuntu -


i using pygtk create file chooser widget. using ubuntu os. want put filter in selecting files. chooser widget should select executable files (diamond icons or in ubuntu). trying use below code:

dialog  = gtk.filechooserdialog(title=none,action=gtk.file_chooser_action_open,                                   buttons=(gtk.stock_cancel,gtk.response_cancel,gtk.stock_ok,gtk.response_ok))  filter_file = gtk.filefilter() filter_file.add_pattern("*.bin") filter_file.add_pattern("*.run") filter_file.add_pattern("*.sh") dialog.add_filter(filter_images) dialog.show() 

it not working. not show executable files in chooser window. there way can put filter on executable files because seems ubuntu not have extension executable files.

i'm not familiar gtk, quick @ docs gtk.filefilter leads me believe using filefilter.add_custom instead of filefilter.add_pattern allow write custom filter function can permission bits file determine if executable or not. example:

import os  def executable_filter(filter_info, data):     path = filter_info[0] #   note checks if current effective user may execute file.  if need know if owner/group/other can execute it, you'll want os.stat module.     return os.access(path, os.x_ok)  filter_file.add_custom((gtk.file_filter_filename, none, none, none), executable_filter, none) 

i can't test this, because don't have gtk set up, think approach work.


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -