Package Things :: Module ThingObjects :: Class Thing
[frames] | no frames]

Class Thing

       object --+    
                |    
timeline.Timeline --+
                    |
                   Thing
Known Subclasses:

A Timeline

A basic Thing -- it is a Timeline. This represents a container of other Things. Use add() to add other Things to it. They will appear as per the keys() you supply to this Thing.

If the user supplies a draw() method, then it will be called and that's where you put the cairo commands to do your actual drawing.

Drawing stuff

If you define a draw() method, it will get called every frame. The signature is: def draw(self,context,frame_number)

Use

Typical use:

 class Alien(Thing):
   def __init__(self,x, speed=1): # up to you
   ## Now initialize the Thing: You *must* do this.
   Thing.__init__( self, id="alien")

ends.

Instance Methods
 
__init__(self, id='thing_id_not_set')
x.__init__(...) initializes x; see x.__class__.__doc__ for signature
 
__len__(self)
 
changeLayer(self, newlayer)
This will change the layer (z-order) of this thing.
 
changeProps(self, **args)
Changes the current key's properties.
 
funcs(self, funcstring, *funcs)
This is used to call functions from frames.
 
getProps(self, *args)
Fetch the named properties of a Thing.
 
goPlay(self, frameorlabel)
Tell this Thing to go to a certain frame number(or label) and play.
 
goStop(self, frameorlabel)
Tell this Thing to go to a certain frame number(or label) and stop.
 
jumps(self, jumpstring, *targets)
This is used to set jumps to other frames.
 
keys(self, keystring, *stuff)
This sets the keys that control the lifespan of Things 1)added to this thing and 2)Whatever you draw().
 
labels(self, labelstring, *labels)
This is used to assign labels to frames.
 
loop(self, bool=True)
Set to True to have this Thing keep looping around(the default.)
 
nextFrame(self)
Send a thing to its next frame.
 
play(self)
Tell this Thing to start playing again.
 
showData(self)
Useful to debug things.
 
stop(self)
Tell this Thing to stop playing.
 
stops(self, stopstring)
This is used to set stops in particular frames.
 
toTop(self)
Move this Thing to the very top layer.

Inherited from timeline.Timeline: add

Inherited from object: __delattr__, __format__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__, __subclasshook__

Instance Variables
  currentFrame
This provides a _Frame instance.
  frame
Just be aware there is a variable of this name and don't use it.
  globalProps
This is a Props() object assigned to the entire Thing.
  lifespan
If you need to start a sequence right after some other thing is done, then get that thing's lifespan and start your thing there.

Inherited from timeline.Timeline: parentThing

Properties

Inherited from object: __class__

Method Details

__init__(self, id='thing_id_not_set')
(Constructor)

 

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

Parameters:
  • id - A string to identify this Thing. It's mainly for debug purposes, but handy within your own code too.
Overrides: object.__init__

changeLayer(self, newlayer)

 

This will change the layer (z-order) of this thing. Zero is the bottom layer. If you find this is not working, then make sure you give layer numbers, to each thing you add(), that are larger than zero.

changeProps(self, **args)

 

Changes the current key's properties. This is one way to move/scale things around.

Use

thing.changeProps( x=10, y=20 )

Better

Use thing.currentFrame.props.x = 10, it's faster.

funcs(self, funcstring, *funcs)

 

This is used to call functions from frames. Wherever you use ^ it will place a function that you name in the args.

NOTE

If you have a jump in the same frame, the function will not get run. You can always avoid a jump; instead have a function that uses goPlay(x).

WARNING

Make sure you name the function; not call it. It's easy to make a mistake. Use funcName and not funcName(). If there are arguments then use a tuple like (funcName, arg1,arg2,...)

Use

Typical use:

 self.funcs( "........^", somefunc )
 self.funcs( "...^", (self.goPlay,10) ) # Here we pass 10 to goPlay.

ends.

getProps(self, *args)

 

Fetch the named properties of a Thing.

Use

x,y,a = self.getProps("x","y","a")

Note

It's quicker to use: self.currentFrame.props.BLAH, where BLAH is a property like x,y or rot.

Parameters:
  • args - Takes any number of string argument naming properties.
Returns:
A list.

goPlay(self, frameorlabel)

 

Tell this Thing to go to a certain frame number(or label) and play.

Use

thing.goPlay(7)

thing.goPlay("die")

goStop(self, frameorlabel)

 

Tell this Thing to go to a certain frame number(or label) and stop.

Use

thing.goStop(2)

thing.goStop("hide")

jumps(self, jumpstring, *targets)

 

This is used to set jumps to other frames. Wherever you use ^ it will place a jump to a frame that you name (a label or a frame number) in the args.

Use

Typical use:

 self.keys ( "#--#----#",...)
 self.jumps( "........^", "start" ) #look for label 'start' and jump to it.
 self.jumps( "...^", 1 ) # keep looping back to frame 1.

ends.

Parameters:
  • jumpstring - A dot (.) is a blank. A caret (^) points at the frame where the jump happens.
  • targets - Any number of strings (labels) or integers (frame numbers). One per jump.

keys(self, keystring, *stuff)

 

This sets the keys that control the lifespan of Things 1)added to this thing and 2)Whatever you draw().

Key syntax

  1. #: Keyframe. Things will appear on a keyframe.
  2. =: A 'same' frame. It must follow a keyframe. This indicates that the previous frame simply continues and does not need another Props() object to describe it.
  3. -: A 'tween'. This must follow a # (keyframe) and end on same. Each in-between frame is given Props that are interpolated. Use tweens to move and fade Things.
  4. .: A blank frame. Everthing goes away on a blank frame.

Use

Typical use:

 #Here we have only one keyframe, hence we need one Props() object.
 p1 = Props ( x=100, y=20, a=0.5 )
 self.keys ( "#=.", p1 )
 
 # If you have more than one keyframe, have a prop for each one:
 self.keys ( "#---#", Props(), Props(rot=pi * 2) )

 #To tween movement do something like this:
 self.keys( "#----------------------#", Props(x=0), Props(x=100) ) #move from 0 to 100 gradually.

ends.

Parameters:
  • keystring - A string that represents the keyframes, blanks and tweens of this Thing. This string dictates where/when children of this Thing will appear.
  • stuff - Any number of Props() objects. Have as many as you have keyframes.

labels(self, labelstring, *labels)

 

This is used to assign labels to frames. Wherever you use ^ it will place a label you name in the args. (The idea is that it points to the frame in the keys() command above it.)

Use

Typical use:

 self.keys  ( "#---------#.", ...)
 self.labels( "...........^", "die" )

 Later, you can say:
 self.goPlay('die')

ends.

Parameters:
  • labelstring - A string of dots (.) and carets (^). The carets point where labels will be assigned.
  • labels - Any number of strings providing the label names for the ^ points in the label string.

nextFrame(self)

 

Send a thing to its next frame. Kind of untested really...

play(self)

 

Tell this Thing to start playing again. However it was stopped, this will cause it to start again.

Use

thing.play()

showData(self)

 

Useful to debug things.

Use

thing.showData()

stop(self)

 

Tell this Thing to stop playing. This is different from a stop in a keyframe in that it's not recorded in the key's properties -- so it won't be remembered.

Use

thing.stop()

stops(self, stopstring)

 

This is used to set stops in particular frames. Wherever you use ^ it will place a stop.

Use

Typical use:

 self.keys ( "#--------#...",...)
 self.stops( "...^.....^" )

ends.

Parameters:
  • stopstring - A dot (.) is a blank. A caret (^) points at the frame to stop at.

Instance Variable Details

currentFrame

This provides a _Frame instance. Within that, the most useful property is 'props'. For example: boat.currentFrame.props.x is the x coord of the boat right now.

globalProps

This is a Props() object assigned to the entire Thing. Can be set from the add() method of a Thing (see Timeline class). You can also simply use it in a Thing's init.

lifespan

If you need to start a sequence right after some other thing is done, then get that thing's lifespan and start your thing there. See Thing.add() for the parentFrame argument.