From: Bryan Oakley on
Uwe Klein wrote:
> Kyle wrote:
>
>> well i actually want it to run on windows platform (should have
>> mentioned it earlier, sorry), so if you could elaborate more, and at
>> last point me in the right direction i would be grateful
>
> Transparent Toplevel ( for some MS versions):
> http://wiki.tcl.tk/10515
> you may want to search for more on the wiki:
> http://wiki.tcl.tk/2?transpa
> http://wiki.tcl.tk/2?transpa*
>
> Lots of fun
>
> uwe

I think the problem with transparent toplevels as implemented in the
core is, whatever alpha you give the toplevel applies to all widgets in
the toplevel. That is, you can't make the toplevel 100% transparent and
have a 100% solid label widget inside.

Too bad. I could find uses for that.

From: slebetman@yahoo.com on
Uwe Klein wrote:
> Jeff Hobbs wrote:
> > Kyle wrote:
> >
> >> as a tutorial project i tried to create a simple digital clock (which
> >> is pretty easy task), however i wanted it to look cool (:
>
> > This is theoretically possible, but it depends on the platform. I know
> > how to do it on Win32, but not other platforms.
> >
> What about using unmanaged/undecorated toplevels for the segments?
> withdraw and place as you like it.
> Ok, the segments can only be rectangles.

Neat idea! You mean something like this? :

proc drawTransDigit {rootname x y number} {
set ret [list]
if {[string is integer -strict $number] &&
[string length $number] == 1
} {
set segmentList {
a 02356789 10 0 50 10
b 045689 0 10 10 50
c 01234789 60 10 10 50
d 2345689 10 60 50 10
e 0268 0 70 10 50
f 013456789 60 70 10 50
g 0235689 10 120 50 10
}
foreach {segment group x1 y1 width height} $segmentList {
if {[string first $number $group] != -1} {
lappend ret [toplevel $rootname$segment -bg red]
wm attributes $rootname$segment -topmost 1
wm overrideredirect $rootname$segment 1
incr x1 $x
incr y1 $y
wm geometry $rootname$segment ${width}x${height}+${x1}+${y1}
}
}
}
return $ret
}

proc drawTransNumber {rootname x y number} {
set ret [list]
foreach i [split $number {}] {
set ret [concat $ret [drawTransDigit $rootname$x $x $y $i]]
incr x 100
}
return $ret
}

# Test:
set foo [drawTransNumber .test 10 10 12345]

# To delete do:
# foreach x $foo {destroy $x}

From: Jeff Hobbs on
Kyle wrote:
> Jeff Hobbs napisa�(a):
>> Kyle wrote:
>>> as a tutorial project i tried to create a simple digital clock (which
>>> is pretty easy task), however i wanted it to look cool (:
>>>
>>> and here comes my problem, id like my clock to appear on desktop as
>>> digits only, but cant find a way to make label's background transparent
>>>
>>> im aware that there are some problems with tk with regard to
>>> transparency (did bit of google search), but i wonder whether its
>>> possible to arrive at solution to this particular problem (doesnt
>>> have to be general, and may include some external libraries, however
>>> id like to stick to tcl)
>>
>> The problem isn't with Tk per se, but that this is inherently
>> something that isn't easy to do across platforms. There are
>> extensions to Tk for X11 Shape and Win32 shaped toplevels (tktrans).
>> However, those won't make what you want easier, because you are
>> intending to change the shape of the toplevel every second.
>>
>> This is theoretically possible, but it depends on the platform. I
>> know how to do it on Win32, but not other platforms.
>>
>
> well i actually want it to run on windows platform (should have
> mentioned it earlier, sorry), so if you could elaborate more, and at
> last point me in the right direction i would be grateful

Look for how SetLayeredWindowAttributes is called in tk/win/tkWinWm.c.
Instead of LWA_ALPHA, if you use LWA_COLORKEY and specify an RGB color
that should be transparent, then you could do essentially what you want.
Combine it with a wm overrideredirect window, making it white where
white is the transparent color, anything you draw on that will be all
that you should see. More info at:

http://msdn.microsoft.com/library/en-us/winui/winui/windowsuserinterface/windowing/windows/windowreference/windowfunctions/setlayeredwindowattributes.asp

--

Jeff Hobbs, The Tcl Guy, http://www.activestate.com/
From: palmtcl on
Following Jeff's pointer below, I added an interface to
SetLayeredWindowAttributes to TWAPI. Sample code to do what you want is
below. Note you need TWAPI 1.1, currently only in CVS, as 1.0 does not
have the SetLayeredWindowAttributes call (or you could use FFIDL to do
the same thing without needing all of TWAPI)

Working code - this works on my sample of one (XP SP2). Note to drag
the clock around you have to click the mouse on an opaque area.

package require Tk
package require twapi 1.1

proc every { ms body } {
eval $body
after $ms [list every $ms $body]

}

proc dragStart {windowX windowY} {
set ::DragHoldPosition(x) $windowX
set ::DragHoldPosition(y) $windowY

}

proc dragTo {screenX screenY} {
set positionX [expr { $screenX - $::DragHoldPosition(x) }]
set positionY [expr { $screenY - $::DragHoldPosition(y) }]
wm geometry . [winfo width .]x[winfo height .]+$positionX+$positionY

}

bind . <Button-1> { dragStart %x %y }
bind . <Button1-Motion> { dragTo %X %Y }
bind . <Button-2> { destroy . }

pack [label .lab -textvariable timevar -font "ansi 54 bold" -foreground
\#aa66ff -background red]
every 500 {set ::timevar [clock format [clock sec] -format %H:%M:%S]}

wm overrideredirect . 1
wm attributes . -topmost 1

# For some reason, we cannot change style bits until window is
visible/mapped
update idletasks

# Get the parent of the Tk toplevel - this is the real toplevel from
# the Windows perspective
set top_id [twapi::get_parent_window [winfo id .]]
# Set its style bits to allow layering
foreach {style exstyle} [twapi::get_window_style $top_id] break
twapi::set_window_style $top_id $style [expr {0x80000+$exstyle}]
# Set transparency color (red is 0x0000ff as per Windows COLORREF
struct
::twapi::SetLayeredWindowAttributes $top_id 0xff 255 1


/Ashok

Jeff Hobbs wrote:
>
> Look for how SetLayeredWindowAttributes is called in tk/win/tkWinWm.c.
> Instead of LWA_ALPHA, if you use LWA_COLORKEY and specify an RGB color
> that should be transparent, then you could do essentially what you want.
> Combine it with a wm overrideredirect window, making it white where
> white is the transparent color, anything you draw on that will be all
> that you should see. More info at:
Jeff Hobbs, The Tcl Guy, http://www.activestate.com/

From: Uwe Klein on
exactement!

very nice,
the "-topmost" option to [wm attributes] breaks on X11.

everything being indented at least one space sugests
you have already put it on the wiki?

uwe