
displaying/hiding a graph on a tab in a panel

igorisfun
Function my_panel() my_globals() //makes some globals PauseUpdate; Silent 1 // building window... NewPanel/N=my_panel/K=1 /W=(104,71,804,621) as "My Panel" ModifyPanel fixedSize=1 SetDrawLayer UserBack SetDrawEnv fsize= 28,fstyle= 1,textrgb= (1,1,1) DrawText 10,33,"My Panel Aide" TabControl size_cal_tab,pos={5,70},size={690,475},proc=my_tabcontrol TabControl size_cal_tab,tabLabel(0)="Tab1",tabLabel(1)="Tab2", tabLabel(2)="Tab3", tabLabel(3)="Tab4" //a bunch of extraneous code that successfully creates controls, e.g. buttons, setvars, etc. display/N=not_graph/HOST=my_panel0 root:testwv //not sure why NewPanel appends 0 to the end of the panel name but it does... End Function my_tabcontrol(ctrlName, tabNum) : TabControl String ctrlName Variable tabNum variable cont_disp,idex,nCont string cont_list, cont_item cont_list=controlnamelist("") nCont=itemsinlist(cont_list) for (idex=0;idex<nCont;idex+=1) cont_item=stringfromlist(idex,cont_list) strswitch (cont_item[0,3]) //...... //extraneous code that successfully hides/shows controls like buttons when various tabs are clicked endfor string myWInList, winStr variable num myWInList = ChildWindowList("my_panel0") num= ItemsInList(myWinList) for(idex=0;idex<num;idex+=1) winStr = stringFromList(idex, myWInList) if(tabNum!=1) if (stringmatch("not", winStr[0,2]) ) KillWindow $"my_Panel0#"+winStr endif endif endfor End
When clicking a tab that is not tab 1 (0th indexed), the graph display of testwv is successfully killed. The problem is that 1) the graph is displayed on tab 0 at startup of the panel and 2) the graph does not reappear if it is killed and then the user clicks on tab 1...
Is there a better method to write the display command? Do I need to use something akin to what is in the
DisplayHelpTopic "TabControl"
where it discusses using a predefined structure WMTabControlAction
? Will I need to rewrite my above tabcontrol to fit in that or can i add it for only 1 specific tab?
Instead of killing your graph, how about hiding it? SetWindow $"my_Panel0#"+winStr, hide = 1 or 0
You should be able to create the graph hidden with Display/HIDE=1. That has some problems sometimes, but you could give it a try. Things that don't work that way are likely bugs, which you will report to us :)
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
January 23, 2018 at 12:07 pm - Permalink
I rewrote my tab control in the form:
I know it's not the most elegant solution, but it works for my purposes of learning igor structures and tabs...
The above code works for me as long as I put a setwindow hide=1 right after the display command in the panel creation function.
However....the popupsetvars from my other question are not hiding correctly. The title of them disappears but the outline and arrow to bring up the popup box remain. Not sure if that is a bug or my own poor programming.
EDIT: using the old style of tabcontrol, the popupsetvars do disappear completely on the non-relevant tabs
January 23, 2018 at 09:37 pm - Permalink
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
January 24, 2018 at 09:39 am - Permalink
Using version 6.3.7.2. Unable to upgrade to 7 yet because some of the custom ipf's I use have not been fully error checked in 7...
Both the old style and new style tab controls are there, just comment/decomment the appropriate 2 lines in size_cal_panel()
Also, I know that a better way to write the new style tabcontrol for hiding the tab buttons would be to rename the tabs to something procedural (e.g. tab0_*, tab1_*, etc) but I already started this way and don't want to rework it right now. If you have a suggestion of a way to do the modifycontrollist calls in 1 call instead of 4, without renaming anything, I'd love to hear it though!
January 24, 2018 at 11:24 pm - Permalink
Is it possible to trick the new style tabcontrol into thinking an event code is being sent from something else? I would like to make the tab advance when the user clicks a button. For the old style tab control I have above, all I need to do is size_cal_tabcontrol("windowname",tabnumber) but it's less obvious if i can pass a tca.eventcode=2, tca.tab=1 kind of argument in the new style...
January 25, 2018 at 01:41 am - Permalink
Is it possible to trick the new style tabcontrol into thinking an event code is being sent from something else? I would like to make the tab advance when the user clicks a button. For the old style tab control I have above, all I need to do is size_cal_tabcontrol("windowname",tabnumber) but it's less obvious if i can pass a tca.eventcode=2, tca.tab=1 kind of argument in the new style...
January 25, 2018 at 01:41 am - Permalink
Assuming that you want to create a function that calls your tabcontrol function, the answer is yes.
You can create an instance of the tabcontrol structure and pass it to your tabcontrol fuction. Just initialize the elements of the structure that your tabcontrol function needs.
January 25, 2018 at 06:04 am - Permalink
Yes, this _can_ be done. The better approach and habit to cultivate is however to create a function that is dedicated solely to switch the tab. Call it when the user clicks the button. The temptation to use a different function to populate the structure that is passed to a panel control panel control opens the door to complications that eventually are not worth the effort. For example ... Gosh, this should work. (three days of hair pulling effort later) ... Oh! I forgot to define this specific element of the structure that I pass to the tabcontrol function and so the code is just jumping out on entry. (speaking from experience here).
--
J. J. Weimer
Chemistry / Chemical & Materials Engineering, UAH
January 25, 2018 at 07:06 am - Permalink
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
January 25, 2018 at 12:53 pm - Permalink
Can you tell us how to run it so that we can see the problem? It would be helpful if the instructions include some comments like, "at this point you should see..., but instead it shows (or doesn't show) this thing...".
John Weeks
WaveMetrics, Inc.
support@wavemetrics.com
January 25, 2018 at 12:57 pm - Permalink
I might bump this after nearly a year. I have found some odd behavior with ModifyControlList. Sometimes, it gives an error "Expected control name" (or equivalent). This seems to be especially true immediately after the controls are added to the panel.
I have found that this problem disappears when I add a ControlUpdate/A/W=... BEFORE I do any modifications to show/hide. So, the properly working code might have to look like this ...
December 26, 2019 at 02:11 pm - Permalink
So, after further testing, I have a MWE to demonstrate the problem. When controls are located on sub-window panels, you must use the SetActiveSubWindow operation BEFORE the ModifyControlList. Otherwise, you run the danger that, when you click off the panel itself, ModifyControlList will not recognize where the controls are located.
Run MakeGraph().
Run TestOnOff(...) with either 1 or 0.
Now, comment out the SetActiveSubWindow operation. Go to the graph and "touch" it to make it active (in the front of the sub-window panel).
Re-run the TestOnOff(...) function. You should get an error that
--> While executing ModifyControlList, the following error occurred: Expected control name
It seems that perhaps ModifyControlList could benefit by a /W=winname flag.
January 12, 2020 at 04:10 pm - Permalink
Add the win= keyword to the command.
January 13, 2020 at 09:22 am - Permalink
Oh. Yes. I see it now in the list. Apologies and thanks!!!
January 13, 2020 at 10:54 am - Permalink
It took me a while to see it in the list, too.
January 13, 2020 at 12:33 pm - Permalink