2 changed files with 75 additions and 0 deletions
@ -0,0 +1,74 @@
@@ -0,0 +1,74 @@
|
||||
#!/usr/bin/env tclsh |
||||
|
||||
# Copyright (C) 2021, Maxim Lihachev, <envrm@yandex.ru> |
||||
# |
||||
# This program is free software: you can redistribute it and/or modify it |
||||
# under the terms of the GNU General Public License as published by the Free |
||||
# Software Foundation, version 3. |
||||
# |
||||
# This program is distributed in the hope that it will be useful, but WITHOUT |
||||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
||||
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
||||
# more details. |
||||
# |
||||
# You should have received a copy of the GNU General Public License along with |
||||
# this program. If not, see <https://www.gnu.org/licenses/>. |
||||
|
||||
# |
||||
# Simple pop-up calendar widget. |
||||
# |
||||
# NB: Window geometry is hardcoded. |
||||
# |
||||
|
||||
package require Tk |
||||
package require widget |
||||
package require widget::calendar |
||||
|
||||
proc showCalendar {} { |
||||
wm title . "TCalendar" |
||||
set t [widget::calendar .t -font "Helvetica 13" -dateformat "%Y-%m-%d" -language ru] |
||||
|
||||
set w 321 |
||||
set h 185 |
||||
|
||||
set x [ expr {([winfo vrootwidth .] - $w)}] |
||||
set y 21 |
||||
|
||||
wm geometry . ${w}x${h}+${x}+${y} |
||||
|
||||
pack $t -fill x -expand 1 |
||||
|
||||
bind . <KeyPress-Control_L><KeyPress-q> exit |
||||
bind . <KeyPress-Control_R><KeyPress-q> exit |
||||
bind . <KeyPress-q> exit |
||||
bind . <Escape> exit |
||||
} |
||||
|
||||
# Close calendar if exists. |
||||
proc closeCalendar {} { |
||||
set cmd [file tail $::argv0] |
||||
|
||||
# user 23192 30619 0 14:45 pts/8 00:00:00 tclsh tcalendar |
||||
lassign [exec ps -ef | grep -E "\[t\]clsh.*$cmd"] uid pid ppid c stime tty time cmd |
||||
|
||||
puts [pid] |
||||
|
||||
puts $pid |
||||
puts "$pid != {} || $pid != [pid]" |
||||
|
||||
if {$pid != {} && $pid != [pid]} { |
||||
exec kill $pid |
||||
return 0 |
||||
} else { |
||||
return 1 |
||||
} |
||||
} |
||||
|
||||
set newCalendar [closeCalendar] |
||||
|
||||
if {$newCalendar} { |
||||
showCalendar |
||||
} else { |
||||
exit |
||||
} |
||||
|
Loading…
Reference in new issue