wxWidgets/wxPython/tests/test_renderHeaderButton.py

131 lines
5.1 KiB
Python
Raw Normal View History

import wx
import cStringIO
#import os; print os.getpid(); raw_input("Press enter...")
class Panel(wx.Panel):
def __init__(self, parent):
wx.Panel.__init__(self, parent)
self.Bind(wx.EVT_PAINT, self.OnPaint)
def OnPaint(self, evt):
dc = wx.PaintDC(self)
dc.SetFont(self.GetFont())
r = wx.RendererNative.Get()
rect = wx.Rect(40,10, 95,r.GetHeaderButtonHeight(self))
#print rect
# simple helper to make calling DrawHeaderButton so many times a
# bit easier and less messy
def dhb(idx, rect, flags=0, sort=0, params=None):
dc.DrawText("%02d." % idx, rect.x-25, rect.y)
r.DrawHeaderButton(self, dc, rect, flags, sort, params)
rect.y += 30
dhb(1, rect)
dhb(2, rect, wx.CONTROL_SELECTED)
dhb(3, rect, wx.CONTROL_CURRENT)
dhb(4, rect, wx.CONTROL_SELECTED|wx.CONTROL_CURRENT)
dhb(5, rect, 0, wx.HDR_SORT_ICON_UP)
dhb(6, rect, 0, wx.HDR_SORT_ICON_DOWN)
dhb(7, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP)
dhb(8, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_DOWN)
rect.x = 180
rect.y = 10
hp = wx.HeaderButtonParams()
hp.m_labelText = "Hello"
dhb(9, rect, params=hp)
hp.m_labelAlignment = wx.ALIGN_CENTER
dhb(10, rect, params=hp)
hp.m_labelAlignment = wx.ALIGN_RIGHT
dhb(11, rect, params=hp)
hp.m_labelAlignment = wx.ALIGN_CENTER
dhb(12, rect, wx.CONTROL_SELECTED, 0, hp)
dhb(13, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP, hp)
hp.m_labelText = "This label is too long"
dhb(14, rect, params=hp)
dhb(15, rect, wx.CONTROL_SELECTED, 0, hp)
dhb(16, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP, hp)
rect.x = 320
rect.y = 10
hp = wx.HeaderButtonParams()
hp.m_labelBitmap = getBitmap()
dhb(17, rect, params=hp)
hp.m_labelAlignment = wx.ALIGN_CENTER
dhb(18, rect, params=hp)
hp.m_labelAlignment = wx.ALIGN_RIGHT
dhb(19, rect, params=hp)
hp.m_labelAlignment = wx.ALIGN_CENTER
dhb(20, rect, wx.CONTROL_SELECTED, 0, hp)
dhb(21, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP, hp)
hp.m_labelText = "label"
hp.m_labelAlignment = wx.ALIGN_LEFT
dhb(22, rect, 0, 0, hp)
hp.m_labelAlignment = wx.ALIGN_CENTER
dhb(23, rect, 0, 0, hp)
hp.m_labelAlignment = wx.ALIGN_RIGHT
dhb(24, rect, 0, 0, hp)
rect.x = 460
rect.y = 10
hp.m_labelAlignment = wx.ALIGN_LEFT
dhb(25, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP, hp)
hp.m_labelAlignment = wx.ALIGN_CENTER
dhb(26, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP, hp)
hp.m_labelAlignment = wx.ALIGN_RIGHT
dhb(27, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP, hp)
hp.m_labelText = "longer label"
hp.m_labelAlignment = wx.ALIGN_LEFT
dhb(28, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP, hp)
hp.m_labelAlignment = wx.ALIGN_CENTER
dhb(29, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP, hp)
hp.m_labelAlignment = wx.ALIGN_RIGHT
dhb(30, rect, wx.CONTROL_SELECTED, wx.HDR_SORT_ICON_UP, hp)
def getData():
return \
'\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\x10\x00\x00\x00\x10\x08\x06\
\x00\x00\x00\x1f\xf3\xffa\x00\x00\x00\x04sBIT\x08\x08\x08\x08|\x08d\x88\x00\
\x00\x01\xceIDAT8\x8d\x95\x93=h\x14A\x14\xc7\x7f\xfbq\xc7m\xce\x0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+\x8b\xae\xfa\xd6&\xfc\xfb\xe3qHP\xfeCgg\xefEtS\xc3*\
\x9a\xbc]Xg\xe9\xd9\'v\xa5\xa7\xee\xb4\xf82E\x90\xfc\xa9\xedT\xf5\x8d/-V\x16\
]\xa2\x82\x99\x80\x08\x92\xd9?\xd9\xdb\x98\x02\xfc\xaf\xfe\x02\xb1S\xd1)\xa5\
\x1a\xc2\x99\x00\x00\x00\x00IEND\xaeB`\x82'
def getBitmap():
return wx.BitmapFromImage(getImage())
def getImage():
stream = cStringIO.StringIO(getData())
return wx.ImageFromStream(stream)
app = wx.App(False)
frm = wx.Frame(None, title="DrawHeaderButton Test", size=(580,300))
pnl = Panel(frm)
frm.Show()
app.MainLoop()