Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Taskbar buttons 1

Status
Not open for further replies.

sh00der

Technical User
Jul 15, 2003
58
CA
Hi, I am programming a GUI and want to include a fast way to access models by incorporating buttons for them that display the appropriate model when clicked. My problem is that there can be about 20 models and some of the buttons are packed off the screen. I was hoping to be able to do something like the taskbar in Windows where the buttons get smaller as the bar is filled or just have them wrap onto the next line.
If the models are stored as a list in modList, the following simple code emulates what I have at the moment,

frame .f1
pack .f1
set bNo 0
foreach model $modList {
button .f1.btn$bNo -text $model -command [list draw $model]
pack .f1.btn$bNo -side left
incr bNo
}

Thanks for reading
 
Unfortunately, I've not encountered any "off-the-shelf" code for doing what you requested, sh00der. There are some toolbar implementations out there (for example, see "toolbar," on the Tcl'ers Wiki), but they don't handle dynamic resizing of their tool-buttons. They don't even seem to handle "wrapping" buttons to an additional column/row, if needed.

So, it looks as though you're going to have to come up with a solution yourself. One path would be to track the information &quot;manually&quot; as you add buttons to your taskbar, and then switch to a condensed form or start wrapping to another row once you've reached a certain number. Another would be to create a binding to your frame's [tt]<Configure>[/tt] event, which is fired when the widget is mapped to the screen and whenever it changes size. With a binding like this:

Code:
bind .taskbar <Configure> {TaskbarConfigure %W %w %h}

your code would call TaskbarConfigure whenever its size changed, passing the widget name and its width and height in pixels. You could then adjust as needed, but you'd need to be careful not to fall into an endless configuration loop, where condensing the toolbar would change its size, triggering the binding again, and potentially becoming small enough in size to trigger the decision to expand it again, which would fire the configure binding again, and so on and so on...

By the way, if you do decide to go with a design of wrapping buttons to a second (or third, etc) row, you might want to use the grid geometry manager for your taskbar's contents instead of pack. grid is a natural for managing layouts like this. For example, to grid your taskbar in rows of no more than 5 buttons each:

Code:
frame .f1
pack .f1

# Note that the -uniform option was introduced in Tk 8.4

grid columnconfigure .f1 {0 1 2 3 4} -weight 1 -uniform A

set bNo 0
foreach model $modList {
    button .f1.btn$bNo -text $model         -command [list draw $model]

    set row [expr {$bNo / 5}]
    set column [expr {$bNo % 5}]
    grid .f1.btn$bNo -row $row -column $column         -sticky nsew -padx 1 -pady 1

    incr bNo
}

- Ken Jones, President, ken@avia-training.com
Avia Training and Consulting, 866-TCL-HELP (866-825-4357) US Toll free
415-643-8692 Voice
415-643-8697 Fax
 
Thanks for your help, I'll have to give the manual method a try. I'm pleased that I wasn't missing something stupid, thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top