13.07.2015 Views

The wxPython tutorial

The wxPython tutorial

The wxPython tutorial

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Creating custom widgetshttp://www.zetcode.com/wxpython/customwidgets/class Widget(wx.Panel):def __init__(self, parent, id):wx.Panel.__init__(self, parent, id, size=(-1, 30), style=wx.SUNKEN_BORDER)self.parent = parentself.font = wx.Font(9, wx.FONTFAMILY_DEFAULT, wx.FONTSTYLE_NORMAL,wx.FONTWEIGHT_NORMAL, False, 'Courier 10 Pitch')self.Bind(wx.EVT_PAINT, self.OnPaint)self.Bind(wx.EVT_SIZE, self.OnSize)def OnPaint(self, event):num = range(75, 700, 75)dc = wx.PaintDC(self)dc.SetFont(self.font)w, h = self.GetSize()self.cw = self.parent.GetParent().cwstep = int(round(w / 10.0))j = 0till = (w / 750.0) * self.cwfull = (w / 750.0) * 700if self.cw >= 700:dc.SetPen(wx.Pen('#FFFFB8'))dc.SetBrush(wx.Brush('#FFFFB8'))dc.DrawRectangle(0, 0, full, 30)dc.SetPen(wx.Pen('#ffafaf'))dc.SetBrush(wx.Brush('#ffafaf'))dc.DrawRectangle(full, 0, till-full, 30)else:dc.SetPen(wx.Pen('#FFFFB8'))dc.SetBrush(wx.Brush('#FFFFB8'))dc.DrawRectangle(0, 0, till, 30)dc.SetPen(wx.Pen('#5C5142'))for i in range(step, 10*step, step):dc.DrawLine(i, 0, i, 6)width, height = dc.GetTextExtent(str(num[j]))dc.DrawText(str(num[j]), i-width/2, 8)j = j + 1def OnSize(self, event):self.Refresh()class Burning(wx.Frame):def __init__(self, parent, id, title):wx.Frame.__init__(self, parent, id, title, size=(330, 200))self.cw = 75panel = wx.Panel(self, -1)CenterPanel = wx.Panel(panel, -1)self.sld = wx.Slider(CenterPanel, -1, 75, 0, 750, (-1, -1), (150, -1), wx.SL_LABELSvbox = wx.BoxSizer(wx.VERTICAL)hbox = wx.BoxSizer(wx.HORIZONTAL)hbox2 = wx.BoxSizer(wx.HORIZONTAL)4 de 9 27/04/2008 1:07

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!