[wxPython] Radio button in button form?

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] Radio button in button form?

Gordon Williams
Hello All,


I am looking for a basic radio button widget in wxPython which looks like a
sunken button when active rather than having an circle with black dot. (as
is available in Tkinter)

I have seen the wxRadioBox and wxRadioButton but I could not find the style
to change to make these buttons rather than circles.

While I am asking, I am also looking for the same thing but in a check
button pattern where multiple buttons can have the sunken appearance.

Thanks,

Gordon Williams


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Radio button in button form?

Robin Dunn
>
> I am looking for a basic radio button widget in wxPython which looks like a
> sunken button when active rather than having an circle with black dot. (as
> is available in Tkinter)
>
> I have seen the wxRadioBox and wxRadioButton but I could not find the style
> to change to make these buttons rather than circles.
>

These are not standard controls provided by the platforms, so it hasn't been
provided for in wxWindows.  It would be easy to create your own though.
Simply derive a class from wxControl and teach it to draw itself the way you
want.


--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Radio button in button form?

Gordon Williams
In reply to this post by Gordon Williams
I have had a look through all the wxPython code that I have and could not
find an example where a class was derived from wxControl.  I dont see how
radio buttons may be made using this approach.

What I am looking for is the equivalent to a Tkinter Radiobutton Widget
where a bunch of raised buttons are put into a frame and the active one is
sunken and has a lighter background colour.  I would have thought that this
would have been a standard widget. Ugh!

I thought that I may have been able to make this style of radio and check
buttons from a wxButton, but I dont see any method to programmatically hold
the button so it appears in the down position.  There doesnt appear to be
any way to change the style of the button.

Anyone have any ideas or better a small example?

Thanks

Regards,

Gordon Williams



----------
> From: Robin Dunn <[hidden email]>
> To: [hidden email]; [hidden email]
> Subject: Re: [wxPython] Radio button in button form?
> Date: November 30, 1999 8:51 PM
>
> >
> > I am looking for a basic radio button widget in wxPython which looks
like a
> > sunken button when active rather than having an circle with black dot.
(as
> > is available in Tkinter)
> >
> > I have seen the wxRadioBox and wxRadioButton but I could not find the
style
> > to change to make these buttons rather than circles.
> >
>
> These are not standard controls provided by the platforms, so it hasn't
been
> provided for in wxWindows.  It would be easy to create your own though.
> Simply derive a class from wxControl and teach it to draw itself the way
you

> want.
>
>
> --
> Robin Dunn
> Software Craftsman
> [hidden email]
> http://AllDunn.com/robin/
> http://AllDunn.com/wxPython/  Check it out!
>


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Radio button in button form?

Robin Dunn
> I thought that I may have been able to make this style of radio and check
> buttons from a wxButton, but I dont see any method to programmatically hold
> the button so it appears in the down position.  There doesnt appear to be
> any way to change the style of the button.
>

Try this:

Derive a class from wxButton and catch the mouse down and up events.  When
the button is in the up state, allow the mouse down event to be processed by
the default handler by calling event.Skip and "eat" the mouse up event by not
calling event.Skip.  When the button is in the down state do the opposite.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

[wxPython] Any progress on pyDE

Hannu Krosing-2
Robin Dunn wrote:
>
> The good news is that Dirk had already offered in his private email to me to
> allow the license to change.  I've been working on something similar and so
> now we're discussing how they might merge...
>
So, has there been any progress, either code- or licence-wize ?

-------------------
Hannu

_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Any progress on pyDE

Robin Dunn
> Robin Dunn wrote:
> >
> > The good news is that Dirk had already offered in his private email to me
to
> > allow the license to change.  I've been working on something similar and
so
> > now we're discussing how they might merge...
> >
> So, has there been any progress, either code- or licence-wize ?
>

I have the latest version of the code and intend to merge parts of it with
some things I am working on.  If that's not ready by the time of the next
release then I'll be putting at least the editor classes (and possibly
others) into the wxPython.lib package.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Radio button in button form?

Gordon Williams
In reply to this post by Gordon Williams
Hello Robin,

I have done what you have suggested using the "skip" and "eat".  It "kind
of" works but it is doing some strange things.

1) The button only looks depressed when the curser is over it.  As soon as
the curser is moved away it bounces up.

2) After a click "on" any other click in another part of the window or
another button causes the button to return to the "off" setting.  The click
is sent to the wrong place.

Any more ideas?  The code is attached below.

Regards,

Gordon Williams
 

----------
> From: Robin Dunn <[hidden email]>
> To: [hidden email]; [hidden email]
> Subject: Re: [wxPython] Radio button in button form?
> Date: December 1, 1999 12:35 PM
>
> > I thought that I may have been able to make this style of radio and
check
> > buttons from a wxButton, but I dont see any method to programmatically
hold
> > the button so it appears in the down position.  There doesnt appear to
be
> > any way to change the style of the button.
> >
>
> Try this:
>
> Derive a class from wxButton and catch the mouse down and up events.
When
> the button is in the up state, allow the mouse down event to be processed
by
> the default handler by calling event.Skip and "eat" the mouse up event by
not
> calling event.Skip.  When the button is in the down state do the
opposite.
>
> --
> Robin Dunn
> Software Craftsman
> [hidden email]
> http://AllDunn.com/robin/
> http://AllDunn.com/wxPython/  Check it out!
>
'''
Derive a class from wxButton and catch the mouse down and up events.  When
the button is in the up state, allow the mouse down event to be processed
by
the default handler by calling event.Skip and "eat" the mouse up event by
not
calling event.Skip.  When the button is in the down state do the opposite.
'''

from wxPython.wx import *

#----------------------------------------------------------------------
class MyRadioButton(wxButton):
    def __init__(self, parent, title, point, tag=""):
        mybutid= wxNewId()
        wxButton.__init__(self, parent, mybutid, title, point, name=tag)
               
        EVT_LEFT_DOWN(self, self.onDown)
        EVT_LEFT_UP(self, self.onUp)
        self.SetBackgroundColour(wxNamedColour("MEDIUM ORCHID"))
        self.SetBackgroundColour(wxBLUE)  # does not work
        self.Refresh(eraseBackground=TRUE)
        self.var= FALSE  #off
       
    def onDown(self, event):
        print "Down Event"
        if self.var:
            self.var= FALSE
            print "skip"
            print self.var
        else:
            event.Skip(TRUE)
            self.var= TRUE    #on
            print "skip"
            print self.var
       
       
    def onUp(self, event):
        print "Up event"
        if not self.var:
            event.Skip(TRUE)
            print "skip"
        print self.var      

class TestPanel(wxPanel):
    def __init__(self, parent):
        wxPanel.__init__(self, parent, -1)
        but_Hello1_ID= wxNewId()
        but_Hello2_ID= wxNewId()
       
        MyRadioButton(self, "Radio1", wxPoint(20,150), tag="mytag")
       
        wxButton(self, but_Hello1_ID, "Hello Normal", wxPoint(20, 20))

        EVT_BUTTON(self, but_Hello1_ID, self.OnClick)

       

    def OnClick(self, event):
        print "Click! (%d)\n" % event.GetId()





if __name__ == '__main__':

    class MainFrame(wxFrame):
        def __init__(self):
            wxFrame.__init__(self, NULL, -1, "Testing...")

            self.CreateStatusBar()
            mainmenu = wxMenuBar()
            menu = wxMenu()
            menu.Append(200, 'E&xit', 'Get the heck outta here!')
            mainmenu.Append(menu, "&File")
            self.SetMenuBar(mainmenu)
            EVT_MENU(self, 200, self.OnExit)
           
            self.panel = TestPanel(self)
            self.SetSize(wxSize(400, 500))

        def OnCloseWindow(self, event):
            self.Destroy()

        def OnExit(self, event):
            self.Close(true)


    class TestApp(wxApp):
       
        def OnInit(self):
            frame = MainFrame()
            frame.Show(true)
            self.SetTopWindow(frame)
            return true
   

    app = TestApp(0)
    app.MainLoop()
 


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Radio button in button form?

Robin Dunn
> I have done what you have suggested using the "skip" and "eat".  It "kind
> of" works but it is doing some strange things.
>

Well, given that it is a fairly nasty hack I'm not surprised.  <grin>


> 1) The button only looks depressed when the curser is over it.  As soon as
> the curser is moved away it bounces up.

This is the normal behaviour of the MSW button control.  If you hold the
button down (which you are in effect doing by skipping the default up
handler) and then move outside the button it releases the button.  The native
control is probably tracking mouse motion events in order to do this.  You
might try eating those too.

>
> 2) After a click "on" any other click in another part of the window or
> another button causes the button to return to the "off" setting.  The click
> is sent to the wrong place.
>

The native control probably has captured the mouse.  You can try doing a
self.ReleaseMouse() in your down handler.  This might solve the above issue
as well.


--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Radio button in button form?

Gordon Williams
In reply to this post by Gordon Williams
Hello Robin,

I have tried the self.ReleaseMouse()  in the handler and no change.  The
enter and leaving handlers dont work.  I get motion events when outside the
button after depressing it so I guess it still thinks that the mouse is
still inside the button.

There are other commands related to handling events.  Any ideas how these
could be used?

Regards,

Gordon Williams

----------
> From: Robin Dunn <[hidden email]>
> To: [hidden email]; [hidden email]
> Subject: Re: [wxPython] Radio button in button form?
> Date: December 6, 1999 2:51 PM
>
> > I have done what you have suggested using the "skip" and "eat".  It
"kind
> > of" works but it is doing some strange things.
> >
>
> Well, given that it is a fairly nasty hack I'm not surprised.  <grin>
>
>
> > 1) The button only looks depressed when the curser is over it.  As soon
as
> > the curser is moved away it bounces up.
>
> This is the normal behaviour of the MSW button control.  If you hold the
> button down (which you are in effect doing by skipping the default up
> handler) and then move outside the button it releases the button.  The
native
> control is probably tracking mouse motion events in order to do this.
You
> might try eating those too.
>
> >
> > 2) After a click "on" any other click in another part of the window or
> > another button causes the button to return to the "off" setting.  The
click
> > is sent to the wrong place.
> >
>
> The native control probably has captured the mouse.  You can try doing a
> self.ReleaseMouse() in your down handler.  This might solve the above
issue

> as well.
>
>
> --
> Robin Dunn
> Software Craftsman
> [hidden email]
> http://AllDunn.com/robin/
> http://AllDunn.com/wxPython/  Check it out!
>


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users