"Custom" LabelBook Layout

Greetings,

I would like to use ditch the menu bar from an application I am writing in favor of LabelBook, however I’ve run into a bit of a snag. I would like to have 4 Tabs, a spacer, then 2 more tabs. I have been able to add a “spacer” by creating an empty page, then disabling the tab for it. The problem with this method is I lose the ctrl+tab navigation once I reach the 4th tab. Basically Ctrl+Tab will no longer advance due to the disabled tab being next in the Tab order.

Is there a better way to add a spacer, or a way to skip the disabled tab? I’m not looking for exact code, just to be pointed in the right direction.

Thanks,

-Mike S

(PS: I would add an example image or code but this computer is flaking out when it tries to connect to my Google Drive)

I would use the LB.EVT_IMAGENOTEBOOK_PAGE_CHANGING event and check if the next tab is disabled. If so, tell it to go to the next tab using something like the ChangeSelection() method.

  • Mike
···

On Thursday, January 30, 2014 3:19:19 PM UTC-6, Mike Stover wrote:

Greetings,

I would like to use ditch the menu bar from an application I am writing in favor of LabelBook, however I’ve run into a bit of a snag. I would like to have 4 Tabs, a spacer, then 2 more tabs. I have been able to add a “spacer” by creating an empty page, then disabling the tab for it. The problem with this method is I lose the ctrl+tab navigation once I reach the 4th tab. Basically Ctrl+Tab will no longer advance due to the disabled tab being next in the Tab order.

Is there a better way to add a spacer, or a way to skip the disabled tab? I’m not looking for exact code, just to be pointed in the right direction.

Thanks,

-Mike S

(PS: I would add an example image or code but this computer is flaking out when it tries to connect to my Google Drive)

My apologies, I accidentally sent my reply directly to Mike Driscoll. Here is what I am using to see if the navigation keys will even attempt to check the tab. So far it has shown me that the the app doesn’t even attempt to look at a disabled tab.

def OnPageChanging(self, event):

newsel = event.GetSelection()

print self.nb.GetEnabled(newsel)

print('Tab: ‘+newsel+’, Enabled: '+str(self.nb.GetEnabled(newsel)))

···

On Thursday, January 30, 2014 4:19:19 PM UTC-5, Mike Stover wrote:

Greetings,

I would like to use ditch the menu bar from an application I am writing in favor of LabelBook, however I’ve run into a bit of a snag. I would like to have 4 Tabs, a spacer, then 2 more tabs. I have been able to add a “spacer” by creating an empty page, then disabling the tab for it. The problem with this method is I lose the ctrl+tab navigation once I reach the 4th tab. Basically Ctrl+Tab will no longer advance due to the disabled tab being next in the Tab order.

Is there a better way to add a spacer, or a way to skip the disabled tab? I’m not looking for exact code, just to be pointed in the right direction.

Thanks,

-Mike S

(PS: I would add an example image or code but this computer is flaking out when it tries to connect to my Google Drive)

You could keep a list of disabled tabs and check if the currently selected tab is in that list. If so, change selection and check again.

Hopefully there’s a better way and someone else will speak up and tell us what it is.

  • Mike
···

On Friday, January 31, 2014 9:27:23 AM UTC-6, Mike Stover wrote:

My apologies, I accidentally sent my reply directly to Mike Driscoll. Here is what I am using to see if the navigation keys will even attempt to check the tab. So far it has shown me that the the app doesn’t even attempt to look at a disabled tab.

def OnPageChanging(self, event):

newsel = event.GetSelection()

print self.nb.GetEnabled(newsel)

print('Tab: ‘+newsel+’, Enabled: '+str(self.nb.GetEnabled(newsel)))

It looks like if the user is attempting to use Ctrl+(shift+)Tab or Page Up/Down to navigate the disabled tab(s) become a impassable wall, and using the *PAGE_CHANGING event to skip the disabled tabs is not going to work. The program literally will not even acknowledge the disabled tab while using mentioned keys to navigate. I tried to leave the tabs enabled and simply skip the disabled one(s) it doesn’t skip the tab(s) at all. Here is the attempt to skip:

In the init:

self.prev_tab = None

def OnPageChanging(self, event):

previous = self.prev_tab

oldsel = event.GetOldSelection()

newsel = event.GetSelection()

if previous <= oldsel and oldsel == 3:

self.nb.AdvanceSelection(5)

elif oldsel == 5 and previous == 0:

self.nb.AdvanceSelection(3)

self.prev_tab = oldsel

print('Previous tab: '+str(previous)+

', Old Selection: '+str(oldsel)+

', New Selection: '+str(newsel)

)

The output in command prompt up to right before reaching the tab that I want to skip:

Previous tab: None, Old Selection: 0, New Selection: 1

Previous tab: 0, Old Selection: 1, New Selection: 2

Previous tab: 1, Old Selection: 2, New Selection: 3

Then when I use the navigation keys to continue:

RuntimeError: maximum recursion depth exceeded in instancecheck

Previous tab: 2, Old Selection: 3, New Selection: 4 (This line is repeated about 163 times, literally)

What am I doing wrong?

Thanks,

-Mike S

···

On Thursday, January 30, 2014 4:19:19 PM UTC-5, Mike Stover wrote:

Greetings,

I would like to use ditch the menu bar from an application I am writing in favor of LabelBook, however I’ve run into a bit of a snag. I would like to have 4 Tabs, a spacer, then 2 more tabs. I have been able to add a “spacer” by creating an empty page, then disabling the tab for it. The problem with this method is I lose the ctrl+tab navigation once I reach the 4th tab. Basically Ctrl+Tab will no longer advance due to the disabled tab being next in the Tab order.

Is there a better way to add a spacer, or a way to skip the disabled tab? I’m not looking for exact code, just to be pointed in the right direction.

Thanks,

-Mike S

(PS: I would add an example image or code but this computer is flaking out when it tries to connect to my Google Drive)

I have also tried self.nb.SetSelection() instead of self.nb.AdvanceSelection() with similar results. Forgot to add that into the previous post.

···

On Friday, January 31, 2014 1:56:52 PM UTC-5, Mike Stover wrote:

It looks like if the user is attempting to use Ctrl+(shift+)Tab or Page Up/Down to navigate the disabled tab(s) become a impassable wall, and using the *PAGE_CHANGING event to skip the disabled tabs is not going to work. The program literally will not even acknowledge the disabled tab while using mentioned keys to navigate. I tried to leave the tabs enabled and simply skip the disabled one(s) it doesn’t skip the tab(s) at all. Here is the attempt to skip:

SNIP

(PS: I would add an example image or code but this computer is flaking out when it tries to connect to my Google Drive)

For now it looks like I will not be adding the blank space between the 2 tabs. I’ll come back to it once I have a better idea on how wxPython / LabelBook is processing the navigation key events.

Thanks,

-Mike S

···

On Friday, January 31, 2014 1:58:50 PM UTC-5, Mike Stover wrote:

I have also tried self.nb.SetSelection() instead of self.nb.AdvanceSelection() with similar results. Forgot to add that into the previous post.

On Friday, January 31, 2014 1:56:52 PM UTC-5, Mike Stover wrote:

It looks like if the user is attempting to use Ctrl+(shift+)Tab or Page Up/Down to navigate the disabled tab(s) become a impassable wall, and using the *PAGE_CHANGING event to skip the disabled tabs is not going to work. The program literally will not even acknowledge the disabled tab while using mentioned keys to navigate. I tried to leave the tabs enabled and simply skip the disabled one(s) it doesn’t skip the tab(s) at all. Here is the attempt to skip:

SNIP

(PS: I would add an example image or code but this computer is flaking out when it tries to connect to my Google Drive)

I know this post was started by me a while ago but, can anyone provide a suggestion on how to accomplish my goal. I was looking through the code for the LabelBook and found the AdvanceSelection function, which with a small tweak should skip the “spacer” tab I am trying to add. I really do not want to adjust the code at the source for various reasons, but still change how it works.

Thanks,

-Mike

···

On Monday, February 3, 2014 2:42:55 PM UTC-5, Mike Stover wrote:

For now it looks like I will not be adding the blank space between the 2 tabs. I’ll come back to it once I have a better idea on how wxPython / LabelBook is processing the navigation key events.

Thanks,

-Mike S

On Friday, January 31, 2014 1:58:50 PM UTC-5, Mike Stover wrote:

I have also tried self.nb.SetSelection() instead of self.nb.AdvanceSelection() with similar results. Forgot to add that into the previous post.

On Friday, January 31, 2014 1:56:52 PM UTC-5, Mike Stover wrote:

It looks like if the user is attempting to use Ctrl+(shift+)Tab or Page Up/Down to navigate the disabled tab(s) become a impassable wall, and using the *PAGE_CHANGING event to skip the disabled tabs is not going to work. The program literally will not even acknowledge the disabled tab while using mentioned keys to navigate. I tried to leave the tabs enabled and simply skip the disabled one(s) it doesn’t skip the tab(s) at all. Here is the attempt to skip:

SNIP

(PS: I would add an example image or code but this computer is flaking out when it tries to connect to my Google Drive)

This sounds like a case for sub-classing the widget you want to customize. So, create a MyLabelBookWithSpacers class that inherits from agw.labelbook, and override the methods that you want to change.

···

On Fri, Apr 18, 2014 at 1:42 PM, Mike Stover hakugin.gin@gmail.com wrote:

I know this post was started by me a while ago but, can anyone provide a suggestion on how to accomplish my goal. I was looking through the code for the LabelBook and found the AdvanceSelection function, which with a small tweak should skip the “spacer” tab I am trying to add. I really do not want to adjust the code at the source for various reasons, but still change how it works.

Thanks,

-Mike

On Monday, February 3, 2014 2:42:55 PM UTC-5, Mike Stover wrote:

For now it looks like I will not be adding the blank space between the 2 tabs. I’ll come back to it once I have a better idea on how wxPython / LabelBook is processing the navigation key events.

Thanks,

-Mike S

On Friday, January 31, 2014 1:58:50 PM UTC-5, Mike Stover wrote:

I have also tried self.nb.SetSelection() instead of self.nb.AdvanceSelection() with similar results. Forgot to add that into the previous post.

On Friday, January 31, 2014 1:56:52 PM UTC-5, Mike Stover wrote:

It looks like if the user is attempting to use Ctrl+(shift+)Tab or Page Up/Down to navigate the disabled tab(s) become a impassable wall, and using the *PAGE_CHANGING event to skip the disabled tabs is not going to work. The program literally will not even acknowledge the disabled tab while using mentioned keys to navigate. I tried to leave the tabs enabled and simply skip the disabled one(s) it doesn’t skip the tab(s) at all. Here is the attempt to skip:

SNIP

(PS: I would add an example image or code but this computer is flaking out when it tries to connect to my Google Drive)

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.


Best Regards,
Michael Moriarity

I got it partially working… The issue is going through the tabs in reverse…

import wx

import wx.lib.agw.labelbook as LB

class MyLabelBook(LB.LabelBook):

def init(self, parent, *args, **kw):

LB.LabelBook.init(self, parent, *args, **kw)

class MyFrame(wx.Frame):

def init(self, parent):

wx.Frame.init(self, parent, -1, “LabelBook Demo”)

self.notebook = LB.LabelBook(self, -1, agwStyle=LB.INB_FIT_LABELTEXT|LB.INB_LEFT|LB.INB_DRAW_SHADOW|LB.INB_GRADIENT_BACKGROUND)

pane_1 = wx.Panel(self.notebook)

pane_2 = wx.Panel(self.notebook)

imagelist = wx.ImageList(32, 32)

self.notebook.AssignImageList(imagelist)

self.notebook.AddPage(pane_1, “Tab1”, 1, 0)

self.notebook.AddPage(pane_2, “Tab2”, 0, 0)

self.notebook.AddPage(pane_2, “Tab3”, 0, 0)

self.notebook.AddPage(pane_2, “Tab4”, 0, 0)

self.notebook.EnableTab(2, False)

self.notebook.Bind(wx.EVT_NAVIGATION_KEY, self.OnNavigationKey)

def OnNavigationKey(self, event):

if event.IsWindowChange():

if self.notebook.GetPageCount() == 0:

return

self._new_AdvanceSelection(event.GetDirection())

else:

event.Skip()

def _new_AdvanceSelection(self, forward=True):

nSel = self.notebook.GetSelection()

if nSel < 0:

return

nMax = self.notebook.GetPageCount() - 1

if forward:

newSelection = (nSel == nMax and [0] or [nSel + 1])[0]

if not self.notebook.GetEnabled(newSelection):

newSelection = (nSel == nMax and [0] or [nSel + 2])[0]

else:

newSelection = (nSel == 0 and [nMax] or [nSel - 1])[0]

if not self.notebook.GetEnabled(newSelection):

newSelection = (nSel == nMax and [0] or [nSel - 1])[0] # Tried -2, and others… doesn’t work.

self.notebook.SetSelection(newSelection)

def Main():

app = wx.App(0)

frame = MyFrame(None)

app.SetTopWindow(frame)

frame.Show()

app.MainLoop()

if name == ‘main’:

Main()

Any suggestions?

···

On Thursday, January 30, 2014 4:19:19 PM UTC-5, Mike Stover wrote:

Greetings,

I would like to use ditch the menu bar from an application I am writing in favor of LabelBook, however I’ve run into a bit of a snag. I would like to have 4 Tabs, a spacer, then 2 more tabs. I have been able to add a “spacer” by creating an empty page, then disabling the tab for it. The problem with this method is I lose the ctrl+tab navigation once I reach the 4th tab. Basically Ctrl+Tab will no longer advance due to the disabled tab being next in the Tab order.

Is there a better way to add a spacer, or a way to skip the disabled tab? I’m not looking for exact code, just to be pointed in the right direction.

Thanks,

-Mike S

(PS: I would add an example image or code but this computer is flaking out when it tries to connect to my Google Drive)

Whoops, nevermind on the reverse navigation… I goofed up and copied the wrong line.

else:

newSelection = (nSel == 0 and [nMax] or [nSel - 1])[0]

if not self.notebook.GetEnabled(newSelection):

newSelection = (nSel == nMax and [0] or [nSel - 1])[0]

Should read:

else:

newSelection = (nSel == 0 and [nMax] or [nSel - 1])[0]

if not self.notebook.GetEnabled(newSelection):

newSelection = (nSel == 0 and [nMax] or [nSel - 2])[0]

···

On Thursday, January 30, 2014 4:19:19 PM UTC-5, Mike Stover wrote:

Greetings,

I would like to use ditch the menu bar from an application I am writing in favor of LabelBook, however I’ve run into a bit of a snag. I would like to have 4 Tabs, a spacer, then 2 more tabs. I have been able to add a “spacer” by creating an empty page, then disabling the tab for it. The problem with this method is I lose the ctrl+tab navigation once I reach the 4th tab. Basically Ctrl+Tab will no longer advance due to the disabled tab being next in the Tab order.

Is there a better way to add a spacer, or a way to skip the disabled tab? I’m not looking for exact code, just to be pointed in the right direction.

Thanks,

-Mike S

(PS: I would add an example image or code but this computer is flaking out when it tries to connect to my Google Drive)

Well, you aren’t using your sub-class for anything. Instead of this line:

self.notebook = LB.LabelBook(self, -1, agwStyle=LB.INB_FIT_LABELTEXT|LB.INB_LEFT|LB.INB_DRAW_SHADOW|LB.INB_GRADIENT_BACKGROUND)

you should use:

self.notebook = MyLabelBook(self, -1, agwStyle=LB.INB_FIT_LABELTEXT|LB.INB_LEFT|LB.INB_DRAW_SHADOW|LB.INB_GRADIENT_BACKGROUND)

Then, you create a method for MyLabelBook, named AdvanceSelection, and call that, instead of writing the method in the frame class as _new_AdvanceSelection. At least, that’s how I would do it.

···

On Fri, Apr 18, 2014 at 4:15 PM, Mike Stover hakugin.gin@gmail.com wrote:

Whoops, nevermind on the reverse navigation… I goofed up and copied the wrong line.

else:

newSelection = (nSel == 0 and [nMax] or [nSel - 1])[0]

if not self.notebook.GetEnabled(newSelection):

newSelection = (nSel == nMax and [0] or [nSel - 1])[0]

Should read:

else:

newSelection = (nSel == 0 and [nMax] or [nSel - 1])[0]

if not self.notebook.GetEnabled(newSelection):

newSelection = (nSel == 0 and [nMax] or [nSel - 2])[0]

On Thursday, January 30, 2014 4:19:19 PM UTC-5, Mike Stover wrote:

Greetings,

I would like to use ditch the menu bar from an application I am writing in favor of LabelBook, however I’ve run into a bit of a snag. I would like to have 4 Tabs, a spacer, then 2 more tabs. I have been able to add a “spacer” by creating an empty page, then disabling the tab for it. The problem with this method is I lose the ctrl+tab navigation once I reach the 4th tab. Basically Ctrl+Tab will no longer advance due to the disabled tab being next in the Tab order.

Is there a better way to add a spacer, or a way to skip the disabled tab? I’m not looking for exact code, just to be pointed in the right direction.

Thanks,

-Mike S

(PS: I would add an example image or code but this computer is flaking out when it tries to connect to my Google Drive)

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.


Best Regards,
Michael Moriarity

I forgot to remove that subclass, for some reason I couldn't get the changed AdvanceSelection function / method to work there even when it was named AdvanceSelection. I'll post the error when I get access to a pc again, currently stuck in traffic.

Here is the working sample using a subclass. I would have posted it over the weekend but was extremely busy with it being Easter weekend and all.

import wx

import wx.lib.agw.labelbook as LB

class MyLabelBook(LB.LabelBook):

def AdvanceSelection(self, forward=True):

nSel = self.GetSelection()

if nSel < 0:

return

nMax = self.GetPageCount() - 1

if forward:

newSelection = (nSel == nMax and [0] or [nSel + 1])[0]

if not self.GetEnabled(newSelection):

newSelection = (nSel == nMax and [0] or [nSel + 2])[0]

else:

newSelection = (nSel == 0 and [nMax] or [nSel - 1])[0]

if not self.GetEnabled(newSelection):

newSelection = (nSel == 0 and [nMax] or [nSel - 2])[0]

self.SetSelection(newSelection)

class MyFrame(wx.Frame):

def init(self, parent):

wx.Frame.init(self, parent, -1, “LabelBook Demo”)

self.notebook = MyLabelBook(self, -1, agwStyle=LB.INB_FIT_LABELTEXT|LB.INB_LEFT|LB.INB_DRAW_SHADOW|LB.INB_GRADIENT_BACKGROUND)

pane_1 = wx.Panel(self.notebook)

pane_2 = wx.Panel(self.notebook)

imagelist = wx.ImageList(32, 32)

self.notebook.AssignImageList(imagelist)

self.notebook.AddPage(pane_1, “Tab1”, 1, 0)

self.notebook.AddPage(pane_2, “Tab2”, 0, 0)

self.notebook.AddPage(pane_2, “”, 0, 0)

self.notebook.AddPage(pane_2, “Tab4”, 0, 0)

self.notebook.EnableTab(2, False)

def Main():

app = wx.App(0)

frame = MyFrame(None)

app.SetTopWindow(frame)

frame.Show()

app.MainLoop()

if name == ‘main’:

Main()

Tested on:

Win7 32bit, PortablePython 2.7.5, wxPython 2.9.5.0 (Classic)

···

On Friday, April 18, 2014 5:51:06 PM UTC-4, Mike Stover wrote:

I forgot to remove that subclass, for some reason I couldn’t get the changed AdvanceSelection function / method to work there even when it was named AdvanceSelection. I’ll post the error when I get access to a pc again, currently stuck in traffic.