[3330] | 1 | # -*- mode: tcl; indent-tabs-mode: nil -*- |
---|
[2023] | 2 | # ---------------------------------------------------------------------- |
---|
| 3 | # COMPONENT: videochooser - list videos |
---|
| 4 | # |
---|
| 5 | # ====================================================================== |
---|
| 6 | # AUTHOR: Derrick Kearney, Purdue University |
---|
[3177] | 7 | # Copyright (c) 2004-2012 HUBzero Foundation, LLC |
---|
[2023] | 8 | # |
---|
| 9 | # See the file "license.terms" for information on usage and redistribution of |
---|
| 10 | # this file, and for a DISCLAIMER OF ALL WARRANTIES. |
---|
| 11 | # ====================================================================== |
---|
| 12 | |
---|
| 13 | package require Itk |
---|
| 14 | package require BLT |
---|
| 15 | package require Img |
---|
| 16 | package require Rappture |
---|
| 17 | package require RapptureGUI |
---|
| 18 | |
---|
| 19 | itcl::class Rappture::VideoChooser { |
---|
| 20 | inherit itk::Widget |
---|
| 21 | |
---|
| 22 | itk_option define -width width Width 300 |
---|
| 23 | itk_option define -height height Height 300 |
---|
| 24 | itk_option define -variable variable Variable "" |
---|
[2069] | 25 | itk_option define -thumbsdir thumbsdir Thumbsdir "" |
---|
[2023] | 26 | |
---|
| 27 | constructor { args } { |
---|
| 28 | # defined below |
---|
| 29 | } |
---|
| 30 | destructor { |
---|
| 31 | # defined below |
---|
| 32 | } |
---|
| 33 | |
---|
[2067] | 34 | public method load {paths} |
---|
| 35 | public method select {id} |
---|
[2023] | 36 | protected method _fixSize {} |
---|
| 37 | |
---|
| 38 | private variable _vcnt 0 ;# counter of videos |
---|
| 39 | private variable _variable "" ;# variable to pass along to each choice |
---|
[2067] | 40 | private variable _paths "" ;# list of choice paths |
---|
[2023] | 41 | private variable _objs "" ;# list of choice objects |
---|
| 42 | } |
---|
| 43 | |
---|
| 44 | |
---|
| 45 | itk::usual VideoChooser { |
---|
| 46 | } |
---|
| 47 | |
---|
| 48 | # ---------------------------------------------------------------------- |
---|
| 49 | # CONSTRUCTOR |
---|
| 50 | # ---------------------------------------------------------------------- |
---|
| 51 | itcl::body Rappture::VideoChooser::constructor {args} { |
---|
| 52 | |
---|
| 53 | itk_component add scroller { |
---|
| 54 | Rappture::Scroller $itk_interior.scroller \ |
---|
| 55 | -xscrollmode auto \ |
---|
| 56 | -yscrollmode off \ |
---|
| 57 | -xscrollside bottom |
---|
| 58 | } |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | $itk_component(scroller) contents frame |
---|
| 62 | |
---|
| 63 | |
---|
| 64 | pack $itk_component(scroller) -fill both -expand yes |
---|
| 65 | |
---|
| 66 | eval itk_initialize $args |
---|
| 67 | } |
---|
| 68 | |
---|
| 69 | # ---------------------------------------------------------------------- |
---|
| 70 | # DESTRUCTOR |
---|
| 71 | # ---------------------------------------------------------------------- |
---|
| 72 | itcl::body Rappture::VideoChooser::destructor {} { |
---|
| 73 | } |
---|
| 74 | |
---|
| 75 | # ---------------------------------------------------------------------- |
---|
| 76 | # USAGE: load |
---|
| 77 | # ---------------------------------------------------------------------- |
---|
| 78 | itcl::body Rappture::VideoChooser::load {paths} { |
---|
| 79 | |
---|
| 80 | set f [$itk_component(scroller) contents] |
---|
| 81 | |
---|
| 82 | foreach path $paths { |
---|
| 83 | incr _vcnt |
---|
| 84 | |
---|
| 85 | set ci [Rappture::VideoChooserInfo $f.vi${_vcnt} \ |
---|
[2069] | 86 | -variable ${_variable} \ |
---|
| 87 | -thumbsdir $itk_option(-thumbsdir)] |
---|
[2023] | 88 | $ci load $path "" |
---|
[2067] | 89 | pack $ci -expand yes -fill both -side left |
---|
[2023] | 90 | |
---|
| 91 | # add the object to the list of video info objs |
---|
[2067] | 92 | lappend _paths $path |
---|
[2023] | 93 | lappend _objs $ci |
---|
| 94 | } |
---|
| 95 | |
---|
| 96 | _fixSize |
---|
| 97 | } |
---|
| 98 | |
---|
[2067] | 99 | # ---------------------------------------------------------------------- |
---|
| 100 | # USAGE: select |
---|
| 101 | # ---------------------------------------------------------------------- |
---|
| 102 | itcl::body Rappture::VideoChooser::select {id} { |
---|
[2023] | 103 | |
---|
[2067] | 104 | set obj "" |
---|
| 105 | |
---|
| 106 | if {[string is integer $id] == 1} { |
---|
| 107 | # treat $id as the index |
---|
| 108 | if {($id < 0) && ($id >= [llength ${_objs}])} { |
---|
| 109 | error "invalid id \"$id\": must be in range 0 to [llength ${_objs}]" |
---|
| 110 | } |
---|
| 111 | } else { |
---|
| 112 | # treat $id as a file path |
---|
| 113 | set idx [lsearch -exact ${_paths} $id] |
---|
| 114 | if {$idx == -1} { |
---|
| 115 | error "invalid id \"$id\": not found in list of loaded objects" |
---|
| 116 | } |
---|
| 117 | set id $idx |
---|
| 118 | } |
---|
| 119 | |
---|
| 120 | # grab the object associated with the id |
---|
| 121 | # and call it's select function. |
---|
| 122 | set obj [lindex ${_objs} $id] |
---|
| 123 | $obj select |
---|
| 124 | } |
---|
| 125 | |
---|
| 126 | |
---|
[2023] | 127 | # ---------------------------------------------------------------------- |
---|
| 128 | # USAGE: _fixSize |
---|
| 129 | # ---------------------------------------------------------------------- |
---|
| 130 | itcl::body Rappture::VideoChooser::_fixSize {} { |
---|
| 131 | |
---|
| 132 | # fix the dimesions of the canvas |
---|
| 133 | } |
---|
| 134 | |
---|
| 135 | # ---------------------------------------------------------------------- |
---|
| 136 | # CONFIGURE: -variable |
---|
| 137 | # ---------------------------------------------------------------------- |
---|
| 138 | itcl::configbody Rappture::VideoChooser::variable { |
---|
| 139 | set _variable $itk_option(-variable) |
---|
| 140 | |
---|
| 141 | if {"" != $_variable} { |
---|
| 142 | upvar #0 $_variable var |
---|
| 143 | |
---|
| 144 | foreach o ${_objs} { |
---|
| 145 | # tell this object's children about the variable change |
---|
| 146 | $o configure -variable $var |
---|
| 147 | } |
---|
| 148 | } |
---|
| 149 | } |
---|
| 150 | |
---|
| 151 | # ---------------------------------------------------------------------- |
---|
| 152 | # OPTION: -width |
---|
| 153 | # ---------------------------------------------------------------------- |
---|
| 154 | itcl::configbody Rappture::VideoChooser::width { |
---|
| 155 | # $_dispatcher event -idle !fixsize |
---|
| 156 | if {[string is integer $itk_option(-width)] == 0} { |
---|
| 157 | error "bad value: \"$itk_option(-width)\": width should be an integer" |
---|
| 158 | } |
---|
| 159 | set _width $itk_option(-width) |
---|
| 160 | after idle [itcl::code $this _fixSize] |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | # ---------------------------------------------------------------------- |
---|
| 164 | # OPTION: -height |
---|
| 165 | # ---------------------------------------------------------------------- |
---|
| 166 | itcl::configbody Rappture::VideoChooser::height { |
---|
| 167 | # $_dispatcher event -idle !fixsize |
---|
| 168 | if {[string is integer $itk_option(-height)] == 0} { |
---|
| 169 | error "bad value: \"$itk_option(-height)\": height should be an integer" |
---|
| 170 | } |
---|
| 171 | set _height $itk_option(-height) |
---|
| 172 | after idle [itcl::code $this _fixSize] |
---|
| 173 | } |
---|