Button creation on the fly
maxifox
Posts: 209
I have to create a page with a number of buttons. The trick is that initally (at the moment of page creation) number of buttons is not known and must be defined later (in run-time) by Netlinx code.
Any idea how to achive the goal in the most effective way?
Indeed, this is a well known situation for SAT decoder channel list... Thanks in advance for all the comment...
Update: this is for G4.
Any idea how to achive the goal in the most effective way?
Indeed, this is a well known situation for SAT decoder channel list... Thanks in advance for all the comment...
Update: this is for G4.
0
Comments
However, I don't think you can create, resize, or reposition buttons in code, just hide or show them. Which perhaps is just as well, so you can assure some level of pleasant appearance. I undertand you once could create an entire panel in code by sending commands to the panel, creating pages and buttons on the fly and destroying them as you move on...at least I recall stories of someone doing that in a training class. This guy purportedly just plugged a blank panel in, and the controller (Axcent series yet) drew the screens.
That's just too much work .
What I do is set an upper limit on the number buttons I want available, create them all, and place them on the page in such a way that I can make them vanish without making it look funky. I make them multi-state bargraphs with three states (though I have more on occassion) - completely transparent, off, and on. Then I track in code which buttons will be active . The ones that are not, I send the level to them that makes them transparent, and ignore any pushes that might come in on them. the ones that are get the appropriate level for their state. This gets ugly when you have a lot of buttons, there is no graceful way to put 30 buttons on a page, then make all but 3 vanish. So I generally only do this when I have a function that might become unavailable under certain conditions. Sometimes I'll have a grey state for it, and sometimes I'll just make it vanish.
The other thing I have done with dynamic buttons is take the opposite approach - put just a few buttons on a page, and treat them like a sliding index to the total data set. If you have five buttons on a page, and 100 functions (which could be channels, or media tracks or titles), your top button indicates where in the list you are - if you are at the top, it's number one. If you are ten pages down, it's number 45. You then send a variable text based on that position to label it, and interpret the PUSH based on the index. You also will need page buttons to scroll through the list and update the index. The nice thing about doing this is that your data set is extremely flexible, and you don't have to change your panel when thedata changes.
I use popup pages to show or hide buttons. If there is a single button I need to make disappear, I will draw a new button around it, move the original out of the way (write down the coordinates so you can put it back exactly where it goes), make the fill on the new button transparent, then use a screen capture program to take a snapshot of the transparent button. Save that as a bitmap, create a new popup page the same dimensions as the transparent button, then use the new bitmap as the background. It sometimes takes a few tries to get it to match perfectly, but once you get it, it's great.
Second, if you need a bunch of buttons to appear on a page, use the above method to create a few or several popup pages with the buttons needed. Then you can make them appear or disappear as needed from the code.
Jeff