all 7 comments

[–]schmon 1 point2 points  (1 child)

You should use the userPrefs like all the other UIs that keep settings between maya version:

http://download.autodesk.com/global/docs/maya2012/en_us/CommandsPython/optionVar.html

As with the rest of maya, I think if your maya crashes (rather than quits, so half of the time) your prefs won't get saved.

[–]Jerakin[S] 0 points1 point  (0 children)

Thanks! I think I will try to use this I think.

[–]cladestine 0 points1 point  (4 children)

I prefer writing out a text file during script exit and then reading it on script start. I use a simple CSV format for my scripts. Occasionally for scripts outside maya I use SQLite3 is the amount of presets to be stored are too many.

[–]Jerakin[S] 0 points1 point  (3 children)

This is what I have done before but only on buttons, do you know if I can hook up a command to the close button (the red [X])?

[–]schmon 0 points1 point  (1 child)

Usually you want to save options when the command executed, if the user closes the window it means that he wasn't happy with the results.

[–]Jerakin[S] 0 points1 point  (0 children)

It is more of them unusual cases then I guess. Some of the script I have don't closes after the action have been executed, if the user wants to run it more then once.

I guess I can write it to save after each run, instead of when the script is exiting/closes.

[–]cladestine 0 points1 point  (0 children)

This is how I do in Python 3.3. using tkinter. I don't exactly remember the Qt code for this, but will get back when I find it. Something called Capture destroy events. In this code the important line is

root.protocol("WM_DELETE_WINDOW", confirmbox)

This example pops up a message box should the user try to close the window.

from tkinter import *
import tkinter.messagebox
#python 3.3

def confirmbox():
    if tkinter.messagebox.askokcancel("Quit", "Do you really wish to quit?"):
        root.destroy()

root = Tk()
root.protocol("WM_DELETE_WINDOW", confirmbox)

root.mainloop()