numericDialog

$canvaseditor numericDialog
opens dialog window for appearance

Works as follows:

Functions undo, redo unapply, re-apply all changes at once.


obj method canvaseditor numericDialog {} {
  $self memory before [$self undoRedoCode]
  $self basicBindings off
  $self statusLine Numerical input
  set dialogWin [my canvas].numeric
  destroy $dialogWin
  toplevel $dialogWin
  wm resizable $dialogWin no no
  wm transient $dialogWin [winfo toplevel [my canvas]]
  wm title $dialogWin Numerical
  bind $dialogWin <Enter> "$self selected blink off"
  bind $dialogWin <Leave> "$self selected blink on"
  bind $dialogWin <Escape> "destroy $dialogWin"
  #
  bind $dialogWin <Destroy> [list apply [list self {
        $self memory after [$self undoRedoCode]
        $self initUndoRedo [$self memory before] [$self memory after]
        $self basicBindings on
        $self selected blink on
      }] $self]
  #
  grid\
    [label $dialogWin.widthLabel -text Width -anchor w -justify left]\
    [entry $dialogWin.width]\
    [label $dialogWin.widthComment -anchor w -justify left -text\
      "Floating point calc allowed,"]\
    -\
    -sticky news
  bind $dialogWin.width <Return> [list apply {
      {self dialogWin} {
        lassign\
          [$self adjustSelWidthHeightNumeric width [$dialogWin.width get]]\
          x y
        $dialogWin.width delete 0 end
        $dialogWin.width insert end $x
      }
    } $self $dialogWin]
  #
  grid\
    [label $dialogWin.heightLabel -text Height -anchor w -justify left]\
    [entry $dialogWin.height]\
    [label $dialogWin.heightComment -anchor w -justify left -text\
      "e. g. 4.0/3.0"]\
    -\
    -sticky news
  bind $dialogWin.height <Return> [list apply {
      {self dialogWin} {
        lassign\
          [$self adjustSelWidthHeightNumeric height [$dialogWin.height get]]\
          x y
        $dialogWin.height delete 0 end
        $dialogWin.height insert end $y
      }
    } $self $dialogWin]
  # Move horizontal
  grid\
    [label $dialogWin.movHorL -text "Move horizontal" -anchor w -justify left]\
    [entry $dialogWin.movHor]\
    [label $dialogWin.movHorComment\
      -text "Number, or left, right, Left, Right"  -anchor w -justify left]\
    -\
    -sticky news
  bind $dialogWin.movHor <Return> [list apply {
      {self entry} {
        set val [$entry get]
        if {[string is double -strict $val]} then {
          lmap dot [$self dots -selected] {
            $dot configure -x [+ [$dot cget -x] $val]
          }
        } else {
          switch -exact -- $val {
            left {
              lassign [$self bbox] left
              lmap dot [$self dots -selected] {
                $dot configure -x [- [$dot cget -x] $left]
              }
            }
            Left {
              set left [min {*}[$self dots -selected cget -x]]
              lmap dot [$self dots -selected] {
                $dot configure -x [- [$dot cget -x] $left]
              }
            }
            right {
              lassign [$self bbox] - - right
              set delta [- [$self setting width] $right]
              lmap dot [$self dots -selected] {
                $dot configure -x [+ [$dot cget -x] $delta]
              }
            }
            Right {
              set right [max {*}[$self dots -selected cget -x]]
              set delta [- [$self setting width] $right]
              lmap dot [$self dots -selected] {
                $dot configure -x [+ [$dot cget -x] $delta]
              }
            }
            default {
              return -code error\
                "Only number, or left, right, Left, Right!"
            }
          }
        }
        $self selected draw coords
      }
    } $self $dialogWin.movHor]
  # Move vertical
  grid\
    [label $dialogWin.movVerL -text "Move vertical" -anchor w -justify left]\
    [entry $dialogWin.movVer]\
    [label $dialogWin.movVerComment\
      -text "Number, or top, bottom, Top, Bottom" -anchor w -justify left]\
    -\
    -sticky news
  bind $dialogWin.movVer <Return> [list apply {
      {self entry} {
        set val [$entry get]
        if {[string is double -strict $val]} then {
          lmap dot [$self dots -selected] {
            $dot configure -y [+ [$dot cget -y] $val]
          }
        } else {
          switch -exact -- $val {
            top {
              lassign [$self bbox] - top
              lmap dot [$self dots -selected] {
                $dot configure -y [- [$dot cget -y] $top]
              }
            }
            Top {
              set top [min {*}[$self dots -selected cget -y]]
              lmap dot [$self dots -selected] {
                $dot configure -y [- [$dot cget -y] $top]
              }
            }
            bottom {
              lassign [$self bbox] - - - bottom
              set delta [- [$self setting height] $bottom]
              lmap dot [$self dots -selected] {
                $dot configure -y [+ [$dot cget -y] $delta]
              }
            }
            Bottom {
              set bottom [max {*}[$self dots -selected cget -y]]
              set delta [- [$self setting height] $bottom]
              lmap dot [$self dots -selected] {
                $dot configure -y [+ [$dot cget -y] $delta]
              }
            }
            default {
              return -code error\
                "Only number, or top, bottom, Top, Bottom!"
            }
          }
        }
        $self selected draw coords
      }
    } $self $dialogWin.movVer]
  set widthHeightLambda {
    {self dialogWin} {
      lassign [$self adjustSelWidthHeightNumeric] x y
      $dialogWin.width delete 0 end
      $dialogWin.width insert end $x
      $dialogWin.height delete 0 end
      $dialogWin.height insert end $y
    }
  }
  apply $widthHeightLambda $self $dialogWin
  #
  grid\
    [label $dialogWin.scaleLabel -text Scale -anchor w -justify left]\
    [entry $dialogWin.scale]\
    [label $dialogWin.scaleComment -anchor w -justify left\
      -text "One or two values, comma separated"]\
    -\
    -sticky news
  bind $dialogWin.scale <Return> [list apply [list {self win} {
        lassign [split [$win get] ,] width height
        set width [fexpr $width]
        if {$height eq ""} then {
          set height $width
        } else {
          set height [fexpr $height]
        }
        $self scaleSelectionNumeric $width $height
        $self memory scale [$win get]
      }] $self $dialogWin.scale]
  bind $dialogWin.scale <Return>\
    +[list apply $widthHeightLambda $self $dialogWin]
  #
  grid\
    [label $dialogWin.rotLabel -text Rotate -anchor w -justify left]\
    [entry $dialogWin.rot]\
    [label $dialogWin.rotComment -anchor w -justify left\
      -text "Floating point calc allowed"]\
    -\
    -sticky news
  if {"angle" in [dict keys [$self memory]]} then {
    $dialogWin.rot insert end [$self memory angle]
  }
  bind $dialogWin.rot <Return> [list apply {
      {self win} {
        set val [expr [$win get]]
        $self rotateSelectionNumeric $val
        $self memory angle [$win get]
      }
    } $self $dialogWin.rot]
  bind $dialogWin.rot <Return>\
    +[list apply $widthHeightLambda $self $dialogWin]
  #
  if {"scale" in [dict keys [$self memory]]} then {
    $dialogWin.scale insert end [$self memory scale]
  }
  #
  grid\
    [label $dialogWin.fColLabel -text "Fill Color" -anchor w -justify left]\
    [entry $dialogWin.fColor]\
    [button $dialogWin.fBrighten -text Brighten\
      -command "$self selected brighten fill 1.1"]\
    [button $dialogWin.fDarken -text Darken\
      -command "$self selected brighten fill 0.97"]\
    -sticky news
  $dialogWin.fColor insert end [my lastFillColor]
  bind $dialogWin.fColor <Return> [list apply {
      {self win} {
        if {[$win get] in {{} transparent}} then {
          $self selected changeFillColor transparent
        } else {
          winfo rgb . [$win get]
          $self selected changeFillColor [$win get]
          $self private lastFillColor [$win get]
        }
      }
    } $self $dialogWin.fColor]
  #
  grid\
    [label $dialogWin.lColLabel -text "Line Color" -anchor w -justify left]\
    [entry $dialogWin.lColor]\
    [button $dialogWin.lBrighten -text Brighten\
      -command "$self selected brighten outline 1.1"]\
    [button $dialogWin.lDarken -text Darken\
      -command "$self selected brighten outline 0.97"]\
    -sticky news
  $dialogWin.lColor insert end [my lastLineColor]
  bind $dialogWin.lColor <Return> [list apply {
      {self win} {
        if {[$win get] in {{} transparent}} then {
          $self selected changeLineColor transparent
        } else {
          winfo rgb . [$win get]
          $self selected changeLineColor [$win get]
          $self private lastLineColor [$win get]
        }
      }
    } $self $dialogWin.lColor]
  #
  grid\
    [label $dialogWin.lWidthLabel -text "Line width" -anchor w -justify left]\
    [entry $dialogWin.lWidth]\
    [button $dialogWin.lWiden -text Widen\
      -command "$self selected wider [expr {2**(1.0/3)}]"]\
    [button $dialogWin.lNarrow -text Narrow\
      -command "$self selected wider [expr {2**(-1.0/3)}]"]\
    -sticky news
  $dialogWin.lWidth insert end 3.0
  bind $dialogWin.lWidth <Return> [list apply {
      {self win} {
        $self selected changeLineWidth [expr [$win get]]
      }
    } $self $dialogWin.lWidth]
  adjustChildGeometry $dialogWin
}

© Wolf-Dieter Busch | Home | Sitemap | Urheber | A-Z