New feature: a GUI proxy for BaCon
Jun 9, 2020 23:54:33 GMT 1
Post by vovchik on Jun 9, 2020 23:54:33 GMT 1
Dear Joe,
Thanks. I have attached a real toggle button demo based on yours. The advantage of using a real one in the Play/Pause case is that, when playing, it stays "prelit" or highlighted. Otherwise it is much the same. And using a toggle button will save space in the compact gui.
Here is the code:
Hope it works for you.
With kind regards,
vovchik
Thanks. I have attached a real toggle button demo based on yours. The advantage of using a real one in the Play/Pause case is that, when playing, it stays "prelit" or highlighted. Otherwise it is much the same. And using a toggle button will save space in the compact gui.
Here is the code:
OPTION GUI TRUE
PRAGMA GUI gtk2
OPTION PARSE FALSE
' Needed if we run this GTK2 sample in GTK3
PRAGMA OPTIONS -Wno-deprecated-declarations
PRAGMA OPTIONS -Wno-write-strings -Wno-deprecated
DECLARE (*ATTACH)() = gtk_fixed_put TYPE void
' ------------------
SUB SPIN_TOGGLE()
' ------------------
IF cnt THEN
CALL GUISET(id, "spinner", "active", 0)
CALL GUISET(id, "toggle", "label", "▶")
CALL GUISET(id, "toggle", "active", FALSE)
CALL GUISET(id, "toggle", "tooltip-text", "Paused.")
PRINT "Spinner OFF."
cnt = 0
ELSE
' stays prelit - highlighted if on
CALL GUISET(id, "spinner", "active", 1)
CALL GUISET(id, "toggle", "label", "⏸")
CALL GUISET(id, "toggle", "active", TRUE)
CALL GUISET(id, "toggle", "tooltip-text", "Playing.")
PRINT "Spinner ON."
cnt = 1
END IF
END SUB
' ------------------
SUB MY_QUIT()
' ------------------
' quit program
PRINT NL$, "End of demo...", NL$
END
END SUB
' ------------------
SUB MK_GUI()
' ------------------
' set window size
win_w = 220
win_h = 60
' define all gui elements
id = GUIDEFINE(" \
{ type=WINDOW name=window callback=delete-event } \
{ type=FIXED name=fixed parent=window } \
{ type=SPINNER name=spinner } \
{ type=TOGGLE_BUTTON name=toggle callback=toggled } \
{ type=IMAGE name=image } \
{ type=BUTTON name=myexit callback=clicked }")
' widget properties
' window
CALL GUISET(id, "window", "window-position", GTK_WIN_POS_CENTER)
CALL GUISET(id, "window", "width-request", win_w)
CALL GUISET(id, "window", "height-request", win_h)
CALL GUISET(id, "window", "title", "Spinner")
' buttons
CALL GUISET(id, "toggle", "width-request", 35)
CALL GUISET(id, "myexit", "width-request", 70)
CALL GUISET(id, "toggle", "height-request", 35)
CALL GUISET(id, "myexit", "height-request", 35)
CALL GUISET(id, "toggle", "label", "▶")
CALL GUISET(id, "myexit", "label", "Exit")
' define tooltips
CALL GUISET(id, "toggle", "tooltip-text", "Toggle BaCon throbber demo.")
CALL GUISET(id, "myexit", "tooltip-text", "Quit BaCon throbber demo.")
' spinner size
CALL GUISET(id, "spinner", "width-request", 24)
CALL GUISET(id, "spinner", "height-request", 24)
' widget placement
CALL GUIFN(id, "fixed", ATTACH, GUIWIDGET(id, "toggle"), 10, 10)
CALL GUIFN(id, "fixed", ATTACH, GUIWIDGET(id, "spinner"), 80, 18)
CALL GUIFN(id, "fixed", ATTACH, GUIWIDGET(id, "myexit"), 140, 10)
END SUB
' make gui
MK_GUI()
' endless loop
WHILE TRUE
event$ = GUIEVENT$(id)
PRINT "Event: ", event$
SELECT event$
CASE "window"
END
CASE "toggle"
SPIN_TOGGLE
CASE "myexit"
MY_QUIT
END SELECT
SLEEP 1
WEND
Hope it works for you.
With kind regards,
vovchik