class_docstr: A collection is a container for several items having the same data
  structure (dtype). Each data type can be declared as local (it is specific
  to a vertex), shared (it is shared among item vertices) or global (it is
  shared by all items). It is based on the BaseCollection but offers a more
  intuitive interface.
  
  Parameters
  ----------
  dtype: list
      Data individual types as (name, dtype, scope, default)
  
  itype: np.dtype or None
      Indices data type
  
  mode : GL_ENUM
      GL_POINTS, GL_LINES, GL_LINE_STRIP, GL_LINE_LOOP,
      GL_TRIANGLES, GL_TRIANGLE_STRIP, GL_TRIANGLE_FAN
  
  vertex: str or tuple of str
     Vertex shader to use to draw this collection
  
  fragment:  str or tuple of str
     Fragment shader to use to draw this collection
  
  kwargs: str
      Scope can also be specified using keyword argument,
      where parameter name must be one of the dtype.
class_docstr_tok: ["A","collection","is","a","container","for","several","items","having","the","same","data","structure","(","dtype",")",".","Each","data","type","can","be","declared","as","local","(","it","is","specific","to","a","vertex",")",",","shared","(","it","is","shared","among","item","vertices",")","or","global","(","it","is","shared","by","all","items",")",".","It","is","based","on","the","BaseCollection","but","offers","a","more","intuitive","interface",".","Parameters","--","--","--","--","--","dtype",":","list","Data","individual","types","as","(","name",",","dtype",",","scope",",","default",")","itype",":","np.dtype","or","None","Indices","data","type","mode",":","GL_ENUM","GL_POINTS",",","GL_LINES",",","GL_LINE_STRIP",",","GL_LINE_LOOP",",","GL_TRIANGLES",",","GL_TRIANGLE_STRIP",",","GL_TRIANGLE_FAN","vertex",":","str","or","tuple","of","str","Vertex","shader","to","use","to","draw","this","collection","fragment",":","str","or","tuple","of","str","Fragment","shader","to","use","to","draw","this","collection","kwargs",":","str","Scope","can","also","be","specified","using","keyword","argument",",","where","parameter","name","must","be","one","of","the","dtype","."]
docstr_tok: []
code: def __init__(
      self, dtype, itype, mode, vertex, fragment, program=None, **kwargs
  ):
      """ """
  
      self._uniforms = {}
      self._attributes = {}
      self._varyings = {}
      self._mode = mode
      vtype = []
      utype = []
  
      self.update = EventEmitter(source=self, type="collection_update")
  
      # Build vtype and utype according to parameters
      declarations = {"uniforms": "", "attributes": "", "varyings": ""}
      defaults = {}
      for item in dtype:
          name, (basetype, count), scope, default = item
          basetype = np.dtype(basetype).name
          if scope[0] == "!":
              scope = scope[1:]
          else:
              scope = kwargs.pop(name, scope)
          defaults[name] = default
          gtype = Collection._gtypes[(basetype, count)]
          if scope == "local":
              # numpy dtypes with size 1 are ambiguous, only add size if it is greater than 1
              vtype.append(
                  (name, basetype, count)
                  if count != 1
                  else (name, basetype)
              )
              declarations["attributes"] += "attribute %s %s;\n" % (
                  gtype,
                  name,
              )
          elif scope == "shared":
              # numpy dtypes with size 1 are ambiguous, only add size if it is greater than 1
              utype.append(
                  (name, basetype, count)
                  if count != 1
                  else (name, basetype)
              )
              declarations["varyings"] += "varying %s %s;\n" % (
                  gtype,
                  name,
              )
          else:
              declarations["uniforms"] += "uniform %s %s;\n" % (
                  gtype,
                  name,
              )
              self._uniforms[name] = None
  
      if len(kwargs) > 0:
          raise NameError(
              "Invalid keyword argument(s): %s" % list(kwargs.keys())
          )
  
      vtype = np.dtype(vtype)
      itype = np.dtype(itype) if itype else None
      utype = np.dtype(utype) if utype else None
  
      BaseCollection.__init__(
          self, vtype=vtype, utype=utype, itype=itype
      )
      self._declarations = declarations
      self._defaults = defaults
  
      # Build program (once base collection is built)
      saved = vertex
      vertex = ""
  
      if self.utype is not None:
          vertex += fetchcode(self.utype) + vertex
      else:
          vertex += "void fetch_uniforms(void) { }\n" + vertex
      vertex += self._declarations["uniforms"]
      vertex += self._declarations["attributes"]
      vertex += saved
  
      self._vertex = vertex
      self._fragment = fragment
  
      if program is None:
          program = ModularProgram(vertex, fragment)
      else:
          program.vert = vertex
          program.frag = fragment
      if hasattr(program, "changed"):
          program.changed.connect(self.update)
      self._programs.append(program)
  
      # Initialize uniforms
      for name in self._uniforms.keys():
          self._uniforms[name] = self._defaults.get(name)
          program[name] = self._uniforms[name]
  
file_path: vispy/vispy/visuals/collections/collection.py
imports: import numpy
  from ...None import gloo
  from .util import fetchcode
  from .base_collection import BaseCollection
  from ..shaders import ModularProgram
  from ...util.event import EventEmitter
label_desc: Use image node_id 1 to create a new Collection object from inherited base classes: BaseCollection with example: obj = Collection(dtype, itype, mode, vertex, fragment, program)