ivanbusquets

check instances of QtWidget in Panel

Oct 24th, 2013
361
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.90 KB | None | 0 0
  1. from PySide import QtGui
  2.  
  3. class TestWidget(QtGui.QLabel):
  4.     def __init__(self, parent=None):
  5.         self.checkInstances()
  6.         super(TestWidget, self).__init__(parent)
  7.        
  8.         self.setObjectName('myID')
  9.         self.setText('only show me once')
  10.  
  11.     def checkInstances(self):
  12.         print 'new instance:', self
  13.         for widget in QtGui.QApplication.allWidgets():
  14.             name = widget.objectName()
  15.             if type(widget) == type(self):
  16.                 print "instance already present"
  17.                 p = widget.parentWidget()
  18.                 while p:
  19.                     if p.parent() and isinstance(p.parent(), QtGui.QStackedWidget):
  20.                         p.parent().removeWidget(p)
  21.                         p = None
  22.                     else:
  23.                         p = p.parentWidget()
  24.  
  25.  
  26. nukescripts.registerWidgetAsPanel('TestWidget', 'test widget', 'myID')
Advertisement
Add Comment
Please, Sign In to add comment