def test_base_binding_force(self):
     t = TestTarget()
     c = ViewCollection(1,2,3,4,5,6,7,8,9,10)
     t << c
     c._Internal_Collection = ['a','b','c']
     c.update_bindings()
     assert t.Values == ('a','b','c')
 def test_base_binding_force(self):
     t = TestTarget()
     c = ViewCollection(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     t << c
     c._Internal_Collection = ['a', 'b', 'c']
     c.update_bindings()
     assert t.Values == ('a', 'b', 'c')
 def test_base_binding_sort(self):
     t = TestTarget()
     c = ViewCollection(1,2,3,4,5,6,7,8,9,10)
     t << c
     c.update_bindings()
     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)
 def test_base_binding_clear(self):
     t = TestTarget()
     c = ViewCollection(1,2,3,4,5,6,7,8,9,10)
     t << 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 = ViewCollection(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)
 def test_filter(self):
     t = TestTarget()
     c = ViewCollection(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     t << 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_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)
 def test_base_binding_clear(self):
     t = TestTarget()
     c = ViewCollection(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     t << c
     c.update_bindings()
     assert t.Values == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     c.clear()
     assert t.Values == ()
Example #10
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
 def test_ViewChanged(self):
     v = ViewCollection(5, 8, 2)
     t = self.Tester()
     v.ViewChanged += t.handle_event
     v.update_filter(lambda x: x < 5)
     assert t.Kwargs['collection'] == v
 def test_iter(self):
     c = ViewCollection(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     result = []
     for item in c:
         result.append(item)
     assert result == [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
 def test_base_binding_auto_update_remove(self):
     t = TestTarget()
     c = ViewCollection(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     t << c
     c.remove(5)
     assert t.Values == (1, 2, 3, 4, 6, 7, 8, 9, 10)
 def test_base_binding_auto_update_add(self):
     t = TestTarget()
     c = ViewCollection(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)
     t << c
     c.add(11)
     assert t.Values == (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11)
 def test_base_binding_auto_update_remove(self):
     t = TestTarget()
     c = ViewCollection(1,2,3,4,5,6,7,8,9,10)
     t << c
     c.remove(5)
     assert t.Values == (1,2,3,4,6,7,8,9,10)
 def test_base_binding_auto_update_add(self):
     t = TestTarget()
     c = ViewCollection(1,2,3,4,5,6,7,8,9,10)
     t << c
     c.add(11)
     assert t.Values == (1,2,3,4,5,6,7,8,9,10,11)
 def test_ViewChanged (self):
     v = ViewCollection(5,8,2)
     t = self.Tester()
     v.ViewChanged += t.handle_event
     v.update_filter(lambda x : x < 5)
     assert t.Kwargs['collection'] == v
                        "Cameras",
                        cr=True,
                        horizontalScrollBarThickness=8,
                        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):
 def test_base_binding(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)
Example #20
0
from mGui import gui, forms, lists
from mGui.bindings import bind
from mGui.observable import ViewCollection
from mGui.qt.QTextField import QTextField
from mGui.scriptJobs import Idle

"""
This example illustrates the optional QTextField object, which (unlike a regular Maya text field)
will fire events on every key pres.

This example DOES NOT WORK in Maya 2017 or later due to the QT5 update.
"""

_items = gui.__all__ + forms.__all__ + lists.__all__

items = ViewCollection(*_items)

class InputBuffer(object):
    '''
    accumulate inputs until a certain amount of time passes
    '''
    def __init__(self, parent, fn, interval=1):
        self.last = time.time()
        self.interval = interval
        self.fn = fn
        self.buffer = []
        self.accumulate = inspect.getargspec(fn).varargs
        self.idleEvent = Idle()
        self.idleEvent += self.update
        self.idleEvent.start(p=parent)
 def test_ViewChanged(self):
     v = ViewCollection(5, 8, 2, synchronous=True)
     t = self.Tester()
     v.onViewChanged += t.handle_event
     v.update_filter(lambda x: x < 5)
     assert t.kwargs['collection'] == v