⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 notebook.itk

📁 linux 下的源代码分析阅读器 red hat公司新版
💻 ITK
📖 第 1 页 / 共 2 页
字号:
## Notebook Widget# ----------------------------------------------------------------------# The Notebook command creates a new window (given by the pathName # argument) and makes it into a Notebook widget. Additional options, # described above may be specified on the command line or in the # option database to configure aspects of the Notebook such as its # colors, font, and text. The Notebook command returns its pathName # argument. At the time this command is invoked, there must not exist # a window named pathName, but path Name's parent must exist.# # A Notebook is a widget that contains a set of pages. It displays one # page from the set as the selected page. When a page is selected, the # page's contents are displayed in the page area. When first created a # Notebook has no pages. Pages may be added or deleted using widget commands # described below.# # A special option may be provided to the Notebook. The -auto option # specifies whether the Nptebook will automatically handle the unpacking # and packing of pages when pages are selected. A value of true signifies # that the notebook will automatically manage it. This is the default # value. A value of false signifies the notebook will not perform automatic # switching of pages.## WISH LIST:#   This section lists possible future enhancements.## ----------------------------------------------------------------------#  AUTHOR: Bill W. Scott                 EMAIL: bscott@spd.dsccc.com##  @(#) $Id: notebook.itk 144 2003-02-05 10:56:26Z mdejong $# ----------------------------------------------------------------------#            Copyright (c) 1995 DSC Technologies Corporation# ======================================================================# Permission to use, copy, modify, distribute and license this software # and its documentation for any purpose, and without fee or written # agreement with DSC, is hereby granted, provided that the above copyright # notice appears in all copies and that both the copyright notice and # warranty disclaimer below appear in supporting documentation, and that # the names of DSC Technologies Corporation or DSC Communications # Corporation not be used in advertising or publicity pertaining to the # software without specific, written prior permission.# # DSC DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING # ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, AND NON-# INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, AND THE# AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE MAINTENANCE, # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. IN NO EVENT SHALL # DSC BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR # ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, # WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTUOUS ACTION,# ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS # SOFTWARE.# ======================================================================## Default resources.#option add *Notebook.background          #d9d9d9      widgetDefaultoption add *Notebook.auto                true         widgetDefault## Usual options.#itk::usual Notebook {    keep -background -cursor}# ------------------------------------------------------------------#                            NOTEBOOK# ------------------------------------------------------------------class iwidgets::Notebook {    inherit itk::Widget        constructor {args} {}        itk_option define -background background Background #d9d9d9     itk_option define -auto auto Auto true     itk_option define -scrollcommand scrollCommand ScrollCommand {}        public method add { args }    public method childsite { args }    public method delete { args }     public method index { args }     public method insert { args }     public method prev { }     public method next { }     public method pageconfigure { args }     public method pagecget { index option }    public method select { index }     public method view { args }         private method _childSites { }     private method _scrollCommand { }     private method _index { pathList index select}     private method _createPage { args }     private method _deletePages { fromPage toPage }     private method _configurePages { args }     private method _tabCommand { }         private variable _currPage -1  ;# numerical index of current page selected    private variable _pages {}     ;# list of Page components    private variable _uniqueID 0   ;# one-up number for unique page numbering    }## Provide a lowercase access method for the Notebook class#proc ::iwidgets::notebook {pathName args} {    uplevel ::iwidgets::Notebook $pathName $args}# ------------------------------------------------------------------#                      CONSTRUCTOR# ------------------------------------------------------------------body iwidgets::Notebook::constructor {args}  {    #    # Create the outermost frame to maintain geometry.    #    itk_component add cs {	frame $itk_interior.cs     } {	keep -cursor -background -width -height    }    pack $itk_component(cs) -fill both -expand yes    pack propagate $itk_component(cs) no        eval itk_initialize $args        # force bg of all pages to reflect Notebook's background.    _configurePages -background $itk_option(-background)}# ------------------------------------------------------------------#                      OPTIONS# ------------------------------------------------------------------# ------------------------------------------------------------------# OPTION -background## Sets the bg color of all the pages in the Notebook.# ------------------------------------------------------------------configbody iwidgets::Notebook::background {    if {$itk_option(-background) != {}} {	_configurePages -background $itk_option(-background)    }}# ------------------------------------------------------------------# OPTION -auto## Determines whether pages are automatically unpacked and# packed when pages get selected.# ------------------------------------------------------------------configbody iwidgets::Notebook::auto {    if {$itk_option(-auto) != {}} {    }}# ------------------------------------------------------------------# OPTION -scrollcommand## Command string to be invoked when the notebook # has any changes to its current page, or number of pages.# # typically for scrollbars.# ------------------------------------------------------------------configbody iwidgets::Notebook::scrollcommand {    if {$itk_option(-scrollcommand) != {}} {	_scrollCommand    }}# ------------------------------------------------------------------# METHOD: add add ?<option> <value>...?# # Creates a page and appends it to the list of pages.# processes pageconfigure for the page added.# ------------------------------------------------------------------body iwidgets::Notebook::add { args } {    # The args list should be an even # of params, if not then    # prob missing value for last item in args list. Signal error.    set len [llength $args]    if { [expr $len % 2] } {	error "value for \"[lindex $args [expr $len - 1]]\" missing"    }        # add a Page component    set pathName [eval _createPage $args]    lappend _pages $pathName        # update scroller    _scrollCommand         # return childsite for the Page component    return [eval $pathName childsite]}# ------------------------------------------------------------------# METHOD: childsite ?<index>?## If index is supplied, returns the child site widget corresponding # to the page index.  If called with no arguments, returns a list # of all child sites# ------------------------------------------------------------------body iwidgets::Notebook::childsite { args } {    set len [llength $args]        switch $len {	0 {	    # ... called with no arguments, return a list	    if { [llength $args] == 0 } {		return [_childSites]	    }	}	1 {	    set index [lindex $args 0]	    # ... otherwise, return child site for the index given	    # empty notebook	    if { $_pages == {} } {		error "can't get childsite,\			no pages in the notebook \"$itk_component(hull)\""	    }	    	    set index [_index $_pages $index $_currPage]	    	    # index out of range	    if { $index < 0 || $index >= [llength $_pages] } {		error "bad Notebook page index in childsite method:\			should be between 0 and [expr [llength $_pages] - 1]"	    }	    	    set pathName [lindex $_pages $index]	    	    set cs [eval $pathName childsite]	    return $cs	}	default {	    # ... too many parameters passed	    error "wrong # args: should be\		    \"$itk_component(hull) childsite ?index?\""	}    }}# ------------------------------------------------------------------# METHOD: delete <index1> ?<index2>?# # Deletes a page or range of pages from the notebook# ------------------------------------------------------------------body iwidgets::Notebook::delete { args } {    # empty notebook    if { $_pages == {} } {	error "can't delete page, no pages in the notebook\		\"$itk_component(hull)\""    }        set len [llength $args]    switch -- $len {	1 {	    set fromPage [_index $_pages [lindex $args 0] $_currPage]	    	    if { $fromPage < 0 || $fromPage >= [llength $_pages] } {		error "bad Notebook page index in delete method:\			should be between 0 and [expr [llength $_pages] - 1]"	    }	    	    set toPage $fromPage	    _deletePages $fromPage $toPage	}		2 {	    set fromPage [_index $_pages [lindex $args 0] $_currPage]	    	    if { $fromPage < 0 || $fromPage >= [llength $_pages] } {		error "bad Notebook page index1 in delete method:\			should be between 0 and [expr [llength $_pages] - 1]"	    }	    	    set toPage [_index $_pages [lindex $args 1] $_currPage]	    	    if { $toPage < 0 || $toPage >= [llength $_pages] } {		error "bad Notebook page index2 in delete method:\			should be between 0 and [expr [llength $_pages] - 1]"		error "bad Notebook page index2"	    }	    	    if { $fromPage > $toPage } {		error "bad Notebook page index1 in delete method:\			index1 is greater than index2"	    }	    	    _deletePages $fromPage $toPage	    	}		default {	    # ... too few/many parameters passed	    error "wrong # args: should be\		    \"$itk_component(hull) delete index1 ?index2?\""	}    }}# ------------------------------------------------------------------# METHOD: index <index>## Given an index identifier returns the numeric index of the page# ------------------------------------------------------------------body iwidgets::Notebook::index { args } {    if { [llength $args] != 1 } {	error "wrong # args: should be\		\"$itk_component(hull) index index\""    }        set index $args        set number [_index $_pages $index $_currPage]        return $number}# ------------------------------------------------------------------# METHOD: insert <index> ?<option> <value>...?## Inserts a page before a index. The before page may# be specified as a label or a page position. # ------------------------------------------------------------------body iwidgets::Notebook::insert { args } {    # ... Error: no args passed    set len [llength $args]    if { $len == 0 } {	error "wrong # args: should be\		\"$itk_component(hull) insert index ?option value?\""    }        # ... set up index and args     set index [lindex $args 0]    set args [lrange $args 1 $len]        # ... Error: unmatched option value pair (len is odd)    # The args list should be an even # of params, if not then    # prob missing value for last item in args list. Signal error.    set len [llength $args]    if { [expr $len % 2] } {	error "value for \"[lindex $args [expr $len - 1]]\" missing"    }        # ... Error: catch notebook empty    if { $_pages == {} } {	error "can't insert page, no pages in the notebook\		\"$itk_component(hull)\""    }        # ok, get the page    set page [_index $_pages $index $_currPage]        # ... Error: catch bad value for before page.    if { $page < 0 || $page >= [llength $_pages] } {	error "bad Notebook page index in insert method:\		should be between 0 and [expr [llength $_pages] - 1]"    }        # ... Start the business of inserting    # create the new page and get its path name...    set pathName [eval _createPage $args]        # grab the name of the page currently selected. (to keep in sync)    set currPathName [lindex $_pages $_currPage]        # insert pathName before $page    set _pages [linsert $_pages $page $pathName]        # keep the _currPage in sync with the insert.    set _currPage [lsearch -exact $_pages $currPathName]        # give scrollcommand chance to update    _scrollCommand         # give them child site back...    return [eval $pathName childsite]}# ------------------------------------------------------------------# METHOD: prev## Selects the previous page. Wraps at first back to last page.# ------------------------------------------------------------------body iwidgets::Notebook::prev { } {    # catch empty notebook    if { $_pages == {} } {	error "can't move to previous page,\		no pages in the notebook \"$itk_component(hull)\""    }        # bump to the previous page and wrap if necessary    set prev [expr $_currPage - 1]    if { $prev < 0 } {	set prev [expr [llength $_pages] - 1]    }        select $prev        return $prev}# ------------------------------------------------------------------# METHOD: next## Selects the next page. Wraps at last back to first page.# ------------------------------------------------------------------body iwidgets::Notebook::next { } {    # catch empty notebook    if { $_pages == {} } {	error "can't move to next page,\		no pages in the notebook \"$itk_component(hull)\""    }        # bump to the next page and wrap if necessary    set next [expr $_currPage + 1]    if { $next >= [llength $_pages] } {	set next 0    }        select $next        return $next}# ------------------------------------------------------------------# METHOD: pageconfigure <index> ?<option> <value>...?## Performs configure on a given page denoted by index.  Index may # be a page number or a pattern matching the label associated with # a page.# ------------------------------------------------------------------body iwidgets::Notebook::pageconfigure { args } {    # ... Error: no args passed    set len [llength $args]    if { $len == 0 } {	error "wrong # args: should be\		\"$itk_component(hull) pageconfigure index ?option value?\""    }        # ... set up index and args     set index [lindex $args 0]    set args [lrange $args 1 $len]        set page [_index $_pages $index $_currPage]        # ... Error: page out of range    if { $page < 0 || $page >= [llength $_pages] } {	error "bad Notebook page index in pageconfigure method:\		should be between 0 and [expr [llength $_pages] - 1]"    }        # Configure the page component    set pathName [lindex $_pages $page]    return [eval $pathName configure $args]}# ------------------------------------------------------------------# METHOD: pagecget <index> <option>## Performs cget on a given page denoted by index.  Index may # be a page number or a pattern matching the label associated with # a page.# ------------------------------------------------------------------body iwidgets::Notebook::pagecget { index option } {    set page [_index $_pages $index $_currPage]        # ... Error: page out of range    if { $page < 0 || $page >= [llength $_pages] } {	error "bad Notebook page index in pagecget method:\

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -