Refactroring Notebook Page Buttons

It's been a very long time since I read about refactroring in 'wxPython in
Action' (and I no longer have the book). Please point me to docs that will
teach me how to accomplish the following.

   The application frame contains a notebook with 10 main pages, most of
which have nested pages. Each page has the same three buttons: Add, Edit,
and Cancel. It makes sense to move those off each page into a separate
module and class. That's the easy part. What has not been found on Web
searches are:

   1) how to insert the buttons at the appropriate place on each
page and

   2) how to provide the appropriate method since each add and edit needs
different code to insert the data into the appropriate database table.
Cancel, of course, is the same for all pages.

Thanks,

Rich

Hi Rich,

It’s kind of hard to know how to advise you based on no code sample or screenshot, since it’s a bit hard to picture exactly what you have from that brief verbal description. That said, I’ll try:

  1. how to insert the buttons at the appropriate place on each page

Are these buttons supposed to be at the same place on each page? How similar are the pages themselves? Maybe you can make a class that is just a notebook page, and have the Add/Edit/Cancel button section already in that. This way you just add the page and the buttons are already there.

  1. how to provide the appropriate method since each add and edit needs different code to insert the data into the appropriate database table. Cancel, of course, is the same for all pages.

Again, hard to know without seeing, but I suppose you would have just a general Add or Edit method that would then look up the details of the database in some list or dictionary somewhere, right?

Che

···

On Sat, Feb 21, 2015 at 6:49 PM, Rich Shepard rshepard@appl-ecosys.com wrote:

It’s been a very long time since I read about refactroring in 'wxPython in

Action’ (and I no longer have the book). Please point me to docs that will

teach me how to accomplish the following.

The application frame contains a notebook with 10 main pages, most of

which have nested pages. Each page has the same three buttons: Add, Edit,

and Cancel. It makes sense to move those off each page into a separate

module and class. That’s the easy part. What has not been found on Web

searches are:

  1. how to insert the buttons at the appropriate place on each

page and

  1. how to provide the appropriate method since each add and edit needs

different code to insert the data into the appropriate database table.

Cancel, of course, is the same for all pages.

Thanks,

Rich

It's kind of hard to know how to advise you based on no code sample or
screenshot, since it's a bit hard to picture exactly what you have from
that brief verbal description. That said, I'll try:

Che,

   I've attached two examples that include the buttons at the bottom of the
data entry widgets, but their physical position on the notebook page depends
on how many widgets are above them.

   The code used to generate the buttons follows:

         # Define buttons

         self.AddButton = wx.Button(self, wx.ID_ADD)
         self.EditButton = wx.Button(self, wx.ID_EDIT)
         self.CancelButton = wx.Button(self, wx.ID_CANCEL)

         btn1Sizer = wx.StdDialogButtonSizer()
         btn1Sizer.Add(self.AddButton, 0, wx.ALL, 0)
         btn1Sizer.Add(self.EditButton, 0, wx.ALL, 0)
         btn1Sizer.Add(self.CancelButton, 0, wx.ALL, 0)

         # Bind to methods

         self.Bind(wx.EVT_BUTTON, self.OnAdd, self.AddButton)
         self.Bind(wx.EVT_BUTTON, self.OnEdit, self.EditButton)
         self.Bind(wx.EVT_BUTTON, self.OnCancel, self.CancelButton)
         btn1Sizer.Realize()

   The button sizer is added to the bottom of the list of containers for each
page; e.g.,

         topBox.Add(sb1Sizer, 0, wx.ALIGN_CENTER|wx.ALL, 5)
         topBox.Add(sb2Sizer, 0, wx.ALIGN_CENTER|wx.ALL, 5)
         topBox.Add(sb3Sizer, 0, wx.ALIGN_CENTER|wx.ALL, 5)
         topBox.Add(commentBox, 0, wx.ALIGN_CENTER|wx.ALL, 5)
         topBox.Add(btn1Sizer, 0, wx.ALIGN_CENTER|wx.ALL, 5)

Are these buttons supposed to be at the same place on each page?

   Yes, at the bottom of all other widgets on that page.

How similar are the pages themselves?

   Not at all. It depends on the category of data.

Again, hard to know without seeing, but I suppose you would have just a
general Add or Edit method that would then look up the details of the
database in some list or dictionary somewhere, right?

   Yes, but I've not been able to envision how such a generic Add or Edit
method would invoke the specific code needed for each database table.

Rich

···

On Mon, 23 Feb 2015, C M wrote: