Skip to content

Adding a filtered view class#88

Open
bob-white wants to merge 1 commit into
masterfrom
filtered_view
Open

Adding a filtered view class#88
bob-white wants to merge 1 commit into
masterfrom
filtered_view

Conversation

@bob-white
Copy link
Copy Markdown
Collaborator

This creates a view into an ObservableCollection and lets you apply a
filter against that view.

Each FilteredView can be bound to a different control, but still reference the same underlying collection.
Similar to the KeysView or ValueView on a mapping class.

When the base collection changes, each view is updated.
Which allows for code like this:

import random
from mGui import gui, forms, lists, observable
from mGui.bindings import bind

for poly_cmd in (cmds.polySphere, cmds.polyCube, cmds.polyCylinder):
    for _ in xrange(random.randint(0, 10)):
        poly_cmd()

meshes = observable.ViewCollection(*cmds.ls(type='mesh'))

sphere_view = observable.FilteredView(meshes, lambda x: 'Sphere' in x)
cube_view = observable.FilteredView(meshes, lambda x: 'Cube' in x)
cyl_view = observable.FilteredView(meshes, lambda x: 'Cylinder' in x)

with gui.BindingWindow() as win:
    with forms.HorizontalStretchForm():
        spheres = gui.TextScrollList()
        spheres.bind.items < bind() < sphere_view
        cubes = gui.TextScrollList()
        cubes.bind.items < bind() < cube_view
        cyls = gui.TextScrollList()
        cyls.bind.items < bind() < cyl_view
        
win.show()

I had run into this problem in the past when trying to display a different subset of a collection on separated tabs in a TabLayout, and solved it by swapping the filter on a ViewCollection when the tab was changed.

This on the other hand allows for multiple filtered views to be bound to multiple visible controls simultaneously.

This creates a view into an ObservableCollection and lets you apply a
filter against that view.

Each FilteredView can be bound to a different control, but still
reference the same underlying collection.

When the base collection changes, each view is updated.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant