def OnColourSelect(self, event):
cdata = wx.ColourData()
cdata.SetColour((self.r,self.g,self.b))
dlg = wx.ColourDialog(self, data=cdata)
dlg.GetColourData().SetChooseFull(True)
if dlg.ShowModal() == wx.ID_OK:
self.r,self.g,self.b = dlg.GetColourData().GetColour().Get(includeAlpha=False)
r = float(self.r)/255.0
g = float(self.g)/255.0
b = float(self.b)/255.0
renderers = self.renWin.GetRenderWindow().GetRenderers()
renderers.InitTraversal()
no_renderers = renderers.GetNumberOfItems()
for i in range(no_renderers):
renderers.GetItemAsObject(i).SetBackground(r, g, b)
self.RefreshScene()
dlg.Destroy()
python类ColourDialog()的实例源码
def on_button_press(self, event):
dialog = wx.ColourDialog(self.panel)
if dialog.ShowModal() == wx.ID_OK:
colour = dialog.GetColourData()
hex_colour = colour.Colour.GetAsString(flags=wx.C2S_HTML_SYNTAX)
self.panel.SetBackgroundColour(colour.Colour)
self.panel.Refresh()
self.text.SetLabel(hex_colour)
self.panel.Layout()
col = colour.Colour
if (col.red * 0.299 + col.green * 0.587 + col.blue * 0.114) > 186:
self.text.SetForegroundColour('black')
else:
self.text.SetForegroundColour('white')
self.event({'colour': colour.Colour, 'hex': hex_colour, 'key': self.key})
def on_cell_dlclick(self, event):
if event.GetCol() == 1:
row = event.GetRow()
table = self.tables[self.currentwellindex][self.currentpartitionindex]
color = table.get_color(row)
global COLOUR_DATA
COLOUR_DATA.SetColour(color)
dlg = wx.ColourDialog(self, COLOUR_DATA)
if dlg.ShowModal() == wx.ID_OK:
COLOUR_DATA = dlg.GetColourData()
color = COLOUR_DATA.GetColour().Get(True)
# TODO: alpha
table.set_color(row, color)
self.grid.ForceRefresh()
dlg.Destroy()
else:
event.Skip()
def on_cell_dlclick(self, event):
if event.GetCol() == 1:
row = event.GetRow()
table = self.tables[self.currentwellindex][self.currentrocktableindex]
color = table.get_color(row)
global COLOUR_DATA
COLOUR_DATA.SetColour(color)
dlg = wx.ColourDialog(self, COLOUR_DATA)
if dlg.ShowModal() == wx.ID_OK:
COLOUR_DATA = dlg.GetColourData()
color = COLOUR_DATA.GetColour().Get(True)
# TODO: alpha
table.set_color(row, color)
self.grid.ForceRefresh()
dlg.Destroy()
else:
event.Skip()
def OnCreateVariable(self,event):
openColourDialog = wx.ColourDialog(self)
if openColourDialog.ShowModal() == wx.ID_CANCEL:
return
openNameChooser = wx.TextEntryDialog(self,"What would you like your new colour variable to be called?")
if openNameChooser.ShowModal() == wx.ID_CANCEL:
return
proposed = openNameChooser.GetValue()
name = ""
seenChar = False
for character in proposed:
if not seenChar:
if character in string.ascii_letters:
name+=character
seenChar=True
elif character in string.ascii_letters+string.digits:
name+=character
if name=="":
i = 0
for name in self.config.setColours:
if name[:14]=="colourVariable":
i+=1
name = "colourVariable"+str(i)
name = "$"+name
self.config.setColourChanged(openColourDialog.GetColourData(),name)
self.LoadConfig(self.config)
def get_color(cls, app=None):
rst = None
dlg = wx.ColourDialog(app)
dlg.GetColourData().SetChooseFull(True)
if dlg.ShowModal() == wx.ID_OK:
rst = dlg.GetColourData().GetColour()
dlg.Destroy()
return rst
def oncolor(self, event):
rst = None
dlg = wx.ColourDialog(self)
dlg.GetColourData().SetChooseFull(True)
if dlg.ShowModal() == wx.ID_OK:
rst = dlg.GetColourData().GetColour()
self.SetBackgroundColour(rst)
self.SetValue(rst.GetAsString(wx.C2S_HTML_SYNTAX))
self.f(event)
dlg.Destroy()
def onOpenColorDialog(self, event):
"""
Creates and opens the wx.ColourDialog
"""
with wx.ColourDialog(self) as dlg:
if dlg.ShowModal() == wx.ID_OK:
data = dlg.GetColourData()
color = str(data.GetColour().Get())
print 'You selected: %s\n' % color
def __init__(self, parent):
wx.Dialog.__init__(self, parent, title="Lookup Table", style=wx.DEFAULT_DIALOG_STYLE|wx.RESIZE_BORDER)
self.SetSizeHints(720,480,-1,-1)
self.parent = parent
self.Bind(wx.EVT_CLOSE, self.OnExit)
self.panelphase = parent.GetParent().GetPage(0)
self.panelvisual = self.GetParent()
self.actor_list3D = ["vtkOpenGLActor", "vtkActor", "vtkMesaActor"]
self.actor_list2D = ["vtkOpenGLImageActor", "vtkImageActor"]
self.sizer = wx.BoxSizer(wx.VERTICAL)
self.hbox = wx.BoxSizer(wx.HORIZONTAL)
self.vbox1 = wx.BoxSizer(wx.VERTICAL)
self.vbox2 = wx.BoxSizer(wx.VERTICAL)
self.font = self.panelvisual.font
self.panels = []
self.listtitles = ["Real Amp","Real Phase", "Fourier Amp","Fourier Phase"]
self.list = wx.ListCtrl(self,wx.ID_ANY,style=wx.LC_REPORT|wx.LC_NO_HEADER|wx.LC_HRULES|wx.SUNKEN_BORDER, size=(200,-1))
self.list.Bind(wx.EVT_LIST_ITEM_SELECTED, self.OnSelectListItem)
self.list.InsertColumn(0,'Settings', width = 200)
self.list.SetFont(self.font)
for i in range(len(self.listtitles)):
if IsNotWX4():
self.list.InsertStringItem(i,self.listtitles[i],i)
else:
self.list.InsertItem(i,self.listtitles[i],i)
self.list.SetItemFont(i, self.font)
self.panels.append(ColourDialog(self))
self.panels[-1].Hide()
self.panels[-1].Layout()
self.GetRadioChoice(i)
self.vbox2.Add(self.panels[-1], 1, wx.EXPAND)
self.vbox1.Add(self.list, 1, wx.EXPAND)
self.panel_hld = wx.StaticText(self, label='')
self.vbox2.Add(self.panel_hld, 1, wx.EXPAND)
self.hbox.Add(self.vbox1, 0, wx.EXPAND,2)
self.hbox.Add(self.vbox2, 1, wx.EXPAND,2)
self.sizer.Add(self.hbox, 1, wx.EXPAND,2)
self.button_update = wx.Button(self, label="Update Scale", size=(720, 30))
self.sizer.Add(self.button_update, 0, wx.EXPAND, 2)
self.Bind(wx.EVT_BUTTON, self.OnClickUpdate,self.button_update)
self.SetSizer(self.sizer)
self.Fit()
self.Layout()
self.Show()