Open with dialog: A python program


In this entry I will show you how to open a file via Geany text-editor (or any other program) by using Python dialog function. I intend to keep things short and simple and explain majority of things with pictures.

Python dialog function, Python open with, Python open file with program

Python dialog function in action: Opening a file.

On the above image you see that we execute the python file by writing ./ to terminal. We could also write python and the file would still open. Do remember however that before you open a python file you need to make the file executable. You do this by writing chmod +x when you are within a terminal client and under the directory where you python file (, in this case) is located.

Pygtk dialog example, Pygtk dialog opening a file

Python Gtk-dialog is opening a file. And here is how it looks with Geany.

Once you select your file the above result should emerge. However, if you select nothing and press Cancel button instead you will get something like.

Python dialog closed, Python dialog no selection

Closed since no selection

You can use the dialog example provided within the zip file below as part of your own trials with python. Remember to make the file executable before trying.  to run it. If geany is not your program of choice change the line: subprocess.Popen([‘geany’, filename]) to be something else like: subprocess.Popen([‘vlc’, filename]) . Do remember to quit and restart your program when making changes.

Open with: program dialog ( .