]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/analogclock/lib_setup/colourselect.py
fixed wxVsnprintf() to write as much as it can if the output buffer is too short
[wxWidgets.git] / wxPython / wx / lib / analogclock / lib_setup / colourselect.py
1 # AnalogClock's colour selector for setup dialog
2 # E. A. Tacao <e.a.tacao |at| estadao.com.br>
3 # http://j.domaindlx.com/elements28/wxpython/
4 # 15 Fev 2006, 22:00 GMT-03:00
5 # Distributed under the wxWidgets license.
6
7 import wx
8 from wx.lib.newevent import NewEvent
9 from wx.lib.buttons import GenBitmapButton
10
11 #----------------------------------------------------------------------------
12
13 (ColourSelectEvent, EVT_COLOURSELECT) = NewEvent()
14
15 #----------------------------------------------------------------------------
16
17 class ColourSelect(GenBitmapButton):
18 def __init__(self, parent, size=(21, 21), value=wx.BLACK):
19 w, h = size[0] - 5, size[1] - 5
20 GenBitmapButton.__init__(self, parent, wx.ID_ANY, wx.EmptyBitmap(w, h),
21 size=size)
22 self.SetBezelWidth(1)
23
24 self.parent = parent
25 self.SetValue(value)
26
27 self.parent.Bind(wx.EVT_BUTTON, self.OnClick, self)
28
29
30 def _makeBitmap(self):
31 bdr = 8; w, h = self.GetSize()
32 bmp = wx.EmptyBitmap(w - bdr, h - bdr)
33
34 dc = wx.MemoryDC()
35 dc.SelectObject(bmp)
36 dc.SetBackground(wx.Brush(self.value, wx.SOLID))
37 dc.Clear()
38 dc.SelectObject(wx.NullBitmap)
39
40 self.SetBitmapLabel(bmp)
41 self.Refresh()
42
43
44 def GetValue(self):
45 return self.value
46
47
48 def SetValue(self, value):
49 self.value = value
50 self._makeBitmap()
51
52
53 def OnClick(self, event):
54 win = wx.GetTopLevelParent(self)
55
56 data = wx.ColourData()
57 data.SetChooseFull(True)
58 data.SetColour(self.value)
59 [data.SetCustomColour(colour_index, win.customcolours[colour_index])
60 for colour_index in range(0, 16)]
61
62 dlg = wx.ColourDialog(win, data)
63 dlg.SetTitle("Select Colour")
64 changed = dlg.ShowModal() == wx.ID_OK
65
66 if changed:
67 data = dlg.GetColourData()
68 self.SetValue(data.GetColour())
69 win.customcolours = [data.GetCustomColour(colour_index) \
70 for colour_index in range(0, 16)]
71 dlg.Destroy()
72
73 if changed:
74 nevt = ColourSelectEvent(id=self.GetId(), obj=self, val=self.value)
75 wx.PostEvent(self.parent, nevt)
76
77
78 #
79 ##
80 ### eof