Qt has it's own INI system for storing gui prefs.  I'm using this
already in a much larger AssetBrowser ui.  The only issue with this is
that I have to write a lot of code for it, see simple snippet below
also it's a separate file to look for.  What I'd like to be able to do
is use Maya's internal methods and write a window pref via the
windowPref cmds.  This is of course just a mel file in the prefs with
mel cmds....

windowPref -topLeftCorner 300 950 -widthHeight 300 350 -parentMain
true TD_RigBox;

optVars are the same

optionVar
 -ca "RigDebugTools_GuiPosition"
 -iva "RigDebugTools_GuiPosition" 449
 -iva "RigDebugTools_GuiPosition" 195

Qt's System look like this...

# Code to implement...

    def writeSettings(self):
        ## Screen Pos Data
        self.Settings.beginGroup("MainWindow")
        self.Settings.setValue("size", QtCore.QVariant(self.size()))
        self.Settings.setValue("pos", QtCore.QVariant(self.pos()))
        self.Settings.endGroup()


    def readSettings(self):
        # Set Window Size
        self.Settings.beginGroup("MainWindow")
        size = self.Settings.value("size",
QtCore.QVariant(QtCore.QSize(818, 684)))
        self.resize(size.toSize())
        pos = self.Settings.value("pos",
QtCore.QVariant(QtCore.QPoint(200, 200)))
        self.move(pos.toPoint())
        self.Settings.endGroup()

# File saved as ini looks like
[MainWindow]
si...@size(1057 685)
p...@point(1302 182)

The advantage of a seperate INI file is it's native QT. If the gui can
run outside of maya these settings will be preserved.

But for simple gui's or simplish gui's and gui's that can only run
inside of maya.  I like the simplicity of the optVar approach employed
by pymel.  It's no biggy.  But perhaps windowPrefs could be wrapped
into a custom dict object much like optVars.

..note:

this is effectively dict.setdefault()
pos = self.Settings.value("pos", QtCore.QVariant(QtCore.QPoint(200,
200)))

What do you guys reckon?  PS we use ConfigObj here as our INI reader.
Never used ConfigParser.  I'll take a look at it when I get 5.

Cheers

-Dave





On Feb 4, 6:02 pm, Chad Dombrova <[email protected]> wrote:
> On Feb 4, 2010, at 9:55 AM, Chris G wrote:
>
> > On Thu, Feb 4, 2010 at 12:33 PM, thirstydevil <[email protected]
> > > wrote:
> >> Lovin pymel for wrapping optVars into a dict.  Wondering if pymel
> >> could wrap the window prefs in the same way?
>
> >> currently I'm doing this, it's the wrong place to be storing the
> >> data.  Qt's native way is over kill for this smallish gui.  What do
> >> you recon?
>
> > You could try the ConfigParser module.  It's simple and effective.
>
> along these lines, also check out iniparse:http://code.google.com/p/iniparse/
>     it has an implementation that is backward compatbile with  
> ConfigParser but it's better at reading in an existing config, making  
> changes, then writing it back out, preserving most formatting.
>
> -chad

-- 
http://groups.google.com/group/python_inside_maya

Reply via email to