Changeset 2023 for trunk/gui/scripts/videoscreen.tcl
- Timestamp:
- Jan 9, 2011 9:30:53 PM (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/gui/scripts/videoscreen.tcl
r1979 r2023 17 17 18 18 option add *Video.width 300 widgetDefault 19 option add *Video*cursor crosshair widgetDefault20 19 option add *Video.height 300 widgetDefault 21 20 option add *Video.foreground black widgetDefault 22 21 option add *Video.controlBackground gray widgetDefault 23 option add *Video.controlDarkBackground #999999 widgetDefault24 option add *Video.plotBackground black widgetDefault25 option add *Video.plotForeground white widgetDefault26 option add *Video.plotOutline gray widgetDefault27 22 option add *Video.font \ 28 23 -*-helvetica-medium-r-normal-*-12-* widgetDefault … … 31 26 inherit itk::Widget 32 27 33 itk_option define -plotforeground plotForeground Foreground ""34 itk_option define -plotbackground plotBackground Background ""35 itk_option define -plotoutline plotOutline PlotOutline ""36 28 itk_option define -width width Width -1 37 29 itk_option define -height height Height -1 30 itk_option define -fileopen fileopen Fileopen "" 38 31 39 32 constructor { args } { … … 109 102 110 103 array set _settings [subst { 111 $this-currenttime 0112 104 $this-framenum 0 113 105 $this-loop 0 … … 122 114 123 115 124 125 116 # Create flow controls... 126 117 … … 132 123 rename -background -controlbackground controlBackground Background 133 124 } 134 135 # pack $itk_component(main) -side top -expand yes -fill both136 125 bind $itk_component(main) <Configure> [itcl::code $this fixSize] 126 127 # hold the video frames in an image on the canvas 128 set _imh [image create photo] 129 $itk_component(main) create image 0 0 -anchor nw -image $_imh 137 130 138 131 # setup movie controls … … 154 147 set imagesDir [file join $RapptureGUI::library scripts images] 155 148 149 # ==== fileopen ==== 150 itk_component add fileopen { 151 button $itk_component(moviecontrols).fileopen \ 152 -borderwidth 1 -padx 1 -pady 1 \ 153 -image [Rappture::icon upload] \ 154 -command [itcl::code $this loadcb] 155 #-command [Rappture::filexfer::upload {piv tool} {id label desc} [itcl::code $this Upload]] 156 #-command [itcl::code $this video seek 0] 157 } { 158 usual 159 ignore -borderwidth 160 rename -highlightbackground -controlbackground controlBackground \ 161 Background 162 } 163 Rappture::Tooltip::for $itk_component(fileopen) \ 164 "Open file" 156 165 157 166 # ==== measuring tool ==== … … 254 263 "Play continuously between marked sections" 255 264 256 # Video Dial257 265 itk_component add dial { 258 Rappture::Videodial $itk_component(moviecontrols).dial \ 266 frame $itk_interior.dial 267 } { 268 usual 269 rename -background -controlbackground controlBackground Background 270 } 271 272 # Video Dial Major 273 itk_component add dialmajor { 274 Rappture::Videodial1 $itk_component(dial).dialmajor \ 259 275 -length 10 -valuewidth 0 -valuepadding 0 -padding 6 \ 260 276 -linecolor "" -activelinecolor "" \ 261 277 -min 0 -max 1 \ 262 -minortick 1 -majortick 5 \ 263 -variable [itcl::scope _settings($this-currenttime)] \ 278 -variable [itcl::scope _settings($this-framenum)] \ 264 279 -dialoutlinecolor black \ 265 280 -knobimage [Rappture::icon knob2] -knobposition center@middle … … 269 284 rename -background -controlbackground controlBackground Background 270 285 } 271 $itk_component(dial) current 0 272 bind $itk_component(dial) <<Value>> [itcl::code $this video update] 286 $itk_component(dialmajor) current 0 287 bind $itk_component(dialmajor) <<Value>> [itcl::code $this video update] 288 289 # Video Dial Minor 290 itk_component add dialminor { 291 Rappture::Videodial2 $itk_component(dial).dialminor \ 292 -padding 0 \ 293 -min 0 -max 1 \ 294 -minortick 1 -majortick 5 \ 295 -variable [itcl::scope _settings($this-framenum)] \ 296 -dialoutlinecolor black 297 } { 298 usual 299 rename -background -controlbackground controlBackground Background 300 } 301 $itk_component(dialminor) current 0 302 bind $itk_component(dialminor) <<Value>> [itcl::code $this video update] 273 303 274 304 itk_component add framenumlabel { … … 282 312 283 313 # Current Frame Number 284 #set ffont "arial 9"285 #set fwidth [calcLabelWidth $ffont]286 314 itk_component add framenum { 287 315 label $itk_component(frnumfr).framenum \ … … 293 321 rename -background -controlbackground controlBackground Background 294 322 } 295 #$itk_component(framenum) value 1296 #bind $itk_component(framenum) <<Value>> \297 # [itcl::code $this video seek -framenum]298 323 Rappture::Tooltip::for $itk_component(framenum) \ 299 324 "Current frame number" … … 315 340 # Speed 316 341 itk_component add speed { 317 Rappture:: Flowspeed $itk_component(moviecontrols).speed \318 -min 1 -max 10 -width 3 -font "arial 9"342 Rappture::Videospeed $itk_component(moviecontrols).speed \ 343 -min 0 -max 1 -width 4 -font "arial 9" -factor 2 319 344 } { 320 345 usual … … 325 350 "Change speed of movie" 326 351 327 $itk_component(speed) value 1352 $itk_component(speed) value 0.25 328 353 bind $itk_component(speed) <<Value>> [itcl::code $this video speed] 329 354 330 355 356 blt::table $itk_component(dial) \ 357 0,0 $itk_component(dialmajor) -fill x \ 358 1,0 $itk_component(dialminor) -fill x 359 360 331 361 blt::table $itk_component(moviecontrols) \ 332 0,0 $itk_component(measure) -padx {2 0} \ 333 0,1 $itk_component(particle) -padx {4 0} \ 362 0,0 $itk_component(fileopen) -padx {2 0} \ 363 0,1 $itk_component(measure) -padx {4 0} \ 364 0,2 $itk_component(particle) -padx {4 0} \ 334 365 0,5 $itk_component(dial) -fill x -padx {2 4} -rowspan 3 \ 335 366 1,0 $itk_component(rewind) -padx {2 0} \ … … 361 392 itcl::body Rappture::VideoScreen::destructor {} { 362 393 array unset _settings $this-* 394 if {[info exists _imh]} { 395 image delete $_imh 396 } 363 397 } 364 398 … … 394 428 } 395 429 430 if {([info exists _movie]) && ("" != ${_movie})} { 431 ${_movie} release 432 } 433 396 434 set _movie [Rappture::Video $type $data] 397 435 file delete $fname 398 436 set _framerate [${_movie} get framerate] 399 set _mspf [expr round(((1.0/${_framerate})*1000)/pow(2,$_settings($this-speed)-1))] 400 set _delay [expr {${_mspf} - ${_ofrd}}] 401 puts stderr "framerate = ${_framerate}" 402 puts stderr "mspf = ${_mspf}" 403 puts stderr "ofrd = ${_ofrd}" 404 puts stderr "delay = ${_delay}" 405 406 ${_movie} seek 0 437 video speed 438 439 video seek 0 440 441 # update the dial and framenum widgets 442 set _settings($this-framenum) 0 443 407 444 408 445 # setup the image display 409 446 410 set _imh [image create photo]411 447 foreach {w h} [query dimensions] break 412 448 if {${_width} == -1} { … … 416 452 set _height $h 417 453 } 418 $itk_component(main) create image 0 0 -anchor nw -image $_imh419 454 420 455 set _lastFrame [$_movie get position end] 421 456 422 457 # update the dial with video information 423 $itk_component(dial) configure -min 0 -max ${_lastFrame} 458 $itk_component(dialmajor) configure -min 0 -max ${_lastFrame} 459 $itk_component(dialminor) configure -min 0 -max ${_lastFrame} 424 460 425 461 fixSize … … 466 502 } 467 503 468 set _width [winfo width $itk_component(main)] 469 set _height [winfo height $itk_component(main)] 504 # set _width [winfo width $itk_component(main)] 505 # set _height [winfo height $itk_component(main)] 506 # 507 # # get an image with the new size 508 # ${_imh} put [${_movie} get image ${_width} ${_height}] 509 # 510 # # fix the dimesions of the canvas 511 # #$itk_component(main) configure -width ${_width} -height ${_height} 512 # 513 # $itk_component(main) configure -scrollregion [$itk_component(main) bbox all] 514 515 ###################### 470 516 471 517 # get an image with the new size 472 518 ${_imh} put [${_movie} get image ${_width} ${_height}] 473 474 # fix the dimesions of the canvas 475 #$itk_component(main) configure -width ${_width} -height ${_height} 476 477 $itk_component(main) configure -scrollregion [$itk_component(main) bbox all] 519 puts stderr "${_width} ${_height}" 520 521 # fix the dimesions of the video canvas 522 $itk_component(main) configure -width ${_width} -height ${_height} 478 523 } 479 524 … … 486 531 "play" { 487 532 if {$_settings($this-play) == 1} { 488 # disable seek while playing489 # bind $itk_component(dial) <<Value>> ""490 533 eventually play 491 534 } else { … … 494 537 set _pendings(play) 0 495 538 set _settings($this-play) 0 496 # enable seek while paused497 # bind $itk_component(dial) <<Value>> [itcl::code $this updateFrame]498 539 } 499 540 } … … 507 548 "speed" { 508 549 set speed [$itk_component(speed) value] 509 set _mspf [expr round(((1.0/${_framerate})*1000)/ pow(2,$speed-1))]550 set _mspf [expr round(((1.0/${_framerate})*1000)/$speed)] 510 551 set _delay [expr {${_mspf} - ${_ofrd}}] 511 552 puts stderr "_mspf = ${_mspf} | $speed | ${_ofrd} | ${_delay}" 512 553 } 513 554 "update" { 514 #video stop 515 # eventually seek [expr round($_settings($this-currenttime))] 516 Seek [expr round($_settings($this-currenttime))] 517 # Seek $_settings($this-framenum) 518 #after idle [itcl::code $this video play] 555 # eventually seek [expr round($_settings($this-framenum))] 556 Seek [expr round($_settings($this-framenum))] 519 557 } 520 558 default { … … 555 593 itcl::body Rappture::VideoScreen::Play {} { 556 594 595 set cur ${_nextframe} 596 557 597 # time how long it takes to retrieve the next frame 558 598 set _ofrd [time { 559 $_movie seek $_nextframe 599 # use seek instead of next fxn incase the ${_nextframe} is 600 # not the current frame+1. this happens when we skip frames 601 # because the underlying c lib is too slow at reading. 602 $_movie seek $cur 560 603 $_imh put [$_movie get image ${_width} ${_height}] 561 604 } 1] … … 574 617 575 618 # update the dial and framenum widgets 576 set _settings($this-currenttime) $cur577 619 set _settings($this-framenum) $cur 578 620 579 if {[expr $cur%100] == 0} {580 # puts stderr "ofrd = ${_ofrd}"581 # puts stderr "delay = ${_delay}"582 # puts stderr "after: [after info]"583 # puts stderr "id = ${_id}"584 }585 621 586 622 # no play cmds pending … … 590 626 # then loop back to loopstart when cur hits loopend 591 627 if {$_settings($this-loop)} { 592 if {$cur == [$itk_component(dial ) mark position loopend]} {593 Seek [$itk_component(dial ) mark position loopstart]628 if {$cur == [$itk_component(dialminor) mark position loopend]} { 629 Seek [$itk_component(dialminor) mark position loopstart] 594 630 } 595 631 } … … 598 634 if {$cur < ${_lastFrame}} { 599 635 set _id [after ${_delay} [itcl::code $this eventually play]] 600 } 601 602 # event generate $itk_component(hull) <<Frame>> 636 } else { 637 video stop 638 } 639 640 event generate $itk_component(hull) <<Frame>> 603 641 } 604 642 … … 624 662 625 663 # update the dial and framenum widgets 664 set _settings($this-framenum) [$_movie get position cur] 626 665 event generate $itk_component(main) <<Frame>> 627 set cur [$_movie get position cur]628 set _settings($this-currenttime) $cur629 set _settings($this-framenum) $cur630 666 631 667 } … … 836 872 ${_obj} Coords $x $y $x $y 837 873 ${_obj} Show object 838 $itk_component(dial ) mark add arrow current874 $itk_component(dialminor) mark add arrow current 839 875 } 840 876 "drag" { … … 898 934 ${_obj} Coords $x $y 899 935 ${_obj} Show object 900 $itk_component(dial ) mark add $name current936 $itk_component(dialminor) mark add $name current 901 937 # bind $itk_component(hull) <<Frame>> [itcl::code $itk_component(main).$name UpdateFrame] 902 938 … … 993 1029 # ---------------------------------------------------------------------- 994 1030 itcl::body Rappture::VideoScreen::writeText {x y text color tags width} { 995 # write text up-left 996 $itk_component(main) create text [expr $x-1] [expr $y-1] \ 1031 $itk_component(main) create text [expr $x-1] [expr $y] \ 997 1032 -tags $tags \ 998 1033 -justify center \ … … 1001 1036 -width $width 1002 1037 1003 # write text down-right 1004 $itk_component(main) create text [expr $x+1] [expr $y+1] \ 1038 $itk_component(main) create text [expr $x+1] [expr $y] \ 1005 1039 -tags $tags \ 1006 1040 -justify center \ … … 1008 1042 -fill black \ 1009 1043 -width $width 1044 1045 $itk_component(main) create text [expr $x] [expr $y-1] \ 1046 -tags $tags \ 1047 -justify center \ 1048 -text $text \ 1049 -fill black \ 1050 -width $width 1051 1052 $itk_component(main) create text [expr $x] [expr $y+1] \ 1053 -tags $tags \ 1054 -justify center \ 1055 -text $text \ 1056 -fill black \ 1057 -width $width 1058 1059 # # write text up-left 1060 # $itk_component(main) create text [expr $x-1] [expr $y-1] \ 1061 # -tags $tags \ 1062 # -justify center \ 1063 # -text $text \ 1064 # -fill black \ 1065 # -width $width 1066 # 1067 # # write text down-right 1068 # $itk_component(main) create text [expr $x+1] [expr $y+1] \ 1069 # -tags $tags \ 1070 # -justify center \ 1071 # -text $text \ 1072 # -fill black \ 1073 # -width $width 1010 1074 1011 1075 # write text at x,y … … 1031 1095 1032 1096 if {($frames != 0) && (${_px2dist} != 0)} { 1033 set t [expr 1.0*$px/$frames /${_px2dist}*${_framerate}]1097 set t [expr 1.0*$px/$frames*${_px2dist}*${_framerate}] 1034 1098 } else { 1035 1099 set t 0.0 … … 1044 1108 itcl::body Rappture::VideoScreen::toggleloop {} { 1045 1109 if {$_settings($this-loop) == 0} { 1046 $itk_component(dial ) mark remove loopstart1047 $itk_component(dial ) mark remove loopend1110 $itk_component(dialminor) mark remove loopstart 1111 $itk_component(dialminor) mark remove loopend 1048 1112 } else { 1049 1113 set cur [$_movie get position cur] … … 1060 1124 } 1061 1125 1062 $itk_component(dial ) mark add loopstart $startframe1063 $itk_component(dial ) mark add loopend $endframe1126 $itk_component(dialminor) mark add loopstart $startframe 1127 $itk_component(dialminor) mark add loopend $endframe 1064 1128 } 1065 1129 … … 1074 1138 error "bad value: \"$itk_option(-width)\": width should be an integer" 1075 1139 } 1076 set ${_width}$itk_option(-width)1140 set _width $itk_option(-width) 1077 1141 after idle [itcl::code $this fixSize] 1078 1142 } … … 1086 1150 error "bad value: \"$itk_option(-height)\": height should be an integer" 1087 1151 } 1088 set ${_height}$itk_option(-height)1152 set _height $itk_option(-height) 1089 1153 after idle [itcl::code $this fixSize] 1090 1154 } 1155 1156 # ---------------------------------------------------------------------- 1157 # OPTION: -fileopen 1158 # ---------------------------------------------------------------------- 1159 itcl::configbody Rappture::VideoScreen::fileopen { 1160 $itk_component(fileopen) configure -command $itk_option(-fileopen) 1161 }
Note: See TracChangeset
for help on using the changeset viewer.