[wxPython] wxScrolledWindow scrolling with keys

How do I make e wxScrolledWindow scrollable with the up and down cursor and PageUp/PageDown? I have one with a few buttons and text fields in it but it doesn't respond when i press the keys :frowning:

thanks

···

--
__________________________________________________________
Sign-up for your own FREE Personalized E-mail at Mail.com
http://www.mail.com/?sr=signup

Get 4 DVDs for $.49 cents! plus shipping & processing. Click to join.
http://oas-central.realmedia.com/RealMedia/ads/click_lx.ads/mail.com/columbiahouse/1112745096/x09/ExactAdv/ColumbiaHouse_IO473_7.19_8.19/blank.gif/636632633232383133383736634333430

How do I make e wxScrolledWindow scrollable with the up and down
cursor and PageUp/PageDown? I have one with a few buttons and
text fields in it but it doesn't respond when i press the keys :frowning:

The wxSCrolledWindow already has support for doing scrolling with the
various keys, but since your window has child controls the focus will be on
one of them. I don't think explicitly setting the focus to the
wxScrolledWindow will work as it will try to find a child that accepts focus
and pass it on the the child, just like wxPanel does.

What you can probably do to make it work is to catch the EVT_KEY_DOWN event
in the child controls and if the key is up/down or pgup/pgdn then pass the
event on to the scrolled window. Something like this may work:

    def PassKey(self, evt):
        key = evt.GetKeyCode()
        if key in [WXK_UP, WXK_DOWN, (etc...)]:
            theScrolledWin.GetEventHandler().ProcessEvent(evt)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi,

Anybody know how to make a simple panel or border with the sunken line and a label, like the radio box examples in the demo?

I can't find anything that looks like it'd do this except the radio box itself. (I wonder if I could use a radio box as a generic container...)

Robb

The control is called a wxStaticBox, sample of use below. BTW, not sure if I wrote this code or not, doesn't look like my style, but could just be that I wrote it a long time ago.

Anyway, pay special attention to the wxStaticBoxSizer, which is what has to be used to properly size the internal controls.

HTH,
Mike

from wxPython.wx import *
DT_HEADERS = ['Code','Name','Value']

class MainPanel(wxPanel):
     def __init__(self,parent):
         wxPanel.__init__(self,parent,-1)

         #box = wxBoxSizer(wxVERTICAL)
         group =wxStaticBox(self,-1,"Details")
         box = wxStaticBoxSizer(group,wxVERTICAL)
         self.list = wxListCtrl(group,100,size=(300,200),
             style=wxLC_REPORT|wxLC_SINGLE_SEL|wxSUNKEN_BORDER)
         for i in range(len(DT_HEADERS)):
             self.list.InsertColumn(i,DT_HEADERS[i])
         box.Add(self.list,1,wxEXPAND|wxALL,4)

         self.SetAutoLayout(true)
         self.SetSizer(box)
         box.Fit(self)
         box.SetSizeHints(self)

     #def OnPaint(self,event):
     # dc = wxPaintDC(self)
     # self.Refresh()
     # event.Skip()

class MainFrame(wxFrame):
     def __init__(self, parent,title):
         wxFrame.__init__(self, parent,-1,title)
         self.CreateStatusBar()

         box = wxBoxSizer(wxVERTICAL)
         self.mp = MainPanel(self)
         box.Add(self.mp,1,wxEXPAND)

         self.SetAutoLayout(true)
         self.SetSizer(box)
         box.Fit(self)
         box.SetSizeHints(self)

         self.Center(wxBOTH)

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

class MainApp(wxApp):
     def OnInit(self):
         frame = MainFrame(NULL,"Wx-Template")
         frame.Show(true)
         self.SetTopWindow(frame)
         return true

def main():
     app = MainApp(0)
     app.MainLoop()

if __name__ == '__main__':
     main()

Robb Shecter wrote:

···

Hi,

Anybody know how to make a simple panel or border with the sunken line and a label, like the radio box examples in the demo?

I can't find anything that looks like it'd do this except the radio box itself. (I wonder if I could use a radio box as a generic container...)

Robb

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users

--
_______________________________________
   Mike C. Fletcher
   Why, yes, I am looking for a job...
   http://members.rogers.com/mcfletch/

Anybody know how to make a simple panel or border with the sunken line
and a label, like the radio box examples in the demo?

wxStaticBox. There is also wxStaticBoxSizer, that willhelp to resize the
box around the items within it.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Hi,

I'm writing a subclass of wxPanel and I want to add custom behavior when a component instantiates itself, setting an instance of my subclass as its Parent. For example, when this happens:

aPanel = NewPanel(...)
aButton = wxButton(aPanel, ...)

...I want to be able to add behavior. I thought that by overriding AddChild I could do this:

class aPanel:
     def AddChild(aChild):
          wxPanel.AddChild(aChild)
          # my custom code goes here...

...but that doesn't work: AddChild is never called. Any ideas?

Thanks,
Robb

Hi,

Thanks to everyone for the help with Static Boxes. In order to use them easier, I wrote NamedPanel, a wxPanel subclass that factors out the complexity. I've put the source code to it in a new cookbook entry:

http://wiki.wxpython.org/index.cgi/WorkingWithStaticBoxes

Robb

..I want to be able to add behavior. I thought that by overriding
AddChild I could do this:

class aPanel:
     def AddChild(aChild):
          wxPanel.AddChild(aChild)
          # my custom code goes here...

...but that doesn't work: AddChild is never called. Any ideas?

You can look in the mail archives for the reasons why AddChild (and most
other virtual methods) can not be overridden in Python-derived classes.

However for some specific cases that is changing in 2.3.3 as there are
wxPyWindow, wxPyControl, and wxPyPanel classes that do have the custom code
needed to do callbacks to specific virtual methods in C++. AddChild isn't
one of them but it can be.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

You can look in the mail archives for the reasons why AddChild (and
most

other virtual methods) can not be overridden in Python-derived classes.

Thanks Robin, I’ll check it out. I had wanted to use this for a semi-hackish
class (this NamedPanel that I put in the wxPython cookbook). Basically,
I was looking for a way to get the panel to lay itself out after a child
had been added by:

  namedPanel = NamedPanel(frame, 'My name goes here')

aButton = wxButton(namedPanel, -1, ‘aButton’)

...without having to call an additional method.  Not too big of a deal.

Robb

I'm trying to display and edit floats in a table, and I find that tehey are rendered correctly, but in certain cases, the editor rounds the number up before displaying it. It always seems to happen if the number has the same number of decimal points as specified in the type name.

For example, I'm trying to edit currency values:

wxGRID_VALUE_FLOAT + ':6,2'

If the value is 4.56, it'll get rounded up. if it's 4.5, it won't. Is this a bug? Anyone know how to turn this off? Thanks,
Robb

I'm trying to display and edit floats in a table, and I find that tehey
are rendered correctly, but in certain cases, the editor rounds the
number up before displaying it. It always seems to happen if the number
has the same number of decimal points as specified in the type name.

For example, I'm trying to edit currency values:

wxGRID_VALUE_FLOAT + ':6,2'

If the value is 4.56, it'll get rounded up. if it's 4.5, it won't. Is
this a bug?

Yes. Please enter a bug report at SF.

Anyone know how to turn this off?

For now you'll probably have to create your own cell editor to get around
this.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robb Shecter wrote:

Fixes: 1. Added a check to HasCapture() in the two OnLeftUp() methods.
2. Added a check to HasCapture() in OnMotion()
2. Added a ToggleMixin.OnMotion implementation that toggles the buttons depending on the mouse location.

Thanks!

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!