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

📄 fsbox.tcl

📁 手写识别是模式识别中研究得一个热点
💻 TCL
📖 第 1 页 / 共 2 页
字号:
# Program: template# Description: file selector box# Author: $__author$# Source: $__self$# Version: $__version$# Date: $__ctime$# State: $__state$## $__Log$## $__Header$global fsBoxset fsBox(activeBackground) ""set fsBox(activeForeground) ""set fsBox(background) ""set fsBox(font) ""set fsBox(foreground) ""set fsBox(scrollActiveForeground) ""set fsBox(scrollBackground) ""set fsBox(scrollForeground) ""set fsBox(scrollSide) leftset fsBox(showPixmap) 0set fsBox(name) ""set fsBox(path) [pwd]set fsBox(pattern) *set fsBox(all) 0set fsBox(button) 0set fsBox(extensions) 0set fsBox(internalPath) [pwd]proc FSBox {{fsBoxMessage "Select file:"} {fsBoxFileName ""} {fsBoxActionOk ""} {fsBoxActionCancel ""}} {########### Procedure: FSBox# Description: show file selector box# Arguments: fsBoxMessage - the text to display#            fsBoxFileName - a file name that should be selected#            fsBoxActionOk - the action that should be performed on ok#            fsBoxActionCancel - the action that should be performed on cancel# Returns: the filename that was selected, or nothing# Sideeffects: none########### # global fsBox(activeBackground) - active background color# global fsBox(activeForeground) - active foreground color# global fsBox(background) - background color# global fsBox(font) - text font# global fsBox(foreground) - foreground color# global fsBox(extensions) - scan directory for extensions# global fsBox(scrollActiveForeground) - scrollbar active background color# global fsBox(scrollBackground) - scrollbar background color# global fsBox(scrollForeground) - scrollbar foreground color# global fsBox(scrollSide) - side where scrollbar is located  global fsBox  set tmpButtonOpt ""  set tmpFrameOpt ""  set tmpMessageOpt ""  set tmpScaleOpt ""  set tmpScrollOpt ""  if {"$fsBox(activeBackground)" != ""} {    append tmpButtonOpt "-activebackground \"$fsBox(activeBackground)\" "  }  if {"$fsBox(activeForeground)" != ""} {    append tmpButtonOpt "-activeforeground \"$fsBox(activeForeground)\" "  }  if {"$fsBox(background)" != ""} {    append tmpButtonOpt "-background \"$fsBox(background)\" "    append tmpFrameOpt "-background \"$fsBox(background)\" "    append tmpMessageOpt "-background \"$fsBox(background)\" "  }  if {"$fsBox(font)" != ""} {    append tmpButtonOpt "-font \"$fsBox(font)\" "    append tmpMessageOpt "-font \"$fsBox(font)\" "  }  if {"$fsBox(foreground)" != ""} {    append tmpButtonOpt "-foreground \"$fsBox(foreground)\" "    append tmpMessageOpt "-foreground \"$fsBox(foreground)\" "  }  if {"$fsBox(scrollActiveForeground)" != ""} {    append tmpScrollOpt "-activeforeground \"$fsBox(scrollActiveForeground)\" "  }  if {"$fsBox(scrollBackground)" != ""} {    append tmpScrollOpt "-background \"$fsBox(scrollBackground)\" "  }  if {"$fsBox(scrollForeground)" != ""} {    append tmpScrollOpt "-foreground \"$fsBox(scrollForeground)\" "  }  set fsBox(name) $fsBoxFileName  if {$fsBox(showPixmap)} {    set fsBox(path) [string trimleft $fsBox(path) @]  }  if {"$fsBox(path)" != "" && [file exists $fsBox(path)] &&      [file isdirectory $fsBox(path)]} {    set fsBox(internalPath) $fsBox(path)  } {    if {"$fsBox(internalPath)" == "" ||        ![file exists $fsBox(internalPath)]} {      set fsBox(internalPath) [pwd]    }  }  # build widget structure  # start build of toplevel  if {"[info commands XFDestroy]" != ""} {    catch {XFDestroy .fsBox}  } {    catch {destroy .fsBox}  }  toplevel .fsBox \    -borderwidth 0  catch ".fsBox config $tmpFrameOpt"  wm geometry .fsBox 350x300   wm title .fsBox {File select box}  wm maxsize .fsBox 1000 1000  wm minsize .fsBox 100 100#  wm positionfrom .fsBox program  wm sizefrom .fsBox user  # end build of toplevel  label .fsBox.message1 \    -anchor c \    -relief raised \    -text "$fsBoxMessage"  catch ".fsBox.message1 config $tmpMessageOpt"  frame .fsBox.frame1 \    -borderwidth 0 \    -relief raised  catch ".fsBox.frame1 config $tmpFrameOpt"  button .fsBox.frame1.ok \    -text "OK" \    -command "      global fsBox      set fsBox(name) \[.fsBox.file.file get\]      if {$fsBox(showPixmap)} {        set fsBox(path) @\[.fsBox.path.path get\]      } {        set fsBox(path) \[.fsBox.path.path get\]      }      set fsBox(internalPath) \[.fsBox.path.path get\]      $fsBoxActionOk      if {\"\[info commands XFDestroy\]\" != \"\"} {        catch {XFDestroy .fsBox}      } {        catch {destroy .fsBox}      }"  catch ".fsBox.frame1.ok config $tmpButtonOpt"  button .fsBox.frame1.rescan \    -text "Rescan" \    -command {      global fsBox      FSBoxFSShow [.fsBox.path.path get] \        [.fsBox.pattern.pattern get] $fsBox(all)}  catch ".fsBox.frame1.rescan config $tmpButtonOpt"  button .fsBox.frame1.cancel \    -text "Cancel" \    -command "      global fsBox      set fsBox(name) {}      set fsBox(path) {}      $fsBoxActionCancel      if {\"\[info commands XFDestroy\]\" != \"\"} {        catch {XFDestroy .fsBox}      } {        catch {destroy .fsBox}      }"  catch ".fsBox.frame1.cancel config $tmpButtonOpt"  if {$fsBox(showPixmap)} {    frame .fsBox.frame2 \      -borderwidth 0 \      -relief raised    catch ".fsBox.frame2 config $tmpFrameOpt"    scrollbar .fsBox.frame2.scrollbar3 \      -command {.fsBox.frame2.canvas2 xview} \      -orient {horizontal} \      -relief {raised}    catch ".fsBox.frame2.scrollbar3 config $tmpScrollOpt"    scrollbar .fsBox.frame2.scrollbar1 \      -command {.fsBox.frame2.canvas2 yview} \      -relief {raised}    catch ".fsBox.frame2.scrollbar1 config $tmpScrollOpt"    canvas .fsBox.frame2.canvas2 \      -confine {true} \      -relief {raised} \      -scrollregion {0c 0c 20c 20c} \      -width {100} \      -xscrollcommand {.fsBox.frame2.scrollbar3 set} \      -yscrollcommand {.fsBox.frame2.scrollbar1 set}    catch ".fsBox.frame2.canvas2 config $tmpFrameOpt"    .fsBox.frame2.canvas2 addtag currentBitmap withtag [.fsBox.frame2.canvas2 create bitmap 5 5 -anchor nw]  }  frame .fsBox.path \    -borderwidth 0 \    -relief raised  catch ".fsBox.path config $tmpFrameOpt"  frame .fsBox.path.paths \    -borderwidth 2 \    -relief raised  catch ".fsBox.path.paths config $tmpFrameOpt"  menubutton .fsBox.path.paths.paths \    -borderwidth 0 \    -menu ".fsBox.path.paths.paths.menu" \    -relief flat \    -text "Pathname:"  catch ".fsBox.path.paths.paths config $tmpButtonOpt"  menu .fsBox.path.paths.paths.menu  catch ".fsBox.path.paths.paths.menu config $tmpButtonOpt"  .fsBox.path.paths.paths.menu add command \     -label "[string trimright $fsBox(internalPath) {/@}]" \     -command "       global fsBox       FSBoxFSShow \[.fsBox.path.path get\] \         \[.fsBox.pattern.pattern get\] \$fsBox(all)       .fsBox.path.path delete 0 end       .fsBox.path.path insert 0 [string trimright $fsBox(internalPath) {/@}]"  entry .fsBox.path.path \    -relief raised  catch ".fsBox.path.path config $tmpMessageOpt"  if {![IsADir $fsBox(internalPath)]} {    set $fsBox(internalPath) [pwd]  }  .fsBox.path.path insert 0 $fsBox(internalPath)  frame .fsBox.pattern \    -borderwidth 0 \    -relief raised  catch ".fsBox.pattern config $tmpFrameOpt"  frame .fsBox.pattern.patterns \    -borderwidth 2 \    -relief raised  catch ".fsBox.pattern.patterns config $tmpFrameOpt"  menubutton .fsBox.pattern.patterns.patterns \    -borderwidth 0 \    -menu ".fsBox.pattern.patterns.patterns.menu" \    -relief flat \    -text "Selection pattern:"  catch ".fsBox.pattern.patterns.patterns config $tmpButtonOpt"  menu .fsBox.pattern.patterns.patterns.menu  catch ".fsBox.pattern.patterns.patterns.menu config $tmpButtonOpt"  .fsBox.pattern.patterns.patterns.menu add checkbutton \    -label "Scan extensions" \    -variable fsBoxExtensions \    -command {      global fsBox      FSBoxFSShow [.fsBox.path.path get] \        [.fsBox.pattern.pattern get] $fsBox(all)}  entry .fsBox.pattern.pattern \    -relief raised  catch ".fsBox.pattern.pattern config $tmpMessageOpt"  .fsBox.pattern.pattern insert 0 $fsBox(pattern)    frame .fsBox.files \    -borderwidth 0 \    -relief raised  catch ".fsBox.files config $tmpFrameOpt"  scrollbar .fsBox.files.vscroll \    -relief raised \    -command ".fsBox.files.files yview"  catch ".fsBox.files.vscroll config $tmpScrollOpt"  scrollbar .fsBox.files.hscroll \    -orient horiz \    -relief raised \    -command ".fsBox.files.files xview"  catch ".fsBox.files.hscroll config $tmpScrollOpt"  listbox .fsBox.files.files \    -exportselection false \    -relief raised \    -xscrollcommand ".fsBox.files.hscroll set" \    -yscrollcommand ".fsBox.files.vscroll set"  catch ".fsBox.files.files config $tmpMessageOpt"  frame .fsBox.file \    -borderwidth 0 \    -relief raised  catch ".fsBox.file config $tmpFrameOpt"  label .fsBox.file.labelfile \    -relief raised \    -text "Filename:"  catch ".fsBox.file.labelfile config $tmpMessageOpt"  entry .fsBox.file.file \    -relief raised  catch ".fsBox.file.file config $tmpMessageOpt"  .fsBox.file.file delete 0 end  .fsBox.file.file insert 0 $fsBox(name)    checkbutton .fsBox.pattern.all \    -offvalue 0 \    -onvalue 1 \    -text "Show all files" \    -variable fsBox(all) \    -command {      global fsBox      FSBoxFSShow [.fsBox.path.path get] \        [.fsBox.pattern.pattern get] $fsBox(all)}  catch ".fsBox.pattern.all config $tmpButtonOpt"  FSBoxFSShow $fsBox(internalPath) $fsBox(pattern) $fsBox(all)  # bindings  bind .fsBox.files.files <Double-Button-1> "    FSBoxFSFileSelectDouble %W $fsBox(showPixmap) \{$fsBoxActionOk\} %y"  bind .fsBox.files.files <ButtonPress-1> "    FSBoxFSFileSelect %W $fsBox(showPixmap) %y"  bind .fsBox.files.files <Button1-Motion> "    FSBoxFSFileSelect %W $fsBox(showPixmap) %y"  bind .fsBox.files.files <Shift-Button1-Motion> "    FSBoxFSFileSelect %W $fsBox(showPixmap) %y"  bind .fsBox.files.files <Shift-ButtonPress-1> "    FSBoxFSFileSelect %W $fsBox(showPixmap) %y"  bind .fsBox.path.path <Tab> {    FSBoxFSNameComplete path}  bind .fsBox.path.path <Return> {    global fsBox    FSBoxFSShow [.fsBox.path.path get] \      [.fsBox.pattern.pattern get] $fsBox(all)    FSBoxFSInsertPath    .fsBox.file.file icursor end    focus .fsBox.file.file}  catch "bind .fsBox.path.path <Up> {}"  bind .fsBox.path.path <Down> {    .fsBox.file.file icursor end    focus .fsBox.file.file}  bind .fsBox.file.file <Tab> {    FSBoxFSNameComplete file}  bind .fsBox.file.file <Return> "    global fsBox    set fsBox(name) \[.fsBox.file.file get\]    if {$fsBox(showPixmap)} {      set fsBox(path) @\[.fsBox.path.path get\]    } {      set fsBox(path) \[.fsBox.path.path get\]    }    set fsBox(internalPath) \[.fsBox.path.path get\]    $fsBoxActionOk    if {\"\[info commands XFDestroy\]\" != \"\"} {      catch {XFDestroy .fsBox}    } {      catch {destroy .fsBox}    }"  bind .fsBox.file.file <Up> {    .fsBox.path.path icursor end    focus .fsBox.path.path}  bind .fsBox.file.file <Down> {    .fsBox.pattern.pattern icursor end    focus .fsBox.pattern.pattern}  bind .fsBox.pattern.pattern <Return> {    global fsBox    FSBoxFSShow [.fsBox.path.path get] \      [.fsBox.pattern.pattern get] $fsBox(all)}  bind .fsBox.pattern.pattern <Up> {    .fsBox.file.file icursor end    focus .fsBox.file.file}  catch "bind .fsBox.pattern.pattern <Down> {}"  # packing  pack append .fsBox.files \              .fsBox.files.vscroll "$fsBox(scrollSide) filly" \              .fsBox.files.hscroll {bottom fillx} \              .fsBox.files.files {left fill expand}  pack append .fsBox.file \              .fsBox.file.labelfile {left} \              .fsBox.file.file {left fill expand}  pack append .fsBox.frame1 \              .fsBox.frame1.ok {left fill expand} \              .fsBox.frame1.rescan {left fill expand} \              .fsBox.frame1.cancel {left fill expand}  pack append .fsBox.path.paths \              .fsBox.path.paths.paths {left}  pack append .fsBox.pattern.patterns \              .fsBox.pattern.patterns.patterns {left}  pack append .fsBox.path \              .fsBox.path.paths {left} \              .fsBox.path.path {left fill expand}  pack append .fsBox.pattern \              .fsBox.pattern.patterns {left} \              .fsBox.pattern.all {right fill} \              .fsBox.pattern.pattern {left fill expand}  if {$fsBox(showPixmap)} {    pack append .fsBox.frame2 \                .fsBox.frame2.scrollbar1 {left filly} \                .fsBox.frame2.canvas2 {top expand fill} \                .fsBox.frame2.scrollbar3 {top fillx}     pack append .fsBox \                .fsBox.message1 {top fill} \                .fsBox.frame1 {bottom fill} \                .fsBox.pattern {bottom fill} \                .fsBox.file {bottom fill} \                .fsBox.path {bottom fill} \                .fsBox.frame2 {right fill} \                .fsBox.files {left fill expand}  } {    pack append .fsBox \                .fsBox.message1 {top fill} \                .fsBox.frame1 {bottom fill} \                .fsBox.pattern {bottom fill} \                .fsBox.file {bottom fill} \                .fsBox.path {bottom fill} \                .fsBox.files {left fill expand}  }  if {"$fsBoxActionOk" == "" && "$fsBoxActionCancel" == ""} {    # wait for the box to be destroyed    update idletask    grab .fsBox    tkwait window .fsBox    if {"[string trim $fsBox(path)]" != "" ||        "[string trim $fsBox(name)]" != ""} {      if {"[string trimleft [string trim $fsBox(name)] /]" == ""} {        return [string trimright [string trim $fsBox(path)] /]      } {        return [string trimright [string trim $fsBox(path)] /]/[string trimleft [string trim $fsBox(name)] /]      }    }  }}########### Procedure: FSBoxFSFileSelect# Description: select file name# Arguments: fsBoxW - the widget#            fsBoxShowPixmap - show pixmaps#            fsBoxY - the y position in the listbox# Returns: none# Sideeffects: none##########proc FSBoxFSFileSelect {fsBoxW fsBoxShowPixmap fsBoxY} {# xf ignore me 6  global fsBox  FSBoxBindSelectOne $fsBoxW $fsBoxY  set fsBoxNearest [$fsBoxW nearest $fsBoxY]  if {$fsBoxNearest >= 0} {    set fsBoxTmpEntry [$fsBoxW get $fsBoxNearest]    if {"[string index $fsBoxTmpEntry \          [expr [string length $fsBoxTmpEntry]-1]]" == "/" ||        "[string index $fsBoxTmpEntry \          [expr [string length $fsBoxTmpEntry]-1]]" == "@"} {      set fsBoxFileName [string range $fsBoxTmpEntry 0 \            [expr [string length $fsBoxTmpEntry]-2]]      if {![IsADir [string trimright $fsBox(internalPath)/$fsBoxFileName @]] &&          ![IsASymlink [string trimright $fsBox(internalPath)/$fsBoxFileName @]]} {        set fsBoxFileName $fsBoxTmpEntry

⌨️ 快捷键说明

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