Write Once, Re-use Many

A set of three buttons, "New," "Modify," and "Remove" will be used on most
panels of the application. It would make sense to write them once then refer
to them in each panel that requires them.

   Is there a standard wxPython way of doing this?

Rich

Rich, maybe just put them into a panel that you save as its own class that is derived from wx.Panel, then just instantiate it anytime you need it. Like (pseudocode of course):

MyButtonPanel(wx.Panel):

self.NewButton = wx.Button(etc…)

self.ModifyButton = wx.Button(etc…)

self.RemoveButton = wx.Button(etc…)

background color stuff, look and feel stuff, etc…

binding stuff etc…
sizer stuff, etc…

then when you want it, just do:

button_panel = MyButtonPanel(arguments)

and it’s all set up. You have to make sure the events from thos buttons get transmitted to the MainFrame, though (you can use self.GetParent() or any of the ways I mentioned about communicating between objects in another email).

Che

···

On Sun, Jul 20, 2014 at 4:02 PM, Rich Shepard rshepard@appl-ecosys.com wrote:

A set of three buttons, “New,” “Modify,” and “Remove” will be used on most

panels of the application. It would make sense to write them once then refer

to them in each panel that requires them.

Is there a standard wxPython way of doing this?

Rich

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

(whoops missed the word class there in front of MyButtonPanel, but again it’s just quick pseudocode as I am heading out the door)

···

On Sun, Jul 20, 2014 at 4:50 PM, C M cmpython@gmail.com wrote:

Rich, maybe just put them into a panel that you save as its own class that is derived from wx.Panel, then just instantiate it anytime you need it. Like (pseudocode of course):

MyButtonPanel(wx.Panel):

self.NewButton = wx.Button(etc…)

self.ModifyButton = wx.Button(etc…)

self.RemoveButton = wx.Button(etc…)

background color stuff, look and feel stuff, etc…

binding stuff etc…
sizer stuff, etc…

then when you want it, just do:

button_panel = MyButtonPanel(arguments)

and it’s all set up. You have to make sure the events from thos buttons get transmitted to the MainFrame, though (you can use self.GetParent() or any of the ways I mentioned about communicating between objects in another email).

Che

On Sun, Jul 20, 2014 at 4:02 PM, Rich Shepard rshepard@appl-ecosys.com wrote:

A set of three buttons, “New,” “Modify,” and “Remove” will be used on most

panels of the application. It would make sense to write them once then refer

to them in each panel that requires them.

Is there a standard wxPython way of doing this?

Rich

You received this message because you are subscribed to the Google Groups “wxPython-users” group.

To unsubscribe from this group and stop receiving emails from it, send an email to wxpython-users+unsubscribe@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Che,

   That's what I considered doing. Wasn't sure if it met pythonic convention.

Thanks,

Rich

···

On Sun, 20 Jul 2014, C M wrote:

Rich, maybe just put them into a panel that you save as its own class that
is derived from wx.Panel, then just instantiate it anytime you need it.
Like (pseudocode of course):

From The Zen of Python "Practicality beats purity" :slight_smile:

If you (plural) don't know what that is try the command:-

import this

···

On 20/07/2014 22:41, Rich Shepard wrote:

On Sun, 20 Jul 2014, C M wrote:

Rich, maybe just put them into a panel that you save as its own class
that
is derived from wx.Panel, then just instantiate it anytime you need it.
Like (pseudocode of course):

Che,

   That's what I considered doing. Wasn't sure if it met pythonic
convention.

Thanks,

Rich

--
My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language.

Mark Lawrence

---
This email is free from viruses and malware because avast! Antivirus protection is active.

Rich,
Take a look at
as one example. In a major project of mine I have a set of classes
which consist of panels & dialogs for each data type and one
which takes a list of initialisers for those panels and produces a
multi component dialogue for me. I also have them return (Result,
Values) as a tupple on any button click which I found simplified my
code a lot.
Gadget/Steve

···

On 20/07/14 21:02, Rich Shepard wrote:

    A set of three buttons, "New," "Modify," and "Remove" will be

used on most

  panels of the application. It would make sense to write them once

then refer

  to them in each panel that requires them.




    Is there a standard wxPython way of doing this?




  Rich

GenericMessageDialog

Also worth taking a look at
.

···

On 21/07/14 06:18, Steve Barnes wrote:

  Rich,

Take a look at
as one example. In a major project of mine I have a set of
classes which consist of panels & dialogs for each data type
and one which takes a list of initialisers for those panels and
produces a multi component dialogue for me. I also have them
return (Result, Values) as a tupple on any button click which I
found simplified my code a lot.
Gadget/Steve
– You received this message because you are subscribed to the Google
Groups “wxPython-users” group.
To unsubscribe from this group and stop receiving emails from it,
send an email to .
For more options, visit .
StdDialogButtonSizer
On 20/07/14 21:02, Rich Shepard
wrote:

      A set of three buttons, "New," "Modify," and "Remove" will be

used on most

    panels of the application. It would make sense to write them

once then refer

    to them in each panel that requires them.



      Is there a standard wxPython way of doing this?



    Rich

GenericMessageDialog

wxpython-users+unsubscribe@googlegroups.com
https://groups.google.com/d/optout

Hi Rich,

  A set of three buttons, "New," "Modify," and "Remove" will be used on most
panels of the application. It would make sense to write them once then refer
to them in each panel that requires them.

  Is there a standard wxPython way of doing this?

Besides what Che and G/S suggested you might want to read the thread "Separating GUI from Logic", it was a few years ago. Kevin's explanation in that thread helped me a lot in better structuring my application.

I ended up with a few "Controllers", e.g. one for master data which I use for things like 'code' stuff like countries, drink types, bottle sizes etc etc,

The Country dialog is then just this:

class Country(MasterDataController):
     def __init__(self, parent, **kwds):
         """Controller for country dialog"""
         self.view = sc.SizedDialog(parent, wx.ID_ANY,
               style=wx.MINIMIZE_BOX|wx.MAXIMIZE_BOX|
                     wx.RESIZE_BORDER|wx.DEFAULT_DIALOG_STYLE,
               title=_(u"Dialog - country data maintenance"))
         self.view.SetName(u"dlgCountry")
         super(Country, self).__init__(models=[u"Country",
                                               u"Country_L",
                                               u"Country_LV"],
                                       **kwds)

         self.setupControls()
         # register controls with persistance
         self.persistRegisterControls()

     def setupControls(self):
         """Create all controlls"""
         self.createOLVList(u"Country_LV")

         sCtrls = [a list of controls for searching]

         eCtrls = [a list of controls which can be edited]

         self.createControls(sCtrls, eCtrls)

All the control and button creation methods and handlers are in "MasterDataController" which in turn is a specialised controller which supports localization of some of the information, so a lot of the actual code is in "CommonController" which is defined as "class CommonController(wx.EvtHandler)".

If a dialog has special requirements that some calculations or checks need to be done before saving to the database then there are some 'hook' methods it can implement.

Werner

···

On 7/20/2014 22:02, Rich Shepard wrote:

Gadget/Steve,

   Will do. I'm using 3.0.0.0, not Phoenix, but I'll study the widget.

Thanks,

Rich

···

On Mon, 21 Jul 2014, Steve Barnes wrote:

Take a look at GenericMessageDialog <http://wxpython.org/Phoenix/docs/html/GenericMessageDialog.html#GenericMessageDialog&gt; as one example.

Steve,

   I already use that in my application. I do not immediately see how that
helps with write-once-reuse-many, but I'll read the docs for insights.

Thanks,

Rich

···

On Mon, 21 Jul 2014, Steve Barnes wrote:

Also worth taking a look at /StdDialogButtonSizer/

Besides what Che and G/S suggested you might want to read the thread
"Separating GUI from Logic", it was a few years ago. Kevin's explanation
in that thread helped me a lot in better structuring my application.

Werner,

   I'll definitely do that.

I ended up with a few "Controllers", e.g. one for master data which I use for things like 'code' stuff like countries, drink types, bottle sizes etc etc,

   And I think this answers my question of wether it's better to keep lookup
tables in the database or the wxPython code. I have two such lookup tables,
one is a list of state abbreviations and associated names, the other a list
of single letters, digits, and symbols that explain why data are missing.
Each should be presented to the user when there's a need to enter the
abbreviation during data entry.

Thanks for the suggestions,

Rich

···

On Mon, 21 Jul 2014, Werner wrote: