Well, i got it. Here is a code i'm working, it still have some bug but it's work ThankS!
import os > import json > > from PySide.QtGui import QMainWindow > from PySide import QtGui, QtCore > from maya import cmds > > from . import Bob > from ..qt_utils import get_anchor > > > class Picker(QMainWindow): > > def __init__(self, parent, data): > super(Picker, self).__init__(parent) > self.ui = Bob.Ui_MainWindow() > self.data = data > self.ui.setupUi(self) > self.rubberband = QtGui.QRubberBand( > QtGui.QRubberBand.Rectangle, self) > self.setMouseTracking(True) > # SIGNALS > self.SCRIPT_JOB_NUMBER = cmds.scriptJob(event=["SelectionChanged", > self.mayaSelectionChange]) > for k, v in data["anim_table"].iteritems(): > if hasattr(self.ui, k): > getattr(self.ui, k).clicked.connect(lambda t=v: > self.select(t)) > self.ui.select_all.clicked.connect( > lambda t=data["anim_table"].values(): self.select(t)) > > def select(self, target): > shift, ctrl = 1, 4 > mod = int(cmds.getModifiers()) > flags = {"replace": mod == 0, > "toggle": mod == shift, > "deselect": mod == ctrl, > "add": mod == ctrl + shift} > cmds.select(target, **flags) > > def mousePressEvent(self, event): > self.origin = event.pos() > self.rubberband.setGeometry( > QtCore.QRect(self.origin, QtCore.QSize())) > self.rubberband.show() > QtGui.QWidget.mousePressEvent(self, event) > > def mouseMoveEvent(self, event): > if self.rubberband.isVisible(): > self.rubberband.setGeometry( > QtCore.QRect(self.origin, event.pos()).normalized()) > QtGui.QWidget.mouseMoveEvent(self, event) > > def mouseReleaseEvent(self, event): > if self.rubberband.isVisible(): > self.rubberband.hide() > selected = [] > rect = self.rubberband.geometry() > for child in self.findChildren(QtGui.QPushButton): > if rect.intersects(child.geometry()): > selected.append(child) > if selected: > # for child in selected: > # print ''.join("%s\n" % i for i in dir(child)) > # print child.isChecked() > [child.click() for child in selected] > self.select([self.data["anim_table"][child.objectName()] > for child in selected]) > else: > print ' Nothing\n' > QtGui.QWidget.mouseReleaseEvent(self, event) > > def mayaSelectionChange(self): > for child in self.findChildren(QtGui.QPushButton): > if child.isChecked() == True: > selection = cmds.ls(selection = True) > if len(selection)>0: > if self.data["anim_table"][child.objectName()] in > [x.encode('UTF8') for x in selection]: > child.setChecked(True) > else: > child.setChecked(False) > else: > child.setChecked(False) > > def closeEvent( self, event ): > # Clean up the script job stuff prior to closing the dialog. > cmds.scriptJob( kill=self.SCRIPT_JOB_NUMBER, force=True ) > super( Picker, self ).closeEvent( event ) > > def show(): > path = os.path.join(os.path.dirname(__file__), "..", "data", > "Bob.json") > with open(path) as fp: > d = json.load(fp) > if d.get("filetype") == "picker_data" and d.get("version") >= 0.1: > Picker(parent=get_anchor(), data=d).show() > > > On Wednesday, April 12, 2017 at 6:17:32 AM UTC+7, Justin Israel wrote: > > > > On Wed, Apr 12, 2017 at 3:57 AM nguyen vuducthuy <nguyenv...@gmail.com > <javascript:>> wrote: > >> Hi there, >> >> I try to create an character picker that when i pressed button i select >> an object in the scene and it will keep highlight until i deselect that >> object. This really help me know what i'm selecting. >> Thank for your help! >> > > Sound like you want to make the button checkable: > http://doc.qt.io/qt-4.8/qabstractbutton.html#checkable-prop > > Then you need to wire up a Maya callback so that the deselection can > update the checked state on the button. > > Justin > > >> -- >> 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 <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/python_inside_maya/cc0ae6f1-a251-4fb3-b063-fba31a54f8b3%40googlegroups.com >> >> <https://groups.google.com/d/msgid/python_inside_maya/cc0ae6f1-a251-4fb3-b063-fba31a54f8b3%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> 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/cdf1a0e7-842d-4a1c-9b46-e89768c9050a%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.