menubar & toolbar connectivity ? 
Author Message
 menubar & toolbar connectivity ?

i have a menubar with items like:
    Edit->Cut
    Edit->Paste
etc.

on the toolbar i have items that represent the same. is there a way of
connecting them together, so that when i disable a menu item, the toolbar
item gets disabled as well?

i am using tk menus and regular buttons for toolbar, but i could use
IWidgets, if that solves my problem !

Thanks in advance
Mel



Mon, 18 Apr 2005 23:49:46 GMT  
 menubar & toolbar connectivity ?

Quote:

> i have a menubar with items like:
>     Edit->Cut
>     Edit->Paste
> etc.

> on the toolbar i have items that represent the same. is there a way of
> connecting them together, so that when i disable a menu item, the toolbar
> item gets disabled as well?

> i am using tk menus and regular buttons for toolbar, but i could use
> IWidgets, if that solves my problem !

> Thanks in advance
> Mel

A classic problem. Here's how I've gone about solving it over the years,
and it can be done in a couple handfulls of code without needing
iwidgets (nothing wrong with IWidgets, but they are no panacea):

I create what I call "actions". Conceptually, an action is a bit of
functionality that the user can do. cut, copy and paste are classic
examples. More than anything though, actions are simply symbolic names
used to reference a list of widgets.

For each action I can associate zero or more widgets or menu items.
Then, instead of enabling and disabling the widgets I enable or disable
the action, and the action knows what widgets to enable or disable.

The widget creation code looks something like this:

     button .cut   -text Cut   -command {action invoke cutAction}
     button .copy  -text Copy  -command {action invoke copyAction}
     button .paste -text Paste -command {action invoke pasteAction}

     action register cutAction   .cut
     action register copyAction  .copy
     action register pasteAction .paste

     .editMenu add command -label "Cut" \
         -command {action invoke cutAction}
     .editMenu add command -label "Copy"  \
         -command {action invoke copyAction}
     .editMenu add command -label "Paste" \
         -command {action invoke pasteAction}

     action register cutAction   {.editMenu "Cut"}
     action register copyAction  {.editMenu "Copy"}
     action register pasteAction {.editMenu "Paste"}

     ... and so on

When I need to enable or disable a feature, I do it like this:

     action enable cutAction
     action enable copyAction
     action disable pasteAction
     ... and so on

It's a thing of beauty (for tk geeks like myself, anyway) to do
something like "action enable cutAction" and watch the menubar, toolbar,
  context-sensitive popup menu and accelerators all snap to attention at
once.

The action command isn't much. I can't post what I'm presently using
because I just re-implemented this scheme for my current employer and
haven't cleared it with them to release the code. I feel comfortable
releasing the concept though, since I started using it years before
coming to work here.

The short summary of the action proc is that it stores the widget path
(or widget path and index for menu items) in an array. When enabling or
disabling an action it simply traverses this list and Does The Right
Thing (eg: does "<widget> configure -state <state>" or "<widget>
entryconfigure <index> -state <state>)

The "action invoke" code is easy to implement, too. It simply looks at
the action name, transmogrifies it to a known name (eg:
::actions::action-cutAction) and eval's it. I also have it query the
state of the action and do nothing if the action is disabled, so that I
can use accelerators with actions, too. This, of course, assumes you
create a proc with the right name for each action and add the test for
the state yourself. You can either just create procs with the right
name, or incorporate a "action proc" command (for example: "action proc
cutAction {args} {body...}" might create a proc named
::actions::action-cutAction)

If it all sounds complicated, it's not. It took me less than hour to
code it up from scratch. It's about 80 lines of code, and that's with
additional features I haven't mentioned here. I recommend anyone doing
GUI work to go through the same exercise so you understand how it works
and why it's so darn handy.

I always thought this might make a good topic for a conference paper
(this, and some interesting spinoffs such as scriptiable GUIs and the
ability to create macros at runtime by recording actions), but I've
never found the time to do it.

--
bryan at bitmover dot com



Tue, 19 Apr 2005 06:41:14 GMT  
 menubar & toolbar connectivity ?

Quote:
> i have a menubar with items like:
>     Edit->Cut
>     Edit->Paste
> etc.

> on the toolbar i have items that represent the same. is there a way of
> connecting them together, so that when i disable a menu item, the toolbar
> item gets disabled as well?

> i am using tk menus and regular buttons for toolbar, but i could use
> IWidgets, if that solves my problem !

Just disable the button when you disable the menu entry.
This cannot be done automatically, as there is no event
associated with menu entry enable/disable...

George



Tue, 19 Apr 2005 17:19:41 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Toolbar & Menubar 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