source: branches/1.4/gui/scripts/videochooser.tcl @ 5660

Last change on this file since 5660 was 5660, checked in by ldelgass, 9 years ago

Merge r5657:5659 from trunk (whitespace/style)

File size: 5.2 KB
Line 
1# -*- mode: tcl; indent-tabs-mode: nil -*-
2# ----------------------------------------------------------------------
3#  COMPONENT: videochooser - list videos
4#
5# ======================================================================
6#  AUTHOR:  Derrick Kearney, Purdue University
7#  Copyright (c) 2004-2012  HUBzero Foundation, LLC
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
13package require Itk
14package require BLT
15package require Img
16package require Rappture
17package require RapptureGUI
18
19itcl::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 ""
25    itk_option define -thumbsdir thumbsdir Thumbsdir ""
26
27    constructor { args } {
28        # defined below
29    }
30    destructor {
31        # defined below
32    }
33
34    public method load {paths}
35    public method select {id}
36    protected method _fixSize {}
37
38    private variable _vcnt 0            ;# counter of videos
39    private variable _variable ""       ;# variable to pass along to each choice
40    private variable _paths ""          ;# list of choice paths
41    private variable _objs ""           ;# list of choice objects
42}
43
44
45itk::usual VideoChooser {
46}
47
48# ----------------------------------------------------------------------
49# CONSTRUCTOR
50# ----------------------------------------------------------------------
51itcl::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# ----------------------------------------------------------------------
72itcl::body Rappture::VideoChooser::destructor {} {
73}
74
75# ----------------------------------------------------------------------
76# USAGE: load
77# ----------------------------------------------------------------------
78itcl::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} \
86                    -variable ${_variable} \
87                    -thumbsdir $itk_option(-thumbsdir)]
88        $ci load $path ""
89        pack $ci -expand yes -fill both -side left
90
91        # add the object to the list of video info objs
92        lappend _paths $path
93        lappend _objs $ci
94    }
95
96    _fixSize
97}
98
99# ----------------------------------------------------------------------
100# USAGE: select
101# ----------------------------------------------------------------------
102itcl::body Rappture::VideoChooser::select {id} {
103
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
127# ----------------------------------------------------------------------
128# USAGE: _fixSize
129# ----------------------------------------------------------------------
130itcl::body Rappture::VideoChooser::_fixSize {} {
131
132    # fix the dimesions of the canvas
133}
134
135# ----------------------------------------------------------------------
136# CONFIGURE: -variable
137# ----------------------------------------------------------------------
138itcl::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# ----------------------------------------------------------------------
154itcl::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# ----------------------------------------------------------------------
166itcl::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}
Note: See TracBrowser for help on using the repository browser.