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.

100 lines
2.8KB

  1. #!/bin/sh
  2. # the next line restarts using wish \
  3. exec wish "$0" "$@"
  4. #
  5. # This was largely cribbed from the TCL demo code. My TCL skills weren't
  6. # that great when I last used it about ten years ago and my Tk skills never
  7. # existed before. So be kind.
  8. #
  9. set font {Helvetica 14}
  10. set ifile {}
  11. set ofile {}
  12. set use_shortnames 0
  13. proc positionWindow w {
  14. wm geometry $w +300+300
  15. }
  16. proc showCmd w {
  17. global ifile ofile use_shortnames ftyperead ftypewrite
  18. set cmd "gpsbabel -i $ftyperead -f $ifile"
  19. if {$use_shortnames > 0} {
  20. set cmd [concat $cmd "-s"]
  21. }
  22. set cmd [concat $cmd "-o $ftypewrite -F $ofile"]
  23. eval exec $cmd
  24. # tk_messageBox -icon info -message $cmd
  25. }
  26. set w .filebox
  27. catch {destroy $w}
  28. toplevel $w
  29. wm title $w "gpsbabel"
  30. wm iconname $w "filebox"
  31. positionWindow $w
  32. #label $w.msg -font $font -wraplength 4i -justify left -text "Enter a file name in the entry box or click on the \"Browse\" buttons to select a file name using the file selection dialog."
  33. #pack $w.msg -side top
  34. frame $w.buttons
  35. pack $w.buttons -side bottom -fill x -pady 2m
  36. button $w.buttons.dismiss -text End -command "destroy $w"
  37. button $w.buttons.code -text OK -command "showCmd $w"
  38. pack $w.buttons.dismiss $w.buttons.code -side left -expand 1
  39. foreach i {read write} {
  40. set f [frame $w.$i]
  41. set ftype "ftype$i"
  42. label $f.lab -text "Select a file to $i: " -anchor e
  43. entry $f.ent -width 20
  44. button $f.but -text "Browse ..." -command "fileDialog $w $f.ent $i"
  45. # TODO: Get this list from 'gpsbabel -?' instead of hardcoding it here.
  46. tk_optionMenu $f.ftypes $ftype geo gpsman gpx \
  47. magellan mapsend pcx mapsource gpsutil tiger csv xmap dna psp \
  48. cetus gpspilot magnav garmin mxf holux ozi tpg tpo igc baroiq
  49. pack $f.lab -side left
  50. pack $f.ent -side left -expand yes -fill x
  51. pack $f.but -side left
  52. pack $f -fill x -padx 1c -pady 3
  53. pack $f.ftypes -side right -padx 45
  54. }
  55. set ftyperead "geo"
  56. set ftypewrite "mapsend"
  57. checkbutton $w.strict -text "Make Up Shortnames" \
  58. -variable use_shortnames -onvalue 1 -offvalue 0
  59. pack $w.strict -anchor c
  60. proc fileDialog {w ent operation} {
  61. # Type names Extension(s) Mac File Type(s)
  62. #
  63. #---------------------------------------------------------
  64. set types {
  65. {"All files" * }
  66. {"loc files" {.loc} }
  67. {"Waypoint files" {.wpt} }
  68. {"GPX files" {.gpx} }
  69. {"Various Palm/OS files" {.pdb} }
  70. }
  71. global ifile ofile
  72. if {$operation == "read"} {
  73. set ifile [tk_getOpenFile -filetypes $types -parent $w]
  74. if [string compare $ifile ""] {
  75. $ent delete 0 end
  76. $ent insert 0 $ifile
  77. $ent xview end
  78. } ;
  79. } else {
  80. set ofile [tk_getSaveFile -filetypes $types -parent $w \
  81. -initialfile Untitled ]
  82. if [string compare $ofile ""] {
  83. $ent delete 0 end
  84. $ent insert 0 $ofile
  85. $ent xview end
  86. } ;
  87. }
  88. }