source: trunk/gui/scripts/image.tcl @ 4730

Last change on this file since 4730 was 3330, checked in by gah, 12 years ago

merge (by hand) with Rappture1.2 branch

File size: 2.7 KB
Line 
1# -*- mode: tcl; indent-tabs-mode: nil -*-
2# ----------------------------------------------------------------------
3#  COMPONENT: image - represents a picture image
4#
5#  This object represents a Tk image.  It is convenient to have it
6#  expressed as an Itcl object, so it can be managed just like a
7#  curve, table, etc.
8# ======================================================================
9#  AUTHOR:  Michael McLennan, Purdue University
10#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
11#
12#  See the file "license.terms" for information on usage and
13#  redistribution of this file, and for a DISCLAIMER OF ALL WARRANTIES.
14# ======================================================================
15package require Itcl
16package require BLT
17
18namespace eval Rappture { # forward declaration }
19
20itcl::class Rappture::Image {
21    constructor {xmlobj path} { # defined below }
22    destructor { # defined below }
23
24    public method tkimage {} { return $_image }
25    public method hints {{keyword ""}}
26
27    private variable _xmlobj ""  ;# ref to lib obj with image data
28    private variable _path ""    ;# path in _xmlobj where data sits
29    private variable _image ""   ;# underlying image data
30    private variable _hints
31}
32
33# ----------------------------------------------------------------------
34# CONSTRUCTOR
35# ----------------------------------------------------------------------
36itcl::body Rappture::Image::constructor {xmlobj path} {
37    if {![Rappture::library isvalid $xmlobj]} {
38        error "bad value \"$xmlobj\": should be LibraryObj"
39    }
40    set _xmlobj $xmlobj
41    set _path $path
42    set data [string trim [$xmlobj get $path.current]]
43    if {[string length $data] == 0} {
44        set _image [image create photo]
45    } else {
46        set _image [image create photo -data $data]
47    }
48
49    set _hints(note) [string trim [$_xmlobj get $_path.note.contents]]
50    set _hints(tooldir) [$_xmlobj get tool.version.application.directory(tool)]
51}
52
53# ----------------------------------------------------------------------
54# DESTRUCTOR
55# ----------------------------------------------------------------------
56itcl::body Rappture::Image::destructor {} {
57    image delete $_image
58}
59
60# ----------------------------------------------------------------------
61# USAGE: hints ?<keyword>?
62#
63# Returns a list of key/value pairs for various hints about showing
64# this image.  If a particular <keyword> is specified, then it returns
65# the hint for that <keyword>, if it exists.
66# ----------------------------------------------------------------------
67itcl::body Rappture::Image::hints {{keyword ""}} {
68    if {$keyword != ""} {
69        if {[info exists _hints($keyword)]} {
70            return $_hints($keyword)
71        }
72        return ""
73    }
74    return [array get _hints]
75}
Note: See TracBrowser for help on using the repository browser.