Toolbar & Menubar connectivity ... 
Author Message
 Toolbar & Menubar connectivity ...

is there a set of api(s) or pakcages to synchronize ENABLE/DISABLE of items
in menubar and toolbar automatically out there ?

Thanks, Mel

CODE is appreciated as usual



Thu, 04 Aug 2005 02:14:39 GMT  
 Toolbar & Menubar connectivity ...

Quote:

> is there a set of api(s) or pakcages to synchronize ENABLE/DISABLE of items
> in menubar and toolbar automatically out there ?

> Thanks, Mel

> CODE is appreciated as usual

It's fairly easy to code up yourself, and makes for a nice little
programming exercise.

A variation of what I do looks roughly like this (off of the top of my
head, not tested, YMMV, void where prohibited by law, do not operate
heavy machinery while using, wait two hours before going swimming, not
suitable for young children, etc)

     # some typical widgets...
     .menubar.editMenu add command -label Paste ...
     .popupMenu add command -label Paste ...
     button .toolbar.paste -text Paste ...

     # associate them with a symbolic name
     associate paste .menubar.editMenu Paste
     associate paste .toolbar.paste
     associate paste .popupMenu Paste

     ....

     # enable only if there's something on the clipboard
     if {there is nothing on the clipboard} {
         disable paste
     } else {
         enable paste
     }

All that's left is to write the procs associate, enable and disable.

Associate is simple:

     proc associate {what args} {
         global widgets
         lappend widgets($what) $args
     }

enable and disable are also pretty simple:

     proc enable {what} {
         global widgets
         foreach item $widgets($what) {
             set widget [lindex $item 0]
             if {[winfo exists $widget]} {
                 if {[winfo class $widget] == "Menu"} {
                     set index [lindex $item 1]
                     $widget entryconfigure $index -state normal
                 } else {
                     $widget configure -state normal
                 }
             }
         }
     }

I've used a variation of this for years and it works great. It's a pain
   to have to associate widgets with a symbolic name, but it's worth the
effort. Besides the obvious benefits, it makes the code easier to
maintain in that if you change widget paths or add or remove widgets you
only have to change the related "associate" commands rather than hunting
down hard-coded widget paths throughout your code.

There are lots of things you can do to make the code even more fancy.
For example, you can support accelerators, build your own widget
wrappers that do the "associate" step automatically, add a disassociate
step, etc.



Thu, 04 Aug 2005 07:23:21 GMT  
 Toolbar & Menubar connectivity ...

Quote:

> > is there a set of api(s) or pakcages to synchronize ENABLE/DISABLE of
items
> > in menubar and toolbar automatically out there ?

> > Thanks, Mel

> > CODE is appreciated as usual

> It's fairly easy to code up yourself, and makes for a nice little
> programming exercise.

[... cool example code snipped ...]

Quote:
> I've used a variation of this for years and it works great. It's a pain
>    to have to associate widgets with a symbolic name, but it's worth the
> effort. Besides the obvious benefits, it makes the code easier to
> maintain in that if you change widget paths or add or remove widgets you
> only have to change the related "associate" commands rather than hunting
> down hard-coded widget paths throughout your code.

> There are lots of things you can do to make the code even more fancy.
> For example, you can support accelerators, build your own widget
> wrappers that do the "associate" step automatically, add a disassociate
> step, etc.

Another tcl gem from Bryan!  This is a really neat idea and deserves a home
on the Wiki if it's not already there somewhere...

Jeff



Thu, 04 Aug 2005 08:24:08 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. menubar & toolbar connectivity ?

2. Menubar and Toolbar back color

3. Background colors of Menubar and Toolbar

4. Seperator line between the menubar and toolbar

5. XP Menubar Template & Classes Release Version 1

6. ANN: Database & Spreadsheet Connectivity Library for Fortran

7. Toolbar & eipManager overhead

8. Tabs & Toolbar

9. Toolbar & Scroll Box

10. VO: Menus & Toolbars

11. ABC Templates @#$%^&*&&*&*!!!!!!

12. VW 2.5 menuBar hide, show

 

 
Powered by phpBB® Forum Software