sketchucation logo sketchucation
    • Login
    πŸ›£οΈ Road Profile Builder | Generate roads, curbs and pavements easily Download

    Toolbars

    Scheduled Pinned Locked Moved Developers' Forum
    18 Posts 5 Posters 738 Views 5 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      Jim
      last edited by

      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.

      Hi

      1 Reply Last reply Reply Quote 0
      • Dan RathbunD Offline
        Dan Rathbun
        last edited by

        @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.

        I'm not here much anymore.

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          And since a toolbar reference is not going to change during the session, I prefer to use an @@var.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • D Offline
            driven
            last edited by

            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?
            you need an image folderif you want to test

            learn from the mistakes of others, you may not live long enough to make them all yourself...

            1 Reply Last reply Reply Quote 0
            • thomthomT Offline
              thomthom
              last edited by

              @driven said:

              can toolbars buttons be disabled?

              http://www.sketchup.com/intl/en/developer/docs/ourdoc/menu#set_validation_proc

              Thomas Thomassen β€” SketchUp Monkey & Coding addict
              List of my plugins and link to the CookieWare fund

              1 Reply Last reply Reply Quote 0
              • Dan RathbunD Offline
                Dan Rathbun
                last edited by

                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.

                I'm not here much anymore.

                1 Reply Last reply Reply Quote 0
                • D Offline
                  driven
                  last edited by

                  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 methodset_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

                  learn from the mistakes of others, you may not live long enough to make them all yourself...

                  1 Reply Last reply Reply Quote 0
                  • D Offline
                    driven
                    last edited by

                    @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

                    learn from the mistakes of others, you may not live long enough to make them all yourself...

                    1 Reply Last reply Reply Quote 0
                    • Dan RathbunD Offline
                      Dan Rathbun
                      last edited by

                      @John: set_validation_proc is an instance method of your UI::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,) then set_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 a UI::Command,) does not.

                      πŸ’­

                      I'm not here much anymore.

                      1 Reply Last reply Reply Quote 0
                      • Dan RathbunD Offline
                        Dan Rathbun
                        last edited by

                        @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!)

                        I'm not here much anymore.

                        1 Reply Last reply Reply Quote 0
                        • thomthomT Offline
                          thomthom
                          last edited by

                          @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 methodset_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

                          Sorry, wrong link.
                          http://www.sketchup.com/intl/en/developer/docs/ourdoc/command#set_validation_proc

                          Use it on the Command object.

                          Thomas Thomassen β€” SketchUp Monkey & Coding addict
                          List of my plugins and link to the CookieWare fund

                          1 Reply Last reply Reply Quote 0
                          • 1 / 1
                          • First post
                            Last post
                          Buy SketchPlus
                          Buy SUbD
                          Buy WrapR
                          Buy eBook
                          Buy Modelur
                          Buy Vertex Tools
                          Buy SketchCuisine
                          Buy FormFonts

                          Advertisement