"Fossies" - the Fresh Open Source Software Archive

Member "ical-tcl/dg_range.tcl" (15 Apr 2019, 3103 Bytes) of package /linux/privat/ical-3.0.4.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Tcl/Tk source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "dg_range.tcl" see the Fossies "Dox" file reference documentation.

    1 # Copyright (c) 1994 by Sanjay Ghemawat
    2 #############################################################################
    3 # Dialog to get date range
    4 #
    5 # Commands
    6 #
    7 #       get_daterange <leader> <startvar> <finishvar>
    8 #
    9 #       Interact with user to get date range.  The initial values of
   10 #       the variables named by <startvar> and <finishvar> are used to
   11 #       initialize the range display.  When interaction is finished,
   12 #       the selected range is stored in <startvar> and <finishvar>.
   13 #       Returns true iff interaction is not cancelled by the user.
   14 
   15 # Hidden global variables
   16 #
   17 #       dr_state(done)          Interaction has finished
   18 #       dr_state(start)         Starting date
   19 #       dr_state(finish)        Finishing date
   20 
   21 set dr_state(done)              0
   22 set dr_state(start)             {}
   23 set dr_state(finish)            {}
   24 
   25 proc get_daterange {leader svar fvar} {
   26     # Initialize state
   27     global dr_state
   28     upvar $svar start
   29     upvar $fvar finish
   30     set dr_state(start)  [date2text_no_weekday $start]
   31     set dr_state(finish) [date2text_no_weekday $finish]
   32     
   33     dr_init
   34 
   35     if ![dr_interact $leader] {return 0}
   36 
   37     if [catch {set start [date_parse $dr_state(start)]}] {return 0}
   38     if [catch {set finish [date_parse $dr_state(finish)]}] {return 0}
   39     return 1
   40 }
   41 
   42 proc dr_init {} {
   43     global dr_state
   44     set f .dr_dialog
   45     if [winfo exists $f] {return}
   46 
   47     toplevel $f -class Dialog
   48     wm title $f "Select Range"
   49     wm iconname $f "Range"
   50     wm protocol $f WM_DELETE_WINDOW {set dr_state(done) 0}
   51 
   52     frame $f.top -class Pane
   53     message $f.text -aspect 800 -text {Restrict item repetition range...}
   54     pack $f.text -in $f.top -side top -expand 1 -fill both -padx 5m -pady 5m
   55 
   56     frame $f.mid -class Pane
   57     entry $f.start -textvariable dr_state(start)
   58     entry $f.finish -textvariable dr_state(finish)
   59     label $f.to -text to
   60     pack $f.start   -in $f.mid -side top -expand 1 -fill both -padx 5m -pady 5m
   61     pack $f.to      -in $f.mid -side top -expand 1 -fill both
   62     pack $f.finish  -in $f.mid -side top -expand 1 -fill both -padx 5m -pady 5m
   63 
   64     make_buttons $f.bot 1 {
   65         {Cancel         {set dr_state(done) 0}}
   66         {Okay           {set dr_state(done) 1}}
   67     }
   68 
   69     pack $f.top -side top -fill both -expand 1
   70     pack $f.mid -side top -fill both -expand 1
   71     pack $f.bot -side bottom -fill x
   72 
   73     bind $f <Control-c> {set dr_state(done) 0}
   74     bind $f <Return>    {set dr_state(done) 1}
   75 
   76     wm withdraw $f
   77     update
   78 
   79     # Set-up a variable trace to track changes to editor state
   80     trace variable dr_state(start)  w dr_validate
   81     trace variable dr_state(finish) w dr_validate
   82     dr_validate
   83 }
   84 
   85 proc dr_interact {leader} {
   86     global dr_state
   87     set f .dr_dialog
   88 
   89     set dr_state(done) -1
   90     dialog_run $leader $f dr_state(done)
   91     return $dr_state(done)
   92 }
   93 
   94 proc dr_validate {args} {
   95     global dr_state
   96     if {[catch {date_parse $dr_state(start)}] ||
   97         [catch {date_parse $dr_state(finish)}]} {
   98         .dr_dialog.bot.b1 configure -state disabled
   99     } else {
  100         .dr_dialog.bot.b1 configure -state normal
  101     }
  102 }