Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I'd like to make a programme, which would allow a user to choose, which application to run. I understand, it is possible to just run a command, which user specifies, but it would be much nicer, if it was possible to also give the user a list of all programmes, of which he or she could choose. Is it possible somehow?

share|improve this question
    
If you downvote the question, please, tell, what is wrong, so I could improve it. –  Ilya May 19 '13 at 16:49

1 Answer 1

up vote 2 down vote accepted

The default GtkAppChooser is probably what you want. Here is an example:

from gi.repository import Gtk

dialog = Gtk.AppChooserDialog()
dialog.set_heading("Choose an application below")
widget = dialog.get_widget()
widget.set_show_all(True)
response = dialog.run()
if response == Gtk.ResponseType.OK:
    appinfo = dialog.get_app_info()
    print "Selected:", appinfo.get_name()
    appinfo.launch(None, None)

Have a look at this documentation page which will show the GtkAppChooserWidget, GtkAppChooseButton and GtkAppChooseDialog to implement inside your application, and the GtkAppChooser interface to work with the options.

GAppInfo.launch() documentation.

share|improve this answer
    
Thanks a lot, that looks, like what I need! It is a pity, I can't find a documentation for PyGObject, but I hope your example will be sufficient for me. Also, would you happen to know, how to run the application, I get from that dialog, using python? Or is there a way to get a command, which you can just run, to launch the chosen application? –  Ilya May 19 '13 at 18:16
    
Just use the C docs. They are very good and translation to Python is very straightforward. GtkAppChooser.get_app_info() returns a GAppInfo which has a launch() method. (developer.gnome.org/gio/2.34/GAppInfo.html) –  Timo May 19 '13 at 18:54
    
Ok, thank you very much! I hope, that will do it. –  Ilya May 19 '13 at 19:20

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.