def __init__( self, parent, referenceComponent = None ): super( OldInput, self ).__init__( parent ) self.selectedInput = None dialog = self.dialog = QtGui.QDialog( self.parent() ) dialog.setLayout( QtGui.QVBoxLayout() ) tree = TreeView() treeWidget = TreeWidget( tree, 'Get existing input' ) model = ColorComponentModel() model.setRoot( ComponentModel().rootComponent ) isInput = lambda comp: isinstance( comp, Input ) model.addColorCondition( isInput , 'red', QtGui.QFont.Bold ) model.addCycler( tree, isInput, treeWidget.addButton( 'Next' ) ) if referenceComponent: model.insertColorCondition( 0, referenceComponent, 'blue', QtGui.QFont.Bold ) cycler = model.addCycler( tree, referenceComponent, treeWidget.addButton( 'Current input' ) ) for i in range( len( cycler.items ) ): cycler.next() tree.setModel( model ) def itemSelected( component ): if isinstance( component, Input ): self.selectedInput = component dialog.accept() tree.doubleClicked.connect( lambda index: itemSelected( model.itemFromIndex( index ).component ) ) dialog.layout().addWidget( treeWidget )
def __init__( self, condition = lambda component: True ): super( ClipBoardBrowser, self ).__init__() tree = TreeView() tree.setModel( ClipBoardModel() ) layout = QtGui.QVBoxLayout( self ) layout.addWidget( TreeWidget( tree ) ) tree.doubleClicked.connect( lambda index: self.componentSelected( tree.model().itemFromIndex( index ).component ) ) self.condition = condition
def __init__( self, parent, condition = None, delegate = None ): super( ClipBoardSelectDialog, self ).__init__( parent ) tree = TreeView() tree.setModel( ClipBoardModel() ) if delegate: tree.setItemDelegate( delegate ) condition = condition( self ) if condition else lambda component: True def doubleClicked( index ): if not index.isValid(): return component = tree.model().itemFromIndex( index ).component if condition( component ): self.result = component self.accept() tree.doubleClicked.connect( doubleClicked ) layout = QtGui.QVBoxLayout( self ) layout.addWidget( TreeWidget( tree, 'Get from Clip board' ) ) self.condition = condition