source: branches/blt4/gui/scripts/drawingentry.tcl @ 1695

Last change on this file since 1695 was 1342, checked in by gah, 16 years ago

preliminary HQ output from molvisviewer; unexpand tabs; all jpeg generation at 100%

File size: 4.1 KB
Line 
1# ----------------------------------------------------------------------
2#  COMPONENT: DrawingEntry - widget for entering numeric values
3#
4#  This widget represents a <number> entry on a control panel.
5#  It is used to enter numeric values.
6# ======================================================================
7#  AUTHOR:  Michael McLennan, Purdue University
8#  Copyright (c) 2004-2005  Purdue Research Foundation
9#
10#  See the file "license.terms" for information on usage and
11#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
12# ======================================================================
13package require Itk
14
15itcl::class Rappture::DrawingEntry {
16    inherit itk::Widget
17
18    itk_option define -state state State "normal"
19
20    constructor {owner path args} { # defined below }
21
22    public method value {args}
23
24    public method label {}
25    public method tooltip {}
26}
27
28itk::usual DrawingEntry {
29    keep -cursor -font
30    keep -foreground -background
31    keep -textbackground
32    keep -selectbackground -selectforeground -selectborderwidth
33}
34
35# ----------------------------------------------------------------------
36# CONSTRUCTOR
37# ----------------------------------------------------------------------
38itcl::body Rappture::DrawingEntry::constructor {owner path args} {
39    if {[catch {$owner isa Rappture::ControlOwner} valid] != 0 || !$valid} {
40        error "bad object \"$owner\": should be Rappture::ControlOwner"
41    }
42    set _path $path
43
44    #
45    # Display the current drawing.
46    #
47    itk_component add drawing {
48        Rappture::Drawing $itk_interior.drawing $owner $path
49    }
50    pack $itk_component(drawing) -expand yes -fill both
51
52    eval itk_initialize $args
53}
54
55# ----------------------------------------------------------------------
56# USAGE: value ?-check? ?<newval>?
57#
58# Clients use this to query/set the value for this widget.  With
59# no args, it returns the current value for the widget.  If the
60# <newval> is specified, it sets the value of the widget and
61# sends a <<Value>> event.  If the -check flag is included, the
62# new value is not actually applied, but just checked for correctness.
63# ----------------------------------------------------------------------
64itcl::body Rappture::DrawingEntry::value {args} {
65puts "value $args"
66    set onlycheck 0
67    set i [lsearch -exact $args -check]
68    if {$i >= 0} {
69        set onlycheck 1
70        set args [lreplace $args $i $i]
71    }
72
73    if {[llength $args] == 1} {
74        if {$onlycheck} {
75            # someday we may add validation...
76            return
77        }
78        set xmlobj [lindex $args 0]
79        $itk_component(drawing) value $xmlobj
80        return $xmlobj
81
82    } elseif {[llength $args] != 0} {
83        error "wrong # args: should be \"value ?-check? ?newval?\""
84    }
85
86    #
87    # Query the value and return.
88    #
89    return [$itk_component(drawing) value]
90}
91
92# ----------------------------------------------------------------------
93# USAGE: label
94#
95# Clients use this to query the label associated with this widget.
96# Reaches into the XML and pulls out the appropriate label string.
97# ----------------------------------------------------------------------
98itcl::body Rappture::DrawingEntry::label {} {
99return ""
100    set label [$_owner xml get $_path.about.label]
101    if {"" == $label} {
102        set label "Drawing"
103    }
104    return $label
105}
106
107# ----------------------------------------------------------------------
108# USAGE: tooltip
109#
110# Clients use this to query the tooltip associated with this widget.
111# Reaches into the XML and pulls out the appropriate description
112# string.  Returns the string that should be used with the
113# Rappture::Tooltip facility.
114# ----------------------------------------------------------------------
115itcl::body Rappture::DrawingEntry::tooltip {} {
116return ""
117    set str [$_owner xml get $_path.about.description]
118    return [string trim $str]
119}
120
121# ----------------------------------------------------------------------
122# CONFIGURATION OPTION: -state
123# ----------------------------------------------------------------------
124itcl::configbody Rappture::DrawingEntry::state {
125    set valid {normal disabled}
126    if {[lsearch -exact $valid $itk_option(-state)] < 0} {
127        error "bad value \"$itk_option(-state)\": should be [join $valid {, }]"
128    }
129}
Note: See TracBrowser for help on using the repository browser.