Toolbar creation - correct method?

Thank you for reading this.

I have a working toolbar but I'm not sure if it's technically correct; I like to do things correctly. I have attached a short section of code.

Also, I note that some GUI options are only available through Microsoft's Windows; I'm a Linux user. I wanted to add ticks to a slider but that seems to be not available to Linux users. However, EVT_SCROLL_CHANGED is listed as only being available in Windows but I found that it works under Linux.

I have experimented with wx.BoxSizer but didn't get very far. Is this the preferred method to add controls to a toolbar?

wxpython question (732 Bytes)

···

--
Regards,
Phil

Thank you for reading this.

I have a working toolbar but I’m not sure if it’s technically correct; I
like to do things correctly. I have attached a short section of code.

Normally AddTool would be used to add toobar buttons, including radio or toggle items. That will ensure that they will be native and look and feel just like toolbars in other applications on the platform. AddControl can be used when you want to have non-button things on the bar, but should be used sparingly.

Also, I note that some GUI options are only available through
Microsoft’s Windows; I’m a Linux user. I wanted to add ticks to a slider
but that seems to be not available to Linux users. However,
EVT_SCROLL_CHANGED is listed as only being available in Windows but I
found that it works under Linux.

I have experimented with wx.BoxSizer but didn’t get very far. Is this
the preferred method to add controls to a toolbar?

Toolbars already manage the layout of the tool items and controls, so there is no need to use a sizer with them. In addition, if you use the frame’s SetToolBar method then the frame will manage the layout of the toolbar itself, so no need to put it in a sizer either.

···

On Monday, June 3, 2019 at 10:48:31 PM UTC-7, Phil wrote:

Robin

Thank you for your reply Robin,

I have found that AddTool and AddControl aren't interchangeable, AddTool seems to require that the tool be an int type.

I'm afraid that I need some hand-holding, the following doesn't satisfy the requirements:;

self.tbutton = wx.ToggleButton(tb, -1, "Stop")

tb.AddTool(self.tbutton)

···

On 6/6/19 12:15 pm, Robin Dunn wrote:

Normally AddTool would be used to add toobar buttons, including radio or toggle items. That will ensure that they will be native and look and feel just like toolbars in other applications on the platform. AddControl can be used when you want to have non-button things on the bar, but should be used sparingly.

--

Regards,
Phil

The integer is just an ID to associate with the tool for accessing it later, etc. Just like menu items you can just pass wx.ID_ANY to let wx generate one for you, and then use the returned item for later access to the item. For example:

    tool = tb.AddTool(wx_ID_ANY, "Checkable", images.Tog1.GetBitmap(),

                      shortHelp="Toggle this",  kind=wx.ITEM_CHECK)

    self.Bind(wx.EVT_TOOL, self.OnToggleToolClick, tool)
···

On Wednesday, June 5, 2019 at 7:38:18 PM UTC-7, Phil wrote:

On 6/6/19 12:15 pm, Robin Dunn wrote:

Normally AddTool would be used to add toobar buttons, including radio
or toggle items. That will ensure that they will be native and look
and feel just like toolbars in other applications on the platform.
AddControl can be used when you want to have non-button things on the
bar, but should be used sparingly.

Thank you for your reply Robin,

I have found that AddTool and AddControl aren’t interchangeable, AddTool
seems to require that the tool be an int type.

I’m afraid that I need some hand-holding, the following doesn’t satisfy
the requirements:;

Robin

Thank you Robin for your explanation and the example.

···

On 7/6/19 1:28 am, Robin Dunn wrote:

The integer is just an ID to associate with the tool for accessing it later, etc. Just like menu items you can just pass wx.ID_ANY to let wx generate one for you, and then use the returned item for later access to the item. For example:
tool = tb.AddTool(wx_ID_ANY, "Checkable", images.Tog1.GetBitmap(),
shortHelp="Toggle this", kind=wx.ITEM_CHECK)
self.Bind(wx.EVT_TOOL, self.OnToggleToolClick, tool)

--
Regards,
Phil

The integer is just an ID to associate with the tool for accessing it later, etc. Just like menu items you can just pass wx.ID_ANY to let wx generate one for you, and then use the returned item for later access to the item. For example:
tool = tb.AddTool(wx_ID_ANY, "Checkable", images.Tog1.GetBitmap(),shortHelp="Toggle this", kind=wx.ITEM_CHECK)

self.Bind(wx.EVT_TOOL, self.OnToggleToolClick, tool)

I had some difficulty interpreting the given example and I have attached amendments that at least create a working toolbar.

What I'd like to do is have two images (ellipse_blue.png and ellipse_green.png) that swap depending if the button is down or up.

My effort centred around the OnToggleToolClick(self, event) procedure using something similar to:

     btnLabel = self\.tbutton\.GetLabel\(\)

     if btnLabel == "Stop":

         then do this

There doesn't appear to be an equivalent to get the button image so I'm thinking that this is not going to lead anywhere.

I have searched for an example but haven't come up with anything.

wxpython question (267 Bytes)

···

On 7/6/19 1:28 am, Robin Dunn wrote:

--

Regards,
Phil

Take a look at toolbar.SetToolNormalBitmap

https://docs.wxpython.org/wx.ToolBar.html#wx.ToolBar.SetToolNormalBitmap

···

On Friday, June 7, 2019 at 12:40:14 AM UTC-7, Phil wrote:

What I’d like to do is have two images (ellipse_blue.png and
ellipse_green.png) that swap depending if the button is down or up.

My effort centred around the OnToggleToolClick(self, event) procedure
using something similar to:

Robin

Thank you Robin, that problem is now solved.

One last question on this subject, how do I check if the toggle button is pressed or not? I have tried GetValue() but that doesn't seem to be the correct method in this instance and event.IsChecked. IsChecked lets me know that the button is pressed but there doesn't seem to be anything like IsNotChecked.

I have attached about ten lines of code.

wxpython question (524 Bytes)

···

On 8/6/19 1:03 am, Robin Dunn wrote:

Take a look at toolbar.SetToolNormalBitmap

wx.ToolBar — wxPython Phoenix 4.2.2 documentation

--

Regards,
Phil

See wx.ToolBar.GetToolState

https://docs.wxpython.org/wx.ToolBar.html#wx.ToolBar.GetToolState

···

On Friday, June 7, 2019 at 7:00:00 PM UTC-7, Phil wrote:

On 8/6/19 1:03 am, Robin Dunn wrote:

Take a look at toolbar.SetToolNormalBitmap

https://docs.wxpython.org/wx.ToolBar.html#wx.ToolBar.SetToolNormalBitmap

Thank you Robin, that problem is now solved.

One last question on this subject, how do I check if the toggle button
is pressed or not? I have tried GetValue() but that doesn’t seem to be
the correct method in this instance and event.IsChecked. IsChecked lets
me know that the button is pressed but there doesn’t seem to be anything
like IsNotChecked.

Robin

Of course, I don't know how I missed that.

I'm finding that wxPython is generally logical and intuitive to use, even for an old duffer like me.

···

On 9/6/19 4:30 am, Robin Dunn wrote:

See wx.ToolBar.GetToolState

wx.ToolBar — wxPython Phoenix 4.2.2 documentation

--

Regards,
Phil