source: trunk/gui/scripts/videochooser.tcl @ 3177

Last change on this file since 3177 was 3177, checked in by mmc, 12 years ago

Updated all of the copyright notices to reference the transfer to
the new HUBzero Foundation, LLC.

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