-
Notifications
You must be signed in to change notification settings - Fork 23
Lists
The controls in mGui.lists
are designed to provide a version of the MVC pattern. They make it easy to work with large amounts of similar content -- for example, displaying a list of files or sorting through a lot of objects in your maya scene -- by splitting the managment of the data from the management of the appearance. A powerful extra benefit of this approach is that you can create 'rich lists' -- for example, you can have a list of objects which each display their own transform information in-line.
All list classes include a member called collection
that represents their contents. When the contents of the collection change, the list will update to reflect the changes. Most of the time you'll use a data binding to update the collection, but you can also use the list's set_collection
method to rebuild the collection. The idea is to decouple the visible appearance of the list items -- which maybe quite complex -- from the simple business of adding or removing items from the collection.
Here's the simplest possible example of a list:
from mGui.gui import *
from mGui.lists import *
with Window(label = 'list test') as w:
example = VerticalList()
w.show()
This will create what looks like an empty window. However typing this into the listener:
w.example.collection.set_collection(range(100))
The empty window will show 100 buttons, numbered from 0 to 99, arranged in a vertical scroll field. If you do this:
w.example.collection.set_collection(range(1000, 1100))
The buttons will be replaced with new buttons numbered from 1000 to 1099. This isn't a very useful example, but it illustrates the key point about lists -- that their appearance is separated from their contents. Changing the collection automatically updates the visuals.
By default, a list class will create a plain button for every item in its collection. Usually this is not what you want. To customize the look of the list items, you create a class derived from lists.ItemTemplate
. This class has a method called widget
, which creates the actual gui items that reflect the contents of the collection.