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

📄 fsbox.tcl

📁 手写识别是模式识别中研究得一个热点
💻 TCL
📖 第 1 页 / 共 2 页
字号:
      }    } {      if {"[string index $fsBoxTmpEntry \            [expr [string length $fsBoxTmpEntry]-1]]" == "*"} {        set fsBoxFileName [string range $fsBoxTmpEntry 0 \          [expr [string length $fsBoxTmpEntry]-2]]        if {![file executable $fsBox(internalPath)/$fsBoxFileName]} {          set fsBoxFileName $fsBoxTmpEntry        }      } {        set fsBoxFileName $fsBoxTmpEntry      }    }    if {![IsADir [string trimright $fsBox(internalPath)/$fsBoxFileName @]]} {      set fsBox(name) $fsBoxFileName      .fsBox.file.file delete 0 end      .fsBox.file.file insert 0 $fsBox(name)      if {$fsBoxShowPixmap} {        catch ".fsBox.frame2.canvas2 itemconfigure currentBitmap -bitmap \"@$fsBox(internalPath)/$fsBox(name)\""      }    }  }}########### Procedure: FSBoxFSFileSelectDouble# Description: select file when double clicked# Arguments: fsBoxW - the widget#            fsBoxShowPixmap - show pixmaps#            fsBoxAction - the action bound to the ok button#            fsBoxY - the y position in the listbox# Returns: none# Sideeffects: none##########proc FSBoxFSFileSelectDouble {fsBoxW fsBoxShowPixmap fsBoxAction fsBoxY} {# xf ignore me 6  global fsBox  FSBoxBindSelectOne $fsBoxW $fsBoxY  set fsBoxNearest [$fsBoxW nearest $fsBoxY]  if {$fsBoxNearest >= 0} {    set fsBoxTmpEntry [$fsBoxW get $fsBoxNearest]    if {"$fsBoxTmpEntry" == "../"} {      set fsBoxTmpEntry [string trimright [string trim $fsBox(internalPath)] "@/"]      if {"$fsBoxTmpEntry" == ""} {        return      }      FSBoxFSShow [file dirname $fsBoxTmpEntry] \        [.fsBox.pattern.pattern get] $fsBox(all)      .fsBox.path.path delete 0 end      .fsBox.path.path insert 0 $fsBox(internalPath)    } {      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        }      } {        if {"[string index $fsBoxTmpEntry \              [expr [string length $fsBoxTmpEntry]-1]]" == "*"} {          set fsBoxFileName [string range $fsBoxTmpEntry 0 \                [expr [string length $fsBoxTmpEntry]-2]]          if {![file executable $fsBox(internalPath)/$fsBoxFileName]} {            set fsBoxFileName $fsBoxTmpEntry          }        } {          set fsBoxFileName $fsBoxTmpEntry        }      }      if {[IsADir [string trimright $fsBox(internalPath)/$fsBoxFileName @]]} {        set fsBox(internalPath) "[string trimright $fsBox(internalPath) {/@}]/$fsBoxFileName"        FSBoxFSShow $fsBox(internalPath) \          [.fsBox.pattern.pattern get] $fsBox(all)        .fsBox.path.path delete 0 end        .fsBox.path.path insert 0 $fsBox(internalPath)      } {        set fsBox(name) $fsBoxFileName        if {$fsBoxShowPixmap} {          set fsBox(path) @$fsBox(internalPath)        } {          set fsBox(path) $fsBox(internalPath)        }        if {"$fsBoxAction" != ""} {          eval "global fsBox; $fsBoxAction"        }        if {"[info commands XFDestroy]" != ""} {          catch {XFDestroy .fsBox}        } {          catch {destroy .fsBox}        }      }    }  }}########### Procedure: FSBoxFSInsertPath# Description: insert current pathname into menu# Arguments: none# Returns: none# Sideeffects: none##########proc FSBoxFSInsertPath {} {# xf ignore me 6  global fsBox  set fsBoxLast [.fsBox.path.paths.paths.menu index last]  set fsBoxNewEntry [string trimright [.fsBox.path.path get] "/@"]  for {set fsBoxCounter 0} {$fsBoxCounter <= $fsBoxLast} {incr fsBoxCounter 1} {    if {"$fsBoxNewEntry" == \          "[lindex [.fsBox.path.paths.paths.menu entryconfigure \                    $fsBoxCounter -label] 4]"} {      return    }  }  if {$fsBoxLast < 9} {    .fsBox.path.paths.paths.menu add command \      -label "$fsBoxNewEntry" \      -command "        global fsBox        FSBoxFSShow $fsBoxNewEntry \          \[.fsBox.pattern.pattern get\] \$fsBox(all)        .fsBox.path.path delete 0 end        .fsBox.path.path insert 0 $fsBoxNewEntry"  } {    for {set fsBoxCounter 0} {$fsBoxCounter < $fsBoxLast} {incr fsBoxCounter 1} {      .fsBox.path.paths.paths.menu entryconfigure \        $fsBoxCounter -label \          [lindex [.fsBox.path.paths.paths.menu entryconfigure \            [expr $fsBoxCounter+1] -label] 4]      .fsBox.path.paths.paths.menu entryconfigure $fsBoxCounter \        -command "          global fsBox          FSBoxFSShow [lindex [.fsBox.path.paths.paths.menu entryconfigure \            [expr $fsBoxCounter+1] -label] 4] \            \[.fsBox.pattern.pattern get\] \$fsBox(all)          .fsBox.path.path delete 0 end          .fsBox.path.path insert 0 [lindex \            [.fsBox.path.paths.paths.menu entryconfigure \              [expr $fsBoxCounter+1] -label] 4]"    }    .fsBox.path.paths.paths.menu entryconfigure $fsBoxLast \      -label "$fsBoxNewEntry"    .fsBox.path.paths.paths.menu entryconfigure $fsBoxCounter \      -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 $fsBoxNewEntry"  }}########### Procedure: FSBoxFSNameComplete# Description: perform name completion for fs box# Arguments: fsBoxType - the type we want to complete (path or file)# Returns: none# Sideeffects: none##########proc FSBoxFSNameComplete {fsBoxType} {# xf ignore me 6  global fsBox  set fsBoxNewFile ""  if {"$fsBoxType" == "path"} {    set fsBoxDirName [file dirname [.fsBox.path.path get]]    set fsBoxFileName [file tail [.fsBox.path.path get]]  } {    set fsBoxDirName [file dirname [.fsBox.path.path get]/]    set fsBoxFileName [file tail [.fsBox.file.file get]]  }  set fsBoxNewFile ""  if {[IsADir [string trimright $fsBoxDirName @]]} {    catch "glob -nocomplain $fsBoxDirName/${fsBoxFileName}*" fsBoxResult    foreach fsBoxCounter $fsBoxResult {      if {"$fsBoxNewFile" == ""} {        set fsBoxNewFile [file tail $fsBoxCounter]      } {        if {"[string index [file tail $fsBoxCounter] 0]" !=            "[string index $fsBoxNewFile 0]"} {          set fsBoxNewFile ""          break        }        set fsBoxCounter1 0        set fsBoxTmpFile1 $fsBoxNewFile        set fsBoxTmpFile2 [file tail $fsBoxCounter]        set fsBoxLength1 [string length $fsBoxTmpFile1]        set fsBoxLength2 [string length $fsBoxTmpFile2]        set fsBoxNewFile ""        if {$fsBoxLength1 > $fsBoxLength2} {          set fsBoxLength1 $fsBoxLength2        }        while {$fsBoxCounter1 < $fsBoxLength1} {          if {"[string index $fsBoxTmpFile1 $fsBoxCounter1]" == \                "[string index $fsBoxTmpFile2 $fsBoxCounter1]"} {            append fsBoxNewFile [string index $fsBoxTmpFile1 $fsBoxCounter1]          } {            break          }          incr fsBoxCounter1 1        }      }    }  }  if {"$fsBoxNewFile" != ""} {    if {[IsADir [string trimright $fsBoxDirName/$fsBoxNewFile @]] ||        ![IsAFile [string trimright $fsBoxDirName/$fsBoxNewFile @]]} {      if {[IsADir [string trimright $fsBoxDirName/$fsBoxNewFile @]]} {        if {"$fsBoxDirName" == "/"} {          .fsBox.path.path delete 0 end          .fsBox.path.path insert 0 "/[string trimright [string trim $fsBoxNewFile /] @]/"        } {          .fsBox.path.path delete 0 end          .fsBox.path.path insert 0 "[string trimright $fsBoxDirName /]/[string trimright [string trim $fsBoxNewFile /] @]/"        }        FSBoxFSShow [.fsBox.path.path get] \          [.fsBox.pattern.pattern get] $fsBox(all)        FSBoxFSInsertPath      } {        .fsBox.path.path delete 0 end        .fsBox.path.path insert 0 "[string trimright $fsBoxDirName /]/[string trimright [string trim $fsBoxNewFile /] @]"      }    } {      .fsBox.path.path delete 0 end      .fsBox.path.path insert 0 "[string trimright $fsBoxDirName {@/}]/"      .fsBox.file.file delete 0 end      .fsBox.file.file insert 0 $fsBoxNewFile      .fsBox.file.file icursor end      focus .fsBox.file.file    }  }}########### Procedure: FSBoxFSShow# Description: show the file list# Arguments: fsBoxPath - the path to show#            fsBoxPattern - selection pattern#            fsBoxAll - show all files# Returns: none# Sideeffects: none##########proc FSBoxFSShow {fsBoxPath fsBoxPattern fsBoxAll} {# xf ignore me 6  global fsBox  set tmpButtonOpt ""  if {"$fsBox(activeBackground)" != ""} {    append tmpButtonOpt "-activebackground \"$fsBox(activeBackground)\" "  }  if {"$fsBox(activeForeground)" != ""} {    append tmpButtonOpt "-activeforeground \"$fsBox(activeForeground)\" "  }  if {"$fsBox(background)" != ""} {    append tmpButtonOpt "-background \"$fsBox(background)\" "  }  if {"$fsBox(font)" != ""} {    append tmpButtonOpt "-font \"$fsBox(font)\" "  }  if {"$fsBox(foreground)" != ""} {    append tmpButtonOpt "-foreground \"$fsBox(foreground)\" "  }  set fsBox(pattern) $fsBoxPattern  if {[file exists $fsBoxPath] && [file readable $fsBoxPath] &&      [IsADir $fsBoxPath]} {    set fsBox(internalPath) $fsBoxPath  } {    if {[file exists $fsBoxPath] && [file readable $fsBoxPath] &&        [IsAFile $fsBoxPath]} {      set fsBox(internalPath) [file dirname $fsBoxPath]      .fsBox.file.file delete 0 end      .fsBox.file.file insert 0 [file tail $fsBoxPath]      set fsBoxPath $fsBox(internalPath)    } {      while {"$fsBoxPath" != "" && "$fsBoxPath" != "/" &&             ![file isdirectory $fsBoxPath]} {        set fsBox(internalPath) [file dirname $fsBoxPath]         set fsBoxPath $fsBox(internalPath)      }    }  }  if {"$fsBoxPath" == ""} {    set fsBoxPath "/"    set fsBox(internalPath) "/"  }  .fsBox.path.path delete 0 end  .fsBox.path.path insert 0 $fsBox(internalPath)  if {[.fsBox.files.files size] > 0} {    .fsBox.files.files delete 0 end  }  if {$fsBoxAll} {    if {[catch "exec ls -F -a $fsBoxPath" fsBoxResult]} {      puts stderr "$fsBoxResult"    }  } {    if {[catch "exec ls -F $fsBoxPath" fsBoxResult]} {      puts stderr "$fsBoxResult"    }  }  set fsBoxElementList [lsort $fsBoxResult]  foreach fsBoxCounter [winfo children .fsBox.pattern.patterns.patterns] {    if {[string length [info commands XFDestroy]] > 0} {      catch {XFDestroy $fsBoxCounter}    } {      catch {destroy $fsBoxCounter}    }  }  menu .fsBox.pattern.patterns.patterns.menu  catch ".fsBox.pattern.patterns.patterns.menu config $tmpButtonOpt"  if {$fsBox(extensions)} {    .fsBox.pattern.patterns.patterns.menu add command \      -label "*" \      -command {        global fsBox        set fsBox(pattern) "*"        .fsBox.pattern.pattern delete 0 end        .fsBox.pattern.pattern insert 0 $fsBox(pattern)        FSBoxFSShow [.fsBox.path.path get] $fsBox(pattern) \          $fsBox(all)}  }  if {"$fsBoxPath" != "/"} {    .fsBox.files.files insert end "../"  }  foreach fsBoxCounter $fsBoxElementList {    if {[string match $fsBoxPattern $fsBoxCounter] ||        [IsADir [string trimright $fsBoxPath/$fsBoxCounter "/@"]]} {      if {"$fsBoxCounter" != "../" &&          "$fsBoxCounter" != "./"} {        .fsBox.files.files insert end $fsBoxCounter      }    }    if {$fsBox(extensions)} {      catch "file rootname $fsBoxCounter" fsBoxRootName      catch "file extension $fsBoxCounter" fsBoxExtension      set fsBoxExtension [string trimright $fsBoxExtension "/*@"]      if {"$fsBoxExtension" != "" && "$fsBoxRootName" != ""} {        set fsBoxInsert 1        set fsBoxLast [.fsBox.pattern.patterns.patterns.menu index last]        for {set fsBoxCounter1 0} {$fsBoxCounter1 <= $fsBoxLast} {incr fsBoxCounter1 1} {          if {"*$fsBoxExtension" == \                "[lindex [.fsBox.pattern.patterns.patterns.menu entryconfigure \                        $fsBoxCounter1 -label] 4]"} {            set fsBoxInsert 0          }        }	if {$fsBoxInsert} {          .fsBox.pattern.patterns.patterns.menu add command \            -label "*$fsBoxExtension" \            -command "              global fsBox              set fsBox(pattern) \"*$fsBoxExtension\"              .fsBox.pattern.pattern delete 0 end              .fsBox.pattern.pattern insert 0 \$fsBox(pattern)              FSBoxFSShow \[.fsBox.path.path get\] \$fsBox(pattern) \                \$fsBox(all)"        }      }    }  }  if {$fsBox(extensions)} {    .fsBox.pattern.patterns.patterns.menu add separator  }  if {$fsBox(extensions) ||       "[.fsBox.pattern.patterns.patterns.menu index last]" == "none"} {    .fsBox.pattern.patterns.patterns.menu add checkbutton \      -label "Scan extensions" \      -variable "fsBox(extensions)" \      -command {        global fsBox        FSBoxFSShow [.fsBox.path.path get] \          [.fsBox.pattern.pattern get] $fsBox(all)}  }}########### Procedure: FSBoxBindSelectOne# Description: action to select the current list item# Arguments: fsBoxW - the widget#            fsBoxY - the y position in the listbox# Returns: none# Sideeffects: none##########proc FSBoxBindSelectOne {fsBoxW fsBoxY} {# xf ignore me 6  set fsBoxNearest [$fsBoxW nearest $fsBoxY]  if {$fsBoxNearest >= 0} {    $fsBoxW select from $fsBoxNearest    $fsBoxW select to $fsBoxNearest  }}proc IsADir {pathName} {########### Procedure: IsADir# Description: check if name is a directory (including symbolic links)# Arguments: pathName - the path to check# Returns: 1 if its a directory, otherwise 0# Sideeffects: none##########  if {[file isdirectory $pathName]} {    return 1  } {    catch "file type $pathName" fileType    if {"$fileType" == "link"} {      if {[catch "file readlink $pathName" linkName]} {        return 0      }      catch "file type $linkName" fileType      while {"$fileType" == "link"} {        if {[catch "file readlink $linkName" linkName]} {          return 0        }      }      return [file isdirectory $linkName]    }  }  return 0}proc IsAFile {fileName} {########### Procedure: IsAFile# Description: check if filename is a file (including symbolic links)# Arguments: fileName - the filename to check# Returns: 1 if its a file, otherwise 0# Sideeffects: none##########  if {[file isfile $fileName]} {    return 1  } {    catch "file type $fileName" fileType    if {"$fileType" == "link"} {      if {[catch "file readlink $fileName" linkName]} {        return 0      }      catch "file type $linkName" fileType      while {"$fileType" == "link"} {        if {[catch "file readlink $linkName" linkName]} {          return 0        }      }      return [file isfile $linkName]    }  }  return 0}proc IsASymlink {fileName} {########### Procedure: IsASymlink# Description: check if filename is a symbolic link# Arguments: fileName - the path/filename to check# Returns: none# Sideeffects: none##########  catch "file type $fileName" fileType  if {"$fileType" == "link"} {    return 1  }  return 0}# eof

⌨️ 快捷键说明

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