ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> wxpython-users
wxpython-users
Re: [wxpython-users] Can a group of radio buttons be used as a one-click selection ?
by C M other posts by this author
May 9 2008 7:46PM messages near this date
[wxpython-users] Can a group of radio buttons be used as a one-click selection ? | Re: [wxpython-users] Can a group of radio buttons be used as a one-click selection ?
On Fri, May 9, 2008 at 8:44 PM, Stef Mientki <s.mientki@[...].nl>  wrote:
>  hello,
> 
>  I want a group of radio buttons,
>  where clicking on one of the buttons,
>  should perform some action.
>  Now this works as long as I don't select the same (already selected)
>  Radiobutton.

First, just a contention:  What would be the (visual) logic of
clicking something that is already selected?  Wouldn't the state of
your GUI/app be as that radioButton indicates already?  If others are
to use this, I would argue that users might think this way too (or you
could argue that this is a good paradigm switch!).

But it should work if you call event.Skip() to allow the button to
"popped" after you tell it to perform some action.  Maybe you were
leaving that out?  See a working sample attached.

HTH,
Che

#Boa:Frame:Frame1

import wx
import datetime

def create(parent):
    return Frame1(parent)

[wxID_FRAME1, wxID_FRAME1PANEL1, wxID_FRAME1PANEL2, wxID_FRAME1RADIOBUTTON2,
 wxID_FRAME1RADIOBUTTON3, wxID_FRAME1TEXTCTRL1,
] = [wx.NewId() for _init_ctrls in range(6)]

class Frame1(wx.Frame):
    def _init_ctrls(self, prnt):
        # generated method, don't edit
        wx.Frame.__init__(self, id=wxID_FRAME1, name='', parent=prnt,
              pos=wx.Point(359, 285), size=wx.Size(226, 133),
              style=wx.DEFAULT_FRAME_STYLE, title='Frame1')
        self.SetClientSize(wx.Size(218, 99))

        self.panel1 = wx.Panel(id=wxID_FRAME1PANEL1, name='panel1', parent=self,
              pos=wx.Point(0, 0), size=wx.Size(218, 99),
              style=wx.TAB_TRAVERSAL)
        self.panel1.SetBackgroundColour(wx.Colour(47, 66, 240))

        self.panel2 = wx.Panel(id=wxID_FRAME1PANEL2, name='panel2',
              parent=self.panel1, pos=wx.Point(0, 0), size=wx.Size(218, 99),
              style=wx.TAB_TRAVERSAL)
        self.panel2.SetBackgroundColour(wx.Colour(214, 222, 239))

        self.radioButton2 = wx.RadioButton(id=wxID_FRAME1RADIOBUTTON2,
              label=u'click for time in black', name='radioButton2',
              parent=self.panel2, pos=wx.Point(8, 8), size=wx.Size(192, 13),
              style=0)
        self.radioButton2.Bind(wx.EVT_LEFT_DOWN, self.OnRadioButton2LeftDown)

        self.radioButton3 = wx.RadioButton(id=wxID_FRAME1RADIOBUTTON3,
              label=u'click for time in blue', name='radioButton3',
              parent=self.panel2, pos=wx.Point(8, 32), size=wx.Size(152, 13),
              style=0)
        self.radioButton3.Bind(wx.EVT_LEFT_DOWN, self.OnRadioButton3LeftDown)

        self.textCtrl1 = wx.TextCtrl(id=wxID_FRAME1TEXTCTRL1, name='textCtrl1',
              parent=self.panel2, pos=wx.Point(8, 56), size=wx.Size(200, 32),
              style=0, value='textCtrl1')

    def __init__(self, parent):
        self._init_ctrls(parent)

    def OnRadioButton2LeftDown(self, event):
        now = str(datetime.datetime.now())
        self.textCtrl1.SetValue(now)
        self.textCtrl1.SetForegroundColour('Black')
        event.Skip()

    def OnRadioButton3LeftDown(self, event):
        now = str(datetime.datetime.now())
        self.textCtrl1.SetValue(now)
        self.textCtrl1.SetForegroundColour('Blue')
        event.Skip()


if __name__ == '__main__':
    app = wx.PySimpleApp()
    frame = create(None)
    frame.Show()

    app.MainLoop()
_______________________________________________
wxpython-users mailing list
wxpython-users@[...].org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users
Thread:
Stef Mientki
C M
Stef Mientki
C M

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved