gooderp18绿色标准版
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

99 lines
2.9KB

  1. # -*-mode: tcl; fill-column: 75; tab-width: 8; coding: iso-latin-1-unix -*-
  2. #
  3. # $Id: FileDlg.tcl,v 1.3 2001/12/09 05:31:07 idiscovery Exp $
  4. #
  5. # Tix Demostration Program
  6. #
  7. # This sample program is structured in such a way so that it can be
  8. # executed from the Tix demo program "widget": it must have a
  9. # procedure called "RunSample". It should also have the "if" statment
  10. # at the end of this file so that it can be run as a standalone
  11. # program using tixwish.
  12. # This file demonstrates the use of the tixFileSelectDialog widget --
  13. # This is a neat file selection dialog that looks like the Motif
  14. # file-selection dialog widget. I know that Motif sucks, but
  15. # tixFileSelectDialog looks neat nevertheless.
  16. #
  17. proc RunSample {w} {
  18. # Create an entry for the user to input a filename. If he can't
  19. # bother to type in the name, he can press the "Browse ..." button
  20. # and call up the file dialog
  21. #
  22. frame $w.top -border 1 -relief raised
  23. tixLabelEntry $w.top.ent -label "Select A File:" -labelside top \
  24. -options {
  25. entry.width 25
  26. entry.textVariable demo_fdlg_filename
  27. label.anchor w
  28. }
  29. bind [$w.top.ent subwidget entry] <Return> "fdlg:okcmd $w"
  30. uplevel #0 set demo_fdlg_filename {}
  31. button $w.top.btn -text "Browse ..." -command "fdlg:browse"
  32. pack $w.top.ent -side left -expand yes -fill x -anchor s -padx 4 -pady 4
  33. pack $w.top.btn -side left -anchor s -padx 4 -pady 4
  34. # Use a ButtonBox to hold the buttons.
  35. #
  36. tixButtonBox $w.box -orientation horizontal
  37. $w.box add ok -text Ok -underline 0 -command "fdlg:okcmd $w" \
  38. -width 6
  39. $w.box add cancel -text Cancel -underline 0 -command "destroy $w" \
  40. -width 6
  41. pack $w.box -side bottom -fill x
  42. pack $w.top -side top -fill both -expand yes
  43. }
  44. # Pop up a file selection dialog
  45. #
  46. proc fdlg:browse {} {
  47. # [Hint]
  48. # The best way to use an FileSelectDialog is not to create one yourself
  49. # but to call the command "tix filedialog". This command creates one file
  50. # dialog box that is shared by different parts of the application.
  51. # This way, your application can save resources because it doesn't
  52. # need to create a lot of file dialog boxes even if it needs to input
  53. # file names at a lot of different occasions.
  54. #
  55. set dialog [tix filedialog tixFileSelectDialog]
  56. $dialog config -command fdlg:select_file
  57. $dialog popup
  58. }
  59. proc fdlg:select_file {file} {
  60. global demo_fdlg_filename
  61. set demo_fdlg_filename $file
  62. }
  63. proc fdlg:okcmd {w} {
  64. global demo_fdlg_filename
  65. if {$demo_fdlg_filename != {}} {
  66. tixDemo:Status "You have selected the file $demo_fdlg_filename"
  67. } else {
  68. tixDemo:Status "You haven't selected any file"
  69. }
  70. destroy $w
  71. }
  72. # This "if" statement makes it possible to run this script file inside or
  73. # outside of the main demo program "widget".
  74. #
  75. if {![info exists tix_demo_running]} {
  76. wm withdraw .
  77. set w .demo
  78. toplevel $w; wm transient $w ""
  79. RunSample $w
  80. bind $w <Destroy> exit
  81. }
上海开阖软件有限公司 沪ICP备12045867号-1