我们从Python开源项目中,提取了以下10个代码示例,用于说明如何使用wx.RadioButton()。
def initFeatures(self): featureSizer = wx.BoxSizer(orient=wx.HORIZONTAL) spanControlBox = widgets.ControlBox(self, label='Welch Span', orient=wx.VERTICAL) self.spanFloatSpin = agwfs.FloatSpin(self, min_val=0.1, max_val=3.0, increment=0.05, value=self.pg.welchConfig.span) self.spanFloatSpin.SetFormat('%f') self.spanFloatSpin.SetDigits(3) self.Bind(agwfs.EVT_FLOATSPIN, self.setSpan, self.spanFloatSpin) self.cp.offlineControls += [self.spanFloatSpin] spanControlBox.Add(self.spanFloatSpin, proportion=1, flag=wx.ALL | wx.EXPAND, border=10) featureSizer.Add(spanControlBox, proportion=1, flag=wx.LEFT | wx.BOTTOM | wx.RIGHT | wx.EXPAND, border=10) # radio buttons for turning log transform on and off logTransControlBox = widgets.ControlBox(self, label='Log Trans', orient=wx.HORIZONTAL) logTransOnRbtn = wx.RadioButton(self, label='On', style=wx.RB_GROUP) self.Bind(wx.EVT_RADIOBUTTON, self.setLogTransOn, logTransOnRbtn) logTransControlBox.Add(logTransOnRbtn, proportion=0, flag=wx.ALL, border=10) self.cp.offlineControls += [logTransOnRbtn] logTransOffRbtn = wx.RadioButton(self, label='Off') self.Bind(wx.EVT_RADIOBUTTON, self.setLogTransOff, logTransOffRbtn) logTransControlBox.Add(logTransOffRbtn, proportion=0, flag=wx.ALL, border=10) self.cp.offlineControls += [logTransOffRbtn] if self.pg.welchConfig.logTrans: logTransOnRbtn.SetValue(True) else: logTransOffRbtn.SetValue(True) featureSizer.Add(logTransControlBox, proportion=1, flag=wx.BOTTOM | wx.RIGHT | wx.EXPAND, border=10) self.sizer.Add(featureSizer, proportion=0, flag=wx.EXPAND)
def initRateControls(self): """Initialize the sample rate and poll size controls. """ rateSizer = wx.BoxSizer(orient=wx.VERTICAL) pollSizeControlBox = widgets.ControlBox(self, label='Poll Size', orient=wx.HORIZONTAL) self.pollSizeSpinCtrl = wx.SpinCtrl(self, style=wx.SP_WRAP, value=str(self.src.pollSize), min=1, max=32) pollSizeControlBox.Add(self.pollSizeSpinCtrl, flag=wx.ALL | wx.EXPAND, border=10) self.Bind(wx.EVT_SPINCTRL, self.setPollSize, self.pollSizeSpinCtrl) rateSizer.Add(pollSizeControlBox, proportion=0, flag=wx.BOTTOM | wx.RIGHT | wx.TOP, border=10) sampRates = np.array((128,256,512,1024)) self.sampRateRadios = [wx.RadioButton(self, label=str(sampRates[0])+'Hz', style=wx.RB_GROUP)] +\ [wx.RadioButton(self, label=str(sr)+'Hz') for sr in sampRates[1:]] self.sampRateRadios[0].SetValue(True) sampRateControlBox= widgets.ControlBox(self, label='Sample Rate', orient=wx.VERTICAL) for sr,rbtn in zip(sampRates, self.sampRateRadios): def sampRadioWrapper(event, sr=sr): self.src.setSampRate(sr) self.Bind(wx.EVT_RADIOBUTTON, sampRadioWrapper, id=rbtn.GetId()) for rbtn in self.sampRateRadios[:-1]: sampRateControlBox.Add(rbtn, proportion=0, flag=wx.TOP | wx.LEFT | wx.RIGHT, border=10) sampRateControlBox.Add(self.sampRateRadios[-1], proportion=0, flag=wx.ALL, border=10) rateSizer.Add(sampRateControlBox, proportion=0, flag=wx.BOTTOM | wx.RIGHT, border=10) self.sizer.Add(rateSizer)
def initRateControls(self): """Initialize the sample rate and poll size controls. """ rateSizer = wx.BoxSizer(orient=wx.VERTICAL) pollSizeControlBox = widgets.ControlBox(self, label='Poll Size', orient=wx.HORIZONTAL) self.pollSizeSpinCtrl = wx.SpinCtrl(self, style=wx.SP_WRAP, value=str(self.src.pollSize), min=1, max=32) pollSizeControlBox.Add(self.pollSizeSpinCtrl, flag=wx.ALL | wx.EXPAND, border=10) self.Bind(wx.EVT_SPINCTRL, self.setPollSize, self.pollSizeSpinCtrl) rateSizer.Add(pollSizeControlBox, proportion=0, flag=wx.BOTTOM | wx.RIGHT | wx.TOP, border=10) sampRates = np.array((128,256,512,1024)) self.sampRateRadios = [wx.RadioButton(self, label=str(sampRates[0])+'Hz', style=wx.RB_GROUP)] +\ [wx.RadioButton(self, label=str(sr)+'Hz') for sr in sampRates[1:]] self.sampRateRadios[0].SetValue(True) sampRateControlBox = widgets.ControlBox(self, label='Sample Rate', orient=wx.VERTICAL) for sr,rbtn in zip(sampRates, self.sampRateRadios): def sampRadioWrapper(event, sr=sr): try: self.src.setSampRate(sr) except Exception as e: wx.LogError('Failed to set sample rate: ' + str(e.message)) self.Bind(wx.EVT_RADIOBUTTON, sampRadioWrapper, id=rbtn.GetId()) for rbtn in self.sampRateRadios[:-1]: sampRateControlBox.Add(rbtn, proportion=0, flag=wx.TOP | wx.LEFT | wx.RIGHT, border=10) sampRateControlBox.Add(self.sampRateRadios[-1], proportion=0, flag=wx.ALL, border=10) rateSizer.Add(sampRateControlBox, proportion=0, flag=wx.BOTTOM | wx.RIGHT, border=10) self.sizer.Add(rateSizer)
def __init__(self, parent): self.panel = wx.ScrolledWindow.__init__(self, parent) self.SetScrollRate(5, 5) self.panelphase = self.GetParent().panelphase self.panelvisual = self.GetParent().panelvisual self.cmvbox = wx.BoxSizer(wx.VERTICAL) self.cmhbox = [] self.imglist = [] self.sellist = [] self.rb = [] self.chkb = [] array = self.panelphase.cms[0][1] dc = wx.ScreenDC() dc.SetFont(self.panelvisual.font) w,h = dc.GetTextExtent("TestString") height = h if IsNotWX4(): image = wx.EmptyImage(array.shape[0],height) else: image = wx.Image(array.shape[0],height) newarray = numpy.zeros((height, array.shape[0], 3), dtype=numpy.uint8) for i in range(self.panelphase.cms.shape[0]): self.cmhbox.append( wx.BoxSizer(wx.HORIZONTAL) ) name = self.panelphase.cms[i][0] array = self.panelphase.cms[i][1] for j in range(height): newarray[j,:,:] = numpy.uint8(255.0*array) image.SetData( newarray.tostring()) bmp = image.ConvertToBitmap() self.imglist.append(wx.StaticBitmap(self, -1, bmp)) self.rb.append( wx.RadioButton(self, -1, label=name, size=(160, height) ) ) self.cmhbox[-1].Add(self.rb[-1], 0) self.cmhbox[-1].Add((5, -1)) self.cmhbox[-1].Add(self.imglist[-1], 1, wx.EXPAND) self.chkb.append( wx.CheckBox(self, -1, 'Reverse', size=(160, height)) ) self.cmhbox[-1].Add(self.chkb[-1], 0, wx.EXPAND) self.cmvbox.Add(self.cmhbox[-1], 1, wx.EXPAND) self.SetSizer(self.cmvbox) self.Fit() self.Layout() self.Show()
def create_wxwindow(self): return self.initfn(wx.RadioButton)(self.parent, self.id, self.label, self.pos, self.size, self.style, self.validator, self.name)
def addRadioButtons(self): boxSizerH = wx.BoxSizer(wx.HORIZONTAL) boxSizerH.Add((2, 0)) boxSizerH.Add(wx.RadioButton(self.panel, -1, 'Blue', style=wx.RB_GROUP)) boxSizerH.Add((33, 0)) boxSizerH.Add(wx.RadioButton(self.panel, -1, 'Gold')) boxSizerH.Add((45, 0)) boxSizerH.Add(wx.RadioButton(self.panel, -1, 'Red' )) self.statBoxSizerV.Add(boxSizerH, 0, wx.ALL, 8) #----------------------------------------------------------
def initSigControls(self): """Initialize signal controls. """ sigSizer = wx.BoxSizer(orient=wx.VERTICAL) waveformControlBox = widgets.ControlBox(self, label='Waveform', orient=wx.VERTICAL) self.waveformComboBox = wx.ComboBox(self, id=wx.ID_ANY, choices=list(waveforms.keys()), value='sinusoid', style=wx.CB_SORT | wx.CB_READONLY) self.waveformComboBox.Bind(wx.EVT_COMBOBOX, self.setWaveform) waveformControlBox.Add(self.waveformComboBox, proportion=0, flag=wx.ALL, border=10) sigSizer.Add(waveformControlBox, proportion=0, flag=wx.ALL | wx.EXPAND, border=10) freqControlBox = widgets.ControlBox(self, label='Base Frequency', orient=wx.HORIZONTAL) self.freqText = wx.StaticText(self, label='%4.1f(Hz)' % 1.0) freqTextSizer = wx.BoxSizer(orient=wx.VERTICAL) freqTextSizer.Add(self.freqText, proportion=1, flag=wx.EXPAND) self.freqSlider = wx.Slider(self, style=wx.SL_HORIZONTAL, value=10, minValue=1, maxValue=300) self.Bind(wx.EVT_SLIDER, self.setFreq, self.freqSlider) freqControlBox.Add(freqTextSizer, proportion=0, flag=wx.ALL, border=10) freqControlBox.Add(self.freqSlider, proportion=1, flag=wx.ALL | wx.EXPAND, border=10) sigSizer.Add(freqControlBox, proportion=0, flag=wx.LEFT | wx.BOTTOM | wx.RIGHT | wx.EXPAND, border=10) mixControlBox = widgets.ControlBox(self, label='Channel Mixer', orient=wx.HORIZONTAL) self.mixNoneButton = wx.RadioButton(self, label='None', style=wx.RB_GROUP) #mixControlBox.Add(self.mixNoneButton, proportion=0, flag=wx.TOP | wx.LEFT | wx.BOTTOM, border=10) mixControlBox.Add(self.mixNoneButton, proportion=0, flag=wx.ALL, border=10) self.mixNoneButton.SetValue(True) self.Bind(wx.EVT_RADIOBUTTON, self.setMixNone, self.mixNoneButton) #self.mixEqualButton = wx.RadioButton(self, label='Equal') #mixControlBox.Add(self.mixEqualButton, proportion=0, flag=wx.ALL, border=10) #self.Bind(wx.EVT_RADIOBUTTON, self.setMixEqual, self.mixEqualButton) self.mixRandomButton = wx.RadioButton(self, label='Random') #mixControlBox.Add(self.mixRandomButton, proportion=0, flag=wx.BOTTOM | wx.RIGHT | wx.TOP, border=10) mixControlBox.Add(self.mixRandomButton, proportion=0, flag=wx.ALL, border=10) self.Bind(wx.EVT_RADIOBUTTON, self.setMixRandom, self.mixRandomButton) sigSizer.Add(mixControlBox, proportion=0, flag=wx.LEFT | wx.BOTTOM | wx.RIGHT | wx.EXPAND, border=10) self.sizer.Add(sigSizer)
def initRateControls(self): """Initialize the poll size control. """ rateSizer = wx.BoxSizer(orient=wx.HORIZONTAL) # poll rate pollSizeControlBox = widgets.ControlBox(self, label='Poll Size', orient=wx.HORIZONTAL) self.pollSizeSpinCtrl = wx.SpinCtrl(self, style=wx.SP_WRAP, value=str(self.src.pollSize), min=1, max=32) pollSizeControlBox.Add(self.pollSizeSpinCtrl, flag=wx.ALL | wx.EXPAND, border=10) self.Bind(wx.EVT_SPINCTRL, self.setPollSize, self.pollSizeSpinCtrl) rateSizer.Add(pollSizeControlBox, proportion=0, flag=wx.ALL | wx.EXPAND, border=10) # speed mode speedModeControlBox = widgets.ControlBox(self, label='Speed Mode', orient=wx.HORIZONTAL) self.speedModeSpinCtrl = wx.SpinCtrl(self, style=wx.SP_WRAP, value=str(self.src.speedMode.value), min=4, max=7) speedModeControlBox.Add(self.speedModeSpinCtrl, flag=wx.ALL | wx.EXPAND, border=10) self.Bind(wx.EVT_SPINCTRL, self.setSpeedMode, self.speedModeSpinCtrl) rateSizer.Add(speedModeControlBox, proportion=0, flag=wx.BOTTOM | wx.RIGHT | wx.TOP | wx.EXPAND, border=10) # number of channels nChans = (32, 64) self.nChanRadios = [wx.RadioButton(self, label=str(nChans[0]), style=wx.RB_GROUP)] +\ [wx.RadioButton(self, label=str(sr)) for sr in nChans[1:]] self.nChanRadios[-1].SetValue(True) nChanControlBox = widgets.ControlBox(self, label='Num Chans', orient=wx.HORIZONTAL) for nc,rbtn in zip(nChans, self.nChanRadios): def nChanRadioWrapper(event, nc=nc): try: self.src.setNChan(nc) except Exception as e: wx.LogError('Failed to set number of channels: ' + str(e.message)) self.Bind(wx.EVT_RADIOBUTTON, nChanRadioWrapper, id=rbtn.GetId()) nChanControlBox.Add(self.nChanRadios[0], proportion=0, flag=wx.ALL | wx.EXPAND, border=10) for rbtn in self.nChanRadios[1:]: nChanControlBox.Add(rbtn, proportion=0, flag=wx.BOTTOM | wx.RIGHT | wx.TOP | wx.EXPAND, border=10) rateSizer.Add(nChanControlBox, proportion=0, flag=wx.BOTTOM | wx.RIGHT | wx.TOP | wx.EXPAND, border=10) self.sizer.Add(rateSizer)
def __init__(self, parent, controller, tagname): """ Constructor @param parent: Parent wx.Window of dialog for modal @param controller: Reference to project controller @param tagname: Tagname of project POU edited """ BlockPreviewDialog.__init__(self, parent, controller, tagname, title=_('Power Rail Properties')) # Init common sizers self._init_sizers(2, 0, 5, None, 2, 1) # Create label for connection type type_label = wx.StaticText(self, label=_('Type:')) self.LeftGridSizer.AddWindow(type_label, flag=wx.GROW) # Create radio buttons for selecting power rail type self.TypeRadioButtons = {} first = True for type, label in [(LEFTRAIL, _('Left PowerRail')), (RIGHTRAIL, _('Right PowerRail'))]: radio_button = wx.RadioButton(self, label=label, style=(wx.RB_GROUP if first else 0)) radio_button.SetValue(first) self.Bind(wx.EVT_RADIOBUTTON, self.OnTypeChanged, radio_button) self.LeftGridSizer.AddWindow(radio_button, flag=wx.GROW) self.TypeRadioButtons[type] = radio_button first = False # Create label for power rail pin number pin_number_label = wx.StaticText(self, label=_('Pin number:')) self.LeftGridSizer.AddWindow(pin_number_label, flag=wx.GROW) # Create spin control for defining power rail pin number self.PinNumber = wx.SpinCtrl(self, min=1, max=50, style=wx.SP_ARROW_KEYS) self.PinNumber.SetValue(1) self.Bind(wx.EVT_SPINCTRL, self.OnPinNumberChanged, self.PinNumber) self.LeftGridSizer.AddWindow(self.PinNumber, flag=wx.GROW) # Add preview panel and associated label to sizers self.RightGridSizer.AddWindow(self.PreviewLabel, flag=wx.GROW) self.RightGridSizer.AddWindow(self.Preview, flag=wx.GROW) # Add buttons sizer to sizers self.MainSizer.AddSizer( self.ButtonSizer, border=20, flag=wx.ALIGN_RIGHT | wx.BOTTOM | wx.LEFT | wx.RIGHT) self.Fit() # Left Power Rail radio button is default control having keyboard focus self.TypeRadioButtons[LEFTRAIL].SetFocus()