OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [insight/] [libgui/] [library/] [ventry.tcl] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 578 markom
# ventry.tcl - Entry with validation
2
# Copyright (C) 1997 Cygnus Solutions.
3
# Written by Tom Tromey <tromey@cygnus.com>.
4
 
5
itcl_class Validated_entry {
6
  # The validation command.  It is passed the contents of the entry.
7
  # It should throw an error if there is a problem; the error text
8
  # will be displayed to the user.
9
  public command {}
10
 
11
  constructor {config} {
12
    upvar \#0 $this state
13
 
14
    # The standard widget-making trick.
15
    set class [$this info class]
16
    set hull [namespace tail $this]
17
    set old_name $this
18
    ::rename $this $this-tmp-
19
    ::frame $hull -class $class -borderwidth 0
20
    ::rename $hull $old_name-win-
21
    ::rename $this $old_name
22
 
23
    ::set ${this}(value) ""
24
    ::entry [namespace tail $this].entry -textvariable ${this}(value)
25
    pack [namespace tail $this].entry -expand 1 -fill both
26
 
27
    bind [namespace tail $this].entry <Map> [list $this _map]
28
    bind [namespace tail $this].entry <Unmap> [list $this _unmap]
29
    bind [namespace tail $this].entry <Destroy> [list $this delete]
30
    # We never want the focus on the frame.
31
    bind [namespace tail $this] <FocusIn> [list focus [namespace tail $this].entry]
32
 
33
    # This window is used when the user enters a bad name for the new
34
    # executable.  The color here is "plum3".  We use a toplevel here
35
    # both to get a nice black border and because a frame would be
36
    # clipped by its parents.
37
    toplevel [namespace tail $this].badname -borderwidth 1 -background black -relief flat
38
    wm withdraw [namespace tail $this].badname
39
    wm overrideredirect [namespace tail $this].badname 1
40
 
41
    ::set state(message) ""
42
 
43
    # FIXME: -textvariable didn't work; I suspect itcl.
44
    ::label [namespace tail $this].badname.text -anchor w -justify left \
45
      -background \#cdd29687cdd2 ;# -textvariable ${this}(message)
46
    pack [namespace tail $this].badname.text -expand 1 -fill both
47
 
48
    # Trace the entry contents.
49
    uplevel \#0 [list trace variable ${this}(value) w [list $this _trace]]
50
  }
51
 
52
  destructor {
53
    upvar \#0 $this state
54
    catch {destroy $this}
55
    uplevel \#0 [list trace vdelete ${this}(value) w [list $this _trace]]
56
    unset state
57
  }
58
 
59
  method configure {config} {}
60
 
61
  # Return 1 if we're in the error state, 0 otherwise.
62
  method is_error {} {
63
    upvar \#0 $this state
64
    return [expr {$state(message) != ""}]
65
  }
66
 
67
  # Return error text.
68
  method error_text {} {
69
    upvar \#0 $this state
70
    return $state(message)
71
  }
72
 
73
  # Some methods to forward messages to the entry.  Add more as
74
  # required.
75
 
76
  # FIXME: itcl 1.5 won't let us have a `delete' method.  Sigh.
77
  method delete_hack {args} {
78
    return [eval [namespace tail $this].entry delete $args]
79
  }
80
 
81
  method get {} {
82
    return [[namespace tail $this].entry get]
83
  }
84
 
85
  method insert {index string} {
86
    return [[namespace tail $this].entry insert $index $string]
87
  }
88
 
89
 
90
  # This is run to display the label.  Private method.
91
  method _display {} {
92
    # FIXME: place above if it would go offscreen.
93
    set y [expr {[winfo rooty [namespace tail $this].entry] + [winfo height [namespace tail $this].entry] + 1}]
94
    set x [expr {round ([winfo rootx [namespace tail $this].entry]
95
                        + 0.12 * [winfo width [namespace tail $this].entry])}]
96
    wm positionfrom [namespace tail $this].badname user
97
    wm geometry [namespace tail $this].badname +$x+$y
98
    # Workaround for Tk 8.0b2 bug on NT.
99
    update
100
    wm deiconify [namespace tail $this].badname
101
    raise [namespace tail $this].badname
102
  }
103
 
104
  # This is run when the entry widget is mapped.  If we have an error,
105
  # map our error label.  Private method.
106
  method _map {} {
107
    if {[is_error]} then {
108
      _display
109
    }
110
  }
111
 
112
  # This is run when the entry widget is unmapped.  Private method.
113
  method _unmap {} {
114
    wm withdraw [namespace tail $this].badname
115
  }
116
 
117
  # This is called when the entry contents change.  Private method.
118
  method _trace {args} {
119
    upvar \#0 $this state
120
 
121
    if {$command != ""} then {
122
      set cmd $command
123
      lappend cmd $state(value)
124
      set cmd [list uplevel \#0 $cmd]
125
    }
126
    if {[info exists cmd] && [catch $cmd msg]} then {
127
      # FIXME: for some reason, the -textvariable on the label doesn't
128
      # work.  I suspect itcl.
129
      set state(message) $msg
130
      [namespace tail $this].badname.text configure -text $msg
131
      _display
132
    } else {
133
      set state(message) ""
134
      wm withdraw [namespace tail $this].badname
135
    }
136
  }
137
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.