Updated 2016-05-31 13:20:09 by JayBy

JayBy 2016-05-30

xtk::notebook extends the ttk::notebook with buttons for scrolling, add and remove tabs.

xtk::notebook creates two new styles based on the default TNotebook style. TNotebookX will be used with the scroll buttons and TNotebookX+ for add and scroll buttons. This means, you can use the default TNotebook style only before creating the notebook.

Download  edit

Version 0.1
xtk_notebook-0.1.zip
(updated version concerning the addTab error)

Usage  edit

package require xtk::notebook ?0.1?

COMMANDS
xtk::notebook <Path> ?options?
Create the new notebook and returns the pathname.
xtk::notebook::addTab <Nb> ?options?
Builtin command for creating a new tab in given notebook. It returns the pathname of the new frame inside the added tab.

NOTEBOOK OPTIONS

Default options from ttk::notebook and new added options:
-addbutton <Bool>
If 'string is true <Bool>', it creates add and close buttons, and also buttons for scrolling.
Default: false
-scrollbuttons <Bool>
If 'string is true <Bool>', it creates the scroll buttons for the tabs.
Default: false
-addcommand <Script>
<Script> is used in place of the builtin command to create a new tab.
Default: builtin command

TAB OPTIONS

Options for the builtin addTab command:
-text <String>
Set title of the new tab.
Default: "Tab <Nr>"
-win <Win>
Define a window, which will be inserted, instead of a new frame. This will be returned by the addTab command.
-index c | current | a | b | e | end | <Number>
Insert tab at specified position:
c|current -> after the current tab
a -> after the current tab
b -> before the current tab
e|end -> at the end
<Number> -> position of the specified number

MG just tried this out on Windows 7, out of curiosity, and ran into a few problems:

  • The "+" button doesn't work, and gives an error:
can't read "_W": no such variable
can't read "_W": no such variable
    while executing
"::xtk::notebook::addTab $_W"
    invoked from within
".nb.addButton invoke "
    invoked from within
".nb.addButton instate !disabled { .nb.addButton invoke } "
    invoked from within
".nb.addButton instate pressed { .nb.addButton state !pressed; .nb.addButton instate !disabled { .nb.addButton invoke } } "
    (command bound to event)

  • Before I got that error from the "+" button, addTab worked fine. Afterwards, though, addTab returned an error: can't read "Nb(.nb,Last)": no such element in array. (The new tab was still added, though.)
  • The scroll buttons are permanantly disabled; I added a bunch of new tabs with really long names, and it just caused tab sizes to shrink. But even when I resized the toplevel so that some tabs were forced out of view, the scroll buttons still remained disabled.

JayBy 2016-05-31

I've updated the download package concerning the addTab error.

I don't use the notebook in my scripts for the moment, it's for later use, but I prefer the '-addcommand' option, with the help of the builtin command to get the frame inside the new tab:
proc crTab {Nb} {
    set p [::xtk::notebook::addTab $Nb -index c]
    # Now you can use your stuff with $p
    # $p is the same you get with [$Nb select]
    ...
}

(This should work also with the 'old' version.)

You have to use the builtin command inside the proc, because it tries to adjust the tabs. Then the scroll buttons should work.

The adjustment of the tabs is a problem, because the ttk::notebook shrinks the tabs automatically, if they reach the end of the line. For the moment, it should be a better solution to fix the width of the tabs with a style like "ttk::style configure TNotebook.Tab -width 10". But, I know, this will cut long titles.

I've planned to insert tooltips for the tab titles and I will rewrite the parts for the adjustment, but this will need some time.