Документ взят из кэша поисковой машины. Адрес оригинального документа : http://kodomo.fbb.msu.ru/hg/allpy/raw-rev/e3ba4c63e622
Дата изменения: Unknown
Дата индексирования: Tue Oct 2 07:35:36 2012
Кодировка:

# HG changeset patch
# User Danya Alexeyevsky
# Date 1276187309 -14400
# Node ID e3ba4c63e622ff938be058b0e3df08f0fd85d22d
# Parent bd3d695f99064c40e8c331bdf296c3cc353f97dd
In sandbox: Some not-really-working stuff (on topic of text rendering)

diff -r bd3d695f9906 -r e3ba4c63e622 sandbox/bufferedcanvas.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sandbox/bufferedcanvas.py Thu Jun 10 20:28:29 2010 +0400
@@ -0,0 +1,142 @@
+"""
+BufferedCanvas -- Double-buffered, flicker-free canvas widget
+Copyright (C) 2005, 2006 Daniel Keep
+
+To use this widget, just override or replace the draw method.
+This will be called whenever the widget size changes, or when
+the update method is explicitly called.
+
+Please submit any improvements/bugfixes/ideas to the following
+url:
+
+ http://wiki.wxpython.org/index.cgi/BufferedCanvas
+
+2006-04-29: Added bugfix for a crash on Mac provided by Marc Jans.
+"""
+
+# Hint: try removing '.sp4msux0rz'
+__author__ = 'Daniel Keep '
+
+__license__ = """
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public License as
+published by the Free Software Foundation; either version 2.1 of the
+License, or (at your option) any later version.
+
+As a special exception, the copyright holders of this library
+hereby recind Section 3 of the GNU Lesser General Public License. This
+means that you MAY NOT apply the terms of the ordinary GNU General
+Public License instead of this License to any given copy of the
+Library. This has been done to prevent users of the Library from being
+denied access or the ability to use future improvements.
+
+This library is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
+General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""
+
+__all__ = ['BufferedCanvas']
+
+import wx
+import wx.lib.scrolledpanel as sp
+
+class BufferedCanvas(sp.ScrolledPanel):
+ """
+ Implements a double-buffered, flicker-free canvas widget.
+
+ Standard usage is to subclass this class, and override the
+ draw method. The draw method is passed a device context, which
+ should be used to do your drawing.
+
+ Also, you should NOT call dc.BeginDrawing() and dc.EndDrawing() --
+ these methods are automatically called for you, although you still
+ need to manually clear the device context.
+
+ If you want to force a redraw (for whatever reason), you should
+ call the update method. This is because the draw method is never
+ called as a result of an EVT_PAINT event.
+ """
+
+ # These are our two buffers. Just be aware that when the buffers
+ # are flipped, the REFERENCES are swapped. So I wouldn't want to
+ # try holding onto explicit references to one or the other ;)
+ buffer = None
+ backbuffer = None
+
+ def __init__(self,
+ parent,
+ ID=-1,
+ pos=wx.DefaultPosition,
+ size=wx.DefaultSize,
+ style=wx.NO_FULL_REPAINT_ON_RESIZE):
+ sp.ScrolledPanel.__init__(self,parent,ID,pos,size,style)
+
+ # Bind events
+ self.Bind(wx.EVT_PAINT, self.onPaint)
+ self.Bind(wx.EVT_SIZE, self.onSize)
+
+ # Disable background erasing (flicker-licious)
+ def disable_event(*pargs,**kwargs):
+ pass # the sauce, please
+ self.Bind(wx.EVT_ERASE_BACKGROUND, disable_event)
+
+ # Ensure that the buffers are setup correctly
+ self.onSize(None)
+
+ ##
+ ## General methods
+ ##
+
+ def draw(self,dc):
+ """
+ Stub: called when the canvas needs to be re-drawn.
+ """
+ pass
+
+
+ def flip(self):
+ """
+ Flips the front and back buffers.
+ """
+ self.buffer,self.backbuffer = self.backbuffer,self.buffer
+ self.Refresh()
+
+
+ def update(self):
+ """
+ Causes the canvas to be updated.
+ """
+ dc = wx.MemoryDC()
+ dc.SelectObject(self.backbuffer)
+ dc.BeginDrawing()
+ self.draw(dc)
+ dc.EndDrawing()
+ self.flip()
+
+ ##
+ ## Event handlers
+ ##
+
+ def onPaint(self, event):
+ # Blit the front buffer to the screen
+ dc = wx.BufferedPaintDC(self, self.buffer)
+
+
+ def onSize(self, event):
+ # Here we need to create a new off-screen buffer to hold
+ # the in-progress drawings on.
+ width,height = self.GetClientSizeTuple()
+ if width == 0:
+ width = 1
+ if height == 0:
+ height = 1
+ self.buffer = wx.EmptyBitmap(width,height)
+ self.backbuffer = wx.EmptyBitmap(width,height)
+
+ # Now update the screen
+ self.update()
diff -r bd3d695f9906 -r e3ba4c63e622 sandbox/gl.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sandbox/gl.py Thu Jun 10 20:28:29 2010 +0400
@@ -0,0 +1,46 @@
+#!/usr/bin/python
+# http://disruption.ca/gutil/example3/example3a.html
+# vim: set noet:
+
+import gutil
+import pygame
+from pygame.locals import *
+from OpenGL.GL import *
+
+from Image import Image
+
+
+def main():
+ pygame.init()
+ gutil.initializeDisplay(800, 600)
+
+ done = False
+
+ cow = Image('cow')
+ alien = Image('alien')
+
+ white = (255,255,255,255)
+ stringTex, w, h, tw, th = gutil.loadText("Cow!", color=white)
+ stringDL = gutil.createTexDL(stringTex, tw, th)
+
+ while not done:
+ glClear(GL_COLOR_BUFFER_BIT)
+ glLoadIdentity()
+ glColor4f(1.0,1.0,1.0,1.0)
+ glTranslatef(100, 400, 0)
+ glCallList(stringDL)
+
+ cow.draw(pos=(100,100),width=128,height=128)
+ alien.draw(pos=(400, 400),rotation=-15,color=(.9,.3,.2,1))
+
+
+ pygame.display.flip()
+
+ eventlist = pygame.event.get()
+ for event in eventlist:
+ if event.type == QUIT \
+ or event.type == KEYDOWN and event.key == K_ESCAPE:
+ done = True
+
+if __name__ == '__main__':
+ main()
diff -r bd3d695f9906 -r e3ba4c63e622 sandbox/wx-dc.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sandbox/wx-dc.py Thu Jun 10 20:28:29 2010 +0400
@@ -0,0 +1,52 @@
+#!/usr/bin/python
+
+import wx
+import bufferedcanvas
+import common
+
+class Text(bufferedcanvas.BufferedCanvas):
+
+ def __init__(self, seqs, *args, **kw):
+ self.seqs = seqs
+ self.font = wx.FFont(12, wx.FONTFAMILY_MODERN)
+ bufferedcanvas.BufferedCanvas.__init__(self, *args, **kw)
+
+ dc = wx.ClientDC(self)
+ dc.SetFont(self.font)
+ w = (len(seqs[0][1])+1) * dc.GetCharWidth()
+ h = (len(seqs)+1) * (dc.GetCharHeight() + 1)
+ self.size = w, h
+ self.SetVirtualSize(self.size)
+
+ self.Bind(wx.EVT_SCROLL, self.onPaint)
+
+ self.SetupScrolling()
+
+ def draw(self, dc):
+ dc.SetBackground(wx.Brush("White"))
+ dc.Clear()
+ dc.SetFont(self.font)
+
+ w = dc.GetCharWidth()
+ h = dc.GetCharHeight()
+ for i, (name, body, ids, colors) in enumerate(self.seqs):
+ for j in xrange(len(body)):
+ x = j * w
+ y = i * (h + 1)
+ dc.SetBrush(wx.Brush(colors[j]))
+ dc.SetPen(wx.Pen(colors[j]))
+ dc.DrawRectangle(x, y, x + w, y + h)
+ dc.SetPen(wx.Pen("Black"))
+ dc.DrawText(body[j], x, y)
+
+ if hasattr(self, 'size'):
+ self.SetVirtualSize(self.size)
+
+seqs = common.autoload('data/small.fasta')
+
+app = wx.App(False)
+top = wx.Frame(None, title='Example', size=(500, 500))
+text = Text(seqs, top)
+top.Show(True)
+
+app.MainLoop()