tcl/tk scrollbar not working - scrollbar

i am given a frame and i try to put a scrollable canvas into it.
everything seems to work fine and i get scrollbar but they dont seem to work.
scrollbar does expand and contract when i resize window and does move when i click on its bottom or top.
for frame .f and canvas .f.c
my yview output changes when i try to scroll
i.e
.f.c yview
.08 .35
.f.c yview
.38 .62
.f.c yview
.75 1
i am not sure what have i missed here?
frame .f
canvas .f.c
put few labels
place them
scrollbar .f.ysb -orient vertical -command ".f.c yview"
.f.c configure -yscrollcommand ".f.ysb set" -scrollregion [list -1000 -1000 1000 1000]
grid .f.c -row 0 -column 0 -sticky nsew
grid .f.ysb -row 0 -column 1 -sticky ns
grid columnconfigure .f 0 -weight 1
grid rowconfigure .f 0 -weight 1

Related

elipzMode prop in Text component(Styled Component) not working as intended

output
Requrement(intended output)*
(All lines should be aligned -
1 st line should be align to others
as below)
Bailees Co...e Shake : 1
Bailees Co...e Shake : 2
Bailees Co...e Shake : 3

Blinking color sequence in Angular

I have a task to create 4 blinking divs in an Angular project. The colors come from an API in an array with 16 elements and each element is an array with 4 elements (string).
ColorPatterns[
Pattern1["Color1", "Color2", "Color3", "Color4"],
Pattern2["Color1", "Color2", "Color3", "Color4"],
...
Pattern16["Color1", "Color2", "Color3", "Color4"],
]
Color1 is for the first div, Color2 is for the second div and so on.
The sequence of 16 must change per 1 second and after the last element (Pattern16) the sequence should start over: Pattern1 -> Pattern2 -> ... -> Pattern16 -> Pattern1 -> ... .
How should this problem be solved in Angular?
Use an Observable to do the timing stuff. If we can to it for one div then others can be repeated.
Observable.interval(1000) //emit every 1 sec with values = 0 then 1 them 2 ..
.map(value=>ColorPaterns[value%16][0]) // 0 for 1st color
.subscribe((firstColor)=>{
// set 1st div color here
})

Obtaining pixel value from 16-bit tiff images using magick package in R

Does anyone know how to obtain the pixel value for each channel (RGB) from 16-bit tiff images using the magick package in R? Currently I am using Mathematica to perform this operation, because I could not find an equivalent way to doing it in mathematica.
I have tried to read the pixel value from the image-magick package and the results is a raw type (e.g. "ff"). I used the function rawToNum (package "pack") to convert the raw type to numeric and the results is close to what I obtain using ImageDate function in Mathematica, but not exactly the same.
You can also access the pixels as a numeric array with the magick package. The example is based on this vignette from the package.
library(magick)
tiger <- image_read('http://jeroen.github.io/images/tiger.svg')
tiger_tiff <- image_convert(tiger, "tiff")
# Access data in raw format and convert to integer
tiger_array <- as.integer(tiger_tiff[[1]])
Then if check the dimension and type you get:
dim(tiger_array)
[1] 900 900 4
is.numeric(tiger_array)
[1] TRUE
I don't know too much about R at all, but I guess you can "shell out" and execute an external command, using system() or somesuch.
If, so, maybe you can use this. First, let's make a 16-bit TIFF file that is a gradient from red-blue just 10 pixels wide and 1 pixel tall:
convert -size 10x1 gradient:red-blue image.tiff
Now we can dump the pixels to a file using ImageMagick:
convert image.tiff rgb:image.rgb
# Now check its length - yes, 60 bytes = 10 pixels with 2 bytes each for RG &B
ls -l image.rgb
-rw-r--r-- 1 mark staff 60 11 Jul 10:32 image.rgb
We can also write the data to stdout like this:
convert image.tiff rgb:-
and also look at it with 1 pixel per line (6 bytes)
convert image.tiff rgb:- | xxd -g 3 -c 6
00000000: ffff00 000000 ...... # Full Red, no Green, no Blue
00000006: 8de300 00721c ....r. # Lots of Red, no Green, a little Blue
0000000c: 1cc700 00e338 .....8
00000012: aaaa00 005555 ....UU
00000018: 388e00 00c771 8....q
0000001e: c77100 00388e .q..8.
00000024: 555500 00aaaa UU....
0000002a: e33800 001cc7 .8....
00000030: 721c00 008de3 r.....
00000036: 000000 00ffff ...... # No Red, no Green, full Blue
I'm hoping you can do something like that in R, with:
system("convert image.tif rgb:-")
Another way of dumping the pixels might be with Perl to slurp the entire file and then unpack the contained unsigned shorts and print them one per line:
convert image.tiff rgb: | perl -e 'my $str=do{local $/; <STDIN>}; print join("\n",unpack("v*",$str)),"\n";'
Sample Output
65535 # Full Red
0 # No Green
0 # No Blue
58253 # Lots of Red
0 # No Green
7282 # A little Blue
50972 # Moderate Red
0
14563
43690
0
21845
36408
0
29127
29127
0
36408
21845
0
43690
14563
0
50972
7282
0 # No Green
58253 # Lots of Blue
0 # No Red
0 # No Green
65535 # Full Blue
Another way of seeing the data may be using od and awk like this:
convert image.tiff rgb: | od -An -tuS | awk '{for(i=1;i<=NF;i++){print $i}}'
65535
0
0
58253
0
7282
50972
0
14563
43690
0
21845
36408
0
29127
29127
0
36408
21845
0
43690
14563
0
50972
7282
0
58253
0
0
65535
where the -An suppresses printing of the address, and the -tuS says the type of the data is unsigned short.
Perhaps a slightly simpler way in ImageMagick would be to use the txt: output format.
Using Mark Setchell's image:
convert -size 10x1 gradient:red-blue image.tiff
Using TXT: as
convert image.tiff txt: | sed -n 's/^.*[(]\(.*\)[)].*[#].*$/\1/p'
Produces:
65535,0,0
58253,0,7282
50972,0,14563
43690,0,21845
36408,0,29127
29127,0,36408
21845,0,43690
14563,0,50972
7282,0,58253
0,0,65535
or Using TXT: to include the pixel coordinates
convert image.tiff txt: | sed -n 's/^\(.*[)]\).*[#].*$/\1/p'
Produces:
0,0: (65535,0,0)
1,0: (58253,0,7282)
2,0: (50972,0,14563)
3,0: (43690,0,21845)
4,0: (36408,0,29127)
5,0: (29127,0,36408)
6,0: (21845,0,43690)
7,0: (14563,0,50972)
8,0: (7282,0,58253)
9,0: (0,0,65535)
Thank you all. The best answer I found was given by a student of mine using the package raster:
library(raster)
img <- stack(filename)
x <- as.matrix(raster(img, 1)) # here we specify the layer 1, 2 or 3
The only issue is that the function as.matrix of the package raster may be confused with the one from the base package, so it may be necessary to specify raster::as.matrix.
#Nate_A gave the answer, but three cents short of a dollar.
After
dim(tiger_array)
[1] 900 900 4
You get each channel color of first pixel by
tiger_array[1,1,1] # red
tiger_array[1,1,2] # green
tiger_array[1,1,3] # blue
Or if you prefer between 0 - 255
tiger_array[1,1,1]*255
tiger_array[1,1,2]*255
tiger_array[1,1,3]*255

Resizing shelf icons to fit its space

I have created two shelf buttons and icons but in the image attachment I have put up, you can see that the yellow icon seems to be working correctly but as for the blue icon, it is sticking to the top-left hand corner of its 'space'
The initial sizing I have created for the yellow icon is 32 x 32 pixels while the blue one is 20 x 20 pixels
Both shelf attributes are pretty much the same but I am unable to get the blue icon to either match in size or have it be in the center.
Thus are there any other ways in which I can resize it, have it in a reasonable sizing like the yellow one without creating another new image to 32 x 32 pixels?
// -------- 32 x 32 pixels --------
shelfButton
-enableCommandRepeat 0
-enable 1
-width 34
-height 34
-manage 1
-visible 1
-label "Yellow Icon"
-image "icon_yellow.png"
-style "iconOnly"
;
// -------- 20 x 20 pixels --------
shelfButton
-enableCommandRepeat 0
-enable 1
-width 34
-height 34
-manage 1
-visible 1
-label "Blue Icon"
-image1 "icon_blue.png"
-style "iconOnly"
;
You need to remove -label flag and add -scaleIcon and iconAndTextHorizontal style.
Tested on the 2016 version.
// -------- 20 x 20 pixels --------
shelfButton
-enableCommandRepeat 0
-enable 1
-width 34
-height 34
-manage 1
-visible 1
-image1 "icon_blue.png"
-scaleIcon // scale
-style "iconAndTextHorizontal"// need for scale
;

blt graph with interval window?

I have a blt real time graph in tcl/tk, the graph collects data over time with no time limit and it keeps storing all the data points into vectors and the user is able to scroll back and forth in the graph. The problem is that if I let the graph collect the points for a long period of time the cpu and memory consumption increases dramatically, i figure that for a 24 hour interval window should be fine. When i try to "unset x(0)" from the graph i get an error saying "command name invalid" i also try with "x delete 0" and same thing. Any help is much appreciated
This is how i initialize the graph:
proc startGraph {} {
global btnColor
global backColor
global startTime
global txtActionLevel
global txtAlertLevel
global x y1 y2 flagTime inStart inTime vectorFlag
global resolution
global notFirstTime
global txtActionLevel
set notFirstTime 0
set resolution 0
# Create stripchart widget
blt::stripchart .s -width 625 -height 330 -background $backColor -plotbackground black -font defaultFont
scrollbar .scroll -command { ScrollToEnd
.s axis view x } -orient horizontal -relief flat -background black -troughcolor $backColor -activebackground black -elementborderwidth 5
.s axis configure x -scrollcommand { .scroll set }
# Create BLT vectors
blt::vector create x
blt::vector create y1
blt::vector create y2
set startTime 0
set flagTime 0
set inStart -1
set inTime 0
set vectorFlag 0
.s configure -borderwidth 0 \
-leftmargin 0 \
-rightmargin 0 \
-plotborderwidth 0 \
-plotpadx {0 0} \
-plotpady {0 0}
.s legend configure -hide yes
.s grid configure -color gray \
-dashes 1 \
-minor 0 \
-hide 0
# X-axis
.s axis configure x -autorange 60 \
-shiftby 1 \
-stepsize 10 \
-subdivisions 1 \
-command FormatXLabel
# Alert txtAlertLevel
#.s tag create line -mapx 2 -mapy 2
proc FormatXLabel {widget x} {
set x [expr round($x)]
return [clock format $x -format "%I:%M:%S"]
}
# Y-axis
#.s axis configure y -title "C o u n t s"
image create photo .countsIcon -format PNG -file counts.png
label .titleGraph -image .countsIcon -background $backColor
place .titleGraph -in .measureView -x 0 -y 160
# Particles
.s element create Particles -symbol {} -color yellow -linewidth 1 \
-smooth linear -xdata x -ydata y1
# Bio
.s element create Bio -symbol {} -color red -linewidth 1 \
-smooth linear -xdata x -ydata y2
.s marker create line -name actionLine -coords {-Inf $txtActionLevel Inf $txtActionLevel} -linewidth 1 -outline orange
.s marker create line -name alertLine -coords {-Inf $txtAlertLevel Inf $txtAlertLevel} -linewidth 1 -outline green
place .s -in .measureView -x 10 -y 50
place .scroll -in .measureView -x 60 -y 380 -width 515 -height 35
#chartTime
}
this is where i add the values to the vectors:
set x(++end) [clock seconds]
set flagTime 0
set vectorFlag 1
set len [y1 length]
if {$len == 0} {
set startTime $x(end)
set y1(++end) $particle_sec
set y2(++end) $x_summary(bio_sec)
#if {$inStart < 0} {
# .s axis configure x -min "" -max ""
# set inStart 0
#}
} else {
set y1(++end) $particle_sec
set y2(++end) $x_summary(bio_sec)
}
puts "Vector length [x length]------"
puts "First value $x(0)----------"
#This is where i'm trying to catch whenever it reaches 60 seconds in this case
#when the length of the vector reaches 60 seconds it will unset the first value
#but it doesn't work it throws and invalid command name error
if {[x length] > 60} {
[unset -nocomplain x(0)]
}
#incr everyten
add_Result $particle_sec $bioSec [format "%.2f" $fv_eff]
for some odd reason when you use blt::vector create the "[unset -nocomplain x(0)]" doesn't seem to work, so i change it back to "x delete 0" without the square brackets and it works now.
When you put unset -nocomplain x(0) in [square brackets] and have it on its own like that, what you get is this:
It tries to unset that variable (I don't know if that will have problems; I don't use BLT vectors in my own code). There will be no errors from this. The result will be the empty string (it's documented).
It takes the result (an empty string) and uses it as a word of a command. The whole word, as you're not concatenating anything with it. The whole first word, in fact. You're going to try to evaluate the command whose name is the empty string, and pass it no other arguments. This is general Tcl semantics.
Now, creating a command with an empty name is legal, slightly tricky (because rename to an empty string deletes it — fully-qualified names are the workaround), and highly unusual. In your case, you've no such command and what you've really got is a bug. The bug? Those square brackets.
Use unset -nocomplain x(0) instead of [unset -nocomplain x(0)].
Note also that in many places online, when Tclers are putting Tcl code fragments inline in a place without fancy formatting, they'll put square brackets around the code. It's just a convention to make things easier to read. You shouldn't be seeing such things here on Stack Overflow.

Resources