Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a filtered view class #88

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Adding a filtered view class #88

wants to merge 1 commit into from

Conversation

bob-white
Copy link
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