Hi Justin, glad to know that using QSettings is the way to go... As I am 
not getting the expected output, I must have done something wrong..
I was able to save the data, but when it comes to the loading part, no 
values are loaded despite it being present in the file contents if I am 
running the whole command. And hence, I thought I may have did something 
wrong..

This is a quick UI code that I have written up:
class SampleUI(QtGui.QWidget):
    def __init__(self, parent=None):
        super(SampleUI, self).__init__(parent)
        self.init_ui()
        self.settings = QtCore.QSettings()
        print(self.settings.fileName())
        # Load the settings into the UI
        self.load()

    def init_ui(self):
        layout = QtGui.QVBoxLayout(self)
        lineEdit1 = QtGui.QLabel("Input Field")
        self.lineEdit2 = QtGui.QLineEdit()
        self.lineEdit2.setObjectName("lineEdit2")

        layout.addWidget(lineEdit1)
        layout.addWidget(self.lineEdit2)

    def load(self):
        settings = self.settings
        print '>>> ', settings.value('lineEdit2')

    def closeEvent(self, event):
        print 'UI is closed'
        settings = self.settings
        settings.setValue('lineEdit2', self.lineEdit2.text())

And this is how I have coded my shelf button:
import sample
my_code = sample.SampleUI()
my_code.show()

If I am running the shelf code the first time round, eg. inputting in "for 
testing" and closing the application, it saves that string.
If I am relaunching the tool the second time round, with the shelf code, 
while it is printing out the string values in the Script Editor, it is not 
showcase in the field.
However, if I only run the code `my_code.show()` (not via the shelf code), 
it will then showcase the string in the field.

-- 
You received this message because you are subscribed to the Google Groups 
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/5da1723a-62fe-4b6d-8e88-48d55093d5b9%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to