[PyQt] Problem with QFileDialog & sideBarUrl not updated correctly
(KDE) + save/restoreState.
Gaël Honorez
gael at nozon.com
Thu Jun 11 13:39:08 BST 2009
Hi,
To begin with, I'm using pyQt 4.5 with Qt 4.5 under centos 5.3 (KDE 3.5).
I'm trying to put a Qt File browser in maya (the standard one is pretty
ugly & lack a lot of functions).
My code looks like that :
*filebrowser.py*
class MayaFileBrowser(QtGui.QFileDialog):
def __init__(self, parent=None):
QtGui.QFileDialog.__init__(self, parent)
def show(self,mode,work):
urlWorks = ('file://%s') % (work)
urlData = ('file://%s/data') % (work)
.....
fileUrl =
[QtCore.QUrl('file:///mnt/shared2/projects'),QtCore.QUrl(urlWorks),.....]
self.setSidebarUrls(fileUrl)
if mode == 0:
fd = self.getOpenFileName(self,'Open File',lastdir)
self.savePrefs()
return fd
.....
I call it like that :
CustomfileBrowser = fileBrowser.MayaFileBrowser()
CustomfileBrowser.show(0,'/mnt/shared2/projects/TDOT')
It's opening in the right mode, right directory, and return the file
correctly. Well, all is working fine except for the sideBarUrl stuff.
As you can see in the code, I'm trying to set in relative to my current
project.
If I change the project, ie.
CustomfileBrowser.show(0,'/mnt/shared2/projects/OtherProject')
The sideBarUrl is not updated, it's still in first project setted.
So I've added some print :
print fileUrl
self.setSidebarUrls(fileUrl)
print self.sidebarUrls()
fileUrl return the new project urls.
sidebarUrls (the query function of the side bar) return the new project
urls.
Still, the file Dialog show the old one.
Only if I redo a instance of my class with
CustomfileBrowser = fileBrowser.MayaFileBrowser()
Then the sideBarUrl is updated, BUT I've lost all the "recent places"
in "look in", and all the layout is reset.
Also, it's updated the second time, if I do
CustomfileBrowser = fileBrowser.MayaFileBrowser()
CustomfileBrowser.show(0,'/mnt/shared2/projects/TDOT')
I see TDOT.
CustomfileBrowser = fileBrowser.MayaFileBrowser()
CustomfileBrowser.show(0,'/mnt/shared2/projects/OtherProject')
I still See TDOT.
CustomfileBrowser.show(0,'/mnt/shared2/projects/OtherProject')
I see OtherProject.
Don't know if it's pyQt or Qt itself, but it's really annoying.
Also, I've tried the restoreState :
Saving at the end with :
settings = QtCore.QSettings("Nozon", "Linux Maya File Dialog")
settings.setValue("allPrefs",QtCore.QVariant(self.saveState()) )
Restoring at the beginning with :
settings = QtCore.QSettings("Nozon", "Linux Maya File Dialog")
prefs = settings.value("allPrefs").toByteArray()
self.restoreState(prefs)
restoreState return 1 (successfull, no error), but I dont see any of my
preference (layout or history) applied.
More information about the PyQt
mailing list