tkbookmarks.tcl 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #!/usr/local/bin/wish
  2. #package require -exact Tk $tcl_version
  3. package require Tk 8.4
  4. puts ""
  5. puts ""
  6. puts "---------------------------------------"
  7. puts "Released under GPLv3.0"
  8. puts "Copyrights © 2022-2026 Daniele Bonini"
  9. puts "This software is supplied AS-IS, without WARRENTY."
  10. puts "Welcome in TKBOOKMARKS!!"
  11. puts "---------------------------------------"
  12. puts ""
  13. puts ""
  14. cd /home/user/util/tkbin
  15. # Variable and Proc declarations
  16. proc setLabel { idx } {
  17. global lbltext
  18. global cmds
  19. set val "_"
  20. if {$idx >= 0 && $idx < [array size cmds]} {
  21. set val $cmds($idx)
  22. set lbltext $val
  23. } else {
  24. set lbltext ""
  25. }
  26. if {"[string range $val 0 3]"=="http"} {
  27. place .fr.bexec -x 20 -y 237
  28. place .fr.bclose -x 120 -y 237
  29. } else {
  30. place forget .fr.bexec
  31. place .fr.bclose -x 20 -y 237
  32. }
  33. }
  34. proc shutdown {} {
  35. # perform necessary housework for ensuring that application files
  36. # are in proper state, lock files are removed, etc.
  37. puts stdout "Good Bye, from TKBOOKMARKS.."
  38. exit
  39. }
  40. # Main Frame
  41. frame .fr
  42. pack .fr -fill both -expand 1
  43. listbox .fr.lb -yscrollcommand { .fr.sb set }
  44. scrollbar .fr.sb -command {.fr.lb yview} -orient vertical
  45. # Reading command list
  46. set fh [open tkbookmarks.ini "r"]
  47. set intli 0
  48. set li 0
  49. while {[gets $fh str] >= 0} {
  50. set i [string first "=" $str 0]
  51. set newcmd [string range $str 0 $i-1]
  52. set newcmdpath [string range $str $i+1 [string length $str]]
  53. set cmdslbl($intli) $newcmd
  54. set cmds($intli) $newcmdpath
  55. .fr.lb insert end $cmdslbl($intli)
  56. incr intli
  57. }
  58. close $fh
  59. # DEBUG
  60. #foreach {cmd cmdpath} [array get cmds "0"] {
  61. # tk_messageBox -message "Command: $cmd Path: $cmdpath" -type ok
  62. #}
  63. #foreach {cmd cmdpath} [array get cmds] {
  64. # tk_messageBox -message "Command: $cmd Path: $cmdpath" -type ok
  65. #}
  66. # ListBox
  67. bind .fr.lb <<ListboxSelect>> { setLabel [%W curselection]}
  68. #place .fr.lb -x 20 -y 20
  69. #place .fr.sb -x 180 -y 20
  70. # Label
  71. set lbltext "url to open"
  72. label .fr.lbl -textvariable lbltext
  73. # .fr.lbl configure -text "exec. cmd"
  74. place .fr.lbl -x 20 -y 200
  75. #pack .fr.lbl.s -side right
  76. # Exec Button
  77. button .fr.bexec -text "Open Url" -command { exec firefox --new-tab $lbltext & }
  78. # pack forget .fr.bexec
  79. # Close Button
  80. button .fr.bclose -text "Exit" -command { shutdown }
  81. place .fr.bclose -x 20 -y 237
  82. # Set frame and controls position
  83. grid .fr.lb .fr.sb -sticky nsew
  84. grid .fr.lb -ipadx 20 -padx 20 -pady 20 -columnspan 2
  85. grid .fr.sb -ipadx 5 -padx 15 -pady 20
  86. grid columnconfigure .fr 0 -weight 1
  87. # Window
  88. wm title . "Bookmarks"
  89. image create photo imgobj -file tkbookmarks.png
  90. wm iconphoto . imgobj
  91. wm resizable . 0 0
  92. wm attributes . -fullscreen 0
  93. wm geometry . 500x330
  94. wm protocol . WM_DELETE_WINDOW { shutdown }