I have a situation where I need to check a condition after the user clicks on a tab before the tab changes. Another way of putting it is I need a “Before Change” event for the Tab Panel. There’s a in-depth discussion from the Nugs Archive 17 years ago
that addresses the very thing I’m trying to do but unfortunately never came to a working conclusion. Using Mouse Down in the Tab Panel comes close (albeit you have to check to see if the user clicked within the coordinates of the tabs themselves) but it doesn’t seem to return control to the point where the user clicked the tab.
Does anybody have any idea how I can do this? If the answer is a sub-classed Tab Panel with a new event (“Before Change”) can someone give me a head start on how to do this (I’ve created simple sub-classed controls but this one is out of my pay grade )
You can do both, the event is called before the change, if you return True it will cancel the action, akin to some other events in xojo but you can change it to whatever you want, the code is there mainly for the detection of the hit.
Precisely, Tim. I have a routine that checks for “all data entered” and one that compares two fields to assure they equal each other on Tab 0. All of the calculations and other functionality on all the tabs after the Tab 0 depend on those conditions being met before they can yield the proper information.
I do this in my Prefs tabpanel when the user changes a pref and tries to change tab without having saved or reverted the change. I’ll have a look to remind myself of what I do to effect that (IIRC, it’s also different under Linux).
If the user does something such as change a pref, I set a flag and make a note of which the current tab is. If the user tries to change tab, then in the tabpanel’s Change event, if the flag is NOT set, I just return (thus allowing the change to the tabpanel to stand). I also just return if the user has clicked the tab that’s actually showing.
Undoing the change: For Win/macOS, just set the tabpanel’s SelectedPanelIndex back to the saved value. For Linux this doesn’t work, I have to set a timer which runs for one msec, and reset the SelectedPanelIndex in the timer’s Action event handler.
Thanks so much for sharing your methodology with me, Tim. The setup I had before I posted this question was almost identical to yours with the exception that I had a message dialog in the Change event that informed the user that all data was not present and therefore control was returning to the calling tab. The problem I had was that the tab would actually change, then the message showed. Control would return properly to the calling tab upon the user’s confirmation of the message (e.g., clicking “OK” to the dialog). The problem there was I didn’t want the tab to change (I wanted it to stay on the calling tab) when data on the calling tab was not complete.
The difference that stands out between what you do and what I tried is the presence of a message dialog in my code. I’m going to try your method to see if the lack of a message dialog interrupting the flow makes a difference. Now, my curiosity is killing me!
Thanks again, Tim … I sincerely appreciate your time taken to try and help me,
No, it gets written by the Change event handler to the message area of the tab you don’t want to change from.
Unfortunately, when creating all this, I made the tabpanel use the entire window it’s in, thus forcing me to put a copy of the message area on each tab. Well - perhaps not so serious, I needed a copy of the OK and Cancel/Revert buttons on each tab anyway, as each has to do different things.
There’s many controls that would benefit from additional events but I feel that Xojo likes to keep things simple. It’s a shame that they don’t implement them behind an advanced feature checkbox if they wanted to keep barrier to entry nice and low.