sizers and inheritance

I might be doing the wrong thing here, but would like to know the answer anyway.

I am attempting to sub-class wx.calendar.CalendarCtrl and create a widget that has a couple of buttons (forward and backwards) that allow traversing the calendar in equal day jumps. But I am not sure how I can get the sizers arranged to show the calendar and the buttons i.e. the following gives me a calendar with the buttons overlaying the calendar. If I add ‘sizer.Add(self)’ then I lose sight of the buttons and just have the calendar.

What is the correct way to do this please?

Thanks for the help! :slight_smile:

Peter

class Calendar (wx.calendar.CalendarCtrl):

“”" “”"

def init (self, *args, **kwargs):

wx.calendar.CalendarCtrl.init(self, *args, **kwargs)

self.Bind(wx.calendar.EVT_CALENDAR_SEL_CHANGED, self.OnDateChange)

forward = wx.Button(self, -1, ‘Next->’)

backward = wx.Button(self, -1, ‘<-Prev’)

self.Bind(wx.EVT_BUTTON, self.OnForward, forward)

self.Bind(wx.EVT_BUTTON, self.OnBackward, backward)

ButtonSizer = wx.BoxSizer(wx.HORIZONTAL)

ButtonSizer.Add(forward)

ButtonSizer.Add(backward)

sizer = wx.BoxSizer(wx.VERTICAL)

sizer.Add(ButtonSizer,0,wx.CENTER)

self.SetSizer(sizer)

self.Fit()

Hi Peter,

I might be doing the wrong thing here, but would like to know the answer anyway.

I am attempting to sub-class wx.calendar.CalendarCtrl and create a widget that has a couple of buttons (forward and backwards) that allow traversing the calendar in equal day jumps. But I am not sure how I can get the sizers arranged to show the calendar and the buttons i.e. the following gives me a calendar with the buttons overlaying the calendar. If I add 'sizer.Add(self)' then I lose sight of the buttons and just have the calendar.

What is the correct way to do this please?

Don't know but;-) , what about:

- a panel
- add calendar to it
- add buttons to it
- add calendar and buttons to a sizer and do panel.SetSizer

Hope it helps
Werner

···

On 17/09/2012 09:45, Peter Milliken wrote:

Thanks Werner - I thought of that, but I really wanted the thing to look and act like a calendar i.e. inherit all the methods etc, the buttons were only to advance the selected date by preset increments, so functionally it would indeed look like a calendar - just one that “stepped” as well as allowed selection of individual dates.

Hopefully somebody will be able to answer this one for me, but thanks for the thought! :slight_smile:

···

On Monday, September 17, 2012 8:50:15 PM UTC+10, werner wrote:

Hi Peter,

On 17/09/2012 09:45, Peter Milliken wrote:

I might be doing the wrong thing here, but would like to know the
answer anyway.

I am attempting to sub-class wx.calendar.CalendarCtrl and create a
widget that has a couple of buttons (forward and backwards) that allow
traversing the calendar in equal day jumps. But I am not sure how I
can get the sizers arranged to show the calendar and the buttons i.e.
the following gives me a calendar with the buttons overlaying the
calendar. If I add ‘sizer.Add(self)’ then I lose sight of the buttons
and just have the calendar.

What is the correct way to do this please?

Don’t know but;-) , what about:

  • a panel

  • add calendar to it

  • add buttons to it

  • add calendar and buttons to a sizer and do panel.SetSizer

Hope it helps

Werner

Thanks Werner - I thought of that, but I really wanted the thing to look and
act like a calendar i.e. inherit all the methods etc, the buttons were only
to advance the selected date by preset increments, so functionally it would
indeed look like a calendar - just one that "stepped" as well as allowed
selection of individual dates.

unfortunately, you can't subclass from wx.Window twice -- so you'll
need to use composition here instead.

so subclass from wx.Panel, put your Calendar control and buttons on that.

You can define __getattr__, and delegate the extra methods to your
Calendar control.

However, that may get a bit ugly -- you've got multiple wx.Windows now
-- the host Panel, the Calendar control, and the buttons, so it can be
a unclear to users what method they are really calling, an which one
they want to call.

But this may be a simple enough case that it will work.

-Chris

···

On Mon, Sep 17, 2012 at 4:50 AM, Peter Milliken <peter.milliken@gmail.com> wrote:

Hopefully somebody will be able to answer this one for me, but thanks for
the thought! :slight_smile:

On Monday, September 17, 2012 8:50:15 PM UTC+10, werner wrote:

Hi Peter,

On 17/09/2012 09:45, Peter Milliken wrote:
> I might be doing the wrong thing here, but would like to know the
> answer anyway.
>
> I am attempting to sub-class wx.calendar.CalendarCtrl and create a
> widget that has a couple of buttons (forward and backwards) that allow
> traversing the calendar in equal day jumps. But I am not sure how I
> can get the sizers arranged to show the calendar and the buttons i.e.
> the following gives me a calendar with the buttons overlaying the
> calendar. If I add 'sizer.Add(self)' then I lose sight of the buttons
> and just have the calendar.
>
> What is the correct way to do this please?
Don't know but;-) , what about:

- a panel
- add calendar to it
- add buttons to it
- add calendar and buttons to a sizer and do panel.SetSizer

Hope it helps
Werner

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

--

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

Thanks Chris - I was hoping to avoid that, but if those are the only options…

···

On Tuesday, September 18, 2012 5:06:01 AM UTC+10, Chris Barker wrote:

On Mon, Sep 17, 2012 at 4:50 AM, Peter Milliken > > peter.m...@gmail.com wrote:

Thanks Werner - I thought of that, but I really wanted the thing to look and

act like a calendar i.e. inherit all the methods etc, the buttons were only

to advance the selected date by preset increments, so functionally it would

indeed look like a calendar - just one that “stepped” as well as allowed

selection of individual dates.

unfortunately, you can’t subclass from wx.Window twice – so you’ll

need to use composition here instead.

so subclass from wx.Panel, put your Calendar control and buttons on that.

You can define getattr, and delegate the extra methods to your

Calendar control.

However, that may get a bit ugly – you’ve got multiple wx.Windows now

– the host Panel, the Calendar control, and the buttons, so it can be

a unclear to users what method they are really calling, an which one

they want to call.

But this may be a simple enough case that it will work.

-Chris

Hopefully somebody will be able to answer this one for me, but thanks for

the thought! :slight_smile:

On Monday, September 17, 2012 8:50:15 PM UTC+10, werner wrote:

Hi Peter,

On 17/09/2012 09:45, Peter Milliken wrote:

I might be doing the wrong thing here, but would like to know the

answer anyway.

I am attempting to sub-class wx.calendar.CalendarCtrl and create a

widget that has a couple of buttons (forward and backwards) that allow

traversing the calendar in equal day jumps. But I am not sure how I

can get the sizers arranged to show the calendar and the buttons i.e.

the following gives me a calendar with the buttons overlaying the

calendar. If I add ‘sizer.Add(self)’ then I lose sight of the buttons

and just have the calendar.

What is the correct way to do this please?

Don’t know but;-) , what about:

  • a panel
  • add calendar to it
  • add buttons to it
  • add calendar and buttons to a sizer and do panel.SetSizer

Hope it helps

Werner

To unsubscribe, send email to wxPython-user...@googlegroups.com

or visit http://groups.google.com/group/wxPython-users?hl=en

Christopher Barker, Ph.D.

Oceanographer

Emergency Response Division

NOAA/NOS/OR&R (206) 526-6959 voice

7600 Sand Point Way NE (206) 526-6329 fax

Seattle, WA 98115 (206) 526-6317 main reception

Chris....@noaa.gov