Toolbars
-
I'm not a newbie to Sketchup but I truly am where toolbars are concerned. Is it my imagination or do you only get one shot at getting it right for a toolbar with a given name. It seems to me that once I have created a toolbar, the only way to change it is to create it with a new name otherwise none of the changes or additions take place.
-
you can certainly modify toolbars...
you may need to turn the toolbar off before restarting sketchup then turn it back on.
or you may even have to do an additional start without the plugin loading at all [disable or move it], before the changes take effect...
but you can modify toolbars
john
-
driven,
OK, just how does one turn toolbars off and on? Why do you have to specify both large and small icons before they will display? Why does tb=UI.toolbar "" return a toolbar entity?
The following example comes from the Ruby API Toolbar section. As is, it will display a toolbar with only one button because the second .add_item is missing. When you add it and rerun, the second button is still missing. Now if you change the name of the toolbar and rerun it, you get what you expect.
toolbar = UI::Toolbar.new "Test" # This command displays Hello World
cmd = UI::Command.new("Test 1") { UI.messagebox("Hello World 1") }
toolbar.add_item cmd
toolbar = toolbar.add_separator
cmd = UI::Command.new("Test 2") { UI.messagebox("Hello World 2") }
toolbar.show -
hi
you should probably ask in dev forum, I don't write plugins, I just try and fix some to use on my mac.
if I paste that code into Ruby console, initially I get 'one' button and one action, if I then turn it off using 'view menu>>last item' or with the toolbar button and re-paste, I then get a second button, but it's for the same action.
what's missing is a wrapper that you add separate items to...
try this
# list commands cmd_Test_1 = UI;;Command.new("Test 1") { UI.messagebox("Hello World 1") } cmd_Test_2 = UI;;Command.new("Test 2") { UI.messagebox("Hello World 2") } cmd_Test_3 = UI;;Command.new("Test 3") { UI.messagebox("Hello World 3") } cmd_Test_4 = UI;;Command.new("Test 4") { UI.messagebox("Hello World 4") } multi_test_toolbar = UI;;Toolbar.new 'Multi_Toolbar_Test' # Create and populate the Toolbar multi_test_toolbar.add_item cmd_Test_1 multi_test_toolbar.add_item cmd_Test_2 multi_test_toolbar.add_item cmd_Test_3 multi_test_toolbar.add_item cmd_Test_4 # Tell the toolbar to show itself. multi_test_toolbar.show
-
@sdmitch said:
OK, just how does one turn toolbars off and on?
View > Toolbars menu, or click the X button at the top=right of a toolbar (to close it.)
@sdmitch said:
Why do you have to specify both large and small icons before they will display?
It's a Microsoft Windows API thang... not Google's fault. You can:
cmd.small_icon = cmd.large_icon = "images/mybutton.png"
but one of them will be stretched and a bit blurry.
(The image path is relative to the file being run, not the "Plugins" dir. You can also use an absolute path.)@sdmitch said:
Why does
tb=UI.toolbar ""
return a toolbar entity?API bug. Poorly written API code.
This bug has been reported, but wasn't fixed for v8. It actually, creates a new toolbar, if the given "title" is not the name of a current toolbar. Mistakes can result in 'orphan' toolbars on the View>Toolbars menu, (and meaningless extra registry entries.)@sdmitch said:
The following example comes from the Ruby API Toolbar section.
The examples in the API suck. Full of typos, often don't make sense.
Be sure to check the comments at the bottom of each API page, for corrections.
-
Thanks John & Dan,
John, your sample code works perfectly the first time but if but if you close the existing toolbar and make a change to the toolbar definition and recreate the toolbar, it is the same as the first time. I find that restarting Sketchup and recreating the toolbar solves that problem however.
Dan, I had been just "X-ing" out of the toolbar but took a look at View>Toolbars and, as you said, there was a reference to a mis-named attempt to load just created toolbar using UI.toolbar. I totally agree about the API. It is in serious need of a rewrite.
-
@sdmitch said:
I find that restarting Sketchup and recreating the toolbar solves that problem however.
You need to keep a persistent reference to the toolbar object, inside a namespace that will not clash with other code.
module Sdmitch @@toolbar = nil def self.toolbar() @@toolbar end end
Sdmitch.toolbar = UI::Toolbar.new("Learn")
So that your singleton method returns your toolbar object, and the module var keeps a reference to it.
-
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. -
@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