Search is not available for this dataset
text stringlengths 75 104k |
|---|
def setRot(self,data,rot):
"""
Sets the rotation of this bone on the given entity.
``data`` is the entity to modify in dictionary form.
``rot`` is the rotation of the bone in the format used in :py:func:`calcSphereCoordinates()`\ .
"""
self.ensureBones(d... |
def setLength(self,data,blength):
"""
Sets the length of this bone on the given entity.
``data`` is the entity to modify in dictionary form.
``blength`` is the new length of the bone.
"""
self.ensureBones(data)
data["_bones"][self.name]["length"]... |
def setParent(self,parent):
"""
Sets the parent of this bone for all entities.
Note that this method must be called before many other methods to ensure internal state has been initialized.
This method also registers this bone as a child of its parent.
"""
... |
def setRotate(self,data):
"""
Sets the OpenGL state required for proper drawing of the model.
Mostly rotates and translates the camera.
It is important to call :py:meth:`unsetRotate()` after calling this method to properly unset state and avoid OpenGL errors.
""... |
def getPivotPoint(self,data):
"""
Returns the point this bone pivots around on the given entity.
This method works recursively by calling its parent and then adding its own offset.
The resulting coordinate is relative to the entity, not the world.
"""
pp... |
def getVertices(self,data):
"""
Returns the vertices of this region already transformed and ready-to-use.
Internally uses :py:meth:`Bone.transformVertices()`\ .
"""
return self.bone.transformVertices(data,self.vertices,self.dims) |
def getTexCoords(self,data):
"""
Returns the texture coordinates, if any, to accompany the vertices of this region already transformed.
Note that it is recommended to check the :py:attr:`enable_tex` flag first.
Internally uses :py:meth:`Material.transformTexCoords()`\ .... |
def startAnimation(self,data,jumptype):
"""
Callback that is called to initialize this animation on a specific actor.
Internally sets the ``_anidata`` key of the given dict ``data``\ .
``jumptype`` is either ``jump`` or ``animate`` to define how to switch to this animat... |
def tickEntity(self,data):
"""
Callback that should be called regularly to update the animation.
It is recommended to call this method about 60 times a second for smooth animations. Irregular calling of this method will be automatically adjusted.
This method sets all th... |
def set_state(self):
"""
Sets the state required for this actor.
Currently translates the matrix to the position of the actor.
"""
x,y,z = self.obj.pos
glTranslatef(x,y,z) |
def unset_state(self):
"""
Resets the state required for this actor to the default state.
Currently resets the matrix to its previous translation.
"""
x,y,z = self.obj.pos
glTranslatef(-x,-y,-z) |
def set_state(self):
"""
Sets the state required for this vertex region.
Currently binds and enables the texture of the material of the region.
"""
glEnable(self.region.material.target)
glBindTexture(self.region.material.target, self.region.material.id)
s... |
def unset_state(self):
"""
Resets the state required for this actor to the default state.
Currently only disables the target of the texture of the material, it may still be bound.
"""
glDisable(self.region.material.target)
self.region.bone.unsetRotate(self.data) |
def ensureModelData(self,obj):
"""
Ensures that the given ``obj`` has been initialized to be used with this model.
If the object is found to not be initialized, it will be initialized.
"""
if not hasattr(obj,"_modeldata"):
self.create(obj,cache=True)
... |
def create(self,obj,cache=False):
"""
Initializes per-actor data on the given object for this model.
If ``cache`` is set to True, the entity will not be redrawn after initialization.
Note that this method may set several attributes on the given object, most of them star... |
def cleanup(self,obj):
"""
Cleans up any left over data structures, including vertex lists that reside in GPU memory.
Behaviour is undefined if it is attempted to use this model with the same object without calling :py:meth:`create()` first.
It is very important to call... |
def redraw(self,obj):
"""
Redraws the model of the given object.
Note that currently this method probably won't change any data since all movement and animation is done through pyglet groups.
"""
self.ensureModelData(obj)
data = obj._modeldata
vl... |
def draw(self,obj):
"""
Actually draws the model of the given object to the render target.
Note that if the batch used for this object already existed, drawing will be skipped as the batch should be drawn by the owner of it.
"""
self.ensureModelData(obj)
... |
def setAnimation(self,obj,animation,transition=None,force=False):
"""
Sets the animation to be used by the object.
See :py:meth:`Actor.setAnimation()` for more information.
"""
self.ensureModelData(obj)
data = obj._modeldata
# Validity check
... |
def setModel(self,model):
"""
Sets the model this actor should use when drawing.
This method also automatically initializes the new model and removes the old, if any.
"""
if self.model is not None:
self.model.cleanup(self)
self.model = model
m... |
def setAnimation(self,animation,transition=None,force=False):
"""
Sets the animation the model of this actor should show.
``animation`` is the name of the animation to switch to.
``transition`` can be used to override the transition between the animations.
... |
def move(self,dist):
"""
Moves the actor using standard trigonometry along the current rotational vector.
:param float dist: Distance to move
.. todo::
Test this method, also with negative distances
"""
x, y = self._rot
y_a... |
def write_reports(self, relative_path, suite_name, reports,
package_name=None):
"""write the collection of reports to the given path"""
dest_path = self.reserve_file(relative_path)
with open(dest_path, 'wb') as outf:
outf.write(toxml(reports, suite_name, packag... |
def reserve_file(self, relative_path):
"""reserve a XML file for the slice at <relative_path>.xml
- the relative path will be created for you
- not writing anything to that file is an error
"""
if os.path.isabs(relative_path):
raise ValueError('%s must be a relative ... |
def toxml(test_reports, suite_name,
hostname=gethostname(), package_name="tests"):
"""convert test reports into an xml file"""
testsuites = et.Element("testsuites")
testsuite = et.SubElement(testsuites, "testsuite")
test_count = len(test_reports)
if test_count < 1:
raise ValueErr... |
def setup(self):
"""
Sets up the OpenGL state.
This method should be called once after the config has been created and before the main loop is started.
You should not need to manually call this method, as it is automatically called by :py:meth:`run()`\ .
Repeate... |
def setupFog(self):
"""
Sets the fog system up.
The specific options available are documented under :confval:`graphics.fogSettings`\ .
"""
fogcfg = self.cfg["graphics.fogSettings"]
if not fogcfg["enable"]:
return
glEnable(GL_FOG)
... |
def run(self,evloop=None):
"""
Runs the application in the current thread.
This method should not be called directly, especially when using multiple windows, use :py:meth:`Peng.run()` instead.
Note that this method is blocking as rendering needs to happen in the main th... |
def changeMenu(self,menu):
"""
Changes to the given menu.
``menu`` must be a valid menu name that is currently known.
.. versionchanged:: 1.2a1
The push/pop handlers have been deprecated in favor of the new :py:meth:`Menu.on_enter() <peng3d.menu.M... |
def addMenu(self,menu):
"""
Adds a menu to the list of menus.
"""
# If there is no menu selected currently, this menu will automatically be made active.
# Add the line above to the docstring if fixed
self.menus[menu.name]=menu
self.peng.sendEvent("peng3d:window.me... |
def dispatch_event(self,event_type,*args):
"""
Internal event handling method.
This method extends the behavior inherited from :py:meth:`pyglet.window.Window.dispatch_event()` by calling the various :py:meth:`handleEvent()` methods.
By default, :py:meth:`Peng.handleEven... |
def toggle_exclusivity(self,override=None):
"""
Toggles mouse exclusivity via pyglet's :py:meth:`set_exclusive_mouse()` method.
If ``override`` is given, it will be used instead.
You may also read the current exclusivity state via :py:attr:`exclusive`\ .
"""
... |
def set2d(self):
"""
Configures OpenGL to draw in 2D.
Note that wireframe mode is always disabled in 2D-Mode, but can be re-enabled by calling ``glPolygonMode(GL_FRONT_AND_BACK, GL_LINE)``\ .
"""
# Light
glDisable(GL_LIGHTING)
# To avoid... |
def set3d(self,cam):
"""
Configures OpenGL to draw in 3D.
This method also applies the correct rotation and translation as set in the supplied camera ``cam``\ .
It is discouraged to use :py:func:`glTranslatef()` or :py:func:`glRotatef()` directly as this may cause visual glitche... |
def redraw_label(self):
"""
Re-draws the text by calculating its position.
Currently, the text will always be centered on the position of the label.
"""
# Convenience variables
sx,sy = self.size
x,y = self.pos
# Label position
sel... |
def redraw_label(self):
"""
Re-draws the label by calculating its position.
Currently, the label will always be centered on the position of the label.
"""
# Convenience variables
sx,sy = self.size
x,y = self.pos
# Label position
x... |
def changeSubMenu(self,submenu):
"""
Changes the submenu that is displayed.
:raises ValueError: if the name was not previously registered
"""
if submenu not in self.submenus:
raise ValueError("Submenu %s does not exist!"%submenu)
elif submenu == self.... |
def draw(self):
"""
Draws the submenu and its background.
Note that this leaves the OpenGL state set to 2d drawing.
"""
# Sets the OpenGL state for 2D-Drawing
self.window.set2d()
# Draws the background
if isinstance(self.bg,Layer):
... |
def delWidget(self,widget):
"""
Deletes the widget by the given name.
Note that this feature is currently experimental as there seems to be a memory leak with this method.
"""
# TODO: fix memory leak upon widget deletion
#print("*"*50)
#print("Start delWi... |
def setBackground(self,bg):
"""
Sets the background of the submenu.
The background may be a RGB or RGBA color to fill the background with.
Alternatively, a :py:class:`peng3d.layer.Layer` instance or other object with a ``.draw()`` method may be supplied.
It is a... |
def getPosSize(self):
"""
Helper function converting the actual widget position and size into a usable and offsetted form.
This function should return a 6-tuple of ``(sx,sy,x,y,bx,by)`` where sx and sy are the size, x and y the position and bx and by are the border size.
... |
def getColors(self):
"""
Overrideable function that generates the colors to be used by various borderstyles.
Should return a 5-tuple of ``(bg,o,i,s,h)``\ .
``bg`` is the base color of the background.
``o`` is the outer color, it is usually the same as t... |
def redraw_bg(self):
# Convenience variables
sx,sy = self.widget.size
x,y = self.widget.pos
bx,by = self.border
# Button background
# Outer vertices
# x y
v1 = x, y+sy
v2 = x+sx, y+sy
v3 = x, ... |
def redraw_label(self):
"""
Re-calculates the position of the Label.
"""
# Convenience variables
sx,sy = self.size
x,y = self.pos
# Label position
self._label.anchor_x = "left"
self._label.x = x+sx/2.+sx
self._label.y = y+sy/2.+sy*... |
def add(self,keybind,kbname,handler,mod=True):
"""
Adds a keybind to the internal registry.
Keybind names should be of the format ``namespace:category.subcategory.name``\ e.g. ``peng3d:actor.player.controls.forward`` for the forward key combo for the player actor.
:para... |
def changeKeybind(self,kbname,combo):
"""
Changes a keybind of a specific keybindname.
:param str kbname: Same as kbname of :py:meth:`add()`
:param str combo: New key combination
"""
for key,value in self.keybinds.items():
if kbname in value:
... |
def mod_is_held(self,modname,modifiers):
"""
Helper method to simplify checking if a modifier is held.
:param str modname: Name of the modifier, see :py:data:`MODNAME2MODIFIER`
:param int modifiers: Bitmask to check in, same as the modifiers argument of the on_key_press etc. han... |
def handle_combo(self,combo,symbol,modifiers,release=False,mod=True):
"""
Handles a key combination and dispatches associated events.
First, all keybind handlers registered via :py:meth:`add` will be handled,
then the pyglet event :peng3d:pgevent:`on_key_combo` with params ``(co... |
def registerEventHandlers(self):
"""
Registers needed keybinds and schedules the :py:meth:`update` Method.
You can control what keybinds are used via the :confval:`controls.controls.forward` etc. Configuration Values.
"""
# Forward
self.peng.keybinds.add(self.pen... |
def get_motion_vector(self):
"""
Returns the movement vector according to held buttons and the rotation.
:return: 3-Tuple of ``(dx,dy,dz)``
:rtype: tuple
"""
if any(self.move):
x, y = self.actor._rot
strafe = math.degrees(math.atan2(*self.... |
def registerEventHandlers(self):
"""
Registers the motion and drag handlers.
Note that because of the way pyglet treats mouse dragging, there is also an handler registered to the on_mouse_drag event.
"""
self.world.registerEventHandler("on_mouse_motion",self.on_mouse_mot... |
def registerEventHandlers(self):
"""
Registers the up and down handlers.
Also registers a scheduled function every 60th of a second, causing pyglet to redraw your window with 60fps.
"""
# Crouch/fly down
self.peng.keybinds.add(self.peng.cfg["controls.controls.cro... |
def update(self,dt):
"""
Should be called regularly to move the actor.
This method does nothing if the :py:attr:`enabled` property is set to False.
This method is called automatically and should not be called manually.
"""
if not self.enabled:
... |
def update(self,dt):
"""
Internal method used for moving the player.
:param float dt: Time delta since the last call to this method
"""
speed = self.movespeed
d = dt * speed # distance covered this tick.
dx, dy, dz = self.get_motion_vector()
# New... |
def add_widgets(self,**kwargs):
"""
Called by the initializer to add all widgets.
Widgets are discovered by searching through the :py:attr:`WIDGETS` class attribute.
If a key in :py:attr:`WIDGETS` is also found in the keyword arguments and
not none, the function with the... |
def add_label_main(self,label_main):
"""
Adds the main label of the dialog.
This widget can be triggered by setting the label ``label_main`` to a string.
This widget will be centered on the screen.
"""
# Main Label
self.wlabel_main = text.Label("... |
def add_btn_ok(self,label_ok):
"""
Adds an OK button to allow the user to exit the dialog.
This widget can be triggered by setting the label ``label_ok`` to a string.
This widget will be mostly centered on the screen, but below the main label
by the double of it... |
def exitDialog(self):
"""
Helper method that exits the dialog.
This method will cause the previously active submenu to activate.
"""
if self.prev_submenu is not None:
# change back to the previous submenu
# could in theory form a stack if one dial... |
def add_btn_confirm(self,label_confirm):
"""
Adds a confirm button to let the user confirm whatever action they were presented with.
This widget can be triggered by setting the label ``label_confirm`` to a string.
This widget will be positioned slightly below the main l... |
def add_btn_cancel(self,label_cancel):
"""
Adds a cancel button to let the user cancel whatever choice they were given.
This widget can be triggered by setting the label ``label_cancel`` to a string.
This widget will be positioned slightly below the main label and to th... |
def update_progressbar(self):
"""
Updates the progressbar by re-calculating the label.
It is not required to manually call this method since setting any of the
properties of this class will automatically trigger a re-calculation.
"""
n,nmin,nmax = self.wprogressb... |
def add_progressbar(self,label_progressbar):
"""
Adds a progressbar and label displaying the progress within a certain task.
This widget can be triggered by setting the label ``label_progressbar`` to
a string.
The progressbar will be displayed centered and below... |
def createWindow(self,cls=None,caption_t=None,*args,**kwargs):
"""
createWindow(cls=window.PengWindow, *args, **kwargs)
Creates a new window using the supplied ``cls``\ .
If ``cls`` is not given, :py:class:`peng3d.window.PengWindow()` will be used.
Any ... |
def run(self,evloop=None):
"""
Runs the application main loop.
This method is blocking and needs to be called from the main thread to avoid OpenGL bugs that can occur.
``evloop`` may optionally be a subclass of :py:class:`pyglet.app.base.EventLoop` to replace the defaul... |
def sendPygletEvent(self,event_type,args,window=None):
"""
Handles a pyglet event.
This method is called by :py:meth:`PengWindow.dispatch_event()` and handles all events.
See :py:meth:`registerEventHandler()` for how to listen to these events.
This meth... |
def addPygletListener(self,event_type,handler):
"""
Registers an event handler.
The specified callable handler will be called every time an event with the same ``event_type`` is encountered.
All event arguments are passed as positional arguments.
This m... |
def sendEvent(self,event,data=None):
"""
Sends an event with attached data.
``event`` should be a string of format ``<namespace>:<category1>.<subcategory2>.<name>``\ .
There may be an arbitrary amount of subcategories. Also note that this
format is not strictly enforced,... |
def addEventListener(self,event,func,raiseErrors=False):
"""
Adds a handler to the given event.
A event may have an arbitrary amount of handlers, though assigning too
many handlers may slow down event processing.
For the format of ``event``\ , see :py:meth:`send... |
def delEventListener(self,event,func):
"""
Removes the given handler from the given event.
If the event does not exist, a :py:exc:`NameError` is thrown.
If the handler has not been registered previously, also a :py:exc:`NameError` will be thrown.
"""
if ... |
def setLang(self,lang):
"""
Sets the default language for all domains.
For recommendations regarding the format of the language code, see
:py:class:`TranslationManager`\ .
Note that the ``lang`` parameter of both :py:meth:`translate()` and
:py:meth:`tran... |
def discoverLangs(self,domain="*"):
"""
Generates a list of languages based on files found on disk.
The optional ``domain`` argument may specify a domain to use when checking
for files. By default, all domains are checked.
This internally uses the :py:mod:`glob`... |
def addCamera(self,camera):
"""
Add the camera to the internal registry.
Each camera name must be unique, or else only the most recent version will be used. This behavior should not be relied on because some objects may cache objects.
Additionally, only instances of :py... |
def addView(self,view):
"""
Adds the supplied :py:class:`WorldView()` object to the internal registry.
The same restrictions as for cameras apply, e.g. no duplicate names.
Additionally, only instances of :py:class:`WorldView()` may be used, everything else raises a :py:... |
def getView(self,name):
"""
Returns the view with name ``name``\ .
Raises a :py:exc:`ValueError` if the view does not exist.
"""
if name not in self.views:
raise ValueError("Unknown world view")
return self.views[name] |
def render3d(self,view=None):
"""
Renders the world in 3d-mode.
If you want to render custom terrain, you may override this method. Be careful that you still call the original method or else actors may not be rendered.
"""
for actor in self.actors.values():
a... |
def render3d(self,view=None):
"""
Renders the world.
"""
super(StaticWorld,self).render3d(view)
self.batch3d.draw() |
def setActiveCamera(self,name):
"""
Sets the active camera.
This method also calls the :py:meth:`Camera.on_activate() <peng3d.camera.Camera.on_activate>` event handler if the camera is not already active.
"""
if name == self.activeCamera:
return # Cam is alre... |
def on_menu_enter(self,old):
"""
Fake event handler, same as :py:meth:`WorldView.on_menu_enter()` but forces mouse exclusivity.
"""
super(WorldViewMouseRotatable,self).on_menu_enter(old)
self.world.peng.window.toggle_exclusivity(True) |
def on_menu_exit(self,new):
"""
Fake event handler, same as :py:meth:`WorldView.on_menu_exit()` but force-disables mouse exclusivity.
"""
super(WorldViewMouseRotatable,self).on_menu_exit(new)
self.world.peng.window.toggle_exclusivity(False) |
def on_key_press(self,symbol,modifiers):
"""
Keyboard event handler handling only the escape key.
If an escape key press is detected, mouse exclusivity is toggled via :py:meth:`PengWindow.toggle_exclusivity()`\ .
"""
if symbol == key.ESCAPE:
self.world.peng.w... |
def on_mouse_motion(self, x, y, dx, dy):
"""
Handles mouse motion and rotates the attached camera accordingly.
For more information about how to customize mouse movement, see the class documentation here :py:class:`WorldViewMouseRotatable()`\ .
"""
if not self.world.peng... |
def step(self, step_name):
"""Start a new step. returns a context manager which allows you to
report an error"""
@contextmanager
def step_context(step_name):
if self.event_receiver.current_case is not None:
raise Exception('cannot open a step within a step')
... |
def resourceNameToPath(self,name,ext=""):
"""
Converts the given resource name to a file path.
A resource path is of the format ``<app>:<cat1>.<cat2>.<name>`` where cat1 and cat2 can be repeated as often as desired.
``ext`` is the file extension to use, e.g. ``.png`` or... |
def resourceExists(self,name,ext=""):
"""
Returns whether or not the resource with the given name and extension exists.
This must not mean that the resource is meaningful, it simply signals that the file exists.
"""
return os.path.exists(self.resourceNameToPath(name,ext)... |
def addCategory(self,name):
"""
Adds a new texture category with the given name.
If the category already exists, it will be overridden.
"""
self.categories[name]={}
self.categoriesTexCache[name]={}
self.categoriesTexBin[name]=pyglet.image.atlas.TextureBin... |
def getTex(self,name,category):
"""
Gets the texture associated with the given name and category.
``category`` must have been created using :py:meth:`addCategory()` before.
If it was loaded previously, a cached version will be returned.
If it was not loaded, it ... |
def loadTex(self,name,category):
"""
Loads the texture of the given name and category.
All textures currently must be PNG files, although support for more formats may be added soon.
If the texture cannot be found, a missing texture will instead be returned. See :py:meth... |
def getMissingTexture(self):
"""
Returns a texture to be used as a placeholder for missing textures.
A default missing texture file is provided in the assets folder of the source distribution.
It consists of a simple checkerboard pattern of purple and black, this image may be co... |
def addFromTex(self,name,img,category):
"""
Adds a new texture from the given image.
``img`` may be any object that supports Pyglet-style copying in form of the ``blit_to_texture()`` method.
This can be used to add textures that come from non-file sources, e.g. Render-t... |
def getModel(self,name):
"""
Gets the model object by the given name.
If it was loaded previously, a cached version will be returned.
If it was not loaded, it will be loaded and inserted into the cache.
"""
if name in self.modelobjcache:
return self.m... |
def loadModel(self,name):
"""
Loads the model of the given name.
The model will also be inserted into the cache.
"""
m = model.Model(self.peng,self,name)
self.modelobjcache[name]=m
self.peng.sendEvent("peng3d:rsrc.model.load",{"peng":self.peng,"name":name... |
def getModelData(self,name):
"""
Gets the model data associated with the given name.
If it was loaded, a cached copy will be returned.
It it was not loaded, it will be loaded and cached.
"""
if name in self.modelcache:
return self.modelcache[name]
... |
def loadModelData(self,name):
"""
Loads the model data of the given name.
The model file must always be a .json file.
"""
path = self.resourceNameToPath(name,".json")
try:
data = json.load(open(path,"r"))
except Exception:
# Tempor... |
def setBackground(self,bg):
"""
Sets the background of the Container.
Similar to :py:meth:`peng3d.gui.SubMenu.setBackground()`\ , but only effects the region covered by the Container.
"""
self.bg = bg
if isinstance(bg,list) or isinstance(bg,tuple):
if... |
def addWidget(self,widget):
"""
Adds a widget to this container.
Note that trying to add the Container to itself will be ignored.
"""
if self is widget: # Prevents being able to add the container to itself, causing a recursion loop on redraw
return
se... |
def draw(self):
"""
Draws the submenu and its background.
Note that this leaves the OpenGL state set to 2d drawing and may modify the scissor settings.
"""
if not self.visible:
# Simple visibility check, has to be tested to see if it works properly
... |
def on_redraw(self):
"""
Redraws the background and any child widgets.
"""
x,y = self.pos
sx,sy = self.size
self.bg_vlist.vertices = [x,y, x+sx,y, x+sx,y+sy, x,y+sy]
self.stencil_vlist.vertices = [x,y, x+sx,y, x+sx,y+sy, x,y+sy]
if isinstance(self.bg,Backg... |
def on_redraw(self):
"""
Redraws the background and contents, including scrollbar.
This method will also check the scrollbar for any movement and will be automatically called on movement of the slider.
"""
n = self._scrollbar.n
self.offset_y = -n # Causes the con... |
def mouse_aabb(mpos,size,pos):
"""
AABB Collision checker that can be used for most axis-aligned collisions.
Intended for use in widgets to check if the mouse is within the bounds of a particular widget.
"""
return pos[0]<=mpos[0]<=pos[0]+size[0] and pos[1]<=mpos[1]<=pos[1]+size[1] |
def addCategory(self,name,nmin=0,n=0,nmax=100):
"""
Adds a category with the given name.
If the category already exists, a :py:exc:`KeyError` will be thrown. Use
:py:meth:`updateCategory()` instead if you want to update a category.
"""
assert isinstance(name,base... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.