|
Post by bigbass on May 12, 2012 22:11:10 GMT 1
* Pjot @peter fixed/modified one of my examples to work with color and it became delay launch appdelay launchThis delays the launch of an app and shows the delay in a progress bar it shows how TIMEOUT causes a delay and this delay can be visualized using the demo add the numbers can be seen counting in the progress bar too which would help when debugging the counting section 'delay-launch.bac INCLUDE "hug.bac" INIT
DECLARE pb, x, offset
FUNCTION set_value INCR x IF x > 100 THEN PRINT "GOOD BYE / launch app here " x = 0 RETURN FALSE END IF SET(pb, x) TEXT(pb, STR$(x)) RETURN TRUE END FUNCTION
SUB start_progress TIMEOUT(10, set_value) END SUB
SUB start_progress2 TIMEOUT(50, set_value) END SUB
SUB start_progress3 TIMEOUT(100, set_value) END SUB
win = WINDOW("DELAY then launch", 250, 130) pb = PROGRESSBAR("0", 200, 30) ATTACH(win, pb, 0, 0) My_btn = BUTTON( "fast", 100, 25) ATTACH( win, My_btn, 10, 40 ) CALLBACK(My_btn, start_progress)
My_btn = BUTTON( "normal", 100, 25) ATTACH( win, My_btn, 10, 70 ) CALLBACK(My_btn, start_progress2)
My_btn = BUTTON( "slow", 100, 25) ATTACH( win, My_btn, 10, 100 ) CALLBACK(My_btn, start_progress3)
DISPLAY
|
|
|
Post by bigbass on May 13, 2012 16:13:56 GMT 1
I was reading that you can't stop a TIMEOUT with a SUB so I found a workaround that can stop a TIMEOUT from a SUB well it acts as an lnterrupt meeting the condition then adds a string then does a test for the new string to be used as an escape from the loop delay-launch-panic-stop 'delay-launch-panic-stop.bac INCLUDE "hug.bac" INIT
DECLARE pb, x, offset
FUNCTION set_value INCR x
IF x > 100 AND PANIC_BUTTON$ = "YES" THEN PRINT "Panic leave ---->", PANIC_BUTTON$ FOCUS(win) x = 0 PANIC_BUTTON$ = "" RETURN FALSE END IF
IF x > 100 THEN PRINT "GOOD BYE / launch app here " x = 0 RETURN FALSE END IF SET(pb, x) TEXT(pb, STR$(x)) RETURN TRUE END FUNCTION
SUB start_progress TIMEOUT(10, set_value) END SUB
SUB start_progress2 TIMEOUT(50, set_value) END SUB
SUB start_progress3 TIMEOUT(100, set_value) END SUB
SUB stop_progress PANIC_BUTTON$ = "YES" x = 100
END SUB
win = WINDOW("DELAY then launch", 250, 130) pb = PROGRESSBAR("0", 200, 30) ATTACH(win, pb, 0, 0) My_btn = BUTTON( "fast", 100, 25) ATTACH( win, My_btn, 10, 40 ) CALLBACK(My_btn, start_progress)
My_btn = BUTTON( "normal", 100, 25) ATTACH( win, My_btn, 10, 70 ) CALLBACK(My_btn, start_progress2)
My_btn = BUTTON( "slow", 100, 25) ATTACH( win, My_btn, 10, 100 ) CALLBACK(My_btn, start_progress3)
My_btn = BUTTON( "Panic Stop", 100, 25) ATTACH( win, My_btn, 130, 100 ) CALLBACK(My_btn, stop_progress)
DISPLAY
|
|
|
Post by bigbass on May 19, 2012 6:11:50 GMT 1
sock_it sock_it after plug_it was run Socket and Plug connect one app to another The next example comes from Pjot basic-converter.proboards.com/index.cgi?board=doc&action=display&thread=275*note a very minor edit made to sock_it.bac this was made to give a message to the GUI that you are waiting for the plug app to be run You must use at least HUG 77 which is the latest at the time of writing The goal of this post is to add another widget to the collection of HUG widgets in one place and not repeat what was already said there is a lot of information that needs to broken down into smaller chewable bites I will be adding more to this as I peel off the layers so I see this as a great opportunity to let the expert write the code (Pjot) and the simple guy me to break it down in smaller parts vovchik has also provided code taking a different approach between the code Peter and vovchik provided they will keep me very busy for some time documenting the victories they made for BaCon what I understood about Pjot's code examples in a quick view image this gets repeated for each new GTK function * the same INCLUDE file gets updated as you go start sock_it start plug_it there are three programs needed the first one 1. ) sock_plug.bac doesn't get compiled it is an include file 2.) sock_it.bac this gets compiled and started first 3.) plug_it.bac this gets compiled and started after sock_it is running 1. ) sock_plug.bac doesn't get compiled it is an include file ' sock_plug.bac ' Import GtkSock/GtkPlug functions gtk$ = HUGLIB$("gtk") IMPORT "gtk_socket_new(void)" FROM gtk$ TYPE long IMPORT "gtk_socket_get_id(long)" FROM gtk$ TYPE long IMPORT "gtk_plug_new(long)" FROM gtk$ TYPE long
' The self-defined GET for the SOCK FUNCTION GET_winid(NUMBER widget)
LOCAL winid
' Get the windowID from the socket winid = gtk_socket_get_id(widget)
RETURN winid
END FUNCTION
' Function to create the SOCKET FUNCTION SOCK(int hug_xsize, int hug_ysize)
LOCAL widget
' Create the socket widget = gtk_socket_new()
' Register and determine size and signal REGISTER(widget, hug_xsize, hug_ysize, "plug-added", 0, 0, 0, 0) ' Determine the GET method METHOD(widget, 3, GET_winid)
' Return the created socket RETURN widget
END FUNCTION
' The self-defined SET for the PLUG SUB SET_widget_to_plug(NUMBER plug_widget, NUMBER gtk_widget)
gtk_container_add(plug_widget, gtk_widget)
ENDSUB
' Function to create the plug FUNCTION PLUG(NUMBER window)
LOCAL widget
' Create the plug widget = gtk_plug_new(window)
' Register and determine signal (no need for size) REGISTER(widget, 0, 0, "embedded", 0, 0, 0, 0) ' Determine the SET method METHOD(widget, 4, SET_widget_to_plug)
' Return the created plug RETURN widget
END FUNCTION
2.) sock_it.bac this gets compiled and started first
' sock_it.bac ' Get HUG functions INCLUDE "hug.bac"
' Get our self-defined widgets INCLUDE "sock_plug.bac"
' Callback for the socket SUB msg PRINT "The plug was inserted!" TEXT( My_label, "The plug was inserted!") END SUB
' Create the main window win = WINDOW("Socket window", 250, 100)
' Create a label with text, 150 x 30 My_label = MARK( "waiting for plug!", 150, 30 )
' Attach the label to the main window ATTACH( win, My_label, 10, 50 )
' Create the socket sock = SOCK(150, 30)
' Add socket to window and setup callback ATTACH(win, sock, 10, 10) CALLBACK(sock, msg)
' Get the windowID from the socket winid = GET(sock)
' Save windowID to a file so the plug can read it OPEN "/tmp/winid.txt" FOR WRITING AS comm WRITELN winid TO comm CLOSE FILE comm
' Endless GTK loop DISPLAY
3.) plug_it.bac this gets compiled and started after sock_it is running
' plug_it.bac ' Get HUG functions INCLUDE "hug.bac"
' Get our self-defined widgets INCLUDE "sock_plug.bac"
' Read winid from a file OPEN "/tmp/winid.txt" FOR READING AS comm READLN winid$ FROM comm CLOSE FILE comm
' Create a widget, has same size as socket txt = MARK("Hello from the plug!", 150, 30)
' Create the plug plug = PLUG(VAL(winid$))
' Assign the widget to the plug SET(plug, txt)
' Make sure the plug is visible SHOW(plug)
' Endless GTK loop DISPLAY
|
|
|
Post by bigbass on May 23, 2012 5:14:29 GMT 1
Spinner-demo.bacThis next code demo is vovchik's work He had added a spinner widget to a small app and I removed the app code and left just the spinner only so we could focus on this GTK spinner widget converted to HUGcongratulations vovchik ! you did a great job Special note : The spinner widget was added directly from GTK and converted to use HUG syntax this means that new widgets can be added to HUG and this is a another great example how to get started *Peter provided 3 examples in tutorial about adding HUG widgets for more info I will post GTK C code of the spinner widget at the end of this post so you can see a working GTK example also
reference info only developer.gnome.org/gtk/2.24/GtkSpinner.html
' spinner-demo.bac INCLUDE "hug.bac" CONST gtk$ = HUGLIB$("gtk")
' --- ' spinner stuff ' --- IMPORT "gtk_spinner_new" FROM gtk$ TYPE long IMPORT "gtk_spinner_start(long)" FROM gtk$ TYPE void IMPORT "gtk_spinner_stop(long)" FROM gtk$ TYPE void
' ------------------ FUNCTION SPIN_END() ' ------------------ PRINT "Stop spinner" gtk_spinner_stop(spinner) RETURN FALSE END FUNCTION
' ------------------ SUB CHECKING() ' ------------------ TIMEOUT(500, SPIN_END) END SUB
' ------------------ SUB SPIN_START() ' ------------------ PRINT "Start spinner" SHOW(spinner) gtk_spinner_start(spinner) TIMEOUT(100, CHECKING) END SUB
' ------------------ SUB EXIT_PROG() ' ------------------ QUIT END END SUB
' ------------------ FUNCTION SPINNER(int hug_xsize, int hug_ysize) ' ------------------ LOCAL widget ' create the spinner widget = gtk_spinner_new() ' register and determine size and signal REGISTER(widget, hug_xsize, hug_ysize, "", 0, 0, 0, 0) RETURN widget END FUNCTION
' ------------------ SUB MK_GUI() ' ------------------ win = WINDOW("spinner demo", 220, 210) check = BUTTON("Check", 70, 30) myquit = BUTTON("Quit", 70, 30) spinner = SPINNER(24, 24) PROPERTY(myquit, "tooltip-text", "Exit program.") ATTACH(win, check, 10, 170) ATTACH(win, spinner, 88, 173) ATTACH(win, myquit, 120, 170) CALLBACK(check, SPIN_START) CALLBACK(myquit, EXIT_PROG) END SUB
MK_GUI DISPLAY
THIS C CODE BELOW IS ONLY FOR A WORKING GTK EXAMPLE TO STUDYAttachment Deleted
#include <gtk/gtk.h> void main (int argc, char **argv) { static GtkWidget *spinner = NULL; GtkWidget *window; gtk_init (&argc, &argv); window = gtk_dialog_new_with_buttons ("GtkSpinner", NULL, 0, GTK_STOCK_CLOSE, GTK_RESPONSE_NONE, NULL); g_signal_connect (window, "response", G_CALLBACK (gtk_main_quit), NULL); g_signal_connect_after (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); spinner = gtk_spinner_new (); gtk_container_add (gtk_dialog_get_content_area (GTK_DIALOG (window)), spinner); gtk_spinner_start (GTK_SPINNER (spinner)); gtk_widget_show_all (window); gtk_main (); }
Attachments:
|
|
|
Post by fragadelic on May 23, 2012 17:13:23 GMT 1
Awesome work guys. This thread is shaping up quite nicely with lots of great examples for new folks.
|
|
|
Post by bigbass on May 24, 2012 15:57:49 GMT 1
Hey fragadelic
I am sure that you have a lot of small snippets you could add and are very welcome to offer any you feel could be "simple and clear" if you don't have free time to strip code to basic building blocks send them to me I will have fun doing it and credit all code to the authors
P.S I extend that to anyone else also that has some code they want to see simplified to be used to help others get familiar using HUG
the focus on this thread is just bare bones simple standalone examples highlighting just one thing and full apps are posted in the Code Projects thread
*there are three examples here that are small full code the plug and socket and the spinner but they show new widgets that were recently added
there's a lot what we can do future tense... but there is a lot that still needs to be done present tense with what we already have
Joe
|
|
|
Post by bigbass on May 25, 2012 15:18:04 GMT 1
I modified this post to show very simple canvas demo INCLUDE "hug.bac"
canvas_x = 450 canvas_y = 380
'---------------------- SUB CLEAN_SCREEN() '---------------------- 'clear terminal output CLEAR 'redraw canvas again canvas = CANVAS(canvas_x, canvas_y) ATTACH(win, canvas, 0,0) CALLBACK(clean, CLEAN_SCREEN) CALLBACK(canvas, HandleMouse) CALLBACK(myquit, QUIT) END SUB
'---------------------- SUB HandleMouse() '---------------------- cursor_x = MOUSE(0) cursor_y = MOUSE(1) IF MOUSE(2) = 1 THEN PRINT PRINT cursor_x, " cursor_x" PRINT cursor_y, " cursor_y" PRINT
DRAW(canvas) LINE("blue", 0, cursor_y, 400, cursor_y) LINE("yellow", cursor_x, 0, cursor_x, 440) END IF END SUB
'---------------------- 'MAIN GUI '---------------------- INIT
HUGOPTIONS("NOSCALING")
win = WINDOW("Get x and y positions", 450, 440) canvas = CANVAS(canvas_x, canvas_y) ATTACH(win, canvas, 0, 0)
mark1 = MARK("Left click to start", 300, 15) ATTACH (win, mark1, 42, 400)
clean = BUTTON("Clean", 70, 30) myquit = BUTTON("Quit", 70, 30)
ATTACH(win, clean, 10 ,390) ATTACH(win, myquit, 318, 390)
CALLBACK(clean, CLEAN_SCREEN) CALLBACK(canvas, HandleMouse) CALLBACK(myquit, QUIT)
DISPLAY
|
|
|
Post by bigbass on May 27, 2012 16:47:58 GMT 1
The next example comes from Pjot I asked Peter to convert the other two functions of the spinner demo (vovchik did) to 100% HUG This shows how we go from a raw idea of using a new GTK widget get it working in BaCon though testing then get it adopted into the HUG family so it becomes ours for everyone to use using HUG for future projects that use this new widget Please note that using GTK is a valid and a great development step to get a working idea to light quickly ( vovchik has a way to get these GTK widgets going quickly a good friend and very smart guy!) I have studied his code method it bridges the GTK to BaCon missing step which we need very much a whole new thread could be dedicated to this method but then the next step is get it into HUG so we can all have easy HUG syntax for the following projects to use these new widgets 'spinner_INCLUDE.bac INCLUDE "hug.bac", INIT, WINDOW, BUTTON, HUGLIB$, METHOD, REGISTER, SET, ATTACH, CALLBACK, QUIT, DISPLAY CONST gtk$ = HUGLIB$("gtk")
' ------------------ ' spinner GTK functions ' ------------------ IMPORT "gtk_spinner_new" FROM gtk$ TYPE long IMPORT "gtk_spinner_start(long)" FROM gtk$ TYPE void IMPORT "gtk_spinner_stop(long)" FROM gtk$ TYPE void
'spinner_INCLUDE.bac ' ------------------ ' The self-defined method for SET ' ------------------ SUB spin_set(NUMBER hug_widget, int value) ' ------------------ IF value THEN gtk_spinner_start(hug_widget) ELSE gtk_spinner_stop(hug_widget) END IF
END SUB
' ------------------ ' The creation of the spinner ' ------------------ FUNCTION SPINNER(int hug_xsize, int hug_ysize) ' ------------------ LOCAL widget
' create the spinner widget = gtk_spinner_new() ' register and determine size and signal REGISTER(widget, hug_xsize, hug_ysize, "", 0, 0, 0, 0) ' We use the SET method to let the widget spin (1) or not (0) METHOD(widget, 4, spin_set)
RETURN widget
END FUNCTION
'spinner-HUG-convertered.bac 'depends on spinner_INCLUDE.bac
INCLUDE "hug.bac" INCLUDE "spinner_INCLUDE.bac" ' ------------------ SUB SPIN_STOP() ' ------------------ PRINT "Stop spinner" SET(spinner, 0) END SUB
' ------------------ SUB SPIN_START() ' ------------------ PRINT "Start spinner" SET(spinner, 1) END SUB
' ------------------ SUB MK_GUI() ' ------------------ INIT win = WINDOW("spinner demo", 220, 210) start = BUTTON("Start", 70, 30) stop = BUTTON("Stop", 70, 30)
myquit = BUTTON("Quit", 70, 30) spinner = SPINNER(24, 24) PROPERTY(myquit, "tooltip-text", "Exit program.")
ATTACH(win, start, 10, 10) ATTACH(win, stop, 10, 40)
ATTACH(win, spinner, 10, 173) ATTACH(win, myquit, 120, 170)
CALLBACK(start, SPIN_START) CALLBACK(stop, SPIN_STOP)
CALLBACK(myquit, QUIT)
END SUB
MK_GUI DISPLAY
|
|
|
Post by bigbass on May 31, 2012 15:43:35 GMT 1
just added a little to get a widget demo going credit goes to vovchick for the lions share of the work thanks mobeus for referencing to the window size using GTK functions I added the real time x y values updating on the window and the stop when you leave the window INCLUDE "hug.bac" INIT
' Changed IMPORT types 'IMPORT "gtk_widget_get_pointer(long,int*,int*)" FROM "libgtk-x11-2.0.so" TYPE void IMPORT "gtk_widget_get_pointer(long,long,long)" FROM "libgtk-x11-2.0.so" TYPE void ' Get DPI IMPORT "gdk_screen_get_default" FROM "libgdk-x11-2.0.so" TYPE long IMPORT "gdk_screen_get_resolution(long)" FROM "libgdk-x11-2.0.so" TYPE double DECLARE x, y DECLARE factor TYPE FLOATING
SUB X_Y_VALUES() TIMEOUT(100, set_value) END SUB
FUNCTION set_value ' x and y values are read the window size is used as a limit IF fixed_x < 350 AND fixed_y < 250 AND fixed_x > -1 AND fixed_y > -1 THEN
gtk_widget_get_pointer(hug_widget_attach(STR$(window)), ADDRESS(x), ADDRESS(y)) fixed_x = x * factor fixed_y = y * factor PRINT fixed_x, ":", fixed_y TEXT(wincoordinates, CONCAT$("Window Coordinates (x:y): ", STR$(fixed_x), ":", STR$(fixed_y)))
' while you stay in the window the condition is true RETURN TRUE END IF ' reset x and y values so app won't hang fixed_x = 0 fixed_y = 0 END FUNCTION
screen = gdk_screen_get_default() dpi = gdk_screen_get_resolution(screen) factor = (float)dpi/100 window = WINDOW("Get Window Coordinates", 350, 250)
txt$ = CONCAT$("Press Start then move the mouse" ,NL$, "Move mouse out of the window to stop") My_label = MARK( txt$, 300, 30 ) ATTACH( window, My_label, 10, 10)
but = BUTTON("Quit", 50,30) but2 = BUTTON("Start", 50,30)
wincoordinates = MARK("Window Coordinates (x:y)", 250, 30) ATTACH(window, but, 235, 215) ATTACH(window, but2, 295, 215)
ATTACH(window, wincoordinates, 0, 200) CALLBACK(but, QUIT) CALLBACK(but2, X_Y_VALUES)
DISPLAY
|
|
|
Post by bigbass on Jun 4, 2012 14:55:51 GMT 1
This next widget is a GTK gem in BaCon and I am very impressed at how easy it is to use and how short the code is this takes advantage of an undocumented feature the example is from Pjot I just want to document this so it doesn't get overlooked or lost as a new widget method I am very busy doing the RAD project we need to use GTK functions and the code gets big quickly so this just amazes me how simple a dialog could be this example opened a widow for me to see how GTK functions work in the simplest possible form SUPER undocumented featurebasic-converter.proboards.com/index.cgi?action=display&board=general&thread=256&page=1and here is the code don't blink or you will miss it 'I used the string form to give an example of the fourth argument uses GTK_STOCK_OK
CONST GTK_STOCK_OK = 1
x = gtk_init(0, 0) x = gtk_dialog_run(gtk_message_dialog_new(0, 0, 0, GTK_STOCK_OK,"Greetings from BaCon!"))
name the file prog2.bac and compile with this bacon -o "`pkg-config --cflags --libs gtk+-2.0`" prog2.bac DOCUMENTATION ONLY now the help file it isn't an INCLUDE file it only explains the arguments that are used above 'in simple terms 'when the third arg is 0 the info icon is used 'when 'the third arg is 1 the triangle warning icon is used 'when 'the third arg is 2 the circle question mark icon is used 'when 'the third arg is 3 the red circle with white line in the center icon is used 'when the third arg is 4 no icon is used 'using GTK terms the third arg some here not used but are offered as options you can use numbers or strings CONST GTK_MESSAGE_INFO = 0 CONST GTK_MESSAGE_WARNING = 1 CONST GTK_MESSAGE_QUESTION = 2 CONST GTK_MESSAGE_ERROR = 3 'the fourth arg 0 = no buttons displayed 'the fourth arg 4 = yes and no buttons displayed 'using GTK terms the fourth arg you can use numbers or strings CONST GTK_STOCK_OK = 1 CONST GTK_STOCK_CLOSE = 2 CONST GTK_STOCK_CANCEL = 3 CONST GTK_BUTTONS_YES_NO = 4 'I used the string form to give an example of the fourth argument uses GTK_STOCK_OK ' the fifth argument is the message you display between double quotes
|
|
|
Post by alexfish on Jun 17, 2012 9:09:09 GMT 1
|
|
|
Post by bigbass on Jun 21, 2012 15:46:34 GMT 1
Thanks for the feedback . Getting back to the basics with some simple widgets . Here is a resizable window using the PROPERTY option. P.S simple but I didn't know you could do this so easily resize-window'resize-window.bac
INCLUDE "hug.bac" INIT
win = WINDOW("resize", 200, 100) PROPERTY(win, "resizable", TRUE) DISPLAY
|
|
|
Post by vovchik on Jul 6, 2012 15:31:46 GMT 1
Dear guys,
Here is a little snippet (straight gtk) that shows how to create an ebox and get a signal (mouse click) out of a widget (text label) that is normally not normally on the lookout for mouse signals. Also the cursor changes when you hover over the label.
It could easily also be done using HUG and a few extra bits.
With kind regards, vovchik
' *********************** ' DECLARATIONS ' ***********************
' lib names CONST gtk$ = "libgtk-x11-2.0.so" CONST gob$ = "libgobject-2.0.so" CONST gdk$ = "libgdk-x11-2.0.so" ' mask for mouse press CONST GDK_BUTTON_PRESS_MASK = 1 << 8 ' cursor style CONST GDK_HAND1 = 58
' *********************** ' END DECLARATIONS ' ***********************
' *********************** ' IMPORTS ' *********************** ' gdk stuff IMPORT "gdk_cursor_new(int)" FROM gdk$ TYPE long IMPORT "gdk_window_set_cursor(long,long)" FROM gdk$ TYPE void ' general gtk stuff IMPORT "gtk_init(int*,void*)" FROM gtk$ TYPE void IMPORT "gtk_main_quit(void)" FROM gtk$ TYPE void IMPORT "gtk_main" FROM gtk$ TYPE void ' window stuff IMPORT "gtk_window_new(int)" FROM gtk$ TYPE long IMPORT "gtk_window_set_title(long,char*)" FROM gtk$ TYPE void IMPORT "gtk_window_set_position(long,int)" FROM gtk$ TYPE void IMPORT "gtk_window_set_default_size(long,int,int)" FROM gtk$ TYPE void ' widget stuff IMPORT "gtk_widget_set_size_request(long,int,int)" FROM gtk$ TYPE void IMPORT "gtk_widget_show(long)" FROM gtk$ TYPE void IMPORT "gtk_widget_set_usize(long,int,int)" FROM gtk$ TYPE void IMPORT "gtk_widget_set_events(long,int)" FROM gtk$ TYPE void IMPORT "gtk_widget_get_window(long)" FROM gtk$ TYPE long IMPORT "gtk_widget_realize(long)" FROM gtk$ TYPE void ' container stuff IMPORT "gtk_container_set_border_width(long,int)" FROM gtk$ TYPE void IMPORT "gtk_container_add(long,long)" FROM gtk$ TYPE void ' event box stuff IMPORT "gtk_event_box_new" FROM gtk$ TYPE long ' label stuff IMPORT "gtk_label_new(char*)" FROM gtk$ TYPE long ' gobject signal stuff IMPORT "g_signal_connect_data(long,char*,void*,long,long,int)" FROM gob$ TYPE void
' *********************** ' END IMPORTS ' ***********************
' *********************** ' SUBS & FUNCTIONS ' ***********************
' ------------------ SUB EXIT_PROG() ' ------------------ gtk_main_quit() END END SUB
' ------------------ FUNCTION CLICKED() ' ------------------ PRINT "Hotspot clicked." RETURN TRUE END FUNCTION
' ------------------ SUB DISPLAY() ' ------------------ gtk_main() END SUB
' ------------------ SUB MK_GUI() ' ------------------ ' start gtk gtk_init(0,0) ' create window window = gtk_window_new(0) gtk_window_set_title(window, "Event Box") gtk_window_set_default_size(window, 230, 150) g_signal_connect_data(window, "destroy", EXIT_PROG, 0, 0, 0) ' set border width gtk_container_set_border_width(window, 60) ' create an event box and add it toplevel window event_box = gtk_event_box_new() gtk_container_add(window, event_box) gtk_widget_show(event_box) ' create a label label = gtk_label_new("Click label.") gtk_container_add(event_box, label) gtk_widget_show(label) ' clip it short gtk_widget_set_usize(label, 110, 20) ' and bind an action to it gtk_widget_set_events(event_box, GDK_BUTTON_PRESS_MASK) gtk_widget_realize(event_box) gtk_widget_show(window) ' change cursor to a hand over the event box cursor = gdk_cursor_new(GDK_HAND1) gdk_window_set_cursor(gtk_widget_get_window(event_box), cursor) g_signal_connect_data(event_box, "button-press-event", CLICKED, 0,0,0) END SUB
' *********************** ' END SUBS & FUNCTIONS ' ***********************
' *********************** ' MAIN ' ***********************
MK_GUI DISPLAY ' *********************** ' END MAIN ' **********************
|
|
|
Post by alexfish on Jul 6, 2012 18:49:30 GMT 1
Here is an example of adding mouse events to a button and adding a frame to event container Make a copy of your hug.bac and name it "EventWidgets.bac" . then edit to suit , play around with other widgets
REM --------------------------------------------------------------------------------------------------
FUNCTION EVENT_BUTTON (STRING hug_text$, int hug_xsize, int hug_ysize)
LOCAL but
but = gtk_button_new_with_mnemonic(hug_text$) REM These lines add mouse events to the button gtk_widget_set_events(but, GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_SCROLL_MASK) g_signal_connect_data(but, "button-press-event", hug_mouse_event, 20, 0, 0) g_signal_connect_data(but, "button-release-event", hug_mouse_event, 0, 0, 0) g_signal_connect_data(but, "motion-notify-event", hug_mouse_event, 0, 0, 0) g_signal_connect_data(but, "leave-notify-event", hug_mouse_event, 30, 0, 0) IF HUG_WIDGET_SHOW THEN gtk_widget_show(but)
hug_widget_xsize(STR$(but)) = hug_xsize hug_widget_ysize(STR$(but)) = hug_ysize hug_widget_signal(STR$(but)) = 2 hug_widget_s_widget(STR$(but)) = but
hug_widget_type$(STR$(but)) = "button" hug_widget_attach(STR$(but)) = but hug_widget_font(STR$(but)) = gtk_bin_get_child(but) hug_widget_focus(STR$(but)) = but
RETURN but
END FUNCTION
REM --------------------------------------------------------------------------------------------------
FUNCTION EVENT_FRAME (int hug_xsize, int hug_ysize)
LOCAL myframe,ebox myframe = gtk_frame_new(0) ebox = gtk_event_box_new() REM add the fram to event box gtk_container_add(ebox, myframe) gtk_widget_set_events(ebox, GDK_POINTER_MOTION_MASK | GDK_KEY_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_SCROLL_MASK) g_signal_connect_data(ebox, "button-press-event", hug_mouse_event, 20, 0, 0) g_signal_connect_data(ebox, "button-release-event", hug_mouse_event, 0, 0, 0) g_signal_connect_data(ebox, "motion-notify-event", hug_mouse_event, 0, 0, 0) g_signal_connect_data(ebox, "leave-notify-event", hug_mouse_event, 30, 0, 0)
IF HUG_WIDGET_SHOW THEN gtk_widget_show_all(ebox) hug_widget_xsize(STR$(ebox)) = hug_xsize hug_widget_ysize(STR$(ebox)) = hug_ysize hug_widget_s_widget(STR$(ebox)) = ebox hug_widget_signal(STR$(ebox)) = 4
hug_widget_type$(STR$(ebox)) = "frame"
RETURN ebox
END FUNCTION
The bacon hug code
INCLUDE "EventWidgets.bac"
FUNCTION Mouse_Event CLEAR IF MOUSE(0) > -1 THEN PRINT "# Mouse X: ", MOUSE(0) PRINT "# Mouse Y: ", MOUSE(1) PRINT "# Mouse Btn.: ", MOUSE(2) PRINT "# Mouse Whl.: ", MOUSE(3) PRINT "# PARENT_ID.: ", MOUSE(4) END IF RETURN TRUE END FUNCTION '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '@ MAIN '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INIT win = WINDOW("BaCon RAD", 200, 300) but=EVENT_BUTTON("Event_Button",100,50) ATTACH(win,but,5,5) frm=EVENT_FRAME(100,100) ATTACH(win,frm,5,100) 'Note can not set the Text in fram with event box TIMEOUT(100,Mouse_Event) DISPLAY
ADDED : Click Code
INCLUDE "EventWidgets.bac" SUB set PRINT "OK" ENDSUB '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ '@ MAIN '~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ INIT win = WINDOW("Click it", 200, 300) frm=RAD_FRAME(100,100) ATTACH(win,frm,5,100) CALLBACK(frm,set) DISPLAY
Have fun
alexfish
|
|
|
Post by vovchik on Jul 6, 2012 21:58:49 GMT 1
Dear Alex,
Very nice and useful. Thanks....
With kind regards, vovchik
|
|