GetOpenCommand and problems under KDE

Hi!

After spending a few months away from my programmes,
I'm returning to my keyboard and lovely (wx)Python.

And here comes a small problem.
I'm using GetOpenCommand to get a command to input it as a argument to
wx.Execute.

Everything works fine when running application under Gnome and Windows, but
I've met some KDE issues - in that WM GetOpenCommand returns None.

The code (a shortcut version):

ft= wx.TheMimeTypesManager.GetFileTypeFromExtension(ext)
mime = ft.GetMimeType() or ""
cmd = ft.GetOpenCommand(file_path, mime)
wx.Execute(cmd)

Is it a known problem which can be easily overcome or is it my
fault?

Thanks for comments.

Hello,

Hi!

After spending a few months away from my programmes,
I'm returning to my keyboard and lovely (wx)Python.

And here comes a small problem.
I'm using GetOpenCommand to get a command to input it as a argument to
wx.Execute.

Everything works fine when running application under Gnome and Windows, but
I've met some KDE issues - in that WM GetOpenCommand returns None.

The code (a shortcut version):

ft= wx.TheMimeTypesManager.GetFileTypeFromExtension(ext)
mime = ft.GetMimeType() or ""
cmd = ft.GetOpenCommand(file_path, mime)
wx.Execute(cmd)

Is it a known problem which can be easily overcome or is it my
fault?

I believe this is a current limitation of the MimeTypesManager, I have heard some chatter of improvements for 2.9.

Currently I try to query what the filemanager is and then let it decide how to open the file.

def GetFileManagerCmd():
     """Get the file manager open command for the current os. Under linux
     it will check for nautilus and konqueror and return which one it finds
     first or 'nautilus' (Gnome) if it finds neither.
     @return: string

     """
     if wx.Platform == '__WXMAC__':
         return 'open'
     elif wx.Platform == '__WXMSW__':
         return 'explorer'
     else:
         # Check for common linux filemanagers returning first one found
         # Gnome/ubuntu KDE/kubuntu xubuntu
         for cmd in ('nautilus', 'konqueror', 'Thunar'):
             result = os.system("which %s > /dev/null" % cmd)
             if result == 0:
                 return cmd
         else:
             return 'nautilus'

Cody

···

On Jul 21, 2008, at 5:49 PM, Sebastian Żurek wrote:

Cody Precord wrote:

Currently I try to query what the filemanager is and then let it
decide how to open the file.

OK - but how do You explicitly 'let it' to open the file? Just something as
simple as wx.Execute('file_manager file_to_be_open') or something more
sophisticated?

Hello,

···

On Jul 21, 2008, at 6:15 PM, Sebastian Żurek wrote:

Cody Precord wrote:

Currently I try to query what the filemanager is and then let it
decide how to open the file.

OK - but how do You explicitly 'let it' to open the file? Just something as
simple as wx.Execute('file_manager file_to_be_open') or something more
sophisticated?

Yep, thats it.

Cody

I believe this is a current limitation of the MimeTypesManager, I have heard some chatter of improvements for 2.9.
Currently I try to query what the filemanager is and then let it decide how to open the file.
def GetFileManagerCmd():
   """Get the file manager open command for the current os. Under linux
   it will check for nautilus and konqueror and return which one it finds
   first or 'nautilus' (Gnome) if it finds neither.
   @return: string

Do you have another function that you use to actually open the file, or is that left up to the caller?

Left up to the caller, I use this primarily as a generic way getting a command to pass to a subprocess call that I fork of into a separate thread.

   """
   if wx.Platform == '__WXMAC__':
       return 'open'
   elif wx.Platform == '__WXMSW__':
       return 'explorer'

If the answer to the above is that there is another function then having it use os.startfile() on windows will probably be better/more efficient than executing explorer.

True, its use is quite limited however and rarely called. So I prefer to minimize on special case handling code when possible.

   else:
       # Check for common linux filemanagers returning first one found
       # Gnome/ubuntu KDE/kubuntu xubuntu
       for cmd in ('nautilus', 'konqueror', 'Thunar'):
           result = os.system("which %s > /dev/null" % cmd)

You may want to check first for xdg-open. If it's installed on the system then it should work no matter which desktop environment is installed. In fact IIUC the major players are migrating their built-in code and APIs to use the new xdg tools (and this is likely what the new wxMimeTypesManager will be built on too.)

Good to know. It will be nice if more of these basic things can have a common interface between Linux distro/environments.

Cody

···

On Jul 21, 2008, at 6:29 PM, Robin Dunn wrote:

Cody - thanks for the idea and the code. Now I've got the things running
properly also under KDE.

Regards!