convert a frame to a panel?

I think I have the terminology wrong ... Please correct me where I've
stuffed it up.
I have a class (edited to save space, but you get the idea from it) :

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

    def new(self):
        coaches = stDataClasses.Coaches.getAll()
        venues = stDataClasses.Venues.getAll()
        squads = stDataClasses.Squads.getAll()

        #self.date = wx.calendar.CalendarCtrl(self, -1)
        #panel.date = wx.DatePickerCtrl(panel, -1)
        self.date = wx.DatePickerCtrl(self, -1)

.
.
.

    def __set_properties(self):
        self.SetTitle(_("SessionCreator"))

    def __do_layout(self):
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_1.Add(self.date, 0, 0, 0)
        sizer_1.Add(self.startTime, 0, 0, 0)
        .
        .
        self.SetSizer(sizer_1)
        sizer_1.Fit(self)
        self.Layout()

blah blah ...

I call it like this :

class MyApp(wx.App):
    def OnInit(self):
        wx.InitAllImageHandlers()
        SessionCreator = stTrainingSession(None, -1, "")
        SessionEditor = stTrainingSession(None, -1, "")
        SessionCreator.new()
        self.SetTopWindow(SessionCreator)
        SessionCreator.Show()
        trainingSession = stDataClasses.TrainingSessions.FromId(3)
        #trainingSession.edit(SessionCreator,trainingSession)
        #SessionEditor.edit(trainingSession)
        print trainingSession
        return 1

# end of class MyApp

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

    testSessionAdd = MyApp(0)
    testSessionAdd.MainLoop()

That's pretty ugly, I know .. (bear with me, I'm new at Python/
wxPython and SQLAlchemy and the learning curve is being climbed!)

I want to be able to convert, if that's the write way to say it, the
trainingsession object, which is essentially a form and a submission
handler, into a panel so I can embed it in another application. Ie:
this object should end up as a panel within a parent/master
application (which will take care of all the menu bars and so on).
Can anyone here suggest how I should change the class so I can call it
a panel and then use that panel in a parent frame?

I get lost in traceback hell when I start creating a wx.Panel in the
new() method and trying to set/read any variables called after that
panel, any hints or pointers to some handy doco much appreciated!

It looks like you could just switch the declaration of the Frame to a
Panel, but you will then
need to create a new Frame to hold the panels, and of course you can't
set the Title on
a panel like you can a Frame.

Remember, Frames are TopLevelWindows, panels are just places to stick
your widgets.

I didn't run your code, but I suspect making your Frame a Panel and
embedding them into
a new frame will look a lot better, too.

Josh

···

On Thu, Aug 19, 2010 at 8:28 PM, Bleve <carl.i.brewer@gmail.com> wrote:

I think I have the terminology wrong ... Please correct me where I've
stuffed it up.
I have a class (edited to save space, but you get the idea from it) :

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

def new(self):
coaches = stDataClasses.Coaches.getAll()
venues = stDataClasses.Venues.getAll()
squads = stDataClasses.Squads.getAll()

   \#self\.date = wx\.calendar\.CalendarCtrl\(self, \-1\)
   \#panel\.date = wx\.DatePickerCtrl\(panel, \-1\)
   self\.date = wx\.DatePickerCtrl\(self, \-1\)

.
.
.

def __set_properties(self):
self.SetTitle(_("SessionCreator"))

def __do_layout(self):
sizer_1 = wx.BoxSizer(wx.VERTICAL)
sizer_1.Add(self.date, 0, 0, 0)
sizer_1.Add(self.startTime, 0, 0, 0)
.
.
self.SetSizer(sizer_1)
sizer_1.Fit(self)
self.Layout()

blah blah ...

I call it like this :

class MyApp(wx.App):
def OnInit(self):
wx.InitAllImageHandlers()
SessionCreator = stTrainingSession(None, -1, "")
SessionEditor = stTrainingSession(None, -1, "")
SessionCreator.new()
self.SetTopWindow(SessionCreator)
SessionCreator.Show()
trainingSession = stDataClasses.TrainingSessions.FromId(3)
#trainingSession.edit(SessionCreator,trainingSession)
#SessionEditor.edit(trainingSession)
print trainingSession
return 1

# end of class MyApp

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

testSessionAdd = MyApp(0)
testSessionAdd.MainLoop()

That's pretty ugly, I know .. (bear with me, I'm new at Python/
wxPython and SQLAlchemy and the learning curve is being climbed!)

I want to be able to convert, if that's the write way to say it, the
trainingsession object, which is essentially a form and a submission
handler, into a panel so I can embed it in another application. Ie:
this object should end up as a panel within a parent/master
application (which will take care of all the menu bars and so on).
Can anyone here suggest how I should change the class so I can call it
a panel and then use that panel in a parent frame?

I get lost in traceback hell when I start creating a wx.Panel in the
new() method and trying to set/read any variables called after that
panel, any hints or pointers to some handy doco much appreciated!

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

--
Josh English
Joshua.R.English@gmail.com

I am making that learning curve climb too; Therefore don't take
anything I say as a factual but more like "look it up and see if this
is the way"

I think I am suppose to make this code as an attachment instead of
inline to the forum post. I'm using the google web forums interface
though. Please forgive my trangressions.

Here is an example of what I think Josh Enlish said:

Note the code is not clean or runnable.

···

#######################################################################

class stTrainingSessionPanel(wx.Panel):
    def __init__(self, *args, **kwds):
        wx.Panel.__init__(self, *args, **kwds)

        # Adding a Panel to a frame is a general wx pracise
        # although not required. There is/was a problem
        # with different operating systems for frames without
        # panel added to it.

        # Putting controls on a panel instead of a frame
        # allows for easily moving this panel to a
        # wx.notebook or some other neat wx window thing.

        ###########################
        # Data access method one
        # You could pass it in on creation of panel
        # and put data into the panel's local attributes.
        self.stDataClasses = kwds["stDataClasses"]

        # or like this
        # self.coaches = kwds["stDataClasses"].Coaches.getAll()

        # OR data access method two
        # you can get and put values from the frame objects instead
        # myval = self.parent.stDataClasses
        # self.parent.stDataClasses = myval
        # I would not recommend this method

        # Instead of creating local attributes in a panel like this:
        # self.coaches = kwds["stDataClasses"].Coaches.getAll()
        # some prefer to store the data in the controls themselves
        # see example __set_ctrl_defaults
        ###########################

        self.__do_layout()
        self.new() # left here incase there is complex data retrieval
        self.__set_ctrl_defaults(kwds["stDataClasses"])

    def __set_ctrl_defaults(self, data):
        # Keep this simple to just creating controls that live
        # on the panel. Complex data retrieval like getting data
        # from a remote server is recommend to be put elsewhere.
        # Creating gui controls should not have to wait for data
        # retrieval in the case of timeouts.

        self.coach = wx.TextCtrl(self,-1, data.Coaches.getitem(0))
.
.
.

    def new(self):
        # You could put new()'s data in the frame if you plan
        # to make multiple panels where each panel could
        # access the frame data.

        # Or you could put data only used by this panel
        # here in this stTrainingSessionPanel() class,
        # depending on how you want to get/make/save the data
        # - such as when you close the (window) frame

        self.coaches = self.stDataClasses.Coaches.getAll()
        self.venues = self.stDataClasses.Venues.getAll()
        self.squads = self.stDataClasses.Squads.getAll()

        #self.date = wx.calendar.CalendarCtrl(self, -1)
        #panel.date = wx.DatePickerCtrl(panel, -1)
        self.date = wx.DatePickerCtrl(self, -1)

.
.
.

    def __do_layout(self):
        sizer_1 = wx.BoxSizer(wx.VERTICAL)
        sizer_1.Add(self.date, 0, 0, 0)
        sizer_1.Add(self.startTime, 0, 0, 0)
        .
        .
        self.SetSizer(sizer_1)
        sizer_1.Fit(self)
        self.Layout()

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

        self.TrainingSessionData = kwds["TrainingSessionData"]
        self.trainingPanel = stTrainingSessionPanel(self, -1,
                                  kwds["stDataClasses"] )

        # You might want your editor editting your
        # newly created session so you might prefer
        # your session editor here as a child window instead
:
        # self.SessionEditor = stTrainingSessionFrame(None, -1, "",
                                             kwds["stDataClasses"])

        self.__set_gui_properties():

        # Might want to use if data retrieval is complex
        self.__set_data_properties(kwds["stDataClasses"])

        # You can put your data setup here in __init__is simple/fast
        # and you want to pass the same data to many other
        # child windows of this frame

        self.__do_layout()

    def __set_gui_properties(self):
        # SetTitle() is a method of a wx.Frame and NOT of wx.Panel
        self.SetTitle(_("SessionCreator"))

    def __set_data_properties(self, data):
        self.data.stuff = data.get_some_slow_sql_query_stuff

    def __do_layout(self):
        # __do_layout() included here in frame here as well incase
        # you want to add more panels to the frame

        # This method is usually NOT needed if you add just one
        # panel OR one control to the frame.
        # It's a default behavior that if a frame (and perhaps a
        # panel too) has just ONE child, that the single
        # child object owned by the frame, will fill
        # the entire client area of the frame
        # (minus wx.men + wx.ToolBar + wx.StatusBar; these are
        # automatically accounted for)

        frameSizer = wx.BoxSizer(wx.VERTICAL)
        frameSizer.Add(self.trainingPanel, 1, wx.EXPAND, 0)
        .
        .
        self.SetSizer(frameSizer)
        frameSizer.Fit(self)
        self.Layout()

blah blah ...

#######################################################################

Please don't hijack the original thread. Instead, create a new one
with a
different, but meaningful Subject title.

Yes, when creating a new thread you can add 1 or more file attachment
files
using the Google Groups Web page "New Post" button. To add
attachments
in any future reply messages to an existing thread then create a
regular email
with the email's Subject line set to the exact thread title. If you
want to reply
with NO attached files then you can simply use the Google Groups Web
page "Reply" button.

Ray

···

On Aug 20, 11:56 am, DevPlayer <devpla...@gmail.com> wrote:

I am making that learning curve climb too; Therefore don't take
anything I say as a factual but more like "look it up and see if this
is the way"

I think I am suppose to make this code as an attachment instead of
inline to the forum post. I'm using the google web forums interface
though. Please forgive my trangressions.

Here is an example of what I think Josh Enlish said:

Note the code is not clean or runnable.

#######################################################################

class stTrainingSessionPanel(wx.Panel):
def __init__(self, *args, **kwds):
wx.Panel.__init__(self, *args, **kwds)

    \# Adding a Panel to a frame is a general wx pracise
    \# although not required\. There is/was a problem
    \# with different operating systems for frames without
    \# panel added to it\.

    \# Putting controls on a panel instead of a frame
    \# allows for easily moving this panel to a
    \# wx\.notebook or some other neat wx window thing\.

    \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#
    \# Data access method one
    \# You could pass it in on creation of panel
    \# and put data into the panel&#39;s local attributes\.
    self\.stDataClasses = kwds\[&quot;stDataClasses&quot;\]

    \# or like this
    \# self\.coaches = kwds\[&quot;stDataClasses&quot;\]\.Coaches\.getAll\(\)

    \# OR data access method two
    \# you can get and put values from the frame objects instead
    \# myval = self\.parent\.stDataClasses
    \# self\.parent\.stDataClasses = myval
    \# I would not recommend this method

    \# Instead of creating local attributes in a panel like this:
    \# self\.coaches = kwds\[&quot;stDataClasses&quot;\]\.Coaches\.getAll\(\)
    \# some prefer to store the data in the controls themselves
    \# see example \_\_set\_ctrl\_defaults
    \#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#\#

    self\.\_\_do\_layout\(\)
    self\.new\(\)      \# left here incase there is complex data retrieval
    self\.\_\_set\_ctrl\_defaults\(kwds\[&quot;stDataClasses&quot;\]\)

def \_\_set\_ctrl\_defaults\(self, data\):
    \# Keep this simple to just creating controls that live
    \# on the panel\. Complex data retrieval like getting data
    \# from a remote server is recommend to be put elsewhere\.
    \# Creating gui controls should not have to wait for data
    \# retrieval in the case of timeouts\.

    self\.coach = wx\.TextCtrl\(self,\-1, data\.Coaches\.getitem\(0\)\)

.
.
.

def new\(self\):
    \# You could put new\(\)&#39;s data in the frame if you plan
    \# to make multiple panels where each panel could
    \# access the frame data\.

    \# Or you could put data only used by this panel
    \# here in this stTrainingSessionPanel\(\) class,
    \# depending on how you want to get/make/save the data
    \# \- such as when you close the \(window\) frame

    self\.coaches = self\.stDataClasses\.Coaches\.getAll\(\)
    self\.venues = self\.stDataClasses\.Venues\.getAll\(\)
    self\.squads = self\.stDataClasses\.Squads\.getAll\(\)

    \#self\.date = wx\.calendar\.CalendarCtrl\(self, \-1\)
    \#panel\.date = wx\.DatePickerCtrl\(panel, \-1\)
    self\.date = wx\.DatePickerCtrl\(self, \-1\)

.
.
.

def \_\_do\_layout\(self\):
    sizer\_1 = wx\.BoxSizer\(wx\.VERTICAL\)
    sizer\_1\.Add\(self\.date, 0, 0, 0\)
    sizer\_1\.Add\(self\.startTime, 0, 0, 0\)
    \.
    \.
    self\.SetSizer\(sizer\_1\)
    sizer\_1\.Fit\(self\)
    self\.Layout\(\)

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

    self\.TrainingSessionData = kwds\[&quot;TrainingSessionData&quot;\]
    self\.trainingPanel = stTrainingSessionPanel\(self, \-1,
                              kwds\[&quot;stDataClasses&quot;\] \)

    \# You might want your editor editting your
    \# newly created session so you might prefer
    \# your session editor here as a child window instead

:
# self.SessionEditor = stTrainingSessionFrame(None, -1, "",
kwds["stDataClasses"])

    self\.\_\_set\_gui\_properties\(\):

    \# Might want to use if data retrieval is complex
    self\.\_\_set\_data\_properties\(kwds\[&quot;stDataClasses&quot;\]\)

    \# You can put your data setup here in \_\_init\_\_is simple/fast
    \# and you want to pass the same data to many other
    \# child windows of this frame

    self\.\_\_do\_layout\(\)

def \_\_set\_gui\_properties\(self\):
    \# SetTitle\(\) is a method of a wx\.Frame and NOT of wx\.Panel
    self\.SetTitle\(\_\(&quot;SessionCreator&quot;\)\)

def \_\_set\_data\_properties\(self, data\):
    self\.data\.stuff = data\.get\_some\_slow\_sql\_query\_stuff

def \_\_do\_layout\(self\):
    \# \_\_do\_layout\(\) included here in frame here as well incase
    \# you want to add more panels to the frame

    \# This method is usually NOT needed if you add just one
    \# panel OR one control to the frame\.
    \# It&#39;s a default behavior that if a frame \(and perhaps a
    \# panel too\) has just ONE child, that the single
    \# child object owned by the frame, will fill
    \# the entire client area of the frame
    \# \(minus wx\.men \+ wx\.ToolBar \+ wx\.StatusBar; these are
    \# automatically accounted for\)

    frameSizer = wx\.BoxSizer\(wx\.VERTICAL\)
    frameSizer\.Add\(self\.trainingPanel, 1, wx\.EXPAND, 0\)
    \.
    \.
    self\.SetSizer\(frameSizer\)
    frameSizer\.Fit\(self\)
    self\.Layout\(\)

blah blah ...

#######################################################################

When did he hijack the thread? I thought he was just coding up Josh's
idea...

···

On Aug 20, 12:34 pm, WinCrazy <pas...@verizon.net> wrote:

Please don't hijack the original thread. Instead, create a new one
with a
different, but meaningful Subject title.

Yes, when creating a new thread you can add 1 or more file attachment
files
using the Google Groups Web page "New Post" button. To add
attachments
in any future reply messages to an existing thread then create a
regular email
with the email's Subject line set to the exact thread title. If you
want to reply
with NO attached files then you can simply use the Google Groups Web
page "Reply" button.

Ray

-------------------
Mike Driscoll

Blog: http://blog.pythonlibrary.org

Thanks for saying so Mike. I thought I did something wrong. Wincrazy,
my first post was done by clicking Replay on the Google groups web
page. Did my reply come across to you oddly?

Mike, or anyone else, were my suggestions in the example code to O.P.
Bleve on or off the mark?

Right on the mark, thank you!

I've moved the class to being a panel and can now load it into a
parent
frame.

Thanks again!

Carl

···

On Aug 21, 8:02 am, DevPlayer <devpla...@gmail.com> wrote:

Thanks for saying so Mike. I thought I did something wrong. Wincrazy,
my first post was done by clicking Replay on the Google groups web
page. Did my reply come across to you oddly?

Mike, or anyone else, were my suggestions in the example code to O.P.
Bleve on or off the mark?