Is it possible to show a file path as a clickable url in a textctrl

Hi,

I wonder if it is possible to show in a textctrl a file path as a clickable url.

I know it is possible for a normal url like http://www.wxpython.org/ but I can't
manage to do it for a file path like c:\myfile.py.

Does anybody know if it is possible ?

Thanks in advance
Dominique

Dominique wrote:

Hi,

I wonder if it is possible to show in a textctrl a file path as a clickable url.

I know it is possible for a normal url like http://www.wxpython.org/ but I can't
manage to do it for a file path like c:\myfile.py.
  

I am not sure but try:
file:///c:\myfile.py

But remember that when you click the link it will open it in a browser. You probably can change this with your own event handler.

Werner

Hi Dominique,

Hi,

I wonder if it is possible to show in a textctrl a file path as a clickable url.

I know it is possible for a normal url like http://www.wxpython.org/ but I can't
manage to do it for a file path like c:\myfile.py.

Does anybody know if it is possible ?

Thanks in advance
Dominique

You can add mouse events to your control, so when the user clicks on it, your handler will attempt to open the file or folder. Here's one way to handle opening Window's file explorer:

import subprocess
subprocess.Popen("explorer %s" % os.path.dirname(path))

If you want to open the file based on its extension, you can use os.startfile(path). Note that if you do this with a python file, it will actually run it since python.exe is not an editor. You'll have to have some kind of if statement to differentiate from that which you want to execute and that which you want to edit.

ยทยทยท

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org
Python Extension Building Network: http://www.pythonlibrary.org

__________ Information from ESET NOD32 Antivirus, version of virus signature database 4001 (20090411) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com

Mike Driscoll <mike <at> pythonlibrary.org> writes:

Hello,

You can add mouse events to your control, so when the user clicks on it,
your handler will attempt to open the file or folder. Here's one way to
handle opening Window's file explorer:

import subprocess
subprocess.Popen("explorer %s" % os.path.dirname(path))

If you want to open the file based on its extension, you can use
os.startfile(path). Note that if you do this with a python file, it will
actually run it since python.exe is not an editor. You'll have to have
some kind of if statement to differentiate from that which you want to
execute and that which you want to edit.

-------------------
Mike Driscoll

Thanks to both of you Werner and Mike.

It works fine.

"file:///filename.ext" appears as a url (in blue and underlined).
With a mouseUp event and os.startfile(path), the file opens up.

Thank you very much for your help.
Dominique