From d423a62327462c88a5669e5209085ac984fa102d Mon Sep 17 00:00:00 2001 From: Dianne Skoll Date: Fri, 15 Jan 2021 18:55:38 -0500 Subject: [PATCH] Add ability to change fg/bg colors. --- scripts/tkremind | 109 ++++++++++++++++++++++++++++++++++------------- 1 file changed, 79 insertions(+), 30 deletions(-) diff --git a/scripts/tkremind b/scripts/tkremind index 17552906..8d3f4bef 100755 --- a/scripts/tkremind +++ b/scripts/tkremind @@ -168,6 +168,18 @@ set OptDescr(CalboxFont) "Font to use in calendar boxes in Tk font format" set Option(HeadingFont) [font actual TkDefaultFont] set OptDescr(HeadingFont) "Font to use in calendar headings in Tk font format" +set Option(BackgroundColor) "#d9d9d9" +set OptDescr(BackgroundColor) "Default background color of calendar boxes" + +set Option(TextColor) "#000000" +set OptDescr(TextColor) "Default text color in calendar boxes" + +set Option(LabelColor) "#000000" +set OptDescr(LabelColor) "Default label color for headings" + +set Option(WinBackground) "#d9d9d9" +set OptDescr(WinBackground) "Background color of calendar window" + set TimerUpdateForChanges "" # Remind program to execute -- supply full path if you want @@ -465,6 +477,7 @@ proc CalEntryOffset { firstDay } { proc CreateCalFrame { w dayNames } { # Figure out reasonable height for text frames global SetFontsWorked + global Option set h [winfo screenheight .] if {$h <= 480} { if {$SetFontsWorked} { @@ -479,7 +492,7 @@ proc CreateCalFrame { w dayNames } { } global MondayFirst - frame $w + frame $w -background $Option(WinBackground) for {set i 0} {$i < 7} {incr i} { if {$MondayFirst} { set index [expr ($i+1)%7] @@ -487,7 +500,7 @@ proc CreateCalFrame { w dayNames } { set index $i } - label $w.day$i -border 1 -text [lindex $dayNames $index] -justify center -font HeadingFont + label $w.day$i -border 1 -text [lindex $dayNames $index] -justify center -font HeadingFont -foreground $Option(LabelColor) -background $Option(WinBackground) grid configure $w.day$i -row 0 -column $i -sticky ew } for {set i 0} {$i < 6} {incr i} { @@ -497,7 +510,7 @@ proc CreateCalFrame { w dayNames } { button $w.l$f -text "" -justify center -command "" \ -state disabled -relief flat -border 0 -padx 0 -pady 0 -font HeadingFont text $w.t$f -width 12 -height $h -border 1 -spacing3 3 -wrap word -relief flat \ - -state disabled -takefocus 0 -cursor {} -font CalboxFont + -state disabled -takefocus 0 -cursor {} -font CalboxFont -foreground $Option(TextColor) -background $Option(BackgroundColor) $w.t$f tag bind TAGGED "EditTaggedReminder $w.t$f" $w.t$f tag bind REM "FireEditor $w.t$f" @@ -527,18 +540,16 @@ proc CreateCalFrame { w dayNames } { #*********************************************************************** proc ConfigureCalFrame { w firstDay numDays } { global CurMonth CurYear TodayMonth TodayYear TodayDay - global tk_version + global tk_version Option set offset [CalEntryOffset $firstDay] set first [expr $offset+1] set last [expr $offset+$numDays] - set bg [lindex [. configure -background] 3] - for {set i 0} {$i < $first} {incr i} { grid $w.l$i $w.t$i - $w.l$i configure -text "" -command "" -state disabled -relief flat + $w.l$i configure -text "" -command "" -state disabled -relief flat -foreground $Option(LabelColor) -background $Option(WinBackground) balloon_add_help $w.l$i "" - $w.t$i configure -relief flat -takefocus 0 -state normal + $w.t$i configure -relief flat -takefocus 0 -state normal -background $Option(WinBackground) $w.t$i delete 1.0 end foreach t [$w.t$i tag names] { $w.t$i tag delete $t @@ -546,16 +557,14 @@ proc ConfigureCalFrame { w firstDay numDays } { $w.t$i tag bind TAGGED "EditTaggedReminder $w.t$i" $w.t$i tag bind REM "FireEditor $w.t$i" $w.t$i configure -state disabled - $w.t$i configure -background $bg - $w.l$i configure -background $bg } for {set i $first} {$i <= $last} {incr i} { grid $w.l$i $w.t$i set d [expr $i-$first+1] $w.l$i configure -text $d -state normal -relief flat \ - -command "ModifyDay $d $firstDay" + -command "ModifyDay $d $firstDay" -foreground $Option(LabelColor) -background $Option(WinBackground) balloon_add_help $w.l$i "Add a reminder..." - $w.t$i configure -relief sunken -takefocus 1 -state normal + $w.t$i configure -relief sunken -takefocus 1 -state normal -foreground $Option(TextColor) -background $Option(BackgroundColor) $w.t$i delete 1.0 end foreach t [$w.t$i tag names] { $w.t$i tag delete $t @@ -563,8 +572,6 @@ proc ConfigureCalFrame { w firstDay numDays } { $w.t$i tag bind TAGGED "EditTaggedReminder $w.t$i" $w.t$i tag bind REM "FireEditor $w.t$i" $w.t$i configure -state disabled - $w.t$i configure -background $bg - $w.l$i configure -background $bg } set forgetIt 0 for {set i [expr $last+1]} {$i < 42} {incr i} { @@ -579,9 +586,9 @@ proc ConfigureCalFrame { w firstDay numDays } { } else { grid rowconfigure $w [expr $row+1] -weight 1 } - $w.l$i configure -text "" -command "" -state disabled -relief flat + $w.l$i configure -text "" -command "" -state disabled -relief flat -foreground $Option(LabelColor) -background $Option(WinBackground) balloon_add_help $w.l$i "" - $w.t$i configure -relief flat -takefocus 0 -state normal + $w.t$i configure -relief flat -takefocus 0 -state normal -background $Option(WinBackground) $w.t$i delete 1.0 end foreach t [$w.t$i tag names] { $w.t$i tag delete $t @@ -589,8 +596,6 @@ proc ConfigureCalFrame { w firstDay numDays } { $w.t$i tag bind TAGGED "EditTaggedReminder $w.t$i" $w.t$i tag bind REM "FireEditor $w.t$i" $w.t$i configure -state disabled - $w.t$i configure -background $bg - $w.l$i configure -background $bg } if { $CurMonth == $TodayMonth && $CurYear == $TodayYear } { set n [expr $TodayDay + $offset] @@ -611,14 +616,14 @@ proc DoQueue {} { #--------------------------------------------------------------------------- proc CreateCalWindow { dayNames } { global Option - frame .h - label .h.title -text "" -justify center -pady 1 -border 1 -relief raised -font HeadingFont + frame .h -background $Option(WinBackground); + label .h.title -text "" -justify center -pady 1 -border 1 -relief raised -font HeadingFont -background $Option(WinBackground) -foreground $Option(LabelColor) pack .h.title -side top -fill x pack .h -side top -expand 0 -fill x CreateCalFrame .cal $dayNames - frame .b + frame .b -background $Option(WinBackground); button .b.prev -image leftarrow -width 24 -command {MoveMonth -1} -border 1 balloon_add_help .b.prev "Go to previous month" button .b.this -text {Today} -command {ThisMonth} -border 1 @@ -635,8 +640,8 @@ proc CreateCalWindow { dayNames } { balloon_add_help .b.quit "Quit TkRemind" button .b.options -text {Options...} -command EditOptions -border 1 balloon_add_help .b.options "Set TkRemind options" - label .b.status -text "" -width 25 -relief sunken -border 1 - label .b.nqueued -text "" -width 20 -relief sunken -border 1 + label .b.status -text "" -width 25 -relief sunken -border 1 -foreground $Option(LabelColor) -background $Option(WinBackground) + label .b.nqueued -text "" -width 20 -relief sunken -border 1 -foreground $Option(LabelColor) -background $Option(WinBackground) pack .b.prev .b.this .b.next .b.goto .b.print .b.options .b.queue .b.quit -side left -fill both pack .b.status -side left -fill x -expand 1 pack .b.nqueued -side left -fill x @@ -653,6 +658,7 @@ proc CreateCalWindow { dayNames } { bind . ".b.next flash; .b.next invoke" bind . ".b.this flash; .b.this invoke" + . configure -background $Option(WinBackground) if {$Option(StartIconified)} { wm iconify . } @@ -754,11 +760,27 @@ proc EditOptions {} { pack $w.extraargs -in $w.eaf -side left -expand 1 -fill x $w.extraargs insert 0 $tmpOpt(ExtraRemindArgs) + # Fonts frame $w.fframe button $w.font -text "Change entry font..." -command "ChooseCalboxFont" button $w.hfont -text "Change heading font..." -command "ChooseHeadingFont" pack $w.font $w.hfont -in $w.fframe -side left -expand 1 -fill x + # Colors + frame $w.colors1 + label $w.textcolor -text "Text Color:" + button $w.btextcolor -background $Option(TextColor) -command [list PickColor TextColor $w.btextcolor] + label $w.bgcolor -text " Background color:" + button $w.bbgcolor -background $Option(BackgroundColor) -command [list PickColor BackgroundColor $w.bbgcolor] + pack $w.textcolor $w.btextcolor $w.bgcolor $w.bbgcolor -in $w.colors1 -side left -expand 1 -fill x + + frame $w.colors2 + label $w.headcolor -text "Heading Color:" + button $w.bheadcolor -background $Option(LabelColor) -command [list PickColor LabelColor $w.bheadcolor] + label $w.wincolor -text " Window color:" + button $w.bwincolor -background $Option(WinBackground) -command [list PickColor WinBackground $w.bwincolor] + pack $w.headcolor $w.bheadcolor $w.wincolor $w.bwincolor -in $w.colors2 -side left -expand 1 -fill x + frame $w.sep1 -border 1 -relief sunken frame $w.sep2 -border 1 -relief sunken @@ -781,15 +803,23 @@ proc EditOptions {} { pack $w.ef -in $w.f -side top -expand 0 -fill x pack $w.eaf -in $w.f -side top -expand 0 -fill x pack $w.fframe -in $w.f -side top -expand 0 -fill x + pack $w.colors1 -in $w.f -side top -expand 0 -fill x + pack $w.colors2 -in $w.f -side top -expand 0 -fill x pack $w.sep2 -in $w.f -side top -expand 0 -fill x -ipady 1 button $w.save -text "Save Options" -command "SaveOptions $w; destroy $w" - button $w.cancel -text "Cancel" -command "destroy $w" - + button $w.cancel -text "Cancel" -command "CancelOptions; destroy $w" + wm protocol $w WM_DELETE_WINDOW "CancelOptions; destroy $w" pack $w.save $w.cancel -in $w.b -side left -expand 0 -fill x CenterWindow $w . } +proc CancelOptions { } { + global Option + font configure CalboxFont {*}$Option(CalboxFont) + font configure HeadingFont {*}$Option(HeadingFont) +} + #*********************************************************************** # %PROCEDURE: ApplyOptions # %ARGUMENTS: @@ -854,6 +884,11 @@ proc SaveOptions { w } { } puts $f "" close $f + FillCalWindow + .h.title configure -background $Option(WinBackground) -foreground $Option(LabelColor) + for {set i 0} {$i < 7} {incr i} { + .cal.day$i configure -foreground $Option(LabelColor) -background $Option(WinBackground) + } } #*********************************************************************** @@ -3089,12 +3124,13 @@ proc TaggedEnter { w } { # Removes highlight from an "editable" reminder as mouse leaves it #*********************************************************************** proc TaggedLeave { w } { + global Option set tag [GetCurrentReminder $w] if {$tag != ""} { set tags [$w tag names current] set index [lsearch -glob $tags "clr*"] if {$index < 0} { - set fg "#000000" + set fg $Option(TextColor) } else { set fg [string range [lindex $tags $index] 3 end] set fg "#$fg" @@ -3736,9 +3772,10 @@ proc ChooseCalboxFont {} { } proc SetCalboxFont {font} { - global Option + global tmpOpt font configure CalboxFont {*}[font actual $font] - set Option(CalboxFont) [font actual $font] + set tmpOpt(CalboxFont) [font actual $font] + raise .opt } proc ChooseHeadingFont {} { @@ -3748,8 +3785,20 @@ proc ChooseHeadingFont {} { } proc SetHeadingFont {font} { - global Option + global tmpOpt font configure HeadingFont {*}[font actual $font] - set Option(HeadingFont) [font actual $font] + set tmpOpt(HeadingFont) [font actual $font] + raise .opt } + +proc PickColor {index button} { + global tmpOpt + set x [tk_chooseColor -initialcolor $tmpOpt($index)] + if {"$x" != ""} { + set tmpOpt($index) $x + $button configure -background $x + } + raise .opt +} + main