[3330] | 1 | # -*- mode: tcl; indent-tabs-mode: nil -*- |
---|
[126] | 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 |
---|
[3177] | 10 | # Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
[126] | 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 | # ====================================================================== |
---|
| 15 | package require Itcl |
---|
| 16 | package require BLT |
---|
| 17 | |
---|
| 18 | namespace eval Rappture { # forward declaration } |
---|
| 19 | |
---|
| 20 | itcl::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 | |
---|
[785] | 27 | private variable _xmlobj "" ;# ref to lib obj with image data |
---|
| 28 | private variable _path "" ;# path in _xmlobj where data sits |
---|
[126] | 29 | private variable _image "" ;# underlying image data |
---|
[785] | 30 | private variable _hints |
---|
[126] | 31 | } |
---|
| 32 | |
---|
| 33 | # ---------------------------------------------------------------------- |
---|
| 34 | # CONSTRUCTOR |
---|
| 35 | # ---------------------------------------------------------------------- |
---|
| 36 | itcl::body Rappture::Image::constructor {xmlobj path} { |
---|
| 37 | if {![Rappture::library isvalid $xmlobj]} { |
---|
[1929] | 38 | error "bad value \"$xmlobj\": should be LibraryObj" |
---|
[126] | 39 | } |
---|
| 40 | set _xmlobj $xmlobj |
---|
[785] | 41 | set _path $path |
---|
[127] | 42 | set data [string trim [$xmlobj get $path.current]] |
---|
[126] | 43 | if {[string length $data] == 0} { |
---|
[1929] | 44 | set _image [image create photo] |
---|
[126] | 45 | } else { |
---|
[1929] | 46 | set _image [image create photo -data $data] |
---|
[126] | 47 | } |
---|
[785] | 48 | |
---|
| 49 | set _hints(note) [string trim [$_xmlobj get $_path.note.contents]] |
---|
| 50 | set _hints(tooldir) [$_xmlobj get tool.version.application.directory(tool)] |
---|
[126] | 51 | } |
---|
| 52 | |
---|
| 53 | # ---------------------------------------------------------------------- |
---|
| 54 | # DESTRUCTOR |
---|
| 55 | # ---------------------------------------------------------------------- |
---|
| 56 | itcl::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 | # ---------------------------------------------------------------------- |
---|
| 67 | itcl::body Rappture::Image::hints {{keyword ""}} { |
---|
[785] | 68 | if {$keyword != ""} { |
---|
[1929] | 69 | if {[info exists _hints($keyword)]} { |
---|
| 70 | return $_hints($keyword) |
---|
| 71 | } |
---|
| 72 | return "" |
---|
[785] | 73 | } |
---|
| 74 | return [array get _hints] |
---|
[126] | 75 | } |
---|