Changes from Version 1 of documentation/PythonManual/Contexts

Show
Ignore:
Author:
lloydw (IP: 192.168.0.1)
Timestamp:
12/17/07 16:26:17 (10 years ago)
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • documentation/PythonManual/Contexts

    v0 v1  
     1[[PageOutline(1-5, Contents)]] 
     2= Contexts = 
     3 
     4== Interface == 
     5 
     6=== Properties === 
     7 
     8|| '''Python property''' || '''Brief description''' || '''Equivalent C++ functions''' || 
     9|| ''dimensions'' || Gets/sets the dimensions of the context. || ''GetDimensions()'', ''SetDimensions()'' || 
     10|| ''documents'' || Retrieves a document within the interface. || ''GetDocument()'', ''GetNumDocuments()'' || 
     11|| ''focus_element'' || Retrieves the context's focus element. || ''GetFocusElement()'' || 
     12|| ''name'' || Retrieves the context's name. || ''GetName()'' || 
     13 
     14==== Retrieving documents ==== 
     15 
     16The ''documents'' property on the context can be referenced in several ways. For example, as an array: 
     17 
     18{{{ 
     19for document in context.documents: 
     20        print document.title 
     21 
     22index = 0 
     23while index < len(context.documents): 
     24        print str(index) + ": " + context.documents[index].title 
     25}}} 
     26 
     27Or as a dictionary, looking documents up by their ID: 
     28 
     29{{{ 
     30try: 
     31        document = context.documents["highscores"] 
     32except KeyError: 
     33        print "No document found!" 
     34}}} 
     35 
     36Or accessing documents as attributes on the ''documents'' property itself: 
     37 
     38{{{ 
     39try: 
     40        document = context.documents.highscores 
     41except AttributeError: 
     42        print "No document found!" 
     43}}} 
     44 
     45=== Methods === 
     46 
     47The following methods are exported from the C++ interface. 
     48 
     49|| '''Python method''' || '''Brief description''' || 
     50|| ''AddEventListener()'' || Attaches an inline event listener to the root of the context.|| 
     51|| ''AddMouseCursor()'' || Adds a previously-loaded mouse cursor to the document. || 
     52|| ''CreateDocument()'' || Creates a new document. || 
     53|| ''LoadDocument()'' || Loads a document from an external RML file. || 
     54|| ''LoadMouseCursor()'' || Loads a mouse cursor from an external RML file. || 
     55|| ''Render()'' || Renders the context. || 
     56|| ''ShowMouseCursor()'' || Shows or hides the mouse cursor. || 
     57|| ''UnloadAllDocuments()'' || Unloads all loaded documents within the context. || 
     58|| ''UnloadAllMouseCursors()'' || Unloads all of the context's mouse cursors. || 
     59|| ''UnloadDocument()'' || Unloads one of the context's documents. || 
     60|| ''UnloadMouseCursor()'' || Unloads one of the context's cursors. || 
     61|| ''Update()'' || Updates the context. || 
     62 
     63== Creating contexts == 
     64 
     65Contexts can be created in Python with the ''CreateContext()'' function in the Rocket module. This function takes the name of the context as a string and the dimensions as an  ''Vector2i'' type. 
     66 
     67{{{ 
     68new_context = rocket.CreateContext("hud", rocket.Vector2i(1024, 768)) 
     69}}} 
     70 
     71== Accessing contexts == 
     72 
     73Existing contexts can be accessed in Python with the ''GetContext()'' function in the Rocket module. 
     74 
     75{{{ 
     76context = rocket.GetContext("hud") 
     77}}}