]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/demo/ColourDialog.py
   4 #--------------------------------------------------------------------------- 
   6 class TestPanel(wx
.Panel
): 
   7     def __init__(self
, parent
, log
): 
   9         wx
.Panel
.__init
__(self
, parent
, -1) 
  11         b 
= wx
.Button(self
, -1, "Create and Show a ColourDialog", (50,50)) 
  12         self
.Bind(wx
.EVT_BUTTON
, self
.OnButton
, b
) 
  15     def OnButton(self
, evt
): 
  16         dlg 
= wx
.ColourDialog(self
) 
  18         # Ensure the full colour dialog is displayed,  
  19         # not the abbreviated version. 
  20         dlg
.GetColourData().SetChooseFull(True) 
  22         if dlg
.ShowModal() == wx
.ID_OK
: 
  24             # If the user selected OK, then the dialog's wx.ColourData will 
  25             # contain valid information. Fetch the data ... 
  26             data 
= dlg
.GetColourData() 
  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())) 
  32         # Once the dialog is destroyed, Mr. wx.ColourData is no longer your 
  33         # friend. Don't use it again! 
  36 #--------------------------------------------------------------------------- 
  39 def runTest(frame
, nb
, log
): 
  40     win 
= TestPanel(nb
, log
) 
  44 #--------------------------------------------------------------------------- 
  48 This class represents the colour chooser dialog. 
  50 Use of this dialog is a multi-stage process.  
  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.  
  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. 
  64 Along with he wx.ColourDialog documentation, see also the wx.ColourData documentation  
  68 if __name__ 
== '__main__': 
  71     run
.main(['', os
.path
.basename(sys
.argv
[0])] + sys
.argv
[1:])