Re: [Maya-Python] Capture inputs from PyQt dialog

2018-08-24 Thread kiteh
Noted with thanks!

-- 
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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/0123812b-d98f-4e00-8843-970709c39f19%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Capture inputs from PyQt dialog

2018-08-23 Thread Justin Israel
On Fri, Aug 24, 2018 at 1:24 PM kiteh  wrote:

> Got it, thanks! Had thought that there may not be a need to perform
> another `setText()
> I have got another question.. sorry for the mass spam.
>
> I tried following what you have mentioned and do the same for my other
> widgets - checkbox and radiobuttons..
> eg. *self.checkbox01.setChecked(settings.value('check_value', False))*
>
> As soon as I tried relaunching my tool in a new session (no previous saved
> states), it errors out and I was presented with the error
> self.checkbox01.setChecked(settings.value('checking', False))
> # TypeError: 'PySide2.QtWidgets.QAbstractButton.setChecked' called with
> wrong argument types:
> #   PySide2.QtWidgets.QAbstractButton.setChecked(unicode)
> # Supported signatures:
> #   PySide2.QtWidgets.QAbstractButton.setChecked(bool) #
>
> Going by the error, I have tried using `bool(0)`, `bool(False)` etc, but
> the error persists.
> Is PyQt handling this differently?
>

PyQt has always had a 'bug' in how it serialized bool values. It writes
them as a string and reads them back that way. PySide seems to do it
correctly. What you should do is:

s.setValue('field', int(val))
bool(s.value('field', False))

If you coerce them to and from int, you will be fine.


> --
> 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 python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/c1504128-9c76-4f1a-87db-7a7bb9c66978%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3HS0BHqoLZw7-U3i86hwwbcs-Wjk5wQGX8Ewe4xEz%2Bdw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Capture inputs from PyQt dialog

2018-08-23 Thread kiteh
Got it, thanks! Had thought that there may not be a need to perform another 
`setText()
I have got another question.. sorry for the mass spam.

I tried following what you have mentioned and do the same for my other 
widgets - checkbox and radiobuttons.. 
eg. *self.checkbox01.setChecked(settings.value('check_value', False))*

As soon as I tried relaunching my tool in a new session (no previous saved 
states), it errors out and I was presented with the error 
self.checkbox01.setChecked(settings.value('checking', False))
# TypeError: 'PySide2.QtWidgets.QAbstractButton.setChecked' called with 
wrong argument types:
#   PySide2.QtWidgets.QAbstractButton.setChecked(unicode)
# Supported signatures:
#   PySide2.QtWidgets.QAbstractButton.setChecked(bool) # 

Going by the error, I have tried using `bool(0)`, `bool(False)` etc, but 
the error persists.
Is PyQt handling this differently?

-- 
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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/c1504128-9c76-4f1a-87db-7a7bb9c66978%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Capture inputs from PyQt dialog

2018-08-23 Thread Justin Israel
Firstly, make sure you are setting an organization and an application name,
so that you don't collide with another Qt application:
http://doc.qt.io/archives/qt-4.8/qsettings.html#QSettings

The reason you aren't seeing your saved text being loaded to your UI is
because you forgot to actually setText the value:

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

Note the second arguments to value() is the default to use if the setting
wasn't not previously set.


On Fri, Aug 24, 2018 at 10:04 AM kiteh  wrote:

> 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 python_inside_maya+unsubscr...@googlegroups.com.
> 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.
>

-- 
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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA3zhz_kpsMTQbcitA_wDzGO433MkEvXgODaRkwHDum8_g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: [Maya-Python] Capture inputs from PyQt dialog

2018-08-23 Thread kiteh
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 python_inside_maya+unsubscr...@googlegroups.com.
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.


Re: [Maya-Python] Capture inputs from PyQt dialog

2018-08-23 Thread Justin Israel
On Fri, Aug 24, 2018 at 9:06 AM kiteh  wrote:

> I have created my tool using PyQt. Things are working correctly and I am
> encountering 2 issues.
>
> 1. This is more of an implementation - I am trying to capture the input
> state of the widgets that User has made within the tool. Eg. User has
> written something in one of the many QLineEdits, checked some options in
> the checkboxes etc. How can I 'save' and load these inputs?
>

Use QSettings  to save and
load the state of your application.
This means you have some point in your app, either as things change or once
on a close or hide event, where you save the state to your QSettings (can
be created on the fly). And then you have a point when you first initialize
your app that you load them back from the QSettings.


>
> 2. Since converting my tool to use PyQt, I came to notice that 'undo-ing'
> functionality does not works, only the actions that my tool has executed
> on. Is this a known issue if one changes from using maya.cmds gui to pyqt?
>

Maya has no way to know what you are doing within your Qt widgets. It only
knows what you do when you call into its cmds API. So you would need to
make use of cmds.undoInfo or the api MDGModifier if you are talking about
controlling Maya operations. But if you are talking about undoing
operations to your custom UI, then you would have to look at having your
own undo:
http://doc.qt.io/archives/qt-4.8/qundo.html


>
>
> --
> 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 python_inside_maya+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/python_inside_maya/9b86a5e5-2b34-4a98-be14-9cb18929615a%40googlegroups.com
> 
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 python_inside_maya+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/python_inside_maya/CAPGFgA1pOyCxteee8HTfuO0p1y5s-eQiy_R56ZiUm7yzAEoH5g%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.