Toolbars
-
@jim said:
What's the differece between an
@variable
and a@@variable
in the previous post's scope?I've always just used class variables (
@variable
) since they are "global" in a module's scope.AN
@@variable
is a class (or module) variable.AN
@variable
is an instance variable. Yes it has global scope within the module, because there is (and can only be,) only one instance of the module.I use both. @@ var for things you might otherwise use a global var for. (Settings and the like.)
And then I use @ vars for values that change a lot, but need to be available to all methods.The big difference comes when it's a Mixin module. @ vars can be mixed into the target class or module. Not sure about the class vars.
-
And since a toolbar reference is not going to change during the session, I prefer to use an
@@var
. -
hi
I'm re-jigging my plugins on_off ruby that's part of a larger toolset and I split of the SU auto-reload as a separate button.
This lets me make a few choices, then reload SU.On using I thought, 'what if I change my mind', so I only show the current state button to start then turn on it's counterpart when it runs.
because I can't remove the first button, I turn it's command to nil, and have a rescue smart alex puts.
so you only ever get two buttons and they only switch on first click.is there a better way?
@rtb = UI;;Toolbar.new("mac Dev Tools") @path = Sketchup.find_support_file("Tools/on_off") #if your ruby's are OFF this still shows up #---------------------------------------------------------------------------- roncmd = nil roffcmd = nil roncmd = UI;;Command.new("rbON") {Sketchup.plugins_disabled = false; roncmd = nil begin @rtb.add_item(roffcmd) rescue puts "I'm one shot per session" end } roffcmd = UI;;Command.new("rbOFF") {Sketchup.plugins_disabled = true; roffcmd = nil begin @rtb.add_item(roncmd) rescue puts "I'm one shot per session" end } # button image paths onicon=(@path + "/images/on.png") officon=(@path + "/images/off.png") roncmd.large_icon = roncmd.small_icon = onicon roffcmd.large_icon = roffcmd.small_icon = officon roncmd.tooltip = %q(Plugins will be "ON" at next StartUp) roffcmd.tooltip = %q(Plugins will be "OFF" at next StartUp) if !Sketchup.plugins_disabled? === true @rtb.add_item(roffcmd); else @rtb.add_item(roncmd); end #if #----------------------------------------------------------------------------
can toolbars buttons be disabled?
-
@driven said:
can toolbars buttons be disabled?
http://www.sketchup.com/intl/en/developer/docs/ourdoc/menu#set_validation_proc
-
And unfortunately .. currently we cannot change via the API, the button image that a
UI::Command
instance is associated with, although doing so is and has long been, a basic feature of Windows Microsoft Foundation Classes (MFC) UI programming. (So we could do it with system calls, using Win32API, etc.)I do believe this is or has been logged as an API feature request.
So for now, you are limited to graying them out.
-
TT + Dan,
I can't seem to get that to work on a mac.
do I need to create a menu item as well, grey it out, and the button follows?
Error: #<NoMethodError: undefined method
set_validation_proc' for #UI::Toolbar:0x113cb6ec>`
I have a menu entry for the 'master' toolbar, but don't really want/need lots of submenu items.
john -
@dan rathbun said:
(So we could do it with system calls, using Win32API, etc.)
I have an applescript 'somewhere' that tracks the toolbar's window position then positions a replacement window in the exact spot, can't remember why I stopped pursuing that approach, Maybe I switched to a webDialog for that one... I'll dig it up
john -
@John:
set_validation_proc
is an instance method of yourUI::Command
class object (which can be assigned to BOTH a menu item, AND a toolbar button, at the same time, or only one or the other, as you desire.)If you are not using
UI::Command
objects for menus (some don't,) thenset_validation_proc
is an instance method of the submenu object (Sketchup::Menu
class,) that is the parent of the menu item.For a menu NOT using a
UI::Command
:@item = @submenu.add_item("My Task") { do_my_task() } @submenu.set_validation_proc(@item) { @task_allowed ? MF_ENABLED ; MF_GRAYED }
For a
UI::Command
, that can be used for menu item AND/OR toolbar button:@my_task_cmd = UI;;Command("My Task") { do_my_task() } @my_task_cmd.set_validation_proc { @task_allowed ? MF_ENABLED ; MF_GRAYED } @submenu.add_item @my_task_cmd @toolbar.add_item @my_task_cmd
Notice how one of the calls to
set_validation_proc
has an argument (a menu item,) and the other (when used with aUI::Command
,) does not. -
@driven said:
@dan rathbun said:
(So we could do it with system calls, using Win32API, etc.)
I have an applescript 'somewhere' that tracks the toolbar's window position then positions a replacement window in the exact spot, can't remember why I stopped pursuing that approach, Maybe I switched to a webDialog for that one... I'll dig it up
Because it's an ugly Hack?
Because it creates too many entries in the View > Toolbar menu ?
Because it clutters the plist with too many toolbar entries ? (This current is a big issue on Windows as toolbar entries go into the Registry.. and slows SU loading way down the more there are!)
-
@driven said:
TT + Dan,
I can't seem to get that to work on a mac.
do I need to create a menu item as well, grey it out, and the button follows?
Error: #<NoMethodError: undefined method
set_validation_proc' for #UI::Toolbar:0x113cb6ec>`
I have a menu entry for the 'master' toolbar, but don't really want/need lots of submenu items.
johnSorry, wrong link.
http://www.sketchup.com/intl/en/developer/docs/ourdoc/command#set_validation_procUse it on the Command object.
Advertisement