gxlib
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
gxlib [2009/08/24 07:43] – suapapa | gxlib [2013/08/03 05:04] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 13: | Line 13: | ||
*[[http:// | *[[http:// | ||
*[[http:// | *[[http:// | ||
+ | *[[http:// | ||
+ | |||
+ | *[[http:// | ||
+ | *[[http:// | ||
+ | *[[http:// | ||
+ | *[[http:// | ||
====== mmap practice ====== | ====== mmap practice ====== | ||
<code python> | <code python> | ||
- | # | + | import tempfile |
+ | fbfp = tempfile.NamedTemporaryFile(bufsize = 640*480*3) | ||
+ | fbfp.write(' | ||
import mmap | import mmap | ||
- | fbfp = open("/ | + | fbmap = mmap.mmap(fbfp.fileno(), |
- | map = mmap.mmap(fbfp.fileno(), | + | </ |
- | for i in range (640, 640*3): | + | <code python> |
- | map[i] = chr(80) | + | >>> |
- | + | >>> | |
- | map.flush() | + | >>> |
- | map.close() | + | >>> |
+ | m[i:i+3]=' | ||
</ | </ | ||
====== wxScrolledWindow practice ====== | ====== wxScrolledWindow practice ====== | ||
- | <code python> | + | |
- | + | *[[http://wiki.wxpython.org/BufferedCanvas|widget BufferedCanvas]] | |
- | import | + | |
- | import | + | |
- | + | ||
- | BUFFERED = 1 | + | |
- | + | ||
- | # | + | |
- | + | ||
- | class MyCanvas(wx.ScrolledWindow): | + | |
- | def __init__(self, | + | |
- | wx.ScrolledWindow.__init__(self, | + | |
- | + | ||
- | self.lines = [] | + | |
- | self.maxWidth | + | |
- | self.maxHeight = 1000 | + | |
- | self.x = self.y = 0 | + | |
- | self.curLine = [] | + | |
- | self.drawing = False | + | |
- | + | ||
- | self.SetBackgroundColour(" | + | |
- | self.SetCursor(wx.StockCursor(wx.CURSOR_PENCIL)) | + | |
- | bmp = images.Test2.GetBitmap() | + | |
- | mask = wx.Mask(bmp, | + | |
- | bmp.SetMask(mask) | + | |
- | self.bmp = bmp | + | |
- | + | ||
- | self.SetVirtualSize((self.maxWidth, | + | |
- | self.SetScrollRate(20, | + | |
- | + | ||
- | if BUFFERED: | + | |
- | # Initialize the buffer bitmap. | + | |
- | self.buffer = wx.EmptyBitmap(self.maxWidth, | + | |
- | dc = wx.BufferedDC(None, | + | |
- | dc.SetBackground(wx.Brush(self.GetBackgroundColour())) | + | |
- | dc.Clear() | + | |
- | self.DoDrawing(dc) | + | |
- | + | ||
- | self.Bind(wx.EVT_LEFT_DOWN, | + | |
- | self.Bind(wx.EVT_LEFT_UP, | + | |
- | self.Bind(wx.EVT_MOTION, | + | |
- | self.Bind(wx.EVT_PAINT, | + | |
- | + | ||
- | + | ||
- | def getWidth(self): | + | |
- | return self.maxWidth | + | |
- | + | ||
- | def getHeight(self): | + | |
- | return self.maxHeight | + | |
- | + | ||
- | + | ||
- | def OnPaint(self, | + | |
- | if BUFFERED: | + | |
- | # Create a buffered paint DC. It will create the real | + | |
- | # wx.PaintDC and then blit the bitmap to it when dc is | + | |
- | # deleted. | + | |
- | # here that's all there is to it. | + | |
- | dc = wx.BufferedPaintDC(self, | + | |
- | else: | + | |
- | dc = wx.PaintDC(self) | + | |
- | self.PrepareDC(dc) | + | |
- | # since we're not buffering in this case, we have to | + | |
- | # paint the whole window, potentially very time consuming. | + | |
- | self.DoDrawing(dc) | + | |
- | + | ||
- | + | ||
- | def DoDrawing(self, | + | |
- | dc.BeginDrawing() | + | |
- | dc.SetPen(wx.Pen(' | + | |
- | dc.DrawRectangle(5, | + | |
- | + | ||
- | dc.SetBrush(wx.LIGHT_GREY_BRUSH) | + | |
- | dc.SetPen(wx.Pen(' | + | |
- | dc.DrawRectangle(15, | + | |
- | + | ||
- | dc.SetFont(wx.Font(14, | + | |
- | dc.SetTextForeground(wx.Colour(0xFF, | + | |
- | te = dc.GetTextExtent(" | + | |
- | dc.DrawText(" | + | |
- | + | ||
- | dc.SetPen(wx.Pen(' | + | |
- | dc.DrawLine(5, | + | |
- | + | ||
- | lst = [(100,110), (150,110), (150,160), (100, | + | |
- | dc.DrawLines(lst, | + | |
- | dc.SetPen(wx.GREY_PEN) | + | |
- | dc.DrawPolygon(lst, | + | |
- | dc.SetPen(wx.GREEN_PEN) | + | |
- | dc.DrawSpline(lst+[(100, | + | |
- | + | ||
- | dc.DrawBitmap(self.bmp, | + | |
- | dc.SetTextForeground(wx.Colour(0, | + | |
- | dc.DrawText(" | + | |
- | + | ||
- | ## | + | |
- | ## | + | |
- | ## | + | |
- | ## print dc.GetFullTextExtent(" | + | |
- | + | ||
- | font = wx.Font(20, wx.SWISS, wx.NORMAL, wx.NORMAL) | + | |
- | dc.SetFont(font) | + | |
- | dc.SetTextForeground(wx.BLACK) | + | |
- | + | ||
- | for a in range(0, 360, 45): | + | |
- | dc.DrawRotatedText(" | + | |
- | + | ||
- | dc.SetPen(wx.TRANSPARENT_PEN) | + | |
- | dc.SetBrush(wx.BLUE_BRUSH) | + | |
- | dc.DrawRectangle(50, | + | |
- | dc.DrawRectangle(100, | + | |
- | + | ||
- | dc.SetPen(wx.Pen(' | + | |
- | dc.DrawEllipticArc(200, | + | |
- | + | ||
- | if not printing: | + | |
- | # This has troubles when used on a print preview in wxGTK, | + | |
- | # probably something to do with the pen styles and the scaling | + | |
- | # it does... | + | |
- | y = 20 | + | |
- | + | ||
- | for style in [wx.DOT, wx.LONG_DASH, | + | |
- | pen = wx.Pen(" | + | |
- | if style == wx.USER_DASH: | + | |
- | pen.SetCap(wx.CAP_BUTT) | + | |
- | pen.SetDashes([1, | + | |
- | | + | |
- | dc.SetPen(pen) | + | |
- | dc.DrawLine(300, | + | |
- | y = y + 10 | + | |
- | + | ||
- | dc.SetBrush(wx.TRANSPARENT_BRUSH) | + | |
- | dc.SetPen(wx.Pen(wx.Colour(0xFF, | + | |
- | dc.DrawRectangle(450, | + | |
- | old_pen = dc.GetPen() | + | |
- | new_pen = wx.Pen(" | + | |
- | dc.SetPen(new_pen) | + | |
- | dc.DrawRectangle(470, | + | |
- | dc.SetPen(old_pen) | + | |
- | dc.DrawRectangle(490, | + | |
- | + | ||
- | dc.GradientFillLinear((20, | + | |
- | " | + | |
- | dc.GradientFillConcentric((20, | + | |
- | " | + | |
- | self.DrawSavedLines(dc) | + | |
- | dc.EndDrawing() | + | |
- | + | ||
- | + | ||
- | def DrawSavedLines(self, | + | |
- | dc.SetPen(wx.Pen(' | + | |
- | + | ||
- | for line in self.lines: | + | |
- | for coords in line: | + | |
- | apply(dc.DrawLine, | + | |
- | + | ||
- | + | ||
- | def SetXY(self, event): | + | |
- | self.x, self.y = self.ConvertEventCoords(event) | + | |
- | + | ||
- | def ConvertEventCoords(self, | + | |
- | newpos = self.CalcUnscrolledPosition(event.GetX(), | + | |
- | return newpos | + | |
- | + | ||
- | def OnLeftButtonEvent(self, | + | |
- | if event.LeftDown(): | + | |
- | self.SetFocus() | + | |
- | self.SetXY(event) | + | |
- | self.curLine = [] | + | |
- | self.CaptureMouse() | + | |
- | self.drawing = True | + | |
- | + | ||
- | elif event.Dragging() and self.drawing: | + | |
- | if BUFFERED: | + | |
- | # If doing buffered drawing we'll just update the | + | |
- | # buffer here and then refresh that portion of the | + | |
- | # window, then that portion of the buffer will be | + | |
- | # redrawn in the EVT_PAINT handler. | + | |
- | dc = wx.BufferedDC(None, | + | |
- | else: | + | |
- | # otherwise we'll draw directly to a wx.ClientDC | + | |
- | dc = wx.ClientDC(self) | + | |
- | self.PrepareDC(dc) | + | |
- | + | ||
- | dc.SetPen(wx.Pen(' | + | |
- | coords = (self.x, self.y) + self.ConvertEventCoords(event) | + | |
- | self.curLine.append(coords) | + | |
- | dc.DrawLine(*coords) | + | |
- | self.SetXY(event) | + | |
- | + | ||
- | if BUFFERED: | + | |
- | # figure out what part of the window to refresh | + | |
- | x1,y1, x2,y2 = dc.GetBoundingBox() | + | |
- | x1,y1 = self.CalcScrolledPosition(x1, | + | |
- | x2,y2 = self.CalcScrolledPosition(x2, | + | |
- | # make a rectangle | + | |
- | rect = wx.Rect() | + | |
- | rect.SetTopLeft((x1, | + | |
- | rect.SetBottomRight((x2, | + | |
- | rect.Inflate(2, | + | |
- | # refresh it | + | |
- | self.RefreshRect(rect) | + | |
- | + | ||
- | elif event.LeftUp() and self.drawing: | + | |
- | self.lines.append(self.curLine) | + | |
- | self.curLine = [] | + | |
- | self.ReleaseMouse() | + | |
- | self.drawing = False | + | |
- | + | ||
- | + | ||
- | ## This is an example of what to do for the EVT_MOUSEWHEEL event, | + | |
- | ## but since wx.ScrolledWindow does this already it's not | + | |
- | ## necessary to do it ourselves. You would need to add an event table | + | |
- | ## entry to __init__() to direct wheelmouse events to this handler. | + | |
- | + | ||
- | ## | + | |
- | ## def OnWheel(self, | + | |
- | ## delta = evt.GetWheelDelta() | + | |
- | ## rot = evt.GetWheelRotation() | + | |
- | ## | + | |
- | ## print delta, rot, linesPer | + | |
- | ## ws = self.wheelScroll | + | |
- | ## ws = ws + rot | + | |
- | ## lines = ws / delta | + | |
- | ## ws = ws - lines * delta | + | |
- | ## self.wheelScroll = ws | + | |
- | ## if lines != 0: | + | |
- | ## lines = lines * linesPer | + | |
- | ## vsx, vsy = self.GetViewStart() | + | |
- | ## | + | |
- | ## | + | |
- | + | ||
- | # | + | |
- | + | ||
- | def runTest(frame, | + | |
- | win = MyCanvas(nb) | + | |
- | return win | + | |
- | + | ||
- | # | + | |
- | + | ||
- | overview = """ | + | |
- | < | + | |
- | < | + | |
- | The wx.ScrolledWindow class manages scrolling for its client area, transforming the | + | |
- | coordinates according to the scrollbar positions, and setting the scroll positions, | + | |
- | thumb sizes and ranges according to the area in view. | + | |
- | </body> | + | |
- | </ | + | |
- | """ | + | |
- | + | ||
- | + | ||
- | if __name__ == ' | + | |
- | import sys,os | + | |
- | import run | + | |
- | run.main(['', | + | |
- | </ | + | |
*wxDC:: | *wxDC:: | ||
- | *wxBitmapFromBits(bits, width, height, | + | *[[http:// |
====== references ====== | ====== references ====== | ||
*[[http:// | *[[http:// | ||
- | *[[http:// | ||
- | |||
- | ===== bterm ===== | ||
- | <code bash> | ||
- | $ sudo apt-get install bogl-bterm | ||
- | $ sudo apt-get install libbogl-dev | ||
- | ... | ||
- | $ bdftobogl -b gulim.bdf > | ||
- | $ bterm -f gulim.bgf | ||
- | bogl: opening /dev/fb0: No such file or directory | ||
- | |||
- | </ |
gxlib.1251099789.txt.gz · Last modified: 2013/08/03 05:04 (external edit)