Hi all, I need some insights on this gui signals + undo.

In my tool, there is a QLineEdit and a QSlider in which both are connected/ 
linked to each other, where if you made changes in the QLineEdit, it will 
updates the QSlider, likewise if you made changes on the QSlider, it will 
updates the values in the QLineEdit.

Currently I am having issues with QSlider where I am trying to collate the 
actions (as User slides it) as 1 undo action.

Here is my code:
# The signal for the slider
self.ui.planeSizeHorizontalSlider.valueChanged.connect(self.plane_size_slider)


def plane_size_slider(self, value):
    img_plane_node = self.get_current_img_plane()
    value /= 10.00
    self.ui.planeSizeLineEdit.setText(str(value))
    self.set_plane_size(img_plane_node, value)

def set_plane_size(self, node, value):
    width = cmds.getAttr("{0}.width".format(node))
    height = cmds.getAttr("{0}.height".format(node))
    ratio =  height / width

    with UndoManager(): # UndoManager is a contextmanager
        cmds.setAttr("{0}.maintainRatio".format(node), 0)
        cmds.setAttr("{0}.width".format(node), value)
        cmds.setAttr("{0}.height".format(node), value * ratio)
        cmds.setAttr("{0}.maintainRatio".format(node), 1)

While in viewport, the imagePlane does gets scaled accordingly as I perform 
changes on the slider for visual purposes, but when it comes to undo, it 
seems to be to factoring into account of all the values that I have made 
(eg. the slider value was initially at 0 and I slide it to 10, and so 10 
actions/ undos)

My question here is, if there are ways in which I can tell my QSlider to:

   - still uses valueChanged (so that User can still visualize the scaling)
   - but collate the 'sliding' as one action/ undo instead?

I tried using `sliderReleased`  but it only seems to scale the item after 
it has been released.

# The signal for the slider
self.ui.planeSizeHorizontalSlider.valueChanged.connect(self.plane_size_slider)
self.ui.planeSizeHorizontalSlider.sliderReleased.connect(self.plane_size_slider)

def plane_size_slider(self, value):
    img_plane_node = self.get_current_img_plane()
    value /= 10.00
    self.ui.planeSizeLineEdit.setText(str(value))

def plane_size_slider_release(self):
    img_plane_node = self.get_current_img_plane()
    value = float(self.ui.planeSizeLineEdit.text())
    self.set_plane_size(img_plane_node, value)

def set_plane_size(self, node, value):
    width = cmds.getAttr("{0}.width".format(node))
    height = cmds.getAttr("{0}.height".format(node))
    ratio =  height / width

    with UndoManager(): # UndoManager is a contextmanager
        cmds.setAttr("{0}.maintainRatio".format(node), 0)
        cmds.setAttr("{0}.width".format(node), value)
        cmds.setAttr("{0}.height".format(node), value * ratio)
        cmds.setAttr("{0}.maintainRatio".format(node), 1)



-- 
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/71125b08-4335-4378-83bc-b38f68e30f9a%40googlegroups.com.

Reply via email to