tktasks.tcl 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  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 TKTASKS!!"
  11. puts "---------------------------------------"
  12. puts ""
  13. puts ""
  14. cd /home/user/util/tkbin
  15. # Variable and Proc declarations
  16. variable taskdate
  17. variable taskfile
  18. variable lbcursel
  19. array set cmdslbl {}
  20. array set cmds {}
  21. proc setLabel { idx } {
  22. global lbltext
  23. global cmdslbl
  24. global cmds
  25. global lbcursel
  26. set lbcursel $idx
  27. set val ""
  28. if {$idx >= 0 && $idx < [array size cmds] && [array size cmds] > 0} {
  29. set val $cmds($idx)
  30. set lbltext $val
  31. } else {
  32. if {[array size cmds] > 0} {
  33. set lbltext ""
  34. } else {
  35. set lbltext "taks description"
  36. }
  37. }
  38. if {"[string range $val 0 2]"!=""} {
  39. #place .fr.bexec -x 20 -y 237
  40. #place .fr.bclose -x 120 -y 237
  41. #tk_messageBox -message "Really? [string range $val 0 2]"
  42. if {"[string range $cmdslbl($idx) 0 0]" == "#"} {
  43. .fr.bexec configure -width 7 -text "ToDo" -command { reTask "" }
  44. } else {
  45. .fr.bexec configure -width 7 -text "Complete" -command { reTask "#" }
  46. }
  47. grid configure .fr.bexec -column 1 -columnspan 2 -row 5 -rowspan 1
  48. grid .fr.bexec -sticky sw -ipadx 0 -padx 0 -pady 40
  49. grid .fr.bclose -sticky sw -ipadx 20 -padx 90 -pady 40
  50. } else {
  51. place forget .fr.bexec
  52. #grid .fr.bexec -sticky e -padx 1000
  53. grid .fr.bclose -sticky sw -ipadx 20 -padx 0 -pady 40
  54. #place .fr.bclose -y 20
  55. }
  56. }
  57. proc scanDate {} {
  58. global datepattern
  59. global taskdate
  60. global taskfile
  61. global cmdslbl
  62. global cmds
  63. #tk_messageBox -message "Really? [clock format [clock scan $datepattern] -format '%d/%m/%Y']"
  64. if {$datepattern == ""} {
  65. return
  66. }
  67. set dateresult 0
  68. catch {set dateresult [catch [clock format [clock scan $datepattern] -format '%d/%m/%Y']]}
  69. if {$dateresult != 0 } {
  70. #tk_messageBox -message "[clock format [clock scan $datepattern] -format '%d/%m/%Y']"
  71. set taskdate "[clock format [clock scan $datepattern] -format %Y-%m-%d]"
  72. } else {
  73. tk_messageBox -message "Error!"
  74. return
  75. }
  76. # Resetting arrays and listbox
  77. if {[array size cmdslbl] > 0} {
  78. array set cmdslbl {}
  79. }
  80. if {[array size cmds] > 0} {
  81. array set cmds {}
  82. }
  83. if {[.fr.lb size] > 0} {
  84. .fr.lb delete 0 [ .fr.lb size ]
  85. }
  86. if { [file exists "tktasks_$taskdate.ini"] == 0 } {
  87. .fr.lb insert end "No scheduled task for that date."
  88. tk_messageBox -message "No scheduled task for that date."
  89. return
  90. }
  91. set taskfile "tktasks_$taskdate.ini"
  92. # Reading tasks list
  93. set fh [open $taskfile "r"]
  94. set intli 0
  95. set li 0
  96. while {[gets $fh str] >= 0} {
  97. #if {"[string range $str 0 0]" == "\#"} {
  98. # continue
  99. #}
  100. set i [string first "=" $str 0]
  101. set newcmd [string range $str 0 $i-1]
  102. set newcmdpath [string range $str $i+1 [string length $str]]
  103. set cmdslbl($intli) $newcmd
  104. set cmds($intli) $newcmdpath
  105. .fr.lb insert end $cmdslbl($intli)
  106. incr intli
  107. }
  108. close $fh
  109. # DEBUG
  110. #foreach {cmd cmdpath} [array get cmds "0"] {
  111. # tk_messageBox -message "Command: $cmd Path: $cmdpath" -type ok
  112. #}
  113. #foreach {cmd cmdpath} [array get cmds] {
  114. # tk_messageBox -message "Command: $cmd Path: $cmdpath" -type ok
  115. #}
  116. }
  117. proc reTask { flag } {
  118. global cmdslbl
  119. global cmds
  120. global lbcursel
  121. global taskfile
  122. set curtask $cmdslbl($lbcursel)
  123. #if {"[string range $curtask 0 0]"!="#"} {
  124. if {$flag == "#"} {
  125. set newcmd "$flag$curtask"
  126. } else {
  127. set newcmd [string range $curtask 1 [string length $curtask]]
  128. }
  129. set cmdslbl($lbcursel) $newcmd
  130. # Writing the new tasks list
  131. set fh [open $taskfile.new {WRONLY CREAT EXCL} "0777"]
  132. for {set i 0} {$i<[array size cmdslbl]} {incr i} {
  133. set newline "$cmdslbl($i)=$cmds($i)"
  134. puts $fh $newline
  135. }
  136. close $fh
  137. file rename -force $taskfile.new $taskfile
  138. .fr.lb delete $lbcursel
  139. .fr.lb insert $lbcursel $newcmd
  140. #}
  141. }
  142. proc shutdown {} {
  143. # perform necessary housework for ensuring that application files
  144. # are in proper state, lock files are removed, etc.
  145. puts stdout "Good Bye, from TKTASKS.."
  146. exit
  147. }
  148. # Main Frame
  149. frame .fr
  150. pack .fr -fill both -expand 1
  151. set today [clock seconds]
  152. set datepattern [clock format $today -format "%d %B %Y"]
  153. entry .fr.txt -width 65 -textvariable datepattern
  154. button .fr.bscan -height 1 -text "Scan Tasks" -command { scanDate }
  155. listbox .fr.lb -yscrollcommand { .fr.sb set }
  156. place .fr.lb -height 120
  157. scrollbar .fr.sb -command {.fr.lb yview} -orient vertical
  158. # ListBox
  159. bind .fr.lb <<ListboxSelect>> { setLabel [%W curselection]}
  160. # Label
  161. set lbltext "task description"
  162. label .fr.lbl -justify left -wraplength 575 -textvariable lbltext
  163. # Exec Button
  164. button .fr.bexec -width 7 -text "Complete" -command { completeTask }
  165. # Close Button
  166. button .fr.bclose -text "Exit" -command { shutdown }
  167. grid .fr.bclose -sticky sw -ipadx 20 -padx 0 -pady 40
  168. # Set frame and controls position
  169. grid configure .fr -row 0 -rowspan 6 -column 0 -columnspan 4
  170. grid configure .fr.txt -column 1 -columnspan 2 -row 0 -rowspan 1
  171. grid configure .fr.bscan -column 2 -columnspan 1 -row 0 -rowspan 1
  172. grid configure .fr.lb -column 1 -columnspan 2 -row 1 -rowspan 1
  173. grid configure .fr.sb -column 2 -columnspan 1 -row 1 -rowspan 1
  174. grid configure .fr.lbl -column 1 -columnspan 2 -row 2 -rowspan 3
  175. #grid configure .fr.bexec -column 1 -columnspan 2 -row 5 -rowspan 1
  176. grid configure .fr.bclose -column 1 -columnspan 2 -row 5 -rowspan 1
  177. grid .fr.txt -sticky w
  178. grid .fr.txt -ipadx 20 -pady 10 -ipady 5
  179. grid .fr.bscan -sticky e
  180. grid .fr.lb -sticky nsew
  181. place .fr.sb -width 5
  182. grid .fr.sb -sticky nes
  183. grid .fr.lb -ipadx 20 -pady 20 -columnspan 2
  184. grid .fr.sb -ipadx 5 -padx 1 -pady 20
  185. #grid .fr.bexec -sticky sw -pady 40
  186. grid .fr.bclose -sticky sw -ipadx 20 -padx 0 -pady 40
  187. grid .fr.lbl -sticky w
  188. grid .fr -sticky w -padx 20
  189. #grid columnconfigure .fr 0 -weight 1
  190. # Window
  191. wm title . "Tasks"
  192. image create photo imgobj -file tktasks.png
  193. wm iconphoto . imgobj
  194. wm resizable . 0 0
  195. wm attributes . -fullscreen 0
  196. wm geometry . 600x420
  197. wm protocol . WM_DELETE_WINDOW { shutdown }