示例#1
0
def main():
    def create_filter(fn):
        regex = re.compile(fn, re.I)
        test = lambda p: regex.search(p)
        items.update_filter(test)

    with gui.Window() as w:
        with forms.NavForm() as nav:
            with forms.VerticalForm() as navbar:
                one = gui.Button()
                two = gui.Button()
                three = gui.Button()
            with forms.HeaderForm() as main:
                filter_field = QTextField()
                main_list = lists.VerticalList()

        items > bind() > main_list.collection
        items.bind.viewCount > bind() > three.bind.label
        items.bind.count > bind() > two.bind.label
        w.update_bindings()

    w.buffer = InputBuffer(w, create_filter)
    filter_field.textChanged += w.buffer.handle
    cmds.scriptJob(lj=True)
    return w
示例#2
0
文件: modMgr.py 项目: alfsici/mGui
    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)
示例#3
0
文件: modMgr.py 项目: Narinyir/mGui
    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)
示例#4
0
    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
示例#5
0
def main():
    def create_filter(fn):
        regex = re.compile(fn, re.I)
        test = lambda p: regex.search(p)
        items.update_filter(test)

    with gui.Window() as w:
        with forms.NavForm() as nav:
            with forms.VerticalForm() as navbar:
                one = gui.Button()
                two = gui.Button()
                three = gui.Button()
            with forms.HeaderForm() as main:
                filter_field = QTextField()
                main_list = lists.VerticalList()

        items > bind() > main_list.collection
        items.bind.viewCount > bind() > three.bind.label
        items.bind.count > bind() > two.bind.label
        w.update_bindings()

    w.buffer = InputBuffer(w, create_filter)
    filter_field.textChanged += w.buffer.handle
    cmds.scriptJob(lj=True)
    return w
示例#6
0
文件: simple.py 项目: alfsici/mGui
    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
示例#7
0
 def test_default_bindings(self):
     ex1 = self.Example('fred', 'flintstone')
     ex2 = self.Example('barney', 'rubble')
     tester = ex1 > bindings.bind() > ex2
     tester()
     assert ex2.val == ex1.name
     tester = ex1 < bindings.bind() < ex2
     tester()
     assert ex1.val == ex2.name
示例#8
0
 def test_default_bindings(self):
     ex1 = self.Example('fred', 'flintstone')
     ex2 = self.Example('barney', 'rubble')
     tester = ex1 > bindings.bind() > ex2
     tester()
     assert ex2.val == ex1.name
     tester = ex1 < bindings.bind() < ex2
     tester()
     assert ex1.val == ex2.name
示例#9
0
 def test_bind_to_cmds_string(self):
     ex = self.Example('cube', 45)
     cmds.file(new=True, f=True)
     cmds.polyCube()
     tester = ex & 'val' > bindings.bind() > ('pCube1', 'tx')
     tester()
     assert cmds.getAttr('pCube1.tx') == 45
     tester2 = ex & 'val' > bindings.bind() > 'pCube1.ty'
     tester2()
     assert cmds.getAttr('pCube1.ty') == 45
示例#10
0
 def test_bind_to_cmds_string(self):
     ex = self.Example('cube', 45)
     cmds.file(new=True, f=True)
     cmds.polyCube()
     tester = ex & 'val' > bindings.bind() > ('pCube1', 'tx')
     tester()
     assert cmds.getAttr('pCube1.tx') == 45
     tester2 = ex & 'val' > bindings.bind() > 'pCube1.ty'
     tester2()
     assert cmds.getAttr('pCube1.ty') == 45
示例#11
0
    def test_two_way_assignment(self):
        fred = self.Example('fred', 'flintstone')
        barney = self.Example('barney', 'rubble')

        test = fred.bind.Name | bindings.bind() | barney.bind.Val
        barney.Val = 'new'
        test()
        assert fred.Name == barney.Val and barney.Val == 'new'

        test = fred | bindings.bind() | barney
        fred.Name = 'new'
        test()
        assert fred.Name == barney.Val and fred.Name == 'new'
示例#12
0
 def test_binding_collection_auto_update_suppress(self):
     fred = self.Example('fred', 'flintstone')
     barney = self.Example('barney', 'rubble')
     wilma = self.Example('wilma', None)
     bambam = self.Example('bambam', None)
     guys = {'fred': None, 'barney': None}
     with bindings.BindingContext(auto_update=False) as ctx:
         fred & 'val' > bindings.bind() > wilma  # default target
         barney & 'val' > bindings.bind() > bambam & 'val'
         fred > bindings.bind() > (guys, 'fred')  # default sources
         barney > bindings.bind() > (guys, 'barney')
     assert len(ctx.bindings) == 4
     assert wilma.val == None
     assert bambam.val == None
     assert guys == {'fred': None, 'barney': None}
示例#13
0
 def test_binding_collection_auto_update_suppress(self):
     fred = self.Example('fred', 'flintstone')
     barney = self.Example('barney', 'rubble')
     wilma = self.Example('wilma', None)
     bambam = self.Example('bambam', None)
     guys = {'fred': None, 'barney': None}
     with bindings.BindingContext(auto_update=False) as ctx:
         fred & 'val' > bindings.bind() > wilma  # default target
         barney & 'val' > bindings.bind() > bambam & 'val'
         fred > bindings.bind() > (guys, 'fred')  # default sources
         barney > bindings.bind() > (guys, 'barney')
     assert len(ctx.bindings) == 4
     assert wilma.val == None
     assert bambam.val == None
     assert guys == {'fred': None, 'barney': None}
示例#14
0
    def text_mix_default_and_non_default_bindings(self):

        ex1 = self.Example('fred', 'flintstone')
        ex2 = {'pebbles':'bambam'}
        tester = ex1 > bindings.bind() > ex2 & 'pebbles'
        tester()
        assert ex2['pebbles'] == 'fred'
 def test_base_binding_force(self):
     t = TestTarget()
     c = ObservableCollection(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     t < bind() < c
     c._internal_collection = ['a', 'b', 'c']  # don't do this in practice!
     c.update_bindings()
     assert t.values == ('a', 'b', 'c')
示例#16
0
 def test_bind_to_pyNode(self):
     ex = self.Example('cube', 45)
     cmds.file(new=True, f=True)
     cube, shape = pm.polyCube()
     tester = ex & 'val' > bindings.bind() > (cube, 'tx')
     tester()
     assert cmds.getAttr('pCube1.tx') == 45
 def test_base_binding_force(self):
     t = TestTarget()
     c = ViewCollection(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     t < bind() < c
     c._internal_collection = ['a', 'b', 'c']
     c.update_bindings()
     assert t.values == ('a', 'b', 'c')
示例#18
0
 def test_collection_deletes_bad_bindings(self):
     fred = self.Example('fred', 'flintstone')
     barney = self.Example('barney', 'rubble')
     wilma = self.Example('wilma', None)
     bambam = self.Example('bambam', None)
     guys = {'fred': None, 'barney': None}
     with bindings.BindingContext(False) as ctx:
         fred & 'val' > bindings.bind() > wilma  # default target
         barney & 'val' > bindings.bind() > bambam & 'val'
         fred > bindings.bind() > (guys, 'fred')  # default sources
         barney > bindings.bind() > (guys, 'barney')
         del (fred)  # delete referent invalidating 2 bindings
     ctx.update()
     assert len(ctx.bindings) == 2
     assert wilma.val is None
     assert guys['fred'] is None
示例#19
0
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
示例#20
0
 def test_bind_to_pyNode(self):
     ex = self.Example('cube', 45)
     cmds.file(new=True, f=True)
     cube, shape = pm.polyCube()
     tester = ex & 'val' > bindings.bind() > (cube, 'tx')
     tester()
     assert cmds.getAttr('pCube1.tx') == 45
示例#21
0
文件: modMgr.py 项目: alfsici/mGui
    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()
示例#22
0
 def test_collection_deletes_bad_bindings(self):
     fred = self.Example('fred', 'flintstone')
     barney = self.Example('barney', 'rubble')
     wilma = self.Example('wilma', None)
     bambam = self.Example('bambam', None)
     guys = {'fred': None, 'barney': None}
     with bindings.BindingContext(False) as ctx:
         fred & 'val' > bindings.bind() > wilma  # default target
         barney & 'val' > bindings.bind() > bambam & 'val'
         fred > bindings.bind() > (guys, 'fred')  # default sources
         barney > bindings.bind() > (guys, 'barney')
         del (fred)  # delete referent invalidating 2 bindings
     ctx.update()
     assert len(ctx.bindings) == 2
     assert wilma.val is None
     assert guys['fred'] is None
示例#23
0
    def test_collection_hierarchy_does_not_recurse_automatically(self):
        fred = self.Example('fred', 'flintstone')
        barney = self.Example('barney', 'rubble')
        wilma = self.Example('wilma', None)
        bambam = self.Example('bambam', None)
        guys = {'fred': None, 'barney': None}
        with bindings.BindingContext(auto_update=True) as outer:
            fred & 'val' > bindings.bind() > wilma
            with bindings.BindingContext(auto_update=False) as middle:
                barney & 'val' > bindings.bind() > bambam & 'val'
                with bindings.BindingContext(auto_update=False) as ctx:
                    fred > bindings.bind() > (guys, 'fred')  # default sources
                    barney > bindings.bind() > (guys, 'barney')

        assert wilma.val == 'flintstone'
        assert not bambam.val == 'rubble'
        assert not guys == {'fred': 'fred', 'barney': 'barney'}
示例#24
0
 def test_bindable_bind_from(self):
     ex = self.Example('fred', 'flintstone')
     ex2 = self.Example('barney', 'rubble')
     test = ex & "name" < bindings.bind() < (ex2, 'val')
     assert isinstance(test, bindings.Binding)
     assert test
     test()
     assert ex.name == ex2.val
示例#25
0
    def test_collection_hierarchy_does_not_recurse_automatically(self):
        fred = self.Example('fred', 'flintstone')
        barney = self.Example('barney', 'rubble')
        wilma = self.Example('wilma', None)
        bambam = self.Example('bambam', None)
        guys = {'fred': None, 'barney': None}
        with bindings.BindingContext(auto_update=True) as outer:
            fred & 'val' > bindings.bind() > wilma
            with bindings.BindingContext(auto_update=False) as middle:
                barney & 'val' > bindings.bind() > bambam & 'val'
                with bindings.BindingContext(auto_update=False) as ctx:
                    fred > bindings.bind() > (guys, 'fred')  # default sources
                    barney > bindings.bind() > (guys, 'barney')

        assert wilma.val == 'flintstone'
        assert not bambam.val == 'rubble'
        assert not guys == {'fred': 'fred', 'barney': 'barney'}
示例#26
0
 def test_bindable_bind_to(self):
     ex = self.Example('fred', 'flintstone')
     ex2 = self.Example('barney', 'rubble')
     test = ex & "Name" > bindings.bind() > (ex2, 'Val')
     assert isinstance(test, bindings.Binding)
     assert test
     test()
     assert ex2.Val == ex.Name
示例#27
0
 def test_bindable_bind_from(self):
     ex = self.Example('fred', 'flintstone')
     ex2 = self.Example('barney', 'rubble')
     test = ex & "name" < bindings.bind() < (ex2, 'val')
     assert isinstance(test, bindings.Binding)
     assert test
     test()
     assert ex.name == ex2.val
 def test_base_binding_clear(self):
     t = TestTarget()
     c = ImmediateObservableCollection(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     t < bind() < c
     c.update_bindings()
     assert t.values == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     c.clear()
     assert t.values == ()
 def test_filter(self):
     t = TestTarget()
     c = ViewCollection(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     t < bind() < c
     t.update_bindings()
     assert t.values == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     c.update_filter(lambda x: x % 2 == 0)
     assert t.values == (2, 4, 6, 8, 10)
 def test_base_binding_reverse(self):
     t = TestTarget()
     c = ImmediateObservableCollection(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     t < bind() < c
     c.update_bindings()
     assert t.values == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     c.reverse()
     assert t.values == (10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
示例#31
0
    def test_collection_hierarchy(self):
        fred = self.Example('fred', 'flintstone')
        barney = self.Example('barney', 'rubble')
        wilma = self.Example('wilma', None)
        bambam = self.Example('bambam', None)
        guys = {'fred':None, 'barney':None}
        with bindings.BindingContext(auto_update=False) as outer:
            _ = fred & 'Val' > bindings.bind() > wilma
            with bindings.BindingContext(auto_update=False) as middle:
                _ = barney & 'Val' > bindings.bind() > bambam & 'Val'
                with bindings.BindingContext(auto_update=False) as ctx:
                    _ = fred > bindings.bind() > (guys, 'fred')  # default sources
                    _ = barney > bindings.bind() > (guys, 'barney')

        outer.update()
        assert wilma.Val == 'flintstone'
        assert bambam.Val == 'rubble'
        assert guys == {'fred':'fred', 'barney':'barney'}
 def test_base_binding_sort(self):
     t = TestTarget()
     c = ViewCollection(1, 2, 3, 4, 10, 5, 6, 7, 8, 9)
     t < bind() < c
     c.update_bindings()
     c.sort()
     assert t.values == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     c.sort(reverse=True)
     assert t.values == (10, 9, 8, 7, 6, 5, 4, 3, 2, 1)
示例#33
0
文件: modMgr.py 项目: AdricEpic/mGui
 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)
示例#34
0
文件: modMgr.py 项目: bob-white/mGui
    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)
示例#35
0
    def test_two_way_assignment(self):
        fred = self.Example('fred', 'flintstone')
        barney = self.Example('barney', 'rubble')

        test = fred.bind.name | bindings.bind() | barney.bind.val
        barney.val = 'new'
        test()
        assert fred.name == barney.val and barney.val == 'new'

        fred.name = 'new2'
        test()
        assert fred.name == barney.val and fred.name == 'new2'
示例#36
0
文件: modMgr.py 项目: Narinyir/mGui
    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)
示例#37
0
    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
示例#38
0
文件: simple.py 项目: AdricEpic/mGui
    def __init__(self):
        self.Color = [0,0,0]
        
        # 2-digit formatting
        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('window', title = 'simple example',  width=512) as self.Window:
                with gui.HorizontalStretchForm('main', width = 512):
                    with gui.VerticalForm('controls', width = 256) as sliders:
                        gui.FloatSliderButtonGrp('red', label = 'red', tag = 0)
                        gui.FloatSliderButtonGrp('green', label = 'green', tag = 1)
                        gui.FloatSliderButtonGrp('blue', label = 'blue', tag = 2)
                    with gui.FillForm('swatch', width = 256):
                        gui.Canvas('canvas').bind.rgbValue <  bind() <  self.bind.Color
                        gui.Text('display').bind.label < bind(pretty) < self.bind.Color
    
            for grp in sliders.Controls:
                grp.changeCommand += self.update_color
                grp.buttonCommand += self.average
示例#39
0
    def __init__(self, collection):

        # this is the collection of stuff to manage
        self.Collection = observable.ViewCollection(*collection)

        with gui.BindingWindow('root', title='bound collection example') as self.Window:
            with gui.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 gui.FlowLayout('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
示例#40
0
文件: modMgr.py 项目: AdricEpic/mGui
 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()     
示例#41
0
文件: modMgr.py 项目: Narinyir/mGui
    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()
示例#42
0
文件: modMgr.py 项目: Narinyir/mGui
    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()
示例#43
0
文件: modMgr.py 项目: bob-white/mGui
    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()
示例#44
0
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
示例#45
0
 def test_override_default_bindings(self):
     ex1 = self.Example('fred', 'flintstone')
     ex2 = self.Example('barney', 'rubble')
     tester = ex1 & 'val' > bindings.bind() > ex2 & 'name'
     tester()
     assert ex2.name == ex1.val
示例#46
0
 def text_mix_default_and_non_default_bindings(self):
     ex1 = self.Example('fred', 'flintstone')
     ex2 = {'pebbles': 'bambam'}
     tester = ex1 > bindings.bind() > ex2 & 'pebbles'
     tester()
     assert ex2['pebbles'] == 'fred'
 def test_base_binding_auto_update_remove(self):
     t = TestTarget()
     c = ObservableCollection(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     t < bind() < c
     c.remove(5)
     assert t.values == (1, 2, 3, 4, 6, 7, 8, 9, 10)
# Init Lights

#Main
mainLightCol = Vector3(Interface.mainColor.rgbValue[0],
                       Interface.mainColor.rgbValue[1],
                       Interface.mainColor.rgbValue[2])
mainLight = Lighting.CreateLight(
    "KeyLight", Vector3(2, 2, 2),
    Lighting.LightData(1, Interface.mainExposure.value, 3000, mainLightCol, 3))
mainAimConstraint = aimConstraint(centerLocator,
                                  mainLight,
                                  aim=(0, 0, -1),
                                  u=(0, 1, 0),
                                  mo=False)
Interface.mainCBox.bind.value > bind() > str(mainLight) + '.visibility'
# Interface.mainExposure.bind.value > bind() > listRelatives(mainLight)[0] +'.aiExposure'
Interface.mainExposure.dragCommand = "Lighting.ChangeLightExposure(mainLight, Interface.mainExposure.value)"
Interface.mainColor.dragCommand = "Lighting.ChangeLightColor(mainLight,Vector3(Interface.mainColor.rgbValue[0], Interface.mainColor.rgbValue[1], Interface.mainColor.rgbValue[2]))"

Interface.mainAimCBox.bind.value > bind() > mainAimConstraint + ".CenterW0"
#Rim
rimLightCol = Vector3(Interface.rimColor.rgbValue[0],
                      Interface.rimColor.rgbValue[1],
                      Interface.rimColor.rgbValue[2])
rimLight = Lighting.CreateLight(
    "RimLight", Vector3(-2, 2, -2),
    Lighting.LightData(1, Interface.rimExposure.value, 3000, rimLightCol, 2))
rimAimConstraint = aimConstraint(centerLocator,
                                 rimLight,
                                 aim=(0, 0, -1),
示例#49
0
 def __init__(self, settings):
     self.settings = settings
     self.field = gui.TextField('namespace').bind.text | bind(
         lambda p: p or self.settings['namespace']) | (self.settings,
                                                       'namespace')
示例#50
0
 def __init__(self, settings):
     self.settings = settings
     self.field = gui.TextField('namespace')
     self.field.bind.text | bind(lambda p: p or self.settings['namespace']) | (self.settings, 'namespace')
示例#51
0
 def test_override_default_bindings(self):
     ex1 = self.Example('fred', 'flintstone')
     ex2 = self.Example('barney', 'rubble')
     tester = ex1 & 'val' > bindings.bind() > ex2 & 'name'
     tester()
     assert ex2.name == ex1.val
                        verticalScrollBarThickness=8) as cameraScrollLayout:
                    with ColumnLayout("CameraCol", rs=10, adj=True,
                                      cal="left") as cameraLayout:
                        Separator(h=10, st="none")
                        with RowLayout(nc=3, adj=2):
                            Text("New Camera name", al="left")
                            newCameraField = TextField("NewCameraField",
                                                       tx="",
                                                       aie=True)
                            addCameraButton = IconTextButton(i=iconsPath +
                                                             "/add-video.png")

                        cameraCollection = ViewCollection()
                        cameraList = lists.VerticalList(
                            synchronous=True, itemTemplate=CameraWidget)
                        cameraCollection > bind() > cameraList.collection

                # with ColumnLayout("Render Settings", rs = 10, adj=1, cat=("both", 10)) as rsLayout:
                #     Text("Export",fn="boldLabelFont")
                #     #Mettre renderview
                #     with RowLayout(nc=3, adj=2):
                #         Text("Export path ", al="left")
                #         TextField("ExportPath", en=False)
                #         IconTextButton(i=":/browseFolder.png",c="SetExportPath('Set export path')")
                #     with ColumnLayout():
                #         pass
        Separator(h=10, st="none")
        with RowLayout(nc=3, adj=2):
            Separator(w=100, st="in")
            renderButton = Button("Render",
                                  c=Callback(RenderSettings.OpenRenderView,
    def widget(self, item):
        # with forms.HorizontalExpandForm(tag=item) as root:
        with RowLayout(nc=3, rat=[(1, 'top', 0), (3, 'top', 0)],
                       adj=2) as root:
            camActiveButton = IconTextButton(item + "_activeButton",
                                             i=iconsPath + "/close-eye.png",
                                             c=Callback(
                                                 ToggleCameraActive,
                                                 newCurrentCameName=item))
            with FrameLayout(item, cll=True) as cameraL:
                with ColumnLayout(rs=5, adj=True):
                    with RowLayout(nc=2,
                                   adj=2,
                                   rat=(1, 'top', 5),
                                   cat=(1, 'right', 5)):
                        dofCBox = CheckBox(item + "_f_dof", l="", v=False)
                        with FrameLayout("Focus", cll=True):
                            with ColumnLayout(rs=0, adj=True,
                                              cat=('both', 25)):
                                with RowLayout(nc=2, adj=2):
                                    Text("FStop", w=60, al="left")
                                    cameraFStop = FloatSliderGrp(item +
                                                                 "_f_fstop",
                                                                 f=True,
                                                                 v=1.0,
                                                                 min=0.0,
                                                                 max=64.0)
                                with RowLayout(nc=2, adj=2):
                                    Text("Distance", w=60, al="left")
                                    cameraFocusDistance = FloatSliderGrp(
                                        item + "_f_distance",
                                        f=True,
                                        v=1.0,
                                        min=0.0,
                                        max=10.0)
                    with RowLayout(nc=2,
                                   adj=2,
                                   rat=(1, 'top', 5),
                                   cat=(1, 'right', 5)):
                        camTurnaroundCBox = CheckBox(item + "_boxTurnaround",
                                                     l="",
                                                     v=False)
                        with FrameLayout("Turnaround", cll=True):
                            with ColumnLayout(rs=0, adj=True,
                                              cat=('both', 25)):
                                with RowLayout(nc=2, adj=2):
                                    Text("Speed", w=60, al="left")
                                    cameraTurnaroundSpeed = FloatSliderGrp(
                                        str(item) + "_f_turnspeed",
                                        f=True,
                                        v=1.0,
                                        min=0.0,
                                        max=300.0)
                                with RowLayout(nc=2, adj=2):
                                    Text("Duration (s) ", w=60, al="left")
                                    cameraTurnaroundDuration = FloatSliderGrp(
                                        str(item) + "_f_turnduration",
                                        f=True,
                                        v=10.0,
                                        min=1.0,
                                        max=15.0)
                    with RowLayout(nc=2,
                                   adj=2,
                                   cal=(2, "left"),
                                   cat=(2, "left", 32)):
                        Text("Focale", fn="plainLabelFont")
                        camFocale = FloatSliderGrp(str(item) + "_f_focale",
                                                   f=True,
                                                   v=35.0,
                                                   min=10.0,
                                                   max=350.0)
                    with RowLayout(nc=2,
                                   adj=2,
                                   cal=(2, "left"),
                                   cat=(2, "left", 32)):
                        camOrientPivot = CheckBox(item + "_camOrientCBox",
                                                  l="",
                                                  v=False)
                        Text("Aim pivot", fn="plainLabelFont")
            IconTextButton(i=":/delete.png",
                           c=Callback(RemoveCamera, item, p=1))

        dofCBox.bind.value > bind() > item + "Shape.depthOfField"
        print("AAAAAAAAAAAAAAA" + str(getAttr(item + "Shape.focalLength")))
        cameraFStop.bind.value > bind() > item + "Shape.fStop"
        print(listAttr(item + "Shape"))
        cameraFocusDistance.bind.value > bind() > item + "Shape.focusDistance"
        camFocale.dragCommand = Callback(camerasDict[item].SetFocale,
                                         newFocale=camFocale.value)
        #camFocale.bind.value > bind() > item+"Shape.focalLength"

        camTurnaroundCBox.onCommand = Callback(
            camerasDict[item].SetTurnaroundKeyframes, p=1)
        camTurnaroundCBox.offCommand = Callback(
            camerasDict[item].SetTurnaroundKeyframes, p=1)

        cameraTurnaroundSpeed.dragCommand = Callback(
            camerasDict[item].SetTurnaroundKeyframes, p=1)
        cameraTurnaroundDuration.dragCommand = Callback(
            camerasDict[item].SetTurnaroundKeyframes, p=1)

        camOrientPivot.onCommand = Callback(camerasDict[item].ToggleAimPivot,
                                            toggle=True)
        camOrientPivot.offCommand = Callback(camerasDict[item].ToggleAimPivot,
                                             toggle=False)

        #camActiveButton.command = Callback(Camera.Camera.SetCurrentCamera, newCurrentCameName = item)
        #camActiveButton.command = Callback(ToggleCameraActive, newCurrentCameName = item)

        return lists.Templated(item, root)