Accessing network folders on windows share from Scientific linux using python file_dialog()

950 Views Asked by At

Sorry, if I have just missed this, but I cannot seem to find a resolution to this problem.

I have written a small program in python 2.7 using Qt designer to deal with the graphical interface. I call file_dialog() at some point to use the OS dialog screen to locate the directory that I wish the program to write to. Here is where the problem arises:

I have a windows share drive available in nautilus: accessed through Places>Connect to server ... I can see all of the files in place through nautilus, and create and destroy files etc, but this location is not visible from the invoked file_dialog() from python. I cannot even find from the command line where the networked share is mounted.

file_dialog is a defined function:

def file_dialog(self):
    dir_path = QtGui.QFileDialog.getExistingDirectory(self)
    return dir_path

Any help would be much appreciated, and sorry that this is probably something trivial.

Thanks a lot in advance.

2

There are 2 best solutions below

1
On

Nautilus uses Gnome VFS (virtual filesystem) layer, so it can access Windows (Samba) shares and other network resources like FTP or HTTP/Webdav as well as non-"classical filesystem resources" like MTP . This feature is implemented as a number of plugins each for a particular type of resources.

Pure Qt itself doesn't have a corresponding portable subsystem, but see this answer. If you could use KDE-specific libraries PyKDE , they also have corresponding subsystem (called KIO) which provides functionality similar to GnomeVFS and Windows native file dialogs, see this docs

Update: Windows and MacOSX have "standard" file dialogs, and likely you may use them as described in the aforementioned recipe. In Linux (more precisely, in X Window System, the graphical part of a typical PC-Linux installation, e.g. Ubuntu) there're no "system dialogs" at all, since every graphical toolkit (Qt, Gtk, Tk, Motif, ...) implements its own set of graphical primitives, widgets and dialogs.

KDE is built upon "Qt foundation" so functionality not implemented in pure Qt can be relatively seamlessly accessed via KDE-specific libraries, and likely this would be the most natural and fast solution. Certainly, you will need to use KFileDialog in Linux instead of QFileDialog with appropriate flags but the rest: event propagation system, widget styles etc will be shared in both Linux-specific code and "portable version".

0
On

Thanks for the help, I found an easier workaround, if I manually (from the terminal) mount the drive (with mount.cifs) to a known folder on the linux system then the QFileDialog has no problem interacting with it at all. It is only a problem if the drive is mounted through the GUI.