xtal
Junior Member
Posts: 61
|
Post by xtal on Apr 21, 2018 14:14:15 GMT -5
Is it possible to Use 1 button for 2 routines Left Click BUTTON A and goto Routine A Right Click BUTTON A and goto Routine B
How would one do this ?
|
|
|
Post by Carl Gundel on Apr 21, 2018 14:47:52 GMT -5
Is it possible to Use 1 button for 2 routines Left Click BUTTON A and goto Routine A Right Click BUTTON A and goto Routine B
How would one do this ? Not using a regular Windows button, but if you fake your own button with a graphicbox you can do it.
|
|
xtal
Junior Member
Posts: 61
|
Post by xtal on Apr 21, 2018 14:51:08 GMT -5
could you provide more detail ?
|
|
|
Post by Alyce Watson on Apr 21, 2018 15:56:03 GMT -5
Carl is suggesting that you do not use a button control, but rather use a graphicbox. You can make it look like a button. See this tutorial for help: Graphicbox - trapping mouse events.
|
|
|
Post by Janet on Apr 21, 2018 17:27:48 GMT -5
Bare bones example
'Design a GUI with a graphicbox graphicbox #w.g, 50, 10, 20, 20 'Open the GUI open "fake button demo" for window as #w #w "trapclose [closeWin]" 'Trap the clicks #w.g "when leftButtonUp [event1]" #w.g "when rightButtonUp [event2]" wait
'Send left button click here [event1] notice "Left Button Clicked" wait
'Send right button click here [event2] notice "Right Button Clicked" wait
[closeWin] close #w end
With a little drawing, you can make your graphicbox look more realistic, even giving a visual that the button was clicked.
'Design a GUI with a graphicbox graphicbox #w.g, 50, 10, 20, 20 'Open the GUI open "fake button demo" for window as #w #w "trapclose [closeWin]" 'Trap the clicks #w.g "when leftButtonUp [event1]" #w.g "when rightButtonUp [event2]" 'Make the graphicbox look like a button #w.g "down" gosub [clickButton] wait
[event1] gosub [clickButton] notice "Left Button Clicked" wait
[event2] gosub [clickButton] notice "Right Button Clicked" wait
[closeWin] close #w end
[clickButton] #w.g "cls" #w.g "fill darkgray" #w.g "color lightgray" #w.g "place 0 0" #w.g "box 18 18" for delay = 1 to 50000:next delay #w.g "cls" #w.g "fill buttonface" #w.g "color lightgray" #w.g "place 0 0" #w.g "box 18 18" #w.g "flush" return
|
|
xtal
Junior Member
Posts: 61
|
Post by xtal on Apr 21, 2018 18:47:30 GMT -5
Thanks for the input, it will be useful..
Too bad a style bit can't accomplish this using a regular button....
|
|
|
Post by Alyce Watson on Apr 22, 2018 4:01:40 GMT -5
Thanks for the input, it will be useful.. Too bad a style bit can't accomplish this using a regular button.... It is more complicated than a control style. Liberty BASIC traps mouse and keyboard events in a graphics window or graphicbox, but only in a limited way for other controls. I placed a request for this event trapping across control types on the wishlist board. Event TrappingUntil such control is built into Liberty BASIC, the easiest way to mimic it is to use graphicboxes as Janet demonstrates, or to modify your gui. For instance, if there are two choices (like a left- or right-click), use a group of two radiobuttons.
|
|
|
Post by Brandon Parker on Apr 25, 2018 12:38:08 GMT -5
You can definitely do this if you venture into using WMLiberty.dll within your project, but the easiest method is what was mentioned by Carl/ Janet. There are advantages and disadvantages to doing it either way.
Here is Janet's example with a slight twist which removes the reliance on the loop within the GoSub along with other small modifications.
'Design a GUI with a graphicbox GraphicBox #w.g, 50, 10, 20, 20 'Open the GUI
Open "Fake Button Demo" For Window As #w
#w "trapclose [closeWin]"
'Trap the clicks
#w.g "When leftButtonDown [lclickDown]"
#w.g "When leftButtonUp [lclickUp]"
#w.g "When rightButtonDown [rclickDown]"
#w.g "When rightButtonUp [rclickUp]"
'Make the graphicbox look like a button
#w.g "down"
GoSub [buttonUp]
Wait
[closeWin] Close #w End
[lclickDown] GoSub [buttonDown] Wait
[lclickUp] GoSub [buttonUp] Notice "Left Button Clicked!" Wait
[rclickDown] GoSub [buttonDown] wait
[rclickUp] GoSub [buttonUp] Notice "Right Button Clicked!" wait
[buttonDown] #w.g "cls" #w.g "fill darkgray" #w.g "color lightgray" #w.g "place 0 0" #w.g "box 18 18" Return
[buttonUp] #w.g "cls" #w.g "fill buttonface" #w.g "color lightgray" #w.g "place 0 0" #w.g "box 18 18" #w.g "flush" Return
{:0)
Brandon Parker
|
|
xtal
Junior Member
Posts: 61
|
Post by xtal on Apr 25, 2018 15:32:22 GMT -5
Thx all, using what Janet posted I have 19 buttons working in a separate program. I would like to use right click to display Tool Tips ,, my current tool tips work about 80% of the time [ie] don't popup. They usually work after pgm reload/restart. I really like the box/baloon type display, that windows does , Can LB emulate this display without using windows API
|
|
|
Post by Rod on Apr 25, 2018 16:11:45 GMT -5
It is perfectly possible to do anything in Liberty BASIC. Whether it is a good idea or not is open to debate. This is "gadget" code that opens floating gadgets that you can move about or close with a click. It could do tooltips easily in any shape you desire.
'floating "gadget" code nomainwin WindowWidth = 120 WindowHeight = 144
'set window stylebits to layered and stay on top WS.EX.LAYERED = 524288 style=WS.EX.LAYERED or _WS_EX_TOPMOST stylebits #1, 0, 0, style, 0
'set graphicbox stylebits to no border stylebits #1.gb, 0, _WS_BORDER, 0, 0 graphicbox #1.gb, 0,0,120,144
'open popup window open "Clock" for window_popup as #1
'get the window handle hMain = HWND(#1)
'set the window to use red as transparent mask 'red bits of your image won't bee seen 'they will be transparent and allow "shaped" or 'floating graphic windows calldll #user32, "SetLayeredWindowAttributes",_ hMain As long,_ 'window handle 255 As long,_ '255 = Red color key (rgb color value) bAlpha As long,_ '0 = Completely transparent (0-255) 1 As long,_ '1 = use color key for transparency / 2 = use bAlpha ret As long 'nonzero=success
'move window with api call clockx=DisplayWidth-130 clocky=10 calldll #user32, "MoveWindow",_ hMain as ulong, _ 'window handle clockx as long,_ 'x location of window clocky as long,_ 'y location of window 120 as long,_ 'desired width of window 144 as long,_ 'desired height of window 1 as boolean,_ 'repaint flag,0=false,1=true ret as long 'nonzero=success if ret=0 then [quit]
' start event tracking #1 "trapclose [quit]" #1.gb "when leftButtonUp [quit]" #1.gb "when leftButtonMove [movewindow]"
'these are simple drawn graphics, you can do photorealist bmp images to 'draw clock face #1.gb "down ; fill red ; home ; backcolor darkgray ; circlefilled 48 ;color white ; circle 49" for angle = 0 to 330 step 30 #1.gb "up ; home ; north ; turn "; angle #1.gb "go 40 ; down ; go 5" next angle #1.gb "flush"
timer 1000, [display] wait
[display] time$ = time$() hours = val(time$) if hours > 12 then hours = hours - 12 minutes = val(mid$(time$, 4, 2)) seconds = val(right$(time$, 2))
' center the cursor and turtle draw the clock #1.gb "up ; home ; down ; north"
' erase each hand if its position has changed if oldHours <> hours then #1.gb "size 2 ; color darkgray ; turn "; oldHours * 30 + int(oldMinutes/2) ; " ; go 19 ; home ; color black ; north" : oldHours = hours if oldMinutes <> minutes then #1.gb "size 2 ; color darkgray ; turn "; oldMinutes * 6 ; " ; go 38 ; home ; color black ; north" : oldMinutes = minutes if oldSeconds <> seconds then #1.gb "size 1 ; color darkgray ; turn "; oldSeconds * 6 ; " ; go 38 ; home ; color black ; north" : oldSeconds = seconds
' redraw all three hands, second hand first #1.gb "size 1 ; turn "; seconds * 6 ; " ; go 38" #1.gb "size 2 ; home ; north ; turn "; hours * 30 + int(minutes/2); " ; go 19" #1.gb "home ; north ; turn "; minutes * 6 ; " ; go 38" #1.gb "delsegment seg" #1.gb "flush seg" wait
[movewindow] 'this is called when we place the window and whenever it is dragged CallDLL #user32, "ReleaseCapture",r As void CallDLL #user32, "SendMessageA",hMain As ULong,_WM_NCLBUTTONDOWN As ULong,_HTCAPTION As Long,0 As Long,r As Long wait
[quit] timer 0 close #1 end
|
|
|
Post by Rod on Apr 25, 2018 16:32:33 GMT -5
I would also say that if you need huge tooltips to make folks understand how your GUI works then your GUI has failed. Gui's should be intuitive and need minimal help. An uber complex GUI that displays EVERYTHING real time whether you want to see it or not with a gazillion buttons that you don't understand isn't really a GUI. Not being critical, its just that we can get wrapped up in our projects and project knowledge that users don't have. The easy option of expecting then to read massive tooltips won't happen, they will just click.
You perhaps need to break the interface down into task based segments. If they are nudging the head have a nudge popup with nudge arrows and done buttons. If you are setting a level display the level and buttons to change the level. So its like having a help file on screen, nudge, ok these are my options, temperature, ok these are my options. So a simple display of the head and position with breakout buttons to tackle the myriad of adjustments you can make. Single tracking screen to show where we are, no interface needed.
You didn't want that advice, I know, sorry.
|
|
xtal
Junior Member
Posts: 61
|
Post by xtal on Apr 25, 2018 19:40:35 GMT -5
Rather than use a help file to document the GRBL commands I chose to put the button descriptions/commands into the ToolTips. For instance 3 buttons are similiar and not often used. $RST=$ $RST=# $RST=* all 3 potentially harmfull...of course they are hopefully out of way.. Its nice to have easy to access info. Thats why I wanted to right click, so I can display button command as long as needed...
|
|
|
Post by Janet on Apr 26, 2018 11:00:16 GMT -5
Rather than use a help file to document the GRBL commands I chose to put the button descriptions/commands into the ToolTips. For instance 3 buttons are similiar and not often used. $RST=$ $RST=# $RST=* all 3 potentially harmfull...of course they are hopefully out of way.. Its nice to have easy to access info. Thats why I wanted to right click, so I can display button command as long as needed... I apologize for being a little late for this party. I loved Rod's submission, but since the original query was for a sans API routine, I thought I'd offer this one. There were 2 choices for the tooltip window, a dialog_modal and a dialog_popup. The benefit of dialog_modal is that the user must close the pseudo-tooltip window before returning to the main window. The disadvantage is having to figure out where to place it. Presumably, you'd want it close to the clicked button. The dialog_popup solves that problem, as it uses the cursor placement for its origin. The disadvantage to dialog_popup is that you can return to the main program without closing it. I opted for dialog_popup but needed to define a flag to close the pseudo-tooltip window if, in fact, it was still open when the main program was closed, or another button was right-clicked. I also used the stylebit _WS_EX_TOPMOST to prevent the pseudo-tooltip from 'going under' the main window. The user can now right-click any button and keep visible for as long as possible. This demo can easily be ported to subs if that's what you prefer. Just remember to define any important variables (such as ttFlag) as global, or pass them into the sub as each is called. 'Define Sizes of GUI Windows and Controls mainWindowWidth = 600 mainWindowHeight = 400 ttWindowWidth = 250 ttWindowHeight = 150 bttnWidth = 24 bttnHeight = 24
' Define the main window WindowWidth = mainWindowWidth WindowHeight = mainWindowHeight
' Define two pseudo-button graphicboxes graphicbox #demo.bttn01 30, 30, bttnWidth, bttnHeight ' Remove borders with stylebits stylebits #demo.bttn01, 0, _WS_BORDER, 0, 0 graphicbox #demo.bttn02 120, 100, bttnWidth, bttnHeight ' Remove borders and make it always on top with stylebits stylebits #demo.bttn02, 0, _WS_BORDER, style, 0
'Open the main window open "Pseudo ToolTips" for window as #demo #demo "Trapclose [closeApp]" ' Make the first graphicbox look like a button bttnHndl$ = "#demo.bttn01" gosub [pseudoButton] ' Define button's left-click event #demo.bttn01 "when leftButtonUp [leftButtonClick]" ' Define button's right-click pseudo-tooltip #demo.bttn01 "when rightButtonUp [rightButtonClick]" ' Make the second graphicbox look like a button bttnHndl$ = "#demo.bttn02" gosub [pseudoButton] ' Define button's left-click event #demo.bttn02 "when leftButtonUp [leftButtonClick]" ' Define button's right-click pseudo-tooltip #demo.bttn02 "when rightButtonUp [rightButtonClick]" ' Set initial ttFlag to 0 ttFlag = 0 wait
[leftButtonClick] notice "You left-clicked this button" wait
[rightButtonClick] ' If a ttWindow is already open then close it if ttFlag = 1 then close #tt ttFlag = 0 end if ' Define the pseudo-tooltip window WindowWidth = ttWindowWidth WindowHeight = ttWindowHeight ' Define a pseudo-tt graphicbox graphicbox #tt.g 0, 0, ttWindowWidth, ttWindowHeight ' Remove borders and make stay on top with stylebits stylebits #tt, 0, _WS_BORDER, _WS_EX_TOPMOST, 0 ' Open the window as a dialog_popup open "" for dialog_popup as #tt ttFlag = 1 #tt "trapclose [closettWindow]" ' Write something in the tooltip #tt.g "down; fill pink; backcolor pink" #tt.g "place 10 30; font Garamond_12" #tt.g "\Place your tooltip info here" #tt.g "\Left-click to close" ' Send left-click to trapclose #tt.g "when leftButtonUp [closettWindow]"
wait [closettWindow] close #tt ttFlag = 0 wait
[pseudoButton] #bttnHndl$ "down; fill black; backcolor Blue" #bttnHndl$ "place 2 2" #bttnHndl$ "boxfilled ";str$(bttnWidth-2);" ";str$(bttnHeight-2) #bttnHndl$ "flush bttn" return
[closeApp] if ttFlag = 1 then close #tt end if close #demo end
|
|
xtal
Junior Member
Posts: 61
|
Post by xtal on Apr 26, 2018 17:37:18 GMT -5
Thx Janet With some tweeking for my app, this may be what I want How can I get a variable size popup window, the data is from 40 char to 3000 char ...
|
|
xtal
Junior Member
Posts: 61
|
Post by xtal on Apr 29, 2018 7:31:30 GMT -5
Can I resize a graphicbox while pgm is running For some reason I can't make the psuedo graphic box #tt larger, but can make it smaller... I think I found it....
|
|