<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://cegui.org.uk/wiki/index.php?action=history&amp;feed=atom&amp;title=User%3ACrond%2Fsandbox%2FeventExample1</id>
		<title>User:Crond/sandbox/eventExample1 - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://cegui.org.uk/wiki/index.php?action=history&amp;feed=atom&amp;title=User%3ACrond%2Fsandbox%2FeventExample1"/>
		<link rel="alternate" type="text/html" href="http://cegui.org.uk/wiki/index.php?title=User:Crond/sandbox/eventExample1&amp;action=history"/>
		<updated>2026-04-07T08:28:07Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.24.1</generator>

	<entry>
		<id>http://cegui.org.uk/wiki/index.php?title=User:Crond/sandbox/eventExample1&amp;diff=4523&amp;oldid=prev</id>
		<title>Crond: delete me</title>
		<link rel="alternate" type="text/html" href="http://cegui.org.uk/wiki/index.php?title=User:Crond/sandbox/eventExample1&amp;diff=4523&amp;oldid=prev"/>
				<updated>2011-06-18T20:53:23Z</updated>
		
		<summary type="html">&lt;p&gt;delete me&lt;/p&gt;
&lt;a href=&quot;http://cegui.org.uk/wiki/index.php?title=User:Crond/sandbox/eventExample1&amp;amp;diff=4523&amp;amp;oldid=4469&quot;&gt;Show changes&lt;/a&gt;</summary>
		<author><name>Crond</name></author>	</entry>

	<entry>
		<id>http://cegui.org.uk/wiki/index.php?title=User:Crond/sandbox/eventExample1&amp;diff=4469&amp;oldid=prev</id>
		<title>Crond: /* Introduction */ 1.1</title>
		<link rel="alternate" type="text/html" href="http://cegui.org.uk/wiki/index.php?title=User:Crond/sandbox/eventExample1&amp;diff=4469&amp;oldid=prev"/>
				<updated>2011-05-29T14:40:45Z</updated>
		
		<summary type="html">&lt;p&gt;‎&lt;span dir=&quot;auto&quot;&gt;&lt;span class=&quot;autocomment&quot;&gt;Introduction: &lt;/span&gt; 1.1&lt;/span&gt;&lt;/p&gt;
&lt;table class='diff diff-contentalign-left'&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;col class='diff-marker' /&gt;
				&lt;col class='diff-content' /&gt;
				&lt;tr style='vertical-align: top;'&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Older revision&lt;/td&gt;
				&lt;td colspan='2' style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Revision as of 14:40, 29 May 2011&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 3:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;Line 3:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Introduction ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Introduction ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;−&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This presents the basics of using &lt;del class=&quot;diffchange diffchange-inline&quot;&gt;event &lt;/del&gt;subscriptions to respond to events. The example retrieves two buttons and defines a method to be called when they are each clicked.&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;+&lt;/td&gt;&lt;td style=&quot;color:black; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;This presents the basics of using subscriptions to respond to events. The example retrieves two buttons and defines a method to be called when they are each clicked.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Requirements ==&lt;/div&gt;&lt;/td&gt;&lt;td class='diff-marker'&gt;&amp;#160;&lt;/td&gt;&lt;td style=&quot;background-color: #f9f9f9; color: #333333; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #e6e6e6; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;== Requirements ==&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>Crond</name></author>	</entry>

	<entry>
		<id>http://cegui.org.uk/wiki/index.php?title=User:Crond/sandbox/eventExample1&amp;diff=4467&amp;oldid=prev</id>
		<title>Crond: 1</title>
		<link rel="alternate" type="text/html" href="http://cegui.org.uk/wiki/index.php?title=User:Crond/sandbox/eventExample1&amp;diff=4467&amp;oldid=prev"/>
				<updated>2011-05-29T14:34:58Z</updated>
		
		<summary type="html">&lt;p&gt;1&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{VersionBadge|0.7}} {{VersionAtLeast|0.7.5}}&lt;br /&gt;
&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&amp;lt;br /&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Introduction ==&lt;br /&gt;
This presents the basics of using event subscriptions to respond to events. The example retrieves two buttons and defines a method to be called when they are each clicked.&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
* Python 2.6 (untested on Python 3.+)&lt;br /&gt;
* PyCEGUI&lt;br /&gt;
* PyOpenGL (GLU and GLUT, as well)&lt;br /&gt;
&lt;br /&gt;
== Notes ==&lt;br /&gt;
The source code uses a modified version of the OpenGL example posted [[User:Crond/sandbox/openglExample|here]].&lt;br /&gt;
&lt;br /&gt;
== Source ==&lt;br /&gt;
&amp;lt;source lang=&amp;quot;python&amp;quot;&amp;gt;&lt;br /&gt;
#!/usr/bin/env python&lt;br /&gt;
#&lt;br /&gt;
#&lt;br /&gt;
# example.py&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Import: std&lt;br /&gt;
import sys&lt;br /&gt;
&lt;br /&gt;
# Import: PyOpenGL&lt;br /&gt;
from OpenGL.GL import *&lt;br /&gt;
from OpenGL.GLU import *&lt;br /&gt;
from OpenGL.GLUT import *&lt;br /&gt;
&lt;br /&gt;
# Import: PyCEGUI&lt;br /&gt;
import PyCEGUI&lt;br /&gt;
from PyCEGUIOpenGLRenderer import OpenGLRenderer as Renderer&lt;br /&gt;
&lt;br /&gt;
# Constants&lt;br /&gt;
PATH_RESOURCES = './'&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Application&lt;br /&gt;
class Application(object):&lt;br /&gt;
&lt;br /&gt;
  # Constructor&lt;br /&gt;
  def __init__(self):&lt;br /&gt;
    super(Application, self).__init__()&lt;br /&gt;
    self.lastFrameTime = 0&lt;br /&gt;
    self.updateFPS = 0&lt;br /&gt;
    return&lt;br /&gt;
&lt;br /&gt;
  # Initialize: OpenGL&lt;br /&gt;
  # - A full list of values for `glutInitDisplayMode` can be found in the GLUT&lt;br /&gt;
  #   documentation.&lt;br /&gt;
  def initializeOpenGL(self):&lt;br /&gt;
    glutInit()&lt;br /&gt;
    glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA)&lt;br /&gt;
    glutInitWindowSize(1024, 768)&lt;br /&gt;
    glutInitWindowPosition(-1, -1) # Let the windowing system figure it out&lt;br /&gt;
    glutCreateWindow(&amp;quot;Crazy Eddie's GUI Mk-2 - glut Base Application&amp;quot;)&lt;br /&gt;
    glutSetCursor(GLUT_CURSOR_NONE)&lt;br /&gt;
    return&lt;br /&gt;
&lt;br /&gt;
  # Initialize: Handlers&lt;br /&gt;
  # - Setup the methods which will be called when events happen.&lt;br /&gt;
  def initializeHandlers(self):&lt;br /&gt;
    glutDisplayFunc(self.handlerDisplay)&lt;br /&gt;
    glutReshapeFunc(self.handlerResize)&lt;br /&gt;
    glutMouseFunc(self.handlerMouse)&lt;br /&gt;
    glutMotionFunc(self.handlerMouseMotion)&lt;br /&gt;
    glutPassiveMotionFunc(self.handlerMouseMotion)&lt;br /&gt;
    return&lt;br /&gt;
&lt;br /&gt;
  # Initialize: PyCEGUI&lt;br /&gt;
  # - Store some components; saves a lot of typing.&lt;br /&gt;
  def initializePyCEGUI(self):&lt;br /&gt;
    Renderer.bootstrapSystem()&lt;br /&gt;
    self.sys = PyCEGUI.System.getSingleton()&lt;br /&gt;
    self.rp = self.sys.getResourceProvider()&lt;br /&gt;
    self.scheme = PyCEGUI.SchemeManager.getSingleton()&lt;br /&gt;
    self.wm = PyCEGUI.WindowManager.getSingleton()&lt;br /&gt;
    return&lt;br /&gt;
&lt;br /&gt;
  # Initialize: Defaults&lt;br /&gt;
  # - Resource locations.&lt;br /&gt;
  def initializeDefaults(self):&lt;br /&gt;
    self.rp.setResourceGroupDirectory('schemes', './datafiles/schemes')&lt;br /&gt;
    self.rp.setResourceGroupDirectory('imagesets', './datafiles/imagesets')&lt;br /&gt;
    self.rp.setResourceGroupDirectory('fonts', './datafiles/fonts')&lt;br /&gt;
    self.rp.setResourceGroupDirectory('layouts', './datafiles/layouts')&lt;br /&gt;
    self.rp.setResourceGroupDirectory('looknfeels', './datafiles/looknfeel')&lt;br /&gt;
    self.rp.setResourceGroupDirectory('schemas', './datafiles/xml_schemas')&lt;br /&gt;
    PyCEGUI.Imageset.setDefaultResourceGroup('imagesets')&lt;br /&gt;
    PyCEGUI.Font.setDefaultResourceGroup('fonts')&lt;br /&gt;
    PyCEGUI.Scheme.setDefaultResourceGroup('schemes')&lt;br /&gt;
    PyCEGUI.WidgetLookManager.setDefaultResourceGroup('looknfeels')&lt;br /&gt;
    PyCEGUI.WindowManager.setDefaultResourceGroup('layouts')&lt;br /&gt;
    parser = self.sys.getXMLParser()&lt;br /&gt;
    if parser.isPropertyPresent('SchemaDefaultResourceGroup'):&lt;br /&gt;
      parser.setProperty('SchemaDefaultResourceGroup', 'schemas')&lt;br /&gt;
    return&lt;br /&gt;
&lt;br /&gt;
  # Initialize: GUI&lt;br /&gt;
  # - This is where we are actually setting up the windows we will see.&lt;br /&gt;
  def initializeGUI(self):&lt;br /&gt;
    self.scheme.create('VanillaSkin.scheme')&lt;br /&gt;
    self.scheme.create('TaharezLook.scheme')&lt;br /&gt;
&lt;br /&gt;
    # GUISheet&lt;br /&gt;
    self.rootWindow = self.wm.loadWindowLayout('VanillaWindows.layout')&lt;br /&gt;
    self.sys.setGUISheet(self.rootWindow)&lt;br /&gt;
&lt;br /&gt;
    # Cursor&lt;br /&gt;
    self.sys.setDefaultMouseCursor('Vanilla-Images', 'MouseArrow')&lt;br /&gt;
&lt;br /&gt;
    # An extra window&lt;br /&gt;
    w = self.wm.createWindow('TaharezLook/FrameWindow', 'Demo window')&lt;br /&gt;
    self.rootWindow.addChildWindow(w)&lt;br /&gt;
    return&lt;br /&gt;
&lt;br /&gt;
  # Initialize: Subscriptions&lt;br /&gt;
  def initializeSubscriptions(self):&lt;br /&gt;
&lt;br /&gt;
    # In order to be able to access the buttons, we need to get a copy of their parent.&lt;br /&gt;
    self.windowNewNode = self.rootWindow.getChild('Demo/NewNode')&lt;br /&gt;
&lt;br /&gt;
    # Now, we get the buttons.&lt;br /&gt;
    self.buttonOkay = self.windowNewNode.getChild('Demo/NewNode/Okay')&lt;br /&gt;
    self.buttonCancel = self.windowNewNode.getChild('Demo/NewNode/Cancel')&lt;br /&gt;
&lt;br /&gt;
    # And subscribe to the events, telling PyCEGUI what method it should call when the event happens.&lt;br /&gt;
    self.buttonOkay.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'buttonOkayClicked')&lt;br /&gt;
    self.buttonCancel.subscribeEvent(PyCEGUI.PushButton.EventClicked, self, 'buttonCancelClicked')&lt;br /&gt;
    return&lt;br /&gt;
&lt;br /&gt;
  # Initialize&lt;br /&gt;
  def Initialize(self):&lt;br /&gt;
    self.initializeOpenGL()&lt;br /&gt;
    self.initializeHandlers()&lt;br /&gt;
    self.initializePyCEGUI()&lt;br /&gt;
    self.initializeDefaults()&lt;br /&gt;
    self.initializeGUI()&lt;br /&gt;
    self.initializeSubscriptions()&lt;br /&gt;
    return&lt;br /&gt;
&lt;br /&gt;
  # Handler: Display&lt;br /&gt;
  def handlerDisplay(self):&lt;br /&gt;
&lt;br /&gt;
    # Injecting the time allows CEGUI to know how much time has passed, and&lt;br /&gt;
    # use that to coordinate certain activities - fading, animation, tooltips,&lt;br /&gt;
    # etc.&lt;br /&gt;
    now = glutGet(GLUT_ELAPSED_TIME)&lt;br /&gt;
    elapsed = (now - self.lastFrameTime) / 1000.0&lt;br /&gt;
    self.lastFrameTime = now&lt;br /&gt;
    self.updateFPS = self.updateFPS - elapsed&lt;br /&gt;
    self.sys.injectTimePulse(elapsed)&lt;br /&gt;
&lt;br /&gt;
    # Actual rendering&lt;br /&gt;
    # - `renderGUI` updates CEGUI's picture of the GUI.&lt;br /&gt;
    # - `glutPostRedisplay` is what actually marks the window as needing to&lt;br /&gt;
    #   be redrawn by OpenGL.&lt;br /&gt;
    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)&lt;br /&gt;
    self.sys.renderGUI()&lt;br /&gt;
    glutPostRedisplay()&lt;br /&gt;
    glutSwapBuffers()&lt;br /&gt;
    return&lt;br /&gt;
&lt;br /&gt;
  # Handler: Resize&lt;br /&gt;
  # - `glViewport` modifies the OpenGL viewport to whatever the window size is.&lt;br /&gt;
  def handlerResize(self, width, height):&lt;br /&gt;
    glViewport(0, 0, width, height)&lt;br /&gt;
    self.sys.notifyDisplaySizeChanged(PyCEGUI.Size(width, height))&lt;br /&gt;
    return&lt;br /&gt;
&lt;br /&gt;
  # Handler: Mouse buttons&lt;br /&gt;
  def handlerMouse(self, button, state, x, y):&lt;br /&gt;
    if button == GLUT_LEFT_BUTTON:&lt;br /&gt;
      if state == GLUT_UP:&lt;br /&gt;
        self.sys.injectMouseButtonUp(PyCEGUI.LeftButton)&lt;br /&gt;
      else:&lt;br /&gt;
        self.sys.injectMouseButtonDown(PyCEGUI.LeftButton)&lt;br /&gt;
    elif button == GLUT_RIGHT_BUTTON:&lt;br /&gt;
      if state == GLUT_UP:&lt;br /&gt;
        self.sys.injectMouseButtonUp(PyCEGUI.RightButton)&lt;br /&gt;
      else:&lt;br /&gt;
        self.sys.injectMouseButtonDown(PyCEGUI.RightButton)&lt;br /&gt;
    return&lt;br /&gt;
&lt;br /&gt;
  # Handler: Mouse motion&lt;br /&gt;
  def handlerMouseMotion(self, x, y):&lt;br /&gt;
    self.sys.injectMousePosition(x, y)&lt;br /&gt;
    return&lt;br /&gt;
&lt;br /&gt;
  # Handler: buttonOkayClicked&lt;br /&gt;
  def buttonOkayClicked(self, args):&lt;br /&gt;
    print('Okay has been clicked.')&lt;br /&gt;
    return&lt;br /&gt;
&lt;br /&gt;
  def buttonCancelClicked(self, args):&lt;br /&gt;
    print('Cancel has been clicked.')&lt;br /&gt;
    return&lt;br /&gt;
&lt;br /&gt;
  # Run&lt;br /&gt;
  def Run(self):&lt;br /&gt;
    self.lastFrameTime = glutGet(GLUT_ELAPSED_TIME)&lt;br /&gt;
    glutMainLoop()&lt;br /&gt;
    return&lt;br /&gt;
&lt;br /&gt;
# Main&lt;br /&gt;
def main():&lt;br /&gt;
  app = Application()&lt;br /&gt;
  app.Initialize()&lt;br /&gt;
  app.Run()&lt;br /&gt;
  return 0&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
# Guard&lt;br /&gt;
if __name__ == '__main__':&lt;br /&gt;
  sys.exit(main())&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;/div&gt;</summary>
		<author><name>Crond</name></author>	</entry>

	</feed>