Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Balloon pop-up

Status
Not open for further replies.

haoose

Technical User
Dec 22, 2003
15
US
Hi everyone,

I have balloon windows that pop-up whenever I place the mouse pointer over a button. Recently I tried extending the length of the balloon text but when I did this the balloon did not even pop-up.

If anyone has ever experienced this problem and has a solution for it I would appreciate any tips.

Thanks
 
Is this a Tk_popup? If so, the "text" is a menu item and is given by the -label option when defining the menu. As far as I know, there are no restrictions on the menu label. Can you post a code snippet?

_________________
Bob Rashkin
 
Hi Bob,

Thanks for the prompt reply. I was able to fix the problem I was having with the limitation on my pop-up. I found a the balloon.tcl example code and it worked great.

Actually, now I am having trouble with the positioning of my balloonhelp labels.I have a hand full of lengthy balloons and it appears that as some of the buttons closer to the bottom of my top level gui will not display the long balloons.

Below is the code I am using for the balloon popup, in balloonhelp_show I am trying to get the coordinates of my tlg (using the parent option) and add 1/4 of x coordinate and 1/2 of the y coordinate to place my balloon help somewhere in the middle of the gui. Basically what I am trying to do is make sure that the balloon label does not go off of the display window no matter how close the button in the tlg is to the edge of the screen. I have done this before for menubutton using the -direction below command but I am having trouble for this label.

+++++++++++++++++++++++++++++++++++++++++++
bind bhInfo <Enter> {
set bhInfo(set) 0
set bhInfo(first) 1
set bhInfo(id) [after 500 {balloonhelp_show %W $bhInfo(%W) %X %Y}]
}

bind bhInfo <Button> {
set bhInfo(first) 0
balloonhelp_cancel
}

bind bhInfo <Leave> {
set bhInfo(first) 0
balloonhelp_cancel
}

bind bhInfo <Motion> {
if {$bhInfo(set) == 0} {
after cancel $bhInfo(id)
set bhInfo(id) [after 500 {balloonhelp_show %W $bhInfo(%W) %X %Y}]
}
}

################################################################################
##
## Function Name: balloonhelp_for
##
## Inputs:
## win - window name
## mesg - text for balloon help
##
## Outputs:
##
## Description:
## Adds balloon help to the widet named <win>. Whenever the mouse
## pointer enters this widget and rests within it for a short delay,
## a balloon help window will automatically appear showing the help
## <mesg>.
##
################################################################################
proc balloonhelp_for {win mesg} {
global bhInfo

set bhInfo($win) $mesg

bindtags $win "[bindtags $win] bhInfo"
#bind $win <Enter> {balloonhelp_pending %W %x %y}
#bind $win <Leave> {balloonhelp_cancel}
}


# ----------------------------------------------------------------------
# USAGE: balloonhelp_cancel
#
# Used internally to mark the point in time when the mouse pointer
# leaves a widget. Cancels any pending balloon help requested earlier
# and hides the balloon help window, in case it is visible.
# ----------------------------------------------------------------------
proc balloonhelp_cancel {} {
global bhInfo

after cancel $bhInfo(id)

if {[winfo exists .balloonhelp] == 1} {
destroy .balloonhelp
}
set bhInfo(set) 0

}

# ----------------------------------------------------------------------
# USAGE: balloonhelp_show <win x y>
#
# Used internally to display the balloon help window for the
# specified <win>.
# ----------------------------------------------------------------------
proc balloonhelp_show {win message {cx 0} {cy 0} } {
global bhInfo

if { ($bhInfo(first) == 1) } {
set bhInfo(first) 2

#tk_dialog .dialog_msg "ERROR Message" \
"win = $win\n\
win parent = [winfo parent $win]" \
"" 0 OK;

if { $cx == 0 && $cy == 0 } {
set x [expr [winfo rootx $win] + ([winfo width $win]/2)]
set y [expr [winfo rooty $win] + [winfo height $win] + 4]
#tk_dialog .dialog_msg "ERROR Message" \
"cx = $cx\ncy = $cy" \
"" 0 OK;
} else {
#tk_dialog .dialog_msg "ERROR Message" \
"cx = $cx\ncy = $cy" \
"" 0 OK;
set x [expr [winfo rootx [winfo parent $win]] + ([winfo width [winfo parent $win]]/4)]
set y [expr [winfo rooty [winfo parent $win]] + ([winfo height [winfo parent $win]]/2)]
#tk_dialog .dialog_msg "ERROR Message" \
"[expr [winfo height [winfo parent $win]]/3]" \
"" 0 OK;

#set x [expr $cx + 4]
#set y [expr $cy + 4]
}
}
toplevel .balloonhelp -borderwidth 1 -bg black -screen [winfo screen $win]
wm overrideredirect .balloonhelp 1
label .balloonhelp.info \
-text $message -relief flat \
-bg LemonChiffon -fg black \
-justify left -padx 2 -pady 0 -anchor c \
-font -*-courier-bold-i-normal-sans-*-170-*

pack .balloonhelp.info -side left -fill y
wm geometry .balloonhelp +${x}+${y}
set bhInfo(set) 1

}

+++++++++++++++++++++++++++++++++++++++++++

thanks,
Oliver
 
I think the problem is that your always adding a positive increment to the coordinates. I suggest you first determine if either x or y are greater than half the window size. Then, if not, do what you're doing now. If either is, however, you should subtract the increment from that coordinate.

_________________
Bob Rashkin
 
Thanks Bob,

I think I see exactly what's happeening. It appears that the balloonhelp will not pop-up if the mouse pointer is within the region/area that the balloon is displayed.

The final x and y left-corner coordinates is fixed. I will have to do something like you mentioned and check for when the pointer is below this region I will subtract the coordinates. I would rather just change the orientation of the balloon when the point is over a button below the midpoint to possibly anchor s. I don't know if this is possible yet.

 
Hi All,

Is there a way for Tcl/Tk to automatically position a balloon pop-up so that it does not go off the screen, like MS Windows apps do?

I have not been able to find a work around for this balloon/mouse pointer problem. I can not get around the fact that a balloon will not display if it is anywhere in the region where the mouse pointer is located.

Ideally, I would NOT like the balloon popup location to be fixed to the center of my top-level-gui (which still does not work correctly). I would like for my popup balloon to be displayed near the button my mouse pointer is hovering over AND within the limits of my screen.

Does anyone have any further suggestions?

Thanks
Oliver
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top