[code] Menu Validation (MF_DISABLED bugged on PC?)
-
This is what I always use for validation procs:
def self.can_paste_proc if self.can_paste? MF_ENABLED else MF_DISABLED | MF_GRAYED end end
I though
MF_DISABLED
prevented the action from triggering. And thatMF_GRAYED
where used only for the visual effect. -
hmm... testing in SU8M1, you're right.
MF_DISABLED
seem to do nothing. OnlyMF_GRAYED
seems to affect anything.
Though I imagine there is a reason I useMF_DISABLED | MF_GRAYED
- just can't remember why. Can't find any notes on it. -
Same behaviour on SU6, 7.1 Windows.
-
@thomthom said:
Though I imagine there is a reason I use
MF_DISABLED | MF_GRAYED
- just can't remember why. Can't find any notes on it.I'll bet it's a cross-platform thangie... it does not seem to matter to Windows if the DISABLED bit is set, so no harm is done.
Need a Mac guy to test it and let us know.
-
@thomthom said:
This is what I always use for validation procs:
Just being clear that the methods above are not the actual validation_proc. I try not to put conditional evaluations into the menu or toolbar procs, if I can do the decision in another place in the code. In most cases, the validation state does not change until the user actually clicks on the item (or button,) so it's better to change the menu item's (or button's) valid state within the command proc, or some other method that gets called. So when the change is made I just change the value of a
@@validation
class var (or@validation
instance var,) and let Sketchup just pick up the value of that var when it must do a UI draw.So creating a menu item, would look like:
item = menu.add_item('Some Menu Label') { ..execute_code.. } menu.set_validation_proc(item) { @@validation }
-
Yea, that'd probably be better.
IN my case I'd need an observer, but it'd still be more efficient.
-
Tested on OSX SU8.0M1 - Same behaviour,
MF_DISABLED
does nothing. -
@thomthom said:
hmm... testing in SU8M1, you're right.
MF_DISABLED
seem to do nothing. OnlyMF_GRAYED
seems to affect anything.@thomthom said:
Same behaviour on SU6, 7.1 Windows.
@thomthom said:
Tested on OSX SU8.0M1 - Same behaviour,
MF_DISABLED
does nothing.Thanks go to ThomThom for filing a Google BugReport on this, 30 JAN 2011.
-
I still wonder why I've been using
MF_DISABLED
... -
Covering your butt.. just in case the API changes in the future?
-
Possibly. Maybe it was in another language where you had to gray and disable. ...Visual Basic...? Can't think of anything else where I've dealt with menus...
Advertisement