| 1 |
#!/usr/bin/env python |
|---|
| 2 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 3 |
##~ License |
|---|
| 4 |
##~ |
|---|
| 5 |
##- The RuneBlade Foundation library is intended to ease some |
|---|
| 6 |
##- aspects of writing intricate Jabber, XML, and User Interface (wxPython, etc.) |
|---|
| 7 |
##- applications, while providing the flexibility to modularly change the |
|---|
| 8 |
##- architecture. Enjoy. |
|---|
| 9 |
##~ |
|---|
| 10 |
##~ Copyright (C) 2002 TechGame Networks, LLC. |
|---|
| 11 |
##~ |
|---|
| 12 |
##~ This library is free software; you can redistribute it and/or |
|---|
| 13 |
##~ modify it under the terms of the BSD style License as found in the |
|---|
| 14 |
##~ LICENSE file included with this distribution. |
|---|
| 15 |
##~ |
|---|
| 16 |
##~ TechGame Networks, LLC can be reached at: |
|---|
| 17 |
##~ 3578 E. Hartsel Drive #211 |
|---|
| 18 |
##~ Colorado Springs, Colorado, USA, 80920 |
|---|
| 19 |
##~ |
|---|
| 20 |
##~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 21 |
|
|---|
| 22 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 23 |
#~ Imports |
|---|
| 24 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 25 |
|
|---|
| 26 |
import logging |
|---|
| 27 |
import sys |
|---|
| 28 |
import time |
|---|
| 29 |
|
|---|
| 30 |
from wxPython import wx |
|---|
| 31 |
from OpenGL import GL, GLUT |
|---|
| 32 |
|
|---|
| 33 |
from RBSkinning import SkinXML |
|---|
| 34 |
from RBSkinning.wxTools.GLViewSetup import GLViewSetup |
|---|
| 35 |
|
|---|
| 36 |
from RBRapier.Renderer import SequenceMgr |
|---|
| 37 |
from RBRapier.Renderer import DisplayList |
|---|
| 38 |
from RBRapier.Renderer.Appearance import Blending |
|---|
| 39 |
from RBRapier.Renderer.Environment import Buffers |
|---|
| 40 |
from RBRapier.Renderer.View import Viewport |
|---|
| 41 |
from RBRapier.Renderer.View import Transformations |
|---|
| 42 |
from RBRapier.Renderer.View import TransformationSettings |
|---|
| 43 |
|
|---|
| 44 |
from RBRapier.Formats.SVG import SVGSkinner |
|---|
| 45 |
from RBRapier.Formats.SVG import RapierRenderItems |
|---|
| 46 |
|
|---|
| 47 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 48 |
#~ Constants / Variables / Etc. |
|---|
| 49 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 50 |
|
|---|
| 51 |
skinxml = """<?xml version='1.0'?> |
|---|
| 52 |
<skin:skin xmlns:skin='http://namespaces.runeblade.com/skin' xmlns:py='http://namespaces.runeblade.com/xmlPython' xmlns='http://namespaces.runeblade.com/wxPythonSkin'> |
|---|
| 53 |
<frame ctxvar='behavior.frame' title='SVG Displayer' show='1' pos='0,0' size='800,600'> |
|---|
| 54 |
<layout fit='0'> |
|---|
| 55 |
<panel> |
|---|
| 56 |
<layout> |
|---|
| 57 |
<glcanvas ctxvar='behavior.glcanvas' sizercfg='1, wxEXPAND' attribList='[WX_GL_RGBA, WX_GL_DOUBLEBUFFER, WX_GL_MIN_ALPHA, 8, WX_GL_DEPTH_SIZE, 8]' /> |
|---|
| 58 |
</layout> |
|---|
| 59 |
</panel> |
|---|
| 60 |
</layout> |
|---|
| 61 |
</frame> |
|---|
| 62 |
|
|---|
| 63 |
<!-- |
|---|
| 64 |
<frame title='Demo PyCrust' show='1' pos='850,0' size='400,800'> |
|---|
| 65 |
<layout fit='0'> |
|---|
| 66 |
<pycrust_shell sizercfg='1, wxEXPAND' locals='{"behavior":context.behavior}'/> |
|---|
| 67 |
</layout> |
|---|
| 68 |
</frame> |
|---|
| 69 |
--> |
|---|
| 70 |
</skin:skin> |
|---|
| 71 |
""" |
|---|
| 72 |
|
|---|
| 73 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 74 |
#~ Definitions |
|---|
| 75 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 76 |
|
|---|
| 77 |
class Behavior(object): |
|---|
| 78 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 79 |
#~ Constants / Variables / Etc. |
|---|
| 80 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 81 |
|
|---|
| 82 |
_fps_score = 0 |
|---|
| 83 |
frametitle = 'SVG Displayer' |
|---|
| 84 |
|
|---|
| 85 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 86 |
#~ Public Methods |
|---|
| 87 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 88 |
|
|---|
| 89 |
def OnSkinInitialize(self): |
|---|
| 90 |
pass |
|---|
| 91 |
|
|---|
| 92 |
def OnSkinFinalize(self): |
|---|
| 93 |
SVGRenderItemFactory=RapierRenderItems.RapierSVGRenderItemFactory() |
|---|
| 94 |
|
|---|
| 95 |
svgfile = ' '.join(sys.argv[1:]) |
|---|
| 96 |
print "Parsing \"%s\" as SVG... (%s)" % (svgfile, time.strftime('%X'),) |
|---|
| 97 |
s = time.time() |
|---|
| 98 |
self.svgitem = SVGSkinner.SkinFile(svgfile, SVGRenderItemFactory=SVGRenderItemFactory).object |
|---|
| 99 |
d = time.time() - s |
|---|
| 100 |
print "done. (%s -- %1.3fs)" % (time.strftime('%X'), d) |
|---|
| 101 |
print |
|---|
| 102 |
|
|---|
| 103 |
self.viewsetup = GLViewSetup(self.glcanvas, 30) |
|---|
| 104 |
self.viewsetup.OnRender.Add(self.ViewInitialize) |
|---|
| 105 |
self.viewsetup.OnRender.Add(self.Render) |
|---|
| 106 |
self.viewsetup.OnRender.Add(self.PostRender) |
|---|
| 107 |
self.viewsetup.StartRendering() |
|---|
| 108 |
|
|---|
| 109 |
def ViewInitialize(self, glviewsetup, canvas): |
|---|
| 110 |
glviewsetup.OnRender.Remove(self.ViewInitialize) |
|---|
| 111 |
self.root = SequenceMgr.RootSequence() |
|---|
| 112 |
|
|---|
| 113 |
self.clearcolor = Buffers.ClearColor((1.0,1.0,1.0,1.0)) |
|---|
| 114 |
self.root.AddElement(self.clearcolor, -2) |
|---|
| 115 |
|
|---|
| 116 |
self.viewport = Viewport.Viewport() |
|---|
| 117 |
self.root.AddElement(self.viewport, -2) |
|---|
| 118 |
|
|---|
| 119 |
self.projection = Transformations.OrthographicMgd(GL.GL_PROJECTION, True, -1, 1, -1, 1, -1, 1) |
|---|
| 120 |
self.root.AddElement(self.projection.GLSelect) |
|---|
| 121 |
self.root.AddPostElement(self.projection.GLDeselect) |
|---|
| 122 |
|
|---|
| 123 |
xform = Transformations.IdentityMgd(GL.GL_MODELVIEW, True) |
|---|
| 124 |
self.root.AddElement(xform.GLSelect) |
|---|
| 125 |
self.root.AddPostElement(xform.GLDeselect) |
|---|
| 126 |
|
|---|
| 127 |
self.root.AddElement(Blending.Blend()) |
|---|
| 128 |
self.svgs = SequenceMgr.Sequence() |
|---|
| 129 |
|
|---|
| 130 |
print "Compling svg... (%s)" % (time.strftime('%X'),) |
|---|
| 131 |
s = time.time() |
|---|
| 132 |
self.svgs.AddElements(self.svgitem.Compile()) |
|---|
| 133 |
del self.svgitem |
|---|
| 134 |
d = time.time() - s |
|---|
| 135 |
print "done. (%s -- %1.3fs)" % (time.strftime('%X'), d) |
|---|
| 136 |
print |
|---|
| 137 |
|
|---|
| 138 |
self.root.AddElement(self.svgs) |
|---|
| 139 |
|
|---|
| 140 |
def Render(self, subject, canvas): |
|---|
| 141 |
self.viewport.SetRectangle(canvas.GetClientRect().asTuple()) |
|---|
| 142 |
self.projection.SetDimensionsAspectRatio(2., 2., self.viewport.GetAspectRatio()) |
|---|
| 143 |
self.root.GLExecute(None) |
|---|
| 144 |
|
|---|
| 145 |
if time.clock() - self._fps_score >= 1.: |
|---|
| 146 |
self.frame.SetTitle(self.frametitle + ' [FPS: %1.1f]' % self.root.Statistics['persecond']) |
|---|
| 147 |
self._fps_score = time.clock() |
|---|
| 148 |
|
|---|
| 149 |
def PostRender(self, glviewsetup, canvas): |
|---|
| 150 |
glviewsetup.OnRender.Remove(self.PostRender) |
|---|
| 151 |
#DisplayList.DisplayList.InsertAspect(self.svgs) |
|---|
| 152 |
|
|---|
| 153 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 154 |
#~ Main |
|---|
| 155 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 156 |
|
|---|
| 157 |
def Run(): |
|---|
| 158 |
application = wx.wxPySimpleApp() |
|---|
| 159 |
behavior = Behavior() |
|---|
| 160 |
behavior.OnSkinInitialize() |
|---|
| 161 |
skin = SkinXML(skinxml, application=application, behavior=behavior) |
|---|
| 162 |
behavior.OnSkinFinalize() |
|---|
| 163 |
skin.context.application.MainLoop() |
|---|
| 164 |
|
|---|
| 165 |
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
|---|
| 166 |
|
|---|
| 167 |
if __name__ == '__main__': |
|---|
| 168 |
logging.basicConfig() |
|---|
| 169 |
logging.root.setLevel(logging.INFO) |
|---|
| 170 |
|
|---|
| 171 |
Run() |
|---|
| 172 |
|
|---|