Help get this topic noticed by sharing it on Twitter, Facebook, or email.

Toggle/control button selection state

This thorny topic has been doing the rounds since I first started using iRule some years ago and there is still no real way to manipulate button states, even though it is desperately required.

iRule itself uses an internal mechanism to select and unselect buttons, using Group tags. This is really useful, but not enough.

It occurred to me that the simplest way to give us the control we need would be to provide an extra widget/command (that could be incorporated anywhere in a macro), with 2 parameter text fields, Select and Deselect, into which can be entered the names of any Select or Deselect Groups respectively. When a macro containing the command runs, this would then have the same effect as pressing a button configured with those Groups.

I think this would provide all our requirements and yet require MINIMAL work for the iRule team to implement as it simply leverages an already existing mechanism. All that is needed is that ONE widget. How hard can that be. But the rewards I think would be enormous.
1 person likes
this idea
+1
Reply
  • Tim (Official Rep) March 03, 2015 13:54
    Ken,
    Why don't you use the Set Variable commands to execute and show the state that you want whether Selected or Deselected.

    Thanks,
    Tim
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Sorry, but that's just a crock. You cannot reasonably do that.

    Answer me this. If a button is in its 'selected' state, what variable assignment can be used to change it? Each button has 3 states and each can have a variable assigned. So which of those do you need to set the variable to change the image? And if you do manage to swap an image, does that change the actual internal selected state of the button? So if you have to set the variable assigned to the selected state in order to change the image to the unselected one, what then happens if another button in the same 'Select Group' is pressed? Does the image change again to the original selected state image? What about if another button in the same 'Deselect Group' is pressed? Presumably the image doesn't change. And if it is then pressed again, what image is used for the selected state now. The original or the one you last set with the variable? Probably the latter, so if you need it to be selected again after that last press, you need to do it manually.

    Besides which, to swap a button image by variable, it appears you need to already know its current state to in order to know which image to swap. And visually you have no way of knowing whether the button really is selected or has simply had its image swapped. You may consider this immaterial, but it's another layer of obfuscation that we could do without.

    Oh and how would you revert back to normal state with all images back to the originals. Setting a variable to empty does weird stuff and I very much doubt it would allow the original images to re-appear. I could be wrong, but I don't think so. In which case, you'd need to set all 3 variables to the original images. For every button you needed to 'reset'.

    I cannot over emphasise how totally cr4p that all is. Sorry, but it's horrifically messy and simply not a viable option. Will you guys stop pretending it's a solution, It's not.

    My idea above is simple to implement and would give us complete control over the real state of a button, exactly as we need. No pretending it is in a different state. We would actually be able to change the state of all buttons in a Group and all that implies. Everything else remains clear and intact. This is THE right way to do it.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Just use one variable for the group of buttons single image. When the button is pressed you check for the value of the variable assigned to the buttons image and based off that you proceed with the commands. First change the image to its pressed/ other state then do all commands. I never liked the toggle setup and use variables for all my toggle buttons and it works really good. It gives you way more control over the gui and what's going on.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Ok, but for which state do you swap images? Do you just ignore the Selected state and place no image there?

    Also, since all the buttons in the Group are different, how can you use just a single variable for all?
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Ah, I'm not really concerned with toggle buttons here. This is the basic scenario:-

    In what you might consider the Home Panel, I have a (Home) Page with a button for each room, each of which is linked to its own Page in another Panel. When I press a button on the Home Page it links to its Page in the other Panel and that room's button (that was pressed) gets selected. All good.

    If I return to the Home Page and press a different room button, that links to its own Page in the other Panel, its button on the Home Page is selected and the first room button automatically now de-selected (using de-select tags). Also all good.

    Now I swipe to a different room page and then return to the Home Page and of course the wrong room button is selected because it does not and can not respond to swiping between Pages in the other Panel.

    That is just illustrative of the problem which is not isolated to just that scenario. What is needed is the ability to be able to control at will the selected state of a button and I have suggested above what I think is the best solution as it provides a complete solution yet is the simplest possible implementation.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Yea I see why you would want that. It can still be done using variables but requires more if/else commands and you would be better off using a variable for current room and in the entrance of the home page check that variable and change the images for your buttons based off the current room selected(variable). This would be easy to implement if we had global macros. Then in each page with room selection just use an entrance to change the images for the buttons to represent the current room. Without that you would have to have a variable for each different button and change them each time a different room is selected. Which also wouldn't be that bad if global macros were avail. Just some ideas incase it doesn't get implemented.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • In the absence of any Select/Deselect command and taking a slightly different approach, I think I can see a way to use variables to achieve what I want. But there are some things still not clear to me.

    A button has 3 states, Default, Pressed and Selected, each of which can have an image and a variable assigned. But...

    If there is NO Selected image for a button, after a button has been pressed and released and I want to swap its image, which variable do I need to set?

    I think that in this case, the button is not actually Selected and so I would need to swap the Default image. Would that be correct? Or is it really actually Selected and I need to set the Selected variable? Which leads me to...

    What if although no Selected image has been provided, there IS an assigned variable to the Selected state? Does the button become 'Selected' when pressed and released? Even if the variable is actually empty?

    It is the utter vagueness of how iRule deals with these objects that has put me off bothering to play around with button images up till now. But I need to figure it out now if I am to achieve what I want and could do with some input from others who have worked it out, to save me from a LOT of trial and error testing. If someone could clarify all this it would be much appreciated.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Tim (Official Rep) March 04, 2015 10:22
    When you set a variable you are in essence changing the actual programming of the project on the fly. So what that means is that if you had a selected image yet you wanted to change the image that appears for that selected state you could do that by setting the variable of the selected image. However, the only time that you would see that new image is when you select that button. Think of it this way. We have 3 themes. If you wanted to, you could with one button ch s neg the entire theme simply by changing All of the images for each image state. The way it would operate would not change but your images could.
    What you want to do in order to handle you solution is to use the default image, because the default image is one that will always be visible so by changing that image with a variable you can make it appear to have various states even though it may not actually be selected.
    For MOST variable usage one would always want to set the variable of the default image as long as they are not changing out the entire look of the interface.
    Our platform is customizable and while sometimes it may seem that if we did things one way or another it would be easier for one application we do take great time and effort and look at big picture ideas and how those ideas could used. A good example is a timer. If we simply created a countdown timer that would facilitate ONE use case. However, instead our development team looked at the bigger picture and saw that by introducing expressions and conditionals we could open up an entirely New capability that ALL people could you use and could use in ways that WE have never imagined. This means that while yeS sometimes things might seem more complicated than they need to be, but given the flexibity we are trying to unlock as many things for programmers so that they can let their imaginations run wild. We are not perfect and have never said that we are, but we do take great pride in our software and I think if you look at the bigger picture you can see that we are giving you more capabilities abd that we have reasons why things have been done the way that they are.
    Sorry for the long winded but maybe this has helped makes it a bit clearer as far as why we have done some of the things that we have.
    Use the default image and you should be good to go.

    Thanks,
    Tim
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Ok, thanks Tim for shedding some more light on this. However, you previously have said that if I don't want a button to be selected when pressing it, just don't include an image for the selected state. Ok, that's clear. But (always a but isn't there:-)...

    With no Selected image, does the button then ever enter the Selected state? I'm thinking that seeing no image means iRule never sets the state of that button to Selected. Am I right?

    So what if you assign a variable to the Selected state instead? At what point will iRule decide that the button CAN have a Selected state? Just by having an assigned variable (even though no actual image)? Would the value of the variable actually affect whether iRule thinks it can set the button to Selected (i.e. unset or empty or with an image ID)? Or does it purely rely on the existence (or not) of a real image provided for the Selected state?

    I'm sorry for all the questions, but I really need to know EXACTLY how iRule handles all this in order to know how to make it do what I want. Otherwise it's all just guesswork and that's a. very time consuming and b. almost certainly unreliable. So I hope you don't mind helping with the additional information.

    Regarding my suggestion for a new command to handle all this, I would say that this is not some small feature to suit just me. All this faffing about with variables is to be able to control the Selected (or not) state of a button and it is a lot of faff. I'm not saying variables are in any way less than essential, but in this instance, a lot of people want to be able control the selected state of a button and for the majority, having to manually construct ones own method using variables is simply too time consuming and complicated. So they don't bother. BUT, iRule has a pretty neat method for doing this built-in. Using tags to group buttons as you want. It really is a great feature. All I'm suggesting is that you provide a hook for us to do the same thing, at will. In a macro of our choosing and not having to press a button to achieve the same thing (which would mostly be impossibly inappropriate anyway).

    I'm not asking for some fancy gimmick that only I would ever make use of. It would be a facility so easy to use everyone would benefit, even those currently incapable of such complex use of variables or without the time to invest in setting up their own mechanism, which in any case would add enormously to the amount of macro code required to do so. Whereas I'm suggesting just one new command.

    There is always a balance between easy to use high level functionality and low level programmability. iRule started with the former and are adding the latter as time goes by. But sometimes ultimate programmability is not an appropriate solution. If it were, we'd all just be messing with Objective C (or whatever) and building our own apps from scratch. Sometimes there needs to be a high level function that eliminates the need for too large an amount of low level coding. All languages have this. Functions that can be employed to avoid having to create an inordinate amount of code every time to do the same thing. That's what we have here - or rather we haven't. We need a high level function to give us control over the Selection state of buttons. Having to do the equivalent by hand using variables is undoubtedly not worth the expense.

    I am now looking at using variables to control button images because I actually want to do something that is not intended. I want the selected image to indicate that there are devices actually ON and not just to indicate that's the button I clicked when last on that page. This is something specific to me and I don't expect any special features in iRule to help me do it. But I do think that a button (de)select command would be extremely useful to everyone else. Make it easy for them to produce great, intuitive Remote control systems with iRule.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Tim (Official Rep) March 04, 2015 15:30
    Ken,
    Ok so its a little hard to explain but I will try to do my best.

    Three image states -
    Default = The image that will always be displayed unless a button is pressed or selected;
    Pressed = The image that will be displayed upon pressing a button, when that button is released the image will revert back to the Default state;
    Selected = The image that will be displayed once a button is selected, this image will be displayed until it is reverted back to the default image by either another button press on a different button (as long as the Selected Group and Deselected Group tags are assigned properly).

    Variables on the three image states -
    Default = By setting this variable you are allowing the default image to be changed by anything in the system. This could be done with a feedback, button press, part of a macro. This will be shown until a button is pressed or selected at which point the Pressed image or the Selected image will show.
    Pressed = By setting this variable you are allowing the pressed state image to be changed in the system. The default image will still show as the default image however, once the button is pressed you would now see the new (variable replaced) image.
    Selected = By setting this variable you are allowing the selected state image to be changed in the system. The default image will still show until the button is selected at which time you would now see the selected state.

    The problem with trying to set a selected and deselected state as part of the macro is that you actually are not selecting or deselecting the button. If you use ONLY the default image state and ignore the selected state then you will be able to set a Selected and a deselected image just as you would like. Simply assign the 'Set Variable' command into the macro of your choice and change the default image from Default to Selected (which ever image you choose). This gives you the ability to manipulate the image state of the button as you would like.

    I hope that this helped shed some light.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Well, not really I'm afraid. There is still the question regarding your previous comment that a button without a Selected image does not get Selected and how that might change when a variable is assigned to that state.

    The reason why I am interested in the Selection state is that if possible I still want to use Select and Deselect Group tags so I need to know under what circumstances a button will be Selected or not.

    Hope you can shed even more light on this :-)
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • It makes it more complicated if you try to combine the two methods. For your situation you would be better not using select/deselect groups and just use variables to control all the image states so there will be 100% accuracy. That way there isn't any trial and error you map it out on paper when/what images will be based off the room that is selected and then manually change the images for the buttons. Drawing it up on paper will help you keep track of variable names and keep the number of variables needed to a minimum. If you go this route you will need atleast one variable to represent the current room and one variable for each unique button(different graphic image for default image). You would still add a pressed state of each button as it will always be the same pressed image when your finger is pushing on the button. We only ever change the default image with the variables.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • I hear what you're saying James, about mixing systems, but it's not necessarily a bad thing. To make a decision about how to do this, I just want to be in full possession of all the facts so it is an informed decision and not based on lack of knowledge and hence maybe not the best choice that could be made.

    I'm hoping Tim will be able to fill in the gaps with more information about when iRule selects a button, depending on what's in the Selected state fields.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Another question has arisen. How can I return the button image to the original - without having to manually set a new image to that variable? If I set the variable to empty, will it not then just use the default image that was originally specified in the Builder? Or has that been lost once it has been changed by a variable?

    In fact it looks to me as if setting the image variable to empty means iRule doesn't actually change the displayed image. It just continues to use the last real image that was specified in the variable. But it's kinda hard to tell what is really going on.

    Once again, I have to keep asking questions as there's simply no documentation to read and find out this stuff.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • You would set variable back the default image number. If you click on the button in the builder you should be able to see the default button number. Just reassign that and it back to normal.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • I want to avoid having to store the original image number. It doubles the number of variables I have to use. I was hoping that setting it to empty would be the same as when undefined and so use the original image, but in fact if the variable is set to empty, iRule just ignores it and doesn't change the image which seems entirely the incorrect behaviour to me.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • you shouldn't need to store the number just instead of assigning nothing assign the original number. Unless you have some system of assigning image variables by using other variables dependent on a settings. In that case you may need the original number to assign it back to. Unless an IRule programmer knows a different way. I know we try to keep variables to a min but realisticly a small string variable takes up very little memory and a minimal impact on the app.
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated