def __init__(self): self.color = [0, 0, 0] # 2-digit formmating pretty = lambda x: '{0[0]:.2f} {0[1]:.2f} {0[2]:.2f}'.format(x) with stylesheets.CSS(gui.FloatSliderButtonGrp, stylesheets.defaults(), columnWidth3=(64, 96, 32), minValue=0, maxValue=1, backgroundColor=(1, 1, 1)): with gui.BindingWindow(title='simple example', width=512) as self.window: with forms.HorizontalStretchForm(width=512) as main: with forms.VerticalForm(width=256) as sliders: red = gui.FloatSliderButtonGrp(label='red', tag=0) green = gui.FloatSliderButtonGrp(label='green', tag=1) blue = gui.FloatSliderButtonGrp(label='blue', tag=2) with forms.FillForm(width=256) as swatch: canvas = gui.Canvas() canvas.bind.rgbValue < bind() < self.bind.color display = gui.Text() display.bind.label < bind(pretty) < self.bind.color for grp in sliders.controls: grp.changeCommand += self.update_color grp.buttonCommand += self.average
def __init__(self, collection): # this is the collection of stuff to manage self.Collection = observable.ViewCollection(*collection) with gui.BindingWindow( None, title='bound collection example') as self.window: with forms.VerticalExpandForm('main') as main: gui.Separator(None, style='none', height=12) gui.Text(None, label="Here's stuff in my list") gui.Separator(None, style='none', height=12) with forms.HorizontalStretchForm('filter') as flt: gui.TextField('filtertext', width=480) gui.Separator(None, horizontal=False, style='none', width=4) with forms.HorizontalExpandForm('display', width=32) as hmm: gui.Text('shown').bind.label < bind( ) < self.Collection.bind.ViewCount gui.Text(None, '/') gui.Text('total').bind.label < bind( ) < self.Collection.bind.Count self.Collection > bind() > lists.VerticalList( 'itemList', itemTemplate=ExampleTemplate).Collection self.window.main.itemList.NewWidget += self.hook_widget_events flt.filtertext.enterCommand += self.update_filter self.KEEPALIVE = self
def basic_list_binding(): ''' Illustrates the basics of binding to a list. The collection 'bound' contains some strings, and we bind it to the VerticalList 'list_view'. Adding items to the collection automatically redraws the list with the new items. In this case they are drawn with buttons, but lists allow you to customize the appearance of items extensively. This example also illustrates how to use closures to capture inter-object references, and how to keep callback functions alive without creating a full class. ''' with gui.BindingWindow(title='example window', menuBar=True) as test_window: bound = ViewCollection('pPlane1', 'pCube2') with forms.VerticalThreePane() as main: header = gui.Text( label="List classes make it easy to manage collections") list_view = lists.VerticalList(synchronous=True) bound > bind() > list_view.collection with forms.HorizontalStretchForm() as buttons: more = gui.Button(label='Add another') close = gui.Button(label='close') # use closures to capture the UI names without a full class def close_window(*_, **__): cmds.deleteUI(test_window) def show_more(*_, **__): r = random.choice( ("pPlane", "pCube", "pSphere")) + str(random.randint(2, 20)) bound.append(r) # bind the functions to the handlers close.command += close_window, test_window more.command += show_more, test_window return test_window
def __init__(self, collection): # this is the collection of stuff to manage self.collection = observable.ViewCollection(*collection) with gui.BindingWindow(title='bound collection example', height=512, width=512) as self.window: with forms.VerticalExpandForm(margin=(16, ), spacing=(8, 12)) as main: gui.Text(label="Type a filter and [enter] to limit the list") with forms.HorizontalExpandForm(width=512, ) as flt: filter_text = gui.TextField(width=400) filter_text.alwaysInvokeEnterCommandOnReturn = True gui.Separator(horizontal=False, style='none', width=4) with forms.HorizontalExpandForm(width=100) as display: gui.Text("showing") shown = gui.Text(width=24) shown.bind.label < bind( ) < self.collection.bind.viewCount gui.Text(label='/') total = gui.Text(width=24) total.bind.label < bind() < self.collection.bind.count with forms.HorizontalExpandForm() as labels: gui.Separator(style=None, width=48) gui.Text("item", width=256, align='center') gui.Separator(style=None, width=16) gui.Text("translation", width=128, align='center') gui.Separator(style=None, width=16) item_list = lists.VerticalList(itemTemplate=ExampleTemplate) self.collection > bind() > item_list.collection item_list.onWidgetCreated += self.hook_widget_events filter_text.enterCommand += self.update_filter self.KEEPALIVE = self