[Closed] Dotnet <> Max Combobox
If you want it to be more iTunes-like where you match on the text anywhere in the name, you could do this:
pat = “” + txt + “”
Looks very cool – I wanted to show you an example of what you could do in Python & PyQt to solve your problem (I am trying to get more awareness about dotNet alternatives in 3dsMax out in the public more)
One of the cool things you can do in PyQt is you could actually make that item (your two controls) into a single reusable widget –
This would be the widget file:
c:/temp/LinkedListWidget.py
# Make my own reusable widget
from PyQt4.QtGui import QWidget
class LinkedListWidget( QWidget ):
def __init__( self, parent ):
QWidget.__init__( self, parent )
from PyQt4.QtGui import QListWidget
from PyQt4.QtGui import QVBoxLayout
from PyQt4.QtGui import QLineEdit
# Create a text field and a listbox
layout = QVBoxLayout()
layout.setContentsMargins( 0, 0, 0, 0 )
self._textEdit = QLineEdit( self )
self._listWidget = QListWidget( self )
self._items = []
layout.addWidget( self._textEdit )
layout.addWidget( self._listWidget )
self.setLayout( layout )
self._connect()
def _connect( self ):
from PyQt4.QtCore import SIGNAL
self.connect( self._textEdit, SIGNAL( 'textChanged(const QString &)' ), self.filterItems )
def filterItems( self, text ):
self._listWidget.clear()
if ( str( text ) ):
import re
expr = re.compile( str( text ).replace( '*', '.*' ), re.IGNORECASE )
filtered = [ item for item in self._items if expr.match( str( item ) ) ]
self._listWidget.addItems( filtered )
self._listWidget.setCurrentRow( 0 )
else:
self._listWidget.addItems( self._items )
def setItems( self, items ):
items.sort()
self._items = items
self._listWidget.clear()
self._listWidget.addItems( items )
Then, from any other tool you’d want to use it for (you could write it for tools inside of max or standalone apps), you now have access to it!
from LinkedListWidget import LinkedListWidget # Import my widget class
This would be it in use inside of max:
c:/temp/test.py
from blur.wingui import Dialog
# Register the location of the linked list widget
import sys
if ( not 'c:/temp' in sys.path ):
sys.path.append( 'c:/temp' )
from LinkedListWidget import LinkedListWidget
class MyDialog( Dialog ):
def __init__( self ):
Dialog.__init__( self )
from PyQt4.QtGui import QVBoxLayout
layout = QVBoxLayout()
widget = LinkedListWidget( self )
layout.addWidget( widget )
self.setLayout( layout )
self.addItems( widget )
def addItems( self, widget ):
# Generate random items
from random import randrange
import string
upper = string.uppercase
lower = string.lowercase
items = []
for i in range( 100 ):
items.append( upper[ randrange( 0, 25 ) ] + lower[ randrange( 0, 25 ) ] + lower[ randrange( 0, 25 ) ] )
widget.setItems( items )
MyDialog().show()
That easy to get a reusable custom widget!
Eric Hulser
Tools Developer
Blur Studio
Is very interesting how many approaches can be used to solve one think.
Many thanks guys