addressDialog.tcl 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #########################################################################################
  2. ## Filename: addressDialog.tcl
  3. ##
  4. ## Proc ShowAddressDlg $oldAdr
  5. ## This proceedure creates and displays a model dialog that blocks until the user applys
  6. ## a new address or presses cancel. The new address (integer 1..30) is returned to the calling
  7. ## proceedure or in the case of cancel, 'false' is returned. It takes one argument, the
  8. ## old instrument address, just to display to the user what the old address was. If no argument
  9. ## is given, the address of '0' is used as the old intrument address.
  10. ##
  11. ## Example usage:
  12. ##
  13. ## set newAdr [ShowAddressDlg $oldAdr]; Blocks until user presses 'Apply' of 'Cancel'
  14. ##
  15. ## ## newAdr is either an integer (1..30) or false
  16. ##
  17. ##
  18. ##
  19. ## Last Modified 05/13/04, djs
  20. ## Removed the line 'wm transient $addressDlg .'
  21. ##
  22. ## Last Modified 05/10/04, djs
  23. ## Initial Development
  24. ##
  25. ## Created 05/2004
  26. ## Author Dan Schraufnagel
  27. ## Copyright (C) Mayo Foundation. All Rights Reserved.
  28. ##
  29. #########################################################################################
  30. package require BWidget
  31. package provide addressDialog 1.0
  32. proc QuitAddressDlg {} {
  33. global addrDlgFlag
  34. global addressDlg
  35. global instrAddress
  36. destroy $addressDlg
  37. set instrAddress false
  38. set addrDlgFlag true
  39. }
  40. proc ApplyValue {} {
  41. global addrDlgFlag
  42. global addressDlg
  43. destroy $addressDlg
  44. set addrDlgFlag true
  45. }
  46. proc ShowAddressDlg { {oldAdr 1} } {
  47. global addressDlg
  48. global instrAddress
  49. global addrDlgFlag
  50. set addrDlgFlag false
  51. # Address Dialog
  52. set addressDlg [toplevel .addressDlg]
  53. wm title $addressDlg "Instrument Address"
  54. # Size and place the Main Window on the screen
  55. wm geometry $addressDlg +400+300
  56. # Re-Direct all Window Close events
  57. wm protocol $addressDlg WM_DELETE_WINDOW QuitAddressDlg
  58. set instrAddress 1
  59. # Create a frame, fields and labels for the meter values
  60. # -relief sunken -text "Magnet Temperature"
  61. set readOut [frame $addressDlg.lf -padx 10 -pady 10]
  62. # Create the Dialog fields
  63. frame $readOut.f0 -padx 10 -pady 10
  64. set lf [labelframe $readOut.lf -text "GPIB Address Failed" -padx 15 -pady 15]
  65. label $lf.lbl -text "The Instrument failed to open at GPIB address: $oldAdr\n\
  66. To try again, select an address and press Apply."
  67. pack $lf.lbl
  68. pack $lf
  69. label $readOut.f0.addressLabel -text "Instrument Address:" -width 20 -anchor e
  70. set adrCombo [ComboBox $readOut.f0.adrCombo -editable false -values "1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\
  71. 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30" -width 7 \
  72. -justify right -modifycmd {set instrAddress [.addressDlg.lf.f0.adrCombo cget -text] }]
  73. $adrCombo setvalue @[expr {$oldAdr - 1}]
  74. grid $readOut.f0.addressLabel $adrCombo -sticky e
  75. pack $readOut.f0
  76. pack $readOut
  77. # Create a Frame and buttons
  78. set btnFrame [frame $addressDlg.btnFrame]
  79. button $btnFrame.applyBtn -text "Apply" -command { ApplyValue }
  80. button $btnFrame.quitBtn -text "Cancel" -command { QuitAddressDlg }
  81. pack $btnFrame -side bottom -padx 5 -pady 5
  82. pack $btnFrame.applyBtn -side left
  83. pack $btnFrame.quitBtn -side right
  84. # Display as a model dialog
  85. wm deiconify $addressDlg
  86. wm state $addressDlg normal
  87. tkwait visibility $addressDlg
  88. focus -force $addressDlg
  89. # wm transient $addressDlg .
  90. grab set $addressDlg
  91. # Block until user secles 'Apply' or 'Cancel'
  92. vwait addrDlgFlag
  93. # Return the new instrument address or false
  94. return $instrAddress
  95. }