]> git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ColourDialog.py
Tinderbox build fix.
[wxWidgets.git] / wxPython / demo / ColourDialog.py
1
2 import wx
3
4 #---------------------------------------------------------------------------
5
6 class TestPanel(wx.Panel):
7 def __init__(self, parent, log):
8 self.log = log
9 wx.Panel.__init__(self, parent, -1)
10
11 b = wx.Button(self, -1, "Create and Show a ColourDialog", (50,50))
12 self.Bind(wx.EVT_BUTTON, self.OnButton, b)
13
14
15 def OnButton(self, evt):
16 dlg = wx.ColourDialog(self)
17
18 # Ensure the full colour dialog is displayed,
19 # not the abbreviated version.
20 dlg.GetColourData().SetChooseFull(True)
21
22 if dlg.ShowModal() == wx.ID_OK:
23
24 # If the user selected OK, then the dialog's wx.ColourData will
25 # contain valid information. Fetch the data ...
26 data = dlg.GetColourData()
27
28 # ... then do something with it. The actual colour data will be
29 # returned as a three-tuple (r, g, b) in this particular case.
30 self.log.WriteText('You selected: %s\n' % str(data.GetColour().Get()))
31
32 # Once the dialog is destroyed, Mr. wx.ColourData is no longer your
33 # friend. Don't use it again!
34 dlg.Destroy()
35
36 #---------------------------------------------------------------------------
37
38
39 def runTest(frame, nb, log):
40 win = TestPanel(nb, log)
41 return win
42
43
44 #---------------------------------------------------------------------------
45
46
47 overview = """\
48 This class represents the colour chooser dialog.
49
50 Use of this dialog is a multi-stage process.
51
52 The actual information about how to display the dialog and the colors in the
53 dialog's 'registers' are contained in a wx.ColourData instance that is created by
54 the dialog at init time. Before displaying the dialog, you may alter these settings
55 to suit your needs. In the example, we set the dialog up to show the extended colour
56 data selection pane. Otherwise, only the more compact and less extensive colour
57 dialog is shown. You may also preset the colour as well as other items.
58
59 If the user selects something and selects OK, then the wx.ColourData instance contains
60 the colour data that the user selected. Before destroying the dialog, retrieve the data.
61 <b>Do not try to retain the wx.ColourData instance.</b> It will probably not be valid
62 after the dialog is destroyed.
63
64 Along with he wx.ColourDialog documentation, see also the wx.ColourData documentation
65 for details.
66 """
67
68 if __name__ == '__main__':
69 import sys,os
70 import run
71 run.main(['', os.path.basename(sys.argv[0])] + sys.argv[1:])
72