def widget(self, item): with BindingContext() as bc: with forms.HorizontalExpandForm('root', parent=self.Parent, height=60) as root: with forms.VerticalExpandForm('cb', width=60) as cbf: gui.CheckBox( 'enabled', label='', tag=item, value=item.enabled).bind.value > bind() > (item, 'enabled') cbf.dock(cbf.enabled, left=20, top=10, bottom=40, right=5) with forms.FillForm('path', width=300): with gui.ColumnLayout('x'): gui.Text('displayName', font='boldLabelFont').bind.label < bind() < ( item, 'name') gui.Text('path', font='smallObliqueLabelFont' ).bind.label < bind() < (item, 'path') with gui.GridLayout('btns', width=140, numberOfColumns=2): edit = gui.Button('edit', label='Edit', tag=item) show = gui.Button('show', label='Show', tag=item) root.cb.enabled.changeCommand += self.update_status root.btns.show.command += self.show_item root.btns.edit.command += self.edit return lists.Templated(item, root, edit=edit.command, show=show.command)
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 widget(self, item): with BindingContext() as bc: with forms.HorizontalExpandForm(height=60, margin=(12, 0), backgroundColor=(.2, .2, .2)) as root: with forms.VerticalExpandForm(width=60) as cbf: enabled = gui.CheckBox(label='', tag=item, value=item.enabled) enabled.bind.value > bind() > (item, 'enabled') cbf.dock(enabled, left=20, top=10, bottom=40, right=5) with forms.FillForm(width=300) as path: with gui.ColumnLayout() as cl: display_name = gui.Text(font='boldLabelFont') display_name.bind.label < bind() < (item, 'name') path = gui.Text(font='smallObliqueLabelFont') path.bind.label < bind() < (item, 'path') with gui.GridLayout(width=200, numberOfColumns=2) as btns: edit = gui.Button(label='Edit', tag=item) show = gui.Button(label='Show', tag=item) enabled.changeCommand += self.update_status show.command += self.show_item edit.command += self.edit return lists.Templated(item, root, edit=edit.command, show=show.command)
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 _layout(self): with forms.LayoutDialogForm() as base: with BindingContext() as bc: with forms.VerticalThreePane(width=512, margin=(4, 4), spacing=(0, 8)) as main: with forms.VerticalForm() as header: gui.Text(label='Installed Modules') with forms.FillForm() as body: mod_list = lists.VerticalList( itemTemplate=ModuleTemplate) mod_list.collection < bind() < (self._manager.modules, 'values') # binds the 'values' method of the ModuleManager's modules{} dictionary with forms.HorizontalStretchForm() as footer: cancel = gui.Button(label='Cancel') cancel.command += self._cancel gui.Separator(style=None) save = gui.Button(label='Save') save.command += self._save base.fill(main, 5) mod_list.update_bindings()
def _layout(self): with forms.LayoutDialogForm('base') as base: with BindingContext() as bc: with forms.VerticalThreePane('root', width=512) as main: with forms.VerticalForm('header'): gui.Text('x', 'Installed modules') with forms.FillForm('middle'): mod_list = lists.VerticalList( 'xxx', itemTemplate=ModuleTemplate) mod_list.Collection < bind() < (self.ModMgr.Modules, 'values') # binds the 'values' method of the ModuleManager's Modules{} dictionary with forms.HorizontalStretchForm('footer'): gui.Button('Cancel', label='cancel').command += self._cancel gui.Separator(None, style='none') gui.Button('Save', label='save').command += self._save base.fill(main, 5) mod_list.update_bindings()
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