Classes and events

Greetings,
I created a Frame that calls several classes (panels) from other py files. I got that part working fine (finally, with Robins help). But when I tried to bind the controls to the Frame, I just got allot of attribute errors.

What I am I trying to figure out are there any methods to bind a button (from a different file)to the parent frame.

OR

Should I bind the buttons to their respective panels?

What I am trying to do is create an application that will use 6 or 7 panels, all form different panels that will communicate between themselves and ultimately a database (I got the database part working).

Any suggestions?

Scott

···

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.8.4 - Release Date: 3/27/2005

scott wrote:

Greetings,
I created a Frame that calls several classes (panels) from other py files. I got that part working fine (finally, with Robins help). But when I tried to bind the controls to the Frame, I just got allot of attribute errors.

What I am I trying to figure out are there any methods to bind a button (from a different file)to the parent frame.

OR

Should I bind the buttons to their respective panels?

What I am trying to do is create an application that will use 6 or 7 panels, all form different panels that will communicate between themselves and ultimately a database (I got the database part working).

Any suggestions?

Scott

(Attaching the relavent code would help...)

It doesn't matter whether the class code is in another file or is in the main .py file itself. It sounds like you need to pass into the panel class definitions the frame object so that
when each panel is instantiated it's controls and their event handlers know the frame to bind to. I.e., events can only be bound to the parent frame, not any other kind of widget such as a panel.
The panels need to have the frame as their parent unless their is another widget inbetween.

Its all a hierarchical grouping of widgets in parent-child relationships. You might want to think of
the widgets being in a tree organization with the wx.Frame at the root. In this case:

                                    <-(using sizer)- wx.Window <-- Panel_1
              wx.Frame <-- wx.Panel <-(using sizer)- wx.Window <-- Panel_2
                                    <-(using sizer)- wx.Window <-- Panel_3
                                    <-- ...

You will also need a way to physically (graphically) organize the panels.
When the first panel is bound to a frame it will fill the frame completely.
The next panel will fill the frame but cover over any previous panels.
Whats need is "container" widgets, such as wx.Window or wx.Notebook, etc.
This will prevent all the panels from inadvertantly covering over each other.
The panels would then be separated from each other in a 2-D fashion.
The panels need something to fill and limit their size and also be positioned
relative to each other.

---------------------FRAME------------------------

                                               >
    panel_that_fills_the_frame |
                                               >
-----wx.Window------ -----wx.Window------ |
> > > > >
> panel 1 | | panel 2 | |
> > > > >
-------------------- -------------------- |
                                               >
------wx.Window----- -----wx.Window------ |
> > > > >
> panel 3 | | panel 4 | |
> > > > >
-------------------- -------------------- |
         ... |
                                               >
------------------------------------------------|

If all the panels are to be viewed at the same time then they will need to be
organized in a 2-D layout using sizers or coordinate placement specification.
Its not apparent to me what appearance you are trying to accomplish.

I hope this helps.

The panels need to have the frame as their parent unless their is

> another widget inbetween.
I thought that's what I did, but I still have something wrong.
Here are two files, the Frame (beta.mainframe.py) and the "Panel" (MySQLPanel.py) and a notebook just for fun.

I would like to use the model for coding as it makes it very easy to read and debug, my other app was 4000 lines of crap.

Thanks for helping,
Scott

···

----------------------------------------------
beta.mainframe.py

import wx
# gui py files
##from cardbuilder import *
##from gridbuilder import *
from sqlbuilder import * #MySQLPanel

#---------------------------------------------------------------------------

class MainFrame(wx.Frame):
     def __init__(self, parent, title):
         wx.Frame.__init__(self, parent, -1, title, size = (950, 720),
                           style=wx.DEFAULT_FRAME_STYLE
                         > wx.NO_FULL_REPAINT_ON_RESIZE)

         self.SetMinSize((640,480))
         self.Centre(wx.BOTH)

         # # #----------------------------
####GUI PANELS
         # # # ---------------------------
         # Add a sizer to the Frame, -> parent and 2 childre
         appSizer_1 = wx.FlexGridSizer(2, 1, 1, 1)
         # sql sizer
         topsizer = wx.BoxSizer(wx.VERTICAL)
         # notebook sizer
         botsizer = wx.BoxSizer(wx.VERTICAL)
         # Make the notebook & pages
         nb = wx.Notebook(self, -1, style=0)
         # add the py files classes as the Notebook Panels

         nb_pg1 = wx.Panel(nb) # Grid(nb)
         nb_pg2 = wx.Panel(nb) # Card(nb)
         nb_pg1.SetBackgroundColour(wx.RED)
         nb_pg2.SetBackgroundColour(wx.CYAN)

         # add pages to nb
         nb.AddPage(nb_pg1, "Database")
         nb.AddPage(nb_pg2, "Card Data")

         # add notebook
         botsizer.Add(nb, 1, wx.ALL|wx.EXPAND, 0)
         # add Top Box
         self.sqlPanel = MySQLPanel(self)
         topsizer.Add(self.sqlPanel, 0, wx.ALL|wx.EXPAND, 0)

         # add children sizers to the parent sizer
         appSizer_1.Add(topsizer, 0, wx.ALL|wx.EXPAND, 0)
         appSizer_1.Add(botsizer, 0, wx.ALL|wx.EXPAND, 0)

         # make it
         self.SetAutoLayout(True)
         self.SetSizer(appSizer_1)
         appSizer_1.AddGrowableRow(1)
         appSizer_1.AddGrowableCol(0)
         self.Layout()

#---Button events - Upper panel
         # These buttons are located on the upper panel
         # mySQLPanel

         #self.Bind(wx.EVT_BUTTON, self.onAddDispatchers, self.btnDisp) #
         #self.Bind(wx.EVT_BUTTON, self.onAddData, self.sql.btnAddData) #
         #self.Bind(wx.EVT_BUTTON, self.onRunSQL, self.sql.btnSQL) #

#---------------------------------------------------------
class MyApp(wx.App):
     def OnInit(self):
         frame = MainFrame(None, "Test")
         frame.Show(True)
         self.SetTopWindow(frame)
         return True

def main():
     app = MyApp(False)
     app.MainLoop()

if __name__ == '__main__':
     main()
#### END

-------------------------------------------------------------------------
MySQLPanel.py

import sys
import wx
# my Frame is for testing
class MyFrame(wx.Frame):
     def __init__(self, parent, ID, title):
         wx.Frame.__init__(self, parent, ID, title, size = (800, 600),
                                     style=wx.DEFAULT_FRAME_STYLE
                                     > wx.CLIP_CHILDREN
                                     > wx.NO_FULL_REPAINT_ON_RESIZE)

         # Parent Box
         mbox = wx.BoxSizer(wx.VERTICAL)

         # Add Panels...
         mbox.Add(MySQLPanel(self), 0, wx.ALL|wx.EXPAND, 0)

         self.SetAutoLayout(True)
         self.SetSizer(mbox)
         self.Layout()

# WORKING CODE !!!!!
class MySQLPanel(wx.Panel):
     """ A panel """
     def __init__(self, parent):
         wx.Panel.__init__(self, parent, -1,
                                     style=wx.SUNKEN_BORDER
                                     > wx.CLIP_CHILDREN
                                     > wx.NO_FULL_REPAINT_ON_RESIZE)

         scrPanel1 = wx.ScrolledWindow(self,-1, size=(-1,-1))#, style=wx.SUNKEN_BORDER|wx.FULL_REPAINT_ON_RESIZE)
         scrPanel1.SetScrollRate(10, 10)

         pbox = wx.BoxSizer(wx.VERTICAL)
         cbox = wx.BoxSizer(wx.VERTICAL)

         # Add subPanels Classes
         pnl1 = subPanel_SQL(scrPanel1)

         cbox.Add(pnl1, 0, wx.ALL|wx.EXPAND)

         scrPanel1.SetAutoLayout(True)
         scrPanel1.SetSizer(cbox)

         pbox.Add(scrPanel1, 0, wx.ALL|wx.EXPAND, 0)

         self.SetAutoLayout(True)
         self.SetSizer(pbox)
         self.Layout()

class subPanel_SQL(wx.Panel):
         def __init__(self, parent):
             wx.Panel.__init__(self, parent, -1,
                                     style=wx.CLIP_CHILDREN
                                     > wx.NO_FULL_REPAINT_ON_RESIZE)

             # Parent
             mainSizer = wx.BoxSizer(wx.HORIZONTAL)

             # Child
             pGridSizer = wx.GridBagSizer(3,3)
             cGridSizerAa = wx.FlexGridSizer(1, 7, 2, 2) # bottom buttons

             # Widgets
             self.labelSQL_1 = wx.StaticText(self, -1, "DataBase ::",
                                                 style=wx.ALIGN_RIGHT)
             self.labelSQL_2 = wx.StaticText(self, -1, "None selected.")
             self.labelSQL_3 = wx.StaticText(self, -1, "Size ::",
                                                 style=wx.ALIGN_RIGHT)
             self.labelSQL_4 = wx.StaticText(self, -1, "0.0 KB")
             self.labelSQL_5 = wx.StaticText(self, -1, "Enter SQL ::",
                                                 style=wx.ALIGN_RIGHT)
             self.tc_SQL = wx.TextCtrl(self, -1, "Enter SQL here",
                                                 style=wx.TE_MULTILINE)
             self.tc_Homy = wx.TextCtrl(self, -1, "20", (-1, -1),
                                                 style=wx.TE_PROCESS_ENTER
                                                 > wx.TE_CENTRE)

             self.btnSQL = wx.Button(self, -1, "Run Query")
             self.btnAddData = wx.Button(self, -1, "Add Calls")
             self.btnDisp = wx.Button(self, -1, "Add Dispatchers")
             self.btnSpare = wx.Button(self, -1, "something")
             self.btnSaveSQL = wx.Button(self, -1, "Save Query")
             #self.btnCommit = wx.Button(self.panel_1, -1, "Commit Changes?")

             # Layout
             cGridSizerAa.AddMany([
                                 (self.btnSQL, 0, wx.ALL | wx.ALIGN_CENTRE, 0),
                                 (self.btnAddData, 0, wx.ALL | wx.ALIGN_CENTRE, 0),
                                 (self.tc_Homy, 0, wx.ALL | wx.ALIGN_CENTRE, 0),
                                 (self.btnDisp, 0, wx.ALL | wx.ALIGN_CENTRE, 0),
                                 (self.btnSaveSQL, 0, wx.ALL | wx.ALIGN_CENTRE, 0),
                                 (self.btnSpare, 0, wx.ALL | wx.ALIGN_CENTRE, 0)
                                 ])
             # POS = (x, y), (r, c) = SPAN
             pGridSizer.AddMany([
                                 (self.labelSQL_1, (0, 0), (1, 1), wx.ALL|wx.EXPAND),
                                 (self.labelSQL_2, (0, 1), (1, 1), wx.ALL|wx.EXPAND),
                                 (self.labelSQL_3, (1, 0), (1, 1), wx.ALL|wx.EXPAND),
                                 (self.labelSQL_4, (1, 1), (1, 1), wx.ALL|wx.EXPAND),
                                 (self.labelSQL_5, (2, 0), (1, 1), wx.ALL|wx.EXPAND),
                                 (self.tc_SQL, (2, 1), (4, 6), wx.ALL|wx.EXPAND),
                                 (cGridSizerAa, (6, 1), (1, 1), wx.ALL|wx.EXPAND)
                                 ])
             pGridSizer.AddGrowableCol(1)

             mainSizer.Add(pGridSizer, 0, wx.ALL | wx.EXPAND, 0)

             self.SetAutoLayout(True)
             self.SetSizer(mainSizer)
             self.Layout()

#### Utilites------------------------------------------------------------
# None

#---------------------------------------------------------
class MyApp(wx.App):
     def OnInit(self):
         frame = MyFrame(None, -1, "SQL test")
         frame.Show(True)
         self.SetTopWindow(frame)
         return True

def main():
     app = MyApp(False)
     app.MainLoop()

if __name__ == '__main__':
     main()
#### END

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.8.5 - Release Date: 3/29/2005

I had not realized I needed the 'self' reference for the pnl1 objects.
Now everything works as excepted.

SM

···

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.8.5 - Release Date: 3/29/2005

I added these 2 lines:

#from sqlbuilder import * #MySQLPanel (commented out)
from MySQLPanel import MySQLPanel (added)

You still haven't told me what you expect to see. The top portion appears to be fine (after the edit above).
The bottom portion is a notebook with 2 pages. Are there supposed to be widgets hung either of them ?

scott wrote:

···

> The panels need to have the frame as their parent unless their is
> another widget inbetween.
I thought that's what I did, but I still have something wrong.
Here are two files, the Frame (beta.mainframe.py) and the "Panel" (MySQLPanel.py) and a notebook just for fun.

I would like to use the model for coding as it makes it very easy to read and debug, my other app was 4000 lines of crap.

Thanks for helping,
Scott

----------------------------------------------
beta.mainframe.py

import wx
# gui py files
##from cardbuilder import *
##from gridbuilder import *
from sqlbuilder import * #MySQLPanel

#---------------------------------------------------------------------------

class MainFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, size = (950, 720),
                          style=wx.DEFAULT_FRAME_STYLE
                        > wx.NO_FULL_REPAINT_ON_RESIZE)

        self.SetMinSize((640,480))
        self.Centre(wx.BOTH)

        # # #----------------------------
####GUI PANELS
        # # # ---------------------------
        # Add a sizer to the Frame, -> parent and 2 childre
        appSizer_1 = wx.FlexGridSizer(2, 1, 1, 1)
        # sql sizer
        topsizer = wx.BoxSizer(wx.VERTICAL)
        # notebook sizer
        botsizer = wx.BoxSizer(wx.VERTICAL)
        # Make the notebook & pages
        nb = wx.Notebook(self, -1, style=0)
        # add the py files classes as the Notebook Panels

        nb_pg1 = wx.Panel(nb) # Grid(nb)
        nb_pg2 = wx.Panel(nb) # Card(nb)
        nb_pg1.SetBackgroundColour(wx.RED)
        nb_pg2.SetBackgroundColour(wx.CYAN)

        # add pages to nb
        nb.AddPage(nb_pg1, "Database")
        nb.AddPage(nb_pg2, "Card Data")

        # add notebook
        botsizer.Add(nb, 1, wx.ALL|wx.EXPAND, 0)
        # add Top Box
        self.sqlPanel = MySQLPanel(self)
        topsizer.Add(self.sqlPanel, 0, wx.ALL|wx.EXPAND, 0)

        # add children sizers to the parent sizer
        appSizer_1.Add(topsizer, 0, wx.ALL|wx.EXPAND, 0)
        appSizer_1.Add(botsizer, 0, wx.ALL|wx.EXPAND, 0)

        # make it
        self.SetAutoLayout(True)
        self.SetSizer(appSizer_1)
        appSizer_1.AddGrowableRow(1)
        appSizer_1.AddGrowableCol(0)
        self.Layout()

#---Button events - Upper panel
        # These buttons are located on the upper panel
        # mySQLPanel

        #self.Bind(wx.EVT_BUTTON, self.onAddDispatchers, self.btnDisp) #
        #self.Bind(wx.EVT_BUTTON, self.onAddData, self.sql.btnAddData) #
        #self.Bind(wx.EVT_BUTTON, self.onRunSQL, self.sql.btnSQL) #

#---------------------------------------------------------
class MyApp(wx.App):
    def OnInit(self):
        frame = MainFrame(None, "Test")
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

def main():
    app = MyApp(False)
    app.MainLoop()

if __name__ == '__main__':
    main()
#### END

-------------------------------------------------------------------------
MySQLPanel.py

import sys
import wx
# my Frame is for testing
class MyFrame(wx.Frame):
    def __init__(self, parent, ID, title):
        wx.Frame.__init__(self, parent, ID, title, size = (800, 600),
                                    style=wx.DEFAULT_FRAME_STYLE
                                    > wx.CLIP_CHILDREN
                                    > wx.NO_FULL_REPAINT_ON_RESIZE)

        # Parent Box
        mbox = wx.BoxSizer(wx.VERTICAL)

        # Add Panels...
        mbox.Add(MySQLPanel(self), 0, wx.ALL|wx.EXPAND, 0)

        self.SetAutoLayout(True)
        self.SetSizer(mbox)
        self.Layout()

# WORKING CODE !!!!!
class MySQLPanel(wx.Panel):
    """ A panel """
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1,
                                    style=wx.SUNKEN_BORDER
                                    > wx.CLIP_CHILDREN
                                    > wx.NO_FULL_REPAINT_ON_RESIZE)

        scrPanel1 = wx.ScrolledWindow(self,-1, size=(-1,-1))#, style=wx.SUNKEN_BORDER|wx.FULL_REPAINT_ON_RESIZE)
        scrPanel1.SetScrollRate(10, 10)

        pbox = wx.BoxSizer(wx.VERTICAL)
        cbox = wx.BoxSizer(wx.VERTICAL)

        # Add subPanels Classes
        pnl1 = subPanel_SQL(scrPanel1)

        cbox.Add(pnl1, 0, wx.ALL|wx.EXPAND)

        scrPanel1.SetAutoLayout(True)
        scrPanel1.SetSizer(cbox)

        pbox.Add(scrPanel1, 0, wx.ALL|wx.EXPAND, 0)

        self.SetAutoLayout(True)
        self.SetSizer(pbox)
        self.Layout()

class subPanel_SQL(wx.Panel):
        def __init__(self, parent):
            wx.Panel.__init__(self, parent, -1,
                                    style=wx.CLIP_CHILDREN
                                    > wx.NO_FULL_REPAINT_ON_RESIZE)

            # Parent
            mainSizer = wx.BoxSizer(wx.HORIZONTAL)

            # Child
            pGridSizer = wx.GridBagSizer(3,3)
            cGridSizerAa = wx.FlexGridSizer(1, 7, 2, 2) # bottom buttons

            # Widgets
            self.labelSQL_1 = wx.StaticText(self, -1, "DataBase ::",
                                                style=wx.ALIGN_RIGHT)
            self.labelSQL_2 = wx.StaticText(self, -1, "None selected.")
            self.labelSQL_3 = wx.StaticText(self, -1, "Size ::",
                                                style=wx.ALIGN_RIGHT)
            self.labelSQL_4 = wx.StaticText(self, -1, "0.0 KB")
            self.labelSQL_5 = wx.StaticText(self, -1, "Enter SQL ::",
                                                style=wx.ALIGN_RIGHT)
            self.tc_SQL = wx.TextCtrl(self, -1, "Enter SQL here",
                                                style=wx.TE_MULTILINE)
            self.tc_Homy = wx.TextCtrl(self, -1, "20", (-1, -1),
                                                style=wx.TE_PROCESS_ENTER
                                                > wx.TE_CENTRE)

            self.btnSQL = wx.Button(self, -1, "Run Query")
            self.btnAddData = wx.Button(self, -1, "Add Calls")
            self.btnDisp = wx.Button(self, -1, "Add Dispatchers")
            self.btnSpare = wx.Button(self, -1, "something")
            self.btnSaveSQL = wx.Button(self, -1, "Save Query")
            #self.btnCommit = wx.Button(self.panel_1, -1, "Commit Changes?")

            # Layout
            cGridSizerAa.AddMany([
                                (self.btnSQL, 0, wx.ALL | wx.ALIGN_CENTRE, 0),
                                (self.btnAddData, 0, wx.ALL | wx.ALIGN_CENTRE, 0),
                                (self.tc_Homy, 0, wx.ALL | wx.ALIGN_CENTRE, 0),
                                (self.btnDisp, 0, wx.ALL | wx.ALIGN_CENTRE, 0),
                                (self.btnSaveSQL, 0, wx.ALL | wx.ALIGN_CENTRE, 0),
                                (self.btnSpare, 0, wx.ALL | wx.ALIGN_CENTRE, 0)
                                ])
            # POS = (x, y), (r, c) = SPAN
            pGridSizer.AddMany([
                                (self.labelSQL_1, (0, 0), (1, 1), wx.ALL|wx.EXPAND),
                                (self.labelSQL_2, (0, 1), (1, 1), wx.ALL|wx.EXPAND),
                                (self.labelSQL_3, (1, 0), (1, 1), wx.ALL|wx.EXPAND),
                                (self.labelSQL_4, (1, 1), (1, 1), wx.ALL|wx.EXPAND),
                                (self.labelSQL_5, (2, 0), (1, 1), wx.ALL|wx.EXPAND),
                                (self.tc_SQL, (2, 1), (4, 6), wx.ALL|wx.EXPAND),
                                (cGridSizerAa, (6, 1), (1, 1), wx.ALL|wx.EXPAND)
                                ])
            pGridSizer.AddGrowableCol(1)
            mainSizer.Add(pGridSizer, 0, wx.ALL | wx.EXPAND, 0)

            self.SetAutoLayout(True)
            self.SetSizer(mainSizer)
            self.Layout()

#### Utilites------------------------------------------------------------
# None

#---------------------------------------------------------
class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, "SQL test")
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

def main():
    app = MyApp(False)
    app.MainLoop()

if __name__ == '__main__':
    main()
#### END

If you look at the thread Robin started I finally figured it out. I did not have (saved) a reference to the pnl1 object in the MySQLPanel class.
Once I added 'self.'pnl1 = subPanel_SQL(scrPanel1), I was able to reference the buttons and everything else in the subclasses.

wx.frame class
...
self.sqlP = MySQLPanel(self)
...
self.Bind(wx.EVT_BUTTON, self.onAdd, self.sqlP.pnl1.btnDisp)

Lengthy, but highly functional. :slight_smile:

As for the notebook pages there are of course real classes for them I didn't need them for the example I posted. All of my Panel classes will follow the same coding style as the posted one. I find it easier to work this way.

Thanks for helping me out.

Scott

Ray Pasco wrote:

···

I added these 2 lines:

#from sqlbuilder import * #MySQLPanel (commented out)
from MySQLPanel import MySQLPanel (added)

You still haven't told me what you expect to see. The top portion appears to be fine (after the edit above).
The bottom portion is a notebook with 2 pages. Are there supposed to be widgets hung either of them ?

scott wrote:

> The panels need to have the frame as their parent unless their is
> another widget inbetween.
I thought that's what I did, but I still have something wrong.
Here are two files, the Frame (beta.mainframe.py) and the "Panel" (MySQLPanel.py) and a notebook just for fun.

I would like to use the model for coding as it makes it very easy to read and debug, my other app was 4000 lines of crap.

Thanks for helping,
Scott

----------------------------------------------
beta.mainframe.py

import wx
# gui py files
##from cardbuilder import *
##from gridbuilder import *
from sqlbuilder import * #MySQLPanel

#---------------------------------------------------------------------------

class MainFrame(wx.Frame):
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, -1, title, size = (950, 720),
                          style=wx.DEFAULT_FRAME_STYLE
                        > wx.NO_FULL_REPAINT_ON_RESIZE)

        self.SetMinSize((640,480))
        self.Centre(wx.BOTH)

        # # #----------------------------
####GUI PANELS
        # # # ---------------------------
        # Add a sizer to the Frame, -> parent and 2 childre
        appSizer_1 = wx.FlexGridSizer(2, 1, 1, 1)
        # sql sizer
        topsizer = wx.BoxSizer(wx.VERTICAL)
        # notebook sizer
        botsizer = wx.BoxSizer(wx.VERTICAL)
        # Make the notebook & pages
        nb = wx.Notebook(self, -1, style=0)
        # add the py files classes as the Notebook Panels

        nb_pg1 = wx.Panel(nb) # Grid(nb)
        nb_pg2 = wx.Panel(nb) # Card(nb)
        nb_pg1.SetBackgroundColour(wx.RED)
        nb_pg2.SetBackgroundColour(wx.CYAN)

        # add pages to nb
        nb.AddPage(nb_pg1, "Database")
        nb.AddPage(nb_pg2, "Card Data")

        # add notebook
        botsizer.Add(nb, 1, wx.ALL|wx.EXPAND, 0)
        # add Top Box
        self.sqlPanel = MySQLPanel(self)
        topsizer.Add(self.sqlPanel, 0, wx.ALL|wx.EXPAND, 0)

        # add children sizers to the parent sizer
        appSizer_1.Add(topsizer, 0, wx.ALL|wx.EXPAND, 0)
        appSizer_1.Add(botsizer, 0, wx.ALL|wx.EXPAND, 0)

        # make it
        self.SetAutoLayout(True)
        self.SetSizer(appSizer_1)
        appSizer_1.AddGrowableRow(1)
        appSizer_1.AddGrowableCol(0)
        self.Layout()

#---Button events - Upper panel
        # These buttons are located on the upper panel
        # mySQLPanel

        #self.Bind(wx.EVT_BUTTON, self.onAddDispatchers, self.btnDisp) #
        #self.Bind(wx.EVT_BUTTON, self.onAddData, self.sql.btnAddData) #
        #self.Bind(wx.EVT_BUTTON, self.onRunSQL, self.sql.btnSQL) #

#---------------------------------------------------------
class MyApp(wx.App):
    def OnInit(self):
        frame = MainFrame(None, "Test")
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

def main():
    app = MyApp(False)
    app.MainLoop()

if __name__ == '__main__':
    main()
#### END

-------------------------------------------------------------------------
MySQLPanel.py

import sys
import wx
# my Frame is for testing
class MyFrame(wx.Frame):
    def __init__(self, parent, ID, title):
        wx.Frame.__init__(self, parent, ID, title, size = (800, 600),
                                    style=wx.DEFAULT_FRAME_STYLE
                                    > wx.CLIP_CHILDREN
                                    > wx.NO_FULL_REPAINT_ON_RESIZE)

        # Parent Box
        mbox = wx.BoxSizer(wx.VERTICAL)

        # Add Panels...
        mbox.Add(MySQLPanel(self), 0, wx.ALL|wx.EXPAND, 0)

        self.SetAutoLayout(True)
        self.SetSizer(mbox)
        self.Layout()

# WORKING CODE !!!!!
class MySQLPanel(wx.Panel):
    """ A panel """
    def __init__(self, parent):
        wx.Panel.__init__(self, parent, -1,
                                    style=wx.SUNKEN_BORDER
                                    > wx.CLIP_CHILDREN
                                    > wx.NO_FULL_REPAINT_ON_RESIZE)

        scrPanel1 = wx.ScrolledWindow(self,-1, size=(-1,-1))#, style=wx.SUNKEN_BORDER|wx.FULL_REPAINT_ON_RESIZE)
        scrPanel1.SetScrollRate(10, 10)

        pbox = wx.BoxSizer(wx.VERTICAL)
        cbox = wx.BoxSizer(wx.VERTICAL)

        # Add subPanels Classes
        pnl1 = subPanel_SQL(scrPanel1)

        cbox.Add(pnl1, 0, wx.ALL|wx.EXPAND)

        scrPanel1.SetAutoLayout(True)
        scrPanel1.SetSizer(cbox)

        pbox.Add(scrPanel1, 0, wx.ALL|wx.EXPAND, 0)

        self.SetAutoLayout(True)
        self.SetSizer(pbox)
        self.Layout()

class subPanel_SQL(wx.Panel):
        def __init__(self, parent):
            wx.Panel.__init__(self, parent, -1,
                                    style=wx.CLIP_CHILDREN
                                    > wx.NO_FULL_REPAINT_ON_RESIZE)

            # Parent
            mainSizer = wx.BoxSizer(wx.HORIZONTAL)

            # Child
            pGridSizer = wx.GridBagSizer(3,3)
            cGridSizerAa = wx.FlexGridSizer(1, 7, 2, 2) # bottom buttons

            # Widgets
            self.labelSQL_1 = wx.StaticText(self, -1, "DataBase ::",
                                                style=wx.ALIGN_RIGHT)
            self.labelSQL_2 = wx.StaticText(self, -1, "None selected.")
            self.labelSQL_3 = wx.StaticText(self, -1, "Size ::",
                                                style=wx.ALIGN_RIGHT)
            self.labelSQL_4 = wx.StaticText(self, -1, "0.0 KB")
            self.labelSQL_5 = wx.StaticText(self, -1, "Enter SQL ::",
                                                style=wx.ALIGN_RIGHT)
            self.tc_SQL = wx.TextCtrl(self, -1, "Enter SQL here",
                                                style=wx.TE_MULTILINE)
            self.tc_Homy = wx.TextCtrl(self, -1, "20", (-1, -1),
                                                style=wx.TE_PROCESS_ENTER
                                                > wx.TE_CENTRE)

            self.btnSQL = wx.Button(self, -1, "Run Query")
            self.btnAddData = wx.Button(self, -1, "Add Calls")
            self.btnDisp = wx.Button(self, -1, "Add Dispatchers")
            self.btnSpare = wx.Button(self, -1, "something")
            self.btnSaveSQL = wx.Button(self, -1, "Save Query")
            #self.btnCommit = wx.Button(self.panel_1, -1, "Commit Changes?")

            # Layout
            cGridSizerAa.AddMany([
                                (self.btnSQL, 0, wx.ALL | wx.ALIGN_CENTRE, 0),
                                (self.btnAddData, 0, wx.ALL | wx.ALIGN_CENTRE, 0),
                                (self.tc_Homy, 0, wx.ALL | wx.ALIGN_CENTRE, 0),
                                (self.btnDisp, 0, wx.ALL | wx.ALIGN_CENTRE, 0),
                                (self.btnSaveSQL, 0, wx.ALL | wx.ALIGN_CENTRE, 0),
                                (self.btnSpare, 0, wx.ALL | wx.ALIGN_CENTRE, 0)
                                ])
            # POS = (x, y), (r, c) = SPAN
            pGridSizer.AddMany([
                                (self.labelSQL_1, (0, 0), (1, 1), wx.ALL|wx.EXPAND),
                                (self.labelSQL_2, (0, 1), (1, 1), wx.ALL|wx.EXPAND),
                                (self.labelSQL_3, (1, 0), (1, 1), wx.ALL|wx.EXPAND),
                                (self.labelSQL_4, (1, 1), (1, 1), wx.ALL|wx.EXPAND),
                                (self.labelSQL_5, (2, 0), (1, 1), wx.ALL|wx.EXPAND),
                                (self.tc_SQL, (2, 1), (4, 6), wx.ALL|wx.EXPAND),
                                (cGridSizerAa, (6, 1), (1, 1), wx.ALL|wx.EXPAND)
                                ])
            pGridSizer.AddGrowableCol(1)
            mainSizer.Add(pGridSizer, 0, wx.ALL | wx.EXPAND, 0)

            self.SetAutoLayout(True)
            self.SetSizer(mainSizer)
            self.Layout()

#### Utilites------------------------------------------------------------
# None

#---------------------------------------------------------
class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, "SQL test")
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

def main():
    app = MyApp(False)
    app.MainLoop()

if __name__ == '__main__':
    main()
#### END

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.308 / Virus Database: 266.8.5 - Release Date: 3/29/2005

Hi Scott,

You might also want to look at Andrea's FoldPanelBar stuff, a very nice alternative or complement to notebooks.

http://xoomer.virgilio.it/infinity77/FoldPanelBar.zip
http://xoomer.virgilio.it/infinity77/FoldPanelBarDoc.zip

See you
Werner

Ray Pasco wrote:

···

scott wrote:

Greetings,
I created a Frame that calls several classes (panels) from other py files. I got that part working fine (finally, with Robins help). But when I tried to bind the controls to the Frame, I just got allot of attribute errors.

What I am I trying to figure out are there any methods to bind a button (from a different file)to the parent frame.

OR

Should I bind the buttons to their respective panels?

What I am trying to do is create an application that will use 6 or 7 panels, all form different panels that will communicate between themselves and ultimately a database (I got the database part working).

Any suggestions?

Scott

(Attaching the relavent code would help...)

It doesn't matter whether the class code is in another file or is in the main .py file itself. It sounds like you need to pass into the panel class definitions the frame object so that
when each panel is instantiated it's controls and their event handlers know the frame to bind to. I.e., events can only be bound to the parent frame, not any other kind of widget such as a panel.
The panels need to have the frame as their parent unless their is another widget inbetween.

Its all a hierarchical grouping of widgets in parent-child relationships. You might want to think of
the widgets being in a tree organization with the wx.Frame at the root. In this case:

                                   <-(using sizer)- wx.Window <-- Panel_1
             wx.Frame <-- wx.Panel <-(using sizer)- wx.Window <-- Panel_2
                                   <-(using sizer)- wx.Window <-- Panel_3
                                   <-- ...

You will also need a way to physically (graphically) organize the panels.
When the first panel is bound to a frame it will fill the frame completely.
The next panel will fill the frame but cover over any previous panels.
Whats need is "container" widgets, such as wx.Window or wx.Notebook, etc.
This will prevent all the panels from inadvertantly covering over each other.
The panels would then be separated from each other in a 2-D fashion.
The panels need something to fill and limit their size and also be positioned
relative to each other.

---------------------FRAME------------------------
> >
> panel_that_fills_the_frame |
> >
> -----wx.Window------ -----wx.Window------ |
> > > > > >
> > panel 1 | | panel 2 | |
> > > > > >
> -------------------- -------------------- |
> >
> ------wx.Window----- -----wx.Window------ |
> > > > > >
> > panel 3 | | panel 4 | |
> > > > > >
> -------------------- -------------------- |
> ... |
> >
>------------------------------------------------|

If all the panels are to be viewed at the same time then they will need to be
organized in a 2-D layout using sizers or coordinate placement specification.
Its not apparent to me what appearance you are trying to accomplish.

I hope this helps.

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org