by Dan Rathbun » Sun Jan 30, 2011 1:35 pm
Re: Menu and Toolbar validation. It seems on SU 8.0M1 the validation flag MF_DISABLED has no effect. The user can still select the item, and the comand is run. Is this a new bug?How does this compare to Mac ?- Code: Select all
# Valid integer values for PC: # # ** MF_BITMAP not used by Sketchup # # 0 = MF_UNCHECKED | MF_ENABLED # 1 = MF_UNCHECKED | MF_GRAYED # 2 = MF_UNCHECKED | MF_DISABLED # 3 = MF_UNCHECKED | MF_GRAYED | MF_DISABLED # # 4 = MF_UNCHECKED | MF_BITMAP | MF_ENABLED # 5 = MF_UNCHECKED | MF_BITMAP | MF_GRAYED # 6 = MF_UNCHECKED | MF_BITMAP | MF_DISABLED # 7 = MF_UNCHECKED | MF_BITMAP | MF_GRAYED | MF_DISABLED # # 8 = MF_CHECKED | MF_ENABLED # 9 = MF_CHECKED | MF_GRAYED # 10 = MF_CHECKED | MF_DISABLED # 11 = MF_CHECKED | MF_GRAYED | MF_DISABLED # # 12 = MF_CHECKED | MF_BITMAP | MF_ENABLED # 13 = MF_CHECKED | MF_BITMAP | MF_GRAYED # 14 = MF_CHECKED | MF_BITMAP | MF_DISABLED # 15 = MF_CHECKED | MF_BITMAP | MF_GRAYED | MF_DISABLED # # note 16 = MF_POPUP
If @@validation is a class var holding the validation integer for a menu item or toolbar item. You could use an instance var @validation. Or you could pass the integer in, by putting a validation argument into the () on the def method line, and changing all the @@validation to just validation: Produce it's Bitwise OR string: - Code: Select all
def valid_string() valid='' if @@validation[3]==1 valid << 'MF_CHECKED | ' else valid << 'MF_UNCHECKED | ' end if @@validation[0]==1 or @@validation[1]==1 if @@validation[0]==1 valid << 'MF_GRAYED' if @@validation[1]==0 valid << 'MF_GRAYED | ' if @@validation[1]==1 end if @@validation[1]==1 valid << 'MF_DISABLED' end else valid << 'MF_ENABLED' end return valid end checked?() method - Code: Select all
def self.checked?() (@@validation & MF_CHECKED).nonzero? ? true : false end
enabled?() method - Code: Select all
def self.enabled?() ((@@validation & MF_GRAYED).nonzero? || (@@validation & MF_DISABLED).nonzero?) ? false : true end
disabled?() method - Code: Select all
def self.disabled?() (@@validation & MF_DISABLED).nonzero? ? true : false end
grayed?() method - Code: Select all
def self.grayed?() (@@validation & MF_GRAYED).nonzero? ? true : false end
unchecked?() method - Code: Select all
def self.unchecked?() (@@validation & MF_CHECKED).nonzero? ? false : true end
EDIT: made Boolean methods use constants and bitwise comparison for cross-platform use, (which greatly simplifys the check for MF_GRAYED.)
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5051
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by thomthom » Sun Jan 30, 2011 2:14 pm
This is what I always use for validation procs: - Code: Select all
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 that MF_GRAYED where used only for the visual effect.
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by thomthom » Sun Jan 30, 2011 2:20 pm
hmm... testing in SU8M1, you're right. MF_DISABLED seem to do nothing. Only MF_GRAYED seems to affect anything. 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.
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by thomthom » Sun Jan 30, 2011 2:31 pm
Same behaviour on SU6, 7.1 Windows.
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Dan Rathbun » Sun Jan 30, 2011 3:49 pm
thomthom wrote: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.
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5051
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by Dan Rathbun » Sun Jan 30, 2011 4:06 pm
thomthom wrote: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 }
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5051
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by thomthom » Sun Jan 30, 2011 4:11 pm
Yea, that'd probably be better.
IN my case I'd need an observer, but it'd still be more efficient.
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by thomthom » Sun Jan 30, 2011 5:55 pm
Tested on OSX SU8.0M1 - Same behaviour, MF_DISABLED does nothing.
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Dan Rathbun » Tue Feb 01, 2011 2:12 pm
thomthom wrote:hmm... testing in SU8M1, you're right. MF_DISABLED seem to do nothing. Only MF_GRAYED seems to affect anything.
thomthom wrote:Same behaviour on SU6, 7.1 Windows.
thomthom wrote: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'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5051
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by thomthom » Tue Feb 01, 2011 2:34 pm
I still wonder why I've been using MF_DISABLED... 
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Dan Rathbun » Tue Feb 01, 2011 2:58 pm
Covering your butt.. just in case the API changes in the future?
I'm not here much anymore. But a PM will fire email notifications.
-

Dan Rathbun
- PluginStore Author

-
- Posts: 5051
- Joined: Tue Oct 06, 2009 3:06 am
- Location: Florida, USA
- Name: Dan Rathbun
- Operating system: Windows
- SketchUp version: 2015
- License type: Pro
- SketchUp use: education
- Level of SketchUp: Advanced
by thomthom » Tue Feb 01, 2011 3:00 pm
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...
-

thomthom
- PluginStore Author

-
- Posts: 19457
- Joined: Tue Nov 13, 2007 12:47 pm
- Location: Trondheim, Norway
- Name: Thomas Thomassen
- Operating system: Windows
- SketchUp version: 2019
- License type: Pro
- SketchUp use: other
- Level of SketchUp: Advanced
-
by Ad Machine » 5 minutes ago
-
Ad Machine
- Robot
-
- Posts: 2012
-
Return to Developers' Forum
|