focus issues?

I'm building a frame with some panels in it, and getting some weird
issues. There's too much code to post, but I wonder if anyone can
suggest where to start looking for this problem :

If I create multiple panels in a frame, some of the input widgets
don't respond to mouse clicks, although this behaviour is inconsistant
(at least, as far as I can tell).

Is there a simple guide to putting multiple panels in a frame (in this
case, AUI).

The frame code is here, is there some magic I need to use to get each
panel to see input or is this too vague?

class stSessionChooserFrame(wx.Frame):
    def __init__(self, *args, **kwds):
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Frame.__init__(self, *args, **kwds)

        self.mgr = wx.aui.AuiManager()
        self.mgr.SetManagedWindow(self)

        leftpanel = wx.Panel(self, -1, size = (200, 150))
        rightpanel = wx.Panel(self, -1, size = (200, 150))
        bottompanel = wx.Panel(self, -1, size = (200, 150))

        SessionChooserPanel = stSCP.stSessionChooserPanel(self)

        SessionCreatorPanel = stSCRP.stTrainingSession(self)
        SessionCreatorPanel.new()

        effortPanel = stEP.stEffortPanel(self)
        session = stDC.TrainingSessions.FromId(thisSessionId)
        rider = stDC.Riders.FromId(defaultRiderId)
        effortPanel.new(session, rider, live)

        self.mgr.AddPane(effortPanel, wx.aui.AuiPaneInfo().Bottom())
        self.mgr.AddPane(SessionChooserPanel,
wx.aui.AuiPaneInfo().Left().Layer(1))
        self.mgr.AddPane(SessionCreatorPanel,
wx.aui.AuiPaneInfo().Center().Layer(2))

        self.mgr.Update()

        # setting up the menus
        fileMenu = wx.Menu()
        helpMenu = wx.Menu()

        # wx.ID_ABOUT and wx.ID_EXIT are standard ID's provided by
wxWidgets
        menuAbout = fileMenu.Append(wx.ID_ABOUT,
"&About",defs.version)
        fileMenu.AppendSeparator()
        menuExit = fileMenu.Append(wx.ID_EXIT,"&Exit", "exterminate")

        # create the menubar
        menuBar = wx.MenuBar()
        menuBar.Append(fileMenu, "&File")
        menuBar.Append(helpMenu, "&Help")
        self.SetMenuBar(menuBar)
        #menuBar.Show()

        self.statusbar = self.CreateStatusBar(2, wx.ST_SIZEGRIP)
        self.statusbar.SetStatusWidths([-2, -1])
        # statusbar fields
        statusbar_fields = [(defs.about),
                            (defs.FullVersion)]
        for i in range(len(statusbar_fields)):
            self.statusbar.SetStatusText(statusbar_fields[i], i)

class MyApp(wx.App):
    def OnInit(self):
        wx.InitAllImageHandlers()
        # pos=(0, 0), size=wx.DisplaySize()
        sessionChooserFrame = stSessionChooserFrame(None, -1, "",
size=(900,600))
        #effort = stEffortFrame(None, -1, "", pos=(0, 0),
size=wx.DisplaySize())
        self.SetTopWindow(sessionChooserFrame)
        sessionChooserFrame.Show()
        return 1

# end of class MyApp

if __name__ == "__main__":
    import gettext
    gettext.install("EffortAdd") # replace with the appropriate
catalog name

    EffortAdd = MyApp(0)
    EffortAdd.MainLoop()

Mea Culpa :
Python 2.6 on win32 (XP) with wxPython 2.8.11.0

Hi,

I'm building a frame with some panels in it, and getting some weird
issues. There's too much code to post, but I wonder if anyone can
suggest where to start looking for this problem :

If I create multiple panels in a frame, some of the input widgets
don't respond to mouse clicks, although this behaviour is inconsistant
(at least, as far as I can tell).

With out a minimal example to reproduce it all I have is a guess. But
I am guessing that these widgets are in a StaticBox and that you
created the widgets after the StaticBox. The StaticBox widget must be
created before its siblings. Another possibility is that you have the
controls parented incorrectly. Such as having the widget that is
contained by the panel being a child of the Frame instead of the
panel.

Cody

···

On Wed, Sep 8, 2010 at 8:45 PM, Bleve <carl.i.brewer@gmail.com> wrote:

One of the widget set panels is a treectrl, and it doesn't behave at
all when placed in the above panel set :

import wx
import wx.calendar
import stDataClasses
import wx.lib.masked as masked
import sprintfunctions
import time
import datetime
import defs
from datetime import date

# defaults :
session = {
'temperature' : 18,
'pressure' : 1024,
'wind_speed' : 0,
'track_dry' : 1,
'humidity' : 60,
'session_duration' : 180
}

class stSessionChooserPanel(wx.Panel):

    def __init__(self, *args, **kwds):
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Panel.__init__(self, *args, **kwds)

        self.SessionChooserPanelBanner = "%s" %
(defs.SessionChooserPanelText)
        self.sessionLabel = wx.StaticText(self, -1, _("Session"),
style=wx.ALIGN_CENTRE)
        #self.sessionChooser = wx.Choice(self, -1, choices=)
        sessions = stDataClasses.TrainingSessions.All()
        sessionCounter = 0
        for session in sessions :
            print "session chooser :", session.date,
session.startTime, session.id
            sessionString = "%s : %s" % (session.date.date(),
session.startTime)
            #self.sessionChooser.Append(sessionString, session.id)
            print session.date.year, session.date.month,
session.date.day
            sessionCounter = sessionCounter + 1
        #self.sessionChooser.SetSelection(sessionCounter - 1)

        # we want to group sessions by year, then month, then date,
then time

        self.tree = wx.TreeCtrl(self)
        self.root = self.tree.AddRoot("Session Tree")
        treeHash = {}
        yearHash = {}
        monthHash = {}
        dayHash = {}
        timeHash = {}
        treeArray =
        for session in sessions :
            year = session.date.year
            month = session.date.month
            day = session.date.day
            time = session.startTime
            id = session.id
            # if the year exists, add the month

            #print year, month, day, time, id
            timeHash[time] = id
            dayHash[day] = timeHash
            monthHash[month] = dayHash
            yearHash[year] = monthHash

        for year in yearHash :
            # add the year tree element
            yearElement = self.tree.AppendItem(self.root, str(year),
0)
            for month in yearHash[year]:
                # add the month tree element to the year above
                monthElement = self.tree.AppendItem(yearElement,
str(month), 0)
                for day in yearHash[year][month]:
                    # add the day tree element to the month
                    dayElement = self.tree.AppendItem(monthElement,
str(day), 0)
                    for time in yearHash[year][month][day]:
                        timeElement = self.tree.AppendItem(dayElement,
str(time), 0)
                        # add the time element to the month, and set
its value to the session Id
                        print year, month, day, time, " :",
yearHash[year][month][day][time]

        self.tree.Expand(self.root)

        #self.OK = wx.Button(self, wx.ID_OK, "Create")
        #self.CANCEL = wx.Button(self, wx.ID_CANCEL, "Cancel!")

        #self.__set_properties()
        self.__do_layout()
        # end wxGlade

        # what do we do with input?
        #self.Bind(wx.EVT_BUTTON, self.OnOK, self.OK)
        #self.Bind(wx.EVT_BUTTON, self.OnCancel, self.CANCEL)

    def __do_layout(self):
        # begin wxGlade: stAddSession.__do_layout

        PanelTextFont = wx.Font(12, wx.NORMAL, wx.ITALIC, wx.BOLD)
        #panelBox = wx.StaticBox(self, -1, defs.effortPanelText)
        panelBox = wx.StaticBox(self, -1,
self.SessionChooserPanelBanner)
        # self.effortPanelBanner
        panelBox.SetFont(PanelTextFont)
        sizer_1 = wx.StaticBoxSizer(panelBox, wx.VERTICAL)

        sizer_1.Add(self.sessionLabel, 0,0,0)
        #sizer_1.Add(self.sessionChooser, 0,0,0)

        sizer_1.Add(self.tree, 0,0,0)
        #sizer_1 = wx.BoxSizer(wx.VERTICAL)
        #sizer_1.Add(self.something, 0, 0, 0)

        self.SetSizer(sizer_1)
        sizer_1.Fit(self)
        self.Layout()
        # end wxGlade

    def OnOK(self, e):
        """inserts into the database to create a new session record"""

    def OnCancel(self, e):
        """Cancel out of create sessions ..."""
        # print "clicked Cancel!"
        self.Close()

Would the staticbox() being in the layout be the problem? Or have I
mucked up the scope of the thing?

···

On Sep 9, 11:54 am, Cody Precord <codyprec...@gmail.com> wrote:

Hi,

With out a minimal example to reproduce it all I have is a guess. But
I am guessing that these widgets are in a StaticBox and that you
created the widgets after the StaticBox. The StaticBox widget must be
created before its siblings. Another possibility is that you have the
controls parented incorrectly. Such as having the widget that is
contained by the panel being a child of the Frame instead of the
panel.

Hi,

With out a minimal example to reproduce it all I have is a guess. But
I am guessing that these widgets are in a StaticBox and that you
created the widgets after the StaticBox. The StaticBox widget must be
created before its siblings. Another possibility is that you have the
controls parented incorrectly. Such as having the widget that is
contained by the panel being a child of the Frame instead of the
panel.

One of the widget set panels is a treectrl, and it doesn't behave at
all when placed in the above panel set :

<snip>
When you have this much code send it as an attachment instead of
in-lining it in the email. (see the info at the top of the
googlegroups page)
</snip>

Would the staticbox() being in the layout be the problem? Or have I
mucked up the scope of the thing?

Did you read my first reply ;)? You need to create the
StaticBox/StaticBoxSizer before any of the windows that will be put in
it. You have created your tree control and other items before the
StaticBox so that is why you have this problem.

Cody

···

On Wed, Sep 8, 2010 at 10:13 PM, Bleve <carl.i.brewer@gmail.com> wrote:

On Sep 9, 11:54 am, Cody Precord <codyprec...@gmail.com> wrote:

<snip>
When you have this much code send it as an attachment instead of
in-lining it in the email. (see the info at the top of the
googlegroups page)
</snip>

Will do, thank you.

> Would the staticbox() being in the layout be the problem? Or have I
> mucked up the scope of the thing?

Did you read my first reply ;)? You need to create the
StaticBox/StaticBoxSizer before any of the windows that will be put in
it. You have created your tree control and other items before the
StaticBox so that is why you have this problem.

I did, but I confess to not really understanding the order in which
python does things. Should I create the staticbox in the main panel
method instead of in the layout?

···

On Sep 9, 1:18 pm, Cody Precord <codyprec...@gmail.com> wrote:

Hi,

> Would the staticbox() being in the layout be the problem? Or have I
> mucked up the scope of the thing?

Did you read my first reply ;)? You need to create the
StaticBox/StaticBoxSizer before any of the windows that will be put in
it. You have created your tree control and other items before the
StaticBox so that is why you have this problem.

I did, but I confess to not really understanding the order in which
python does things. Should I create the staticbox in the main panel
method instead of in the layout?

The StaticBox is a special case it needs to be created before the
widgets that will go into it or they will not get mouse events ect...

In your sample code your doing the following (rough) flow

1) Panel __init__
2) create TreeCtrl()
3) _doLayout
4) create StaticBox()
5) Put TreeCtrl in StaticBox

You see that #4 is where you create the StaticBox and that it comes
after #2 where you create the TreeCtrl that you later add to the
StaticBox. You need to create the StaticBox before any of the controls
that go in it.

So,

1) Panel __init__
2) create StaticBox()
3) create TreeCrl
...

Cody

···

On Wed, Sep 8, 2010 at 10:25 PM, Bleve <carl.i.brewer@gmail.com> wrote:

Ok, I can't see how to attach to this with the google groups
interface, so I'll just add a few snippets now I've changed this a bit
(it still won't let me expand or contract the treectrl). I renamed
sizer_1 to be SCsizer just in case I had some scope issues, but I
doubt that's a problem) :

class stSessionChooserPanel(wx.Panel):

    def __init__(self, *args, **kwds):
        kwds["style"] = wx.DEFAULT_FRAME_STYLE
        wx.Panel.__init__(self, *args, **kwds)

        self.SessionChooserPanelBanner = "%s" %
(defs.SessionChooserPanelText)
        PanelTextFont = wx.Font(12, wx.NORMAL, wx.ITALIC, wx.BOLD)
        self.panelBox = wx.StaticBox(self, -1,
self.SessionChooserPanelBanner)
        self.SCsizer = wx.StaticBoxSizer(self.panelBox, wx.VERTICAL)

.
.
.

    def __do_layout(self):
        # begin wxGlade: stAddSession.__do_layout

        PanelTextFont = wx.Font(12, wx.NORMAL, wx.ITALIC, wx.BOLD)
        #panelBox = wx.StaticBox(self, -1, defs.effortPanelText)
        #panelBox = wx.StaticBox(self, -1,
self.SessionChooserPanelBanner)
        # self.effortPanelBanner
        self.panelBox.SetFont(PanelTextFont)
        #sizer_1 = wx.StaticBoxSizer(self.panelBox, wx.VERTICAL)

        self.SCsizer.Add(self.sessionLabel, 0,0,0)
        #sizer_1.Add(self.sessionChooser, 0,0,0)

        self.SCsizer.Add(self.tree, 0,0,0)
        #sizer_1 = wx.BoxSizer(wx.VERTICAL)
        #sizer_1.Add(self.something, 0, 0, 0)

        self.SetSizer(self.SCsizer)
        self.SCsizer.Fit(self)
        self.Layout()
        # end wxGlade

So I *think* I've defined the StaticBox before the treectrl, but it's
still not seeing mouse events, or at least, isn't responding to them
in any way that I would expect. But .. I may be an idiot, and
treectrl may need me to bind something to do expansion and
contraction?

···

On Sep 9, 1:32 pm, Cody Precord <codyprec...@gmail.com> wrote:

The StaticBox is a special case it needs to be created before the
widgets that will go into it or they will not get mouse events ect...

In your sample code your doing the following (rough) flow

1) Panel __init__
2) create TreeCtrl()
3) _doLayout
4) create StaticBox()
5) Put TreeCtrl in StaticBox

You see that #4 is where you create the StaticBox and that it comes
after #2 where you create the TreeCtrl that you later add to the
StaticBox. You need to create the StaticBox before any of the controls
that go in it.

So,

1) Panel __init__
2) create StaticBox()
3) create TreeCrl
...

Hi,

The StaticBox is a special case it needs to be created before the
widgets that will go into it or they will not get mouse events ect...

In your sample code your doing the following (rough) flow

1) Panel __init__
2) create TreeCtrl()
3) _doLayout
4) create StaticBox()
5) Put TreeCtrl in StaticBox

You see that #4 is where you create the StaticBox and that it comes
after #2 where you create the TreeCtrl that you later add to the
StaticBox. You need to create the StaticBox before any of the controls
that go in it.

So,

1) Panel __init__
2) create StaticBox()
3) create TreeCrl
...

Ok, I can't see how to attach to this with the google groups
interface, so I'll just add a few snippets now I've changed this a bit
(it still won't let me expand or contract the treectrl). I renamed
sizer_1 to be SCsizer just in case I had some scope issues, but I
doubt that's a problem) :

Please carefully read the information at the top of the google group
page, there is some text in bold about how to send attachments. This
is an email group you don't have to use the googlegroups web
interface.

So I *think* I've defined the StaticBox before the treectrl, but it's
still not seeing mouse events, or at least, isn't responding to them
in any way that I would expect. But .. I may be an idiot, and
treectrl may need me to bind something to do expansion and
contraction?

Please make a minimal running sample file that exhibits the problem.
(MakingSampleApps - wxPyWiki)

Cody

···

On Wed, Sep 8, 2010 at 10:48 PM, Bleve <carl.i.brewer@gmail.com> wrote:

On Sep 9, 1:32 pm, Cody Precord <codyprec...@gmail.com> wrote: