Hide/Remove a Toolbar

Hi all,

I have a problem hiding a toolbar.
My application is as such:

frame

    toolbar

    panel

     
  SplitterWindow.  

When I use toolbar.Hide() to
remove the toolbar I need the splitter to expand to fill the space that
the toolbar has made free but I can’t find a way to make this happen. Hide
just leaves a big blank space at the top of the frame where the toolbar
used to be. I’ve tried a few things, a Refresh() on the frame, panel,
splitter and everything else inbetween with no result. The panel
has a Sizer which I tried a Layout() on. Nothing works - what am
I doing wrong?

Thanks

Bones

···
  • NOTICE FROM DIMENSION DATA AUSTRALIA

This message is confidential, and may contain proprietary or legally privileged information. If you have received this email in error, please notify the sender and delete it immediately.

Internet communications are not secure. You should scan this message and any attachments for viruses. Under no circumstances do we accept liability for any loss or damage which may result from your receipt of this message or any attachments.


You will proabbly have to entirely remove the toolbar by calling frame.SetToolBar(None). Then you can either Destroy or Hide the toolbar.

···

Greg.Lucas-Smith@didata.com.au wrote:

Hi all,

  I have a problem hiding a toolbar. My application is as such:

frame
        toolbar
        panel
                SplitterWindow.

  When I use toolbar.Hide() to remove the toolbar I need the splitter to expand to fill the space that the toolbar has made free but I can't find a way to make this happen. Hide just leaves a big blank space at the top of the frame where the toolbar used to be. I've tried a few things, a Refresh() on the frame, panel, splitter and everything else inbetween with no result. The panel has a Sizer which I tried a Layout() on. Nothing works - what am I doing wrong?

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

This is what I use:

def toggleToolbar(self, event):
     self.GetToolBar().Show(event.IsChecked())
     self.SendSizeEvent()

self is the main window of the app (a subclass of wx.Frame). It is called from a checkable menu item.

The same works for the statusbar btw:

def toggleStatusBar(self, event):
     self.GetStatusBar().Show(event.IsChecked())
     self.SendSizeEvent()

Cheers, Frank

···

Greg.Lucas-Smith@didata.com.au wrote:

Hi all,

  I have a problem hiding a toolbar.

Thanks for your reply!

  I tried your suggestion and the frame did change, but rather that
fill the gap at the top of the frame, it made the main window (the
splitter) bigger at the bottom (past the bottom edge of the frame) and
still left a big blank spot at the top. Is this because the toolbar
still exists and the frame is allowing for it?

  Any other ideas?

Thanks,

Bones

···

On Thu, 11 Nov 2004 22:23:15 +0100, Frank Niessink <frankn@cibit.nl> wrote:

Greg.Lucas-Smith@didata.com.au wrote:
>
> Hi all,
>
> I have a problem hiding a toolbar.

This is what I use:

def toggleToolbar(self, event):
     self.GetToolBar().Show(event.IsChecked())
     self.SendSizeEvent()

self is the main window of the app (a subclass of wx.Frame). It is
called from a checkable menu item.

The same works for the statusbar btw:

def toggleStatusBar(self, event):
     self.GetStatusBar().Show(event.IsChecked())
     self.SendSizeEvent()

Cheers, Frank

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

Heres the code for the problem below, man this is frustrating!

self.SetToolBar(None)
self.toolbar.Show(False)
self.SendSizeEvent()

  Where self is obviously the frame.

···

On Fri, 12 Nov 2004 08:45:40 +0800, Greg Lucas-Smith <bwobbones@gmail.com> wrote:

Thanks for your reply!

  I tried your suggestion and the frame did change, but rather that
fill the gap at the top of the frame, it made the main window (the
splitter) bigger at the bottom (past the bottom edge of the frame) and
still left a big blank spot at the top. Is this because the toolbar
still exists and the frame is allowing for it?

  Any other ideas?

Thanks,

Bones

On Thu, 11 Nov 2004 22:23:15 +0100, Frank Niessink <frankn@cibit.nl > wrote:
> Greg.Lucas-Smith@didata.com.au wrote:
> >
> > Hi all,
> >
> > I have a problem hiding a toolbar.
>
> This is what I use:
>
> def toggleToolbar(self, event):
> self.GetToolBar().Show(event.IsChecked())
> self.SendSizeEvent()
>
> self is the main window of the app (a subclass of wx.Frame). It is
> called from a checkable menu item.
>
> The same works for the statusbar btw:
>
> def toggleStatusBar(self, event):
> self.GetStatusBar().Show(event.IsChecked())
> self.SendSizeEvent()
>
> Cheers, Frank
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
>
>

Greg Lucas-Smith wrote:

Heres the code for the problem below, man this is frustrating!

self.SetToolBar(None) self.toolbar.Show(False)
self.SendSizeEvent()

  Where self is obviously the frame.

What happens if you remove the first line? So just:

self.toolbar.Show(False)
self.SendSizeEvent()

Cheers, Frank

Nothing happens. It doesn't even push the splitterwindow down as I
described. Could the splitter be controlling it's own starting
position? I thought the frame would do that, but obviously not! Any
other ideas?

Bones

···

On Fri, 12 Nov 2004 21:16:12 +0100, Frank Niessink <frankn@cibit.nl> wrote:

Greg Lucas-Smith wrote:
> Heres the code for the problem below, man this is frustrating!
>
> self.SetToolBar(None)
> self.toolbar.Show(False)
> self.SendSizeEvent()
>
> Where self is obviously the frame.

What happens if you remove the first line? So just:

self.toolbar.Show(False)
self.SendSizeEvent()

Cheers, Frank

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

Thanks for your suggestions, a combination of these and a:

wxLayoutAlgorithm().LayoutWindow(self, self.panel)

has done the job.

Bones

···

On Sun, 14 Nov 2004 20:13:48 +0800, Greg Lucas-Smith <bwobbones@gmail.com> wrote:

Nothing happens. It doesn't even push the splitterwindow down as I
described. Could the splitter be controlling it's own starting
position? I thought the frame would do that, but obviously not! Any
other ideas?

Bones

On Fri, 12 Nov 2004 21:16:12 +0100, Frank Niessink <frankn@cibit.nl > wrote:
> Greg Lucas-Smith wrote:
> > Heres the code for the problem below, man this is frustrating!
> >
> > self.SetToolBar(None)
> > self.toolbar.Show(False)
> > self.SendSizeEvent()
> >
> > Where self is obviously the frame.
>
> What happens if you remove the first line? So just:
>
>
>
> self.toolbar.Show(False)
> self.SendSizeEvent()
>
> Cheers, Frank
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
> For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
>
>

Here is a full example - press enter to make the toolbar hide and show:

import wx
from traceback import print_exc

class HideToolbarTest(wx.Frame):
    def __init__(self):
        wx.Frame.__init__(self, None, -1, "ToolbarTest", size = (666,480), style = wx.DEFAULT_FRAME_STYLE)
        panel = wx.Panel(self, -1)
        self.panel = panel
        panel.SetSize(self.GetClientSize())
        panel.SetBackgroundColour(wx.NamedColour("WHITE"))
               toolbar = self.CreateToolBar( wx.TB_HORIZONTAL|wx.NO_BORDER|wx.TB_FLAT|wx.TB_TEXT)
        self.toolbar = toolbar
        toolbar.AddTool(101, wx.Bitmap("greg.bmp", wx.BITMAP_TYPE_BMP), wx.NullBitmap, False, "", "Help String", "Help String") toolbar.AddSeparator()
        toolbar.AddTool(102, wx.Bitmap("greg.bmp", wx.BITMAP_TYPE_BMP), wx.NullBitmap, False, "", "Help String", "Help String")
        self.Bind(wx.EVT_TOOL, self.ButtonPressed, id=101)
        self.Bind(wx.EVT_TOOL, self.ButtonPressed, id=102)
        toolbar.Realize()
        self.SetToolBar(toolbar)
               panel.Bind(wx.EVT_KEY_DOWN, self.OnKeyDown)
               self.Show(True)
           def ButtonPressed(self, event):
        print "hello"
           def OnKeyDown(self, evt):
        if evt.KeyCode() == wx.WXK_RETURN:
            if self.toolbar.IsShown():
                self.toolbar.Show(False)
            else:
                self.toolbar.Show(True)
            # this is the important bit - instruct the frame to recalculate its component locations
            wx.LayoutAlgorithm().LayoutWindow(self, self.panel)
       class MyApp(wx.App):
    def __init__(self, flag):
        wx.App.__init__(self, flag)
          def OnInit(self):
        frame = HideToolbarTest()
        self.SetTopWindow(frame)
        return True

def run():
    try:
        app = MyApp(False)
        app.MainLoop()
    except:
        print print_exc()
       if __name__ == '__main__':
    run()

Frank Niessink wrote:

···

Greg Lucas-Smith wrote:

Nothing happens. It doesn't even push the splitterwindow down as I
described. Could the splitter be controlling it's own starting
position? I thought the frame would do that, but obviously not! Any
other ideas?

Could you post a short, but complete, sample that demonstrates the problem?

Thanks, Frank

bwobbones wrote:

Robin,

Thanks for the update, but a question about the overhead of destroying/creating a toolbar everytime? The app I'm writing that inspired this question has quite a complex toolbar, when I do as you suggest there is a noticable flicker in the window. Is there any other way?

Yes. Don't allow the frame to manage the toolbar itself, (don't use CreateToolBar or SetToolBar.) Instead use a sizer to manage the size and placement of the toolbar and the panel yourself, and call sizer.Hide(toolbar) or sizer.Show(toolbar)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Robin Dunn wrote:

Yes. Don't allow the frame to manage the toolbar itself, (don't use CreateToolBar or SetToolBar.) Instead use a sizer to manage the size and placement of the toolbar and the panel yourself

There is an example of this in the Wiki

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                         
NOAA/OR&R/HAZMAT (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

OK,

  I've put the toolbar in a sizer with

  sizer = wx.BoxSizer(wx.VERTICAL)
  sizer.Add(toolbar, 0, wx.ALIGN_TOP)

  and now all of the buttons on the toolbar are inactive (not sending events). Any ideas? I've tried

  wx.EVT_TOOL(self, 101, self.Function)
  self.Bind(wx.EVT_TOOL, self.Func, id=101)

  and for fun:

  self.Bind(wx.EVT_TOOL_ENTER, self.Test, id=101)

  All with no effect - the buttons appear on the screen but won't click or show any sign of being a button (or useful at all). I'm really trying here!

Bones.

Chris Barker wrote:

···

Robin Dunn wrote:

Yes. Don't allow the frame to manage the toolbar itself, (don't use CreateToolBar or SetToolBar.) Instead use a sizer to manage the size and placement of the toolbar and the panel yourself

There is an example of this in the Wiki

-Chris