classes
accept_action index remove selected
append insrt remove_all
browser object select
count prepend select_action
List of objects
SYNTAX
List()
List("templatename")
DESCRIPTION
The List class provides useful tools for creating and manipulating lists of objects.
For example, if you have
a network of cells connected at synapses and each synapse is a separate object, you may want to use
lists to help organize the network. You could create one list of all pre-synaptic connections and
another of post-synaptic connections, as well as a list of all the connecting cells.
-
List()
- Create an empty list. Objects added to the list are referenced.
Objects removed from the list are unreferenced.
-
List("templatename")
- Create a list of all the object instances of the template.
These object instances are NOT referenced and therefore the list
dynamically changes as objects of template instances are
created and destroyed. Adding and removing objects
from this kind of list is not allowed.
List
SYNTAX
.append(object)
DESCRIPTION
Append an object to a list, and return the number of items in list.
List
SYNTAX
.prepend(object)
DESCRIPTION
Add an object to the beginning of a list, and return the number of objects in the list.
The inserted object has index=0. Following objects have an incremented
index.
List
SYNTAX
.insrt(i, object)
DESCRIPTION
Insert an object before item i, and return the number of items in the list.
The inserted object has index i, following items have an incremented
index.
Not called insert because that name is a keyword
List
SYNTAX
.remove(i)
DESCRIPTION
Remove the object at index i. Following items have a decremented
index. ie it's often most convenient to remove items from back
to front. Return the number of objects remaining in the list.
List
SYNTAX
.remove_all()
DESCRIPTION
Remove all the objects from the list. Return 0.
List
SYNTAX
.index(object)
DESCRIPTION
Return the index of the object in the list. Return a -1 if the
object is not in the list.
List
SYNTAX
.count()
DESCRIPTION
Return the number of objects in the list.
List
SYNTAX
.browser()
.browser("title", "strname")
.browser("title", strdef, "command")
DESCRIPTION
-
.browser(["title"], ["strname"])
- Make the list visible on the screen.
The items are normally the object names but if the second arg is
present and is the name of a string symbol that is defined
in the object's template, then that string is displayed in the list.
-
.browser("title", strdef, "command")
- Browser labels are computed. For each item, command is executed
with
hoc_ac_ set
to the index of the item. On return, the
contents of strdef are used as the label. Some objects
notify the List when they change, ie point processes when they change
their location notify the list.
List
SYNTAX
.selected()
DESCRIPTION
Return the index of the highlighted object or -1 if no object is highlighted.
SEE ALSO
browser
List
SYNTAX
.select(i)
DESCRIPTION
Highlight the object at index i.
SEE ALSO
browser
List
SYNTAX
list.select_action("command")
list.select_action("command", 0or1)
DESCRIPTION
Execute a command when an item in the
list browser is selected by single clicking the mouse.
hoc_ac_
contains the index when the command is executed. Thus
l.select_action("action(hoc_ac_)")
is convenient usage.
action will be invoked within the object context that existed when
select_action
was called.
If the second arg exists and is 1 then the action is only called on
the mouse button release. If nothing is selected at that time then
then hoc_ac_ = -1
EXAMPLES
This example shows that the object context is saved when an action is
registered.
execute following example
begintemplate A
objref this, list, obj
proc init() {
list = new List()
list.append(this)
for i=0,4 {
obj = new Random()
list.append(obj)
}
list.browser()
list.select_action("act(hoc_ac_)")
}
proc act() {
printf("item %d selected in list of object %s\n", $1, this)
}
endtemplate A
objref a[2]
for i=0,1 a[i] = new A()
List
SYNTAX
list.accept_action("command")
DESCRIPTION
Execute a command when double clicking
on an item displayed in the list browser by the mouse.
hoc_ac_
contains the index when the command is executed. Command is
executed within the object context that existed when accept_action
was called.
EXAMPLES
objref list, obj
list = new List()
for i=0,4 {
obj = new Random()
list.append(obj)
obj = new List()
list.append(obj)
}
list.browser()
list.accept_action("act()")
proc act() {
printf("item %d accepted\n", hoc_ac_)
}
List
SYNTAX
.object(i)
DESCRIPTION
Return the object at index i.
neuron/general/classes/list.hel : 4802 Jul 19