|
Post by vovchik on May 28, 2012 14:31:13 GMT 1
Dear guys, Please have a look at the attached c prog. It allows you to move widgets around with the mouse and, if run in a terminal, shows x:y mouse location coordinates. The compile line is in the code (very top). I think we might be getting close to having mouse placement in a RAD. With kind regards, vovchik Attachments:
|
|
|
Post by alexfish on May 28, 2012 14:52:03 GMT 1
Dear guys, Please have a look at the attached c prog. It allows you to move widgets around with the mouse and, if run in a terminal, shows x:y mouse location coordinates. The compile line is in the code (very top). I think we might be getting close to having mouse placement in a RAD. With kind regards, vovchik WoW , Nice one , just need to make a .so + the API's . then make available in the rad tool can then test this against the ID of the widget ADDED can try this to make a .so gcc -Wall -g `pkg-config --cflags --libs gtk+-2.0` -o libgetcursor.so getcursor.c -shared -D_GNU_SOURCE -fPIC to get the info nm -D ./libgetcursor.so regards alexfish
|
|
|
Post by alexfish on May 28, 2012 16:00:51 GMT 1
Found This one , gets the cursor postion compile gcc -Wall -lX11 getcurpos.c -o getcurpos could be uses recursive from the exec tool , but will look at other options ADDED some code INCLUDE "hug.bac" FUNCTION get_mouse mousepos_x_y$=EXEC$("path/to/getcurpos") PRINT mousepos_x_y$ RETURN TRUE END FUNCTION win=WINDOW("Test mouse",600,400) TIMEOUT(100, get_mouse) DISPLAY ADDED .. IF trying this Demo :: NOTICE WHAT HAPPENS TO THE print out when mouse is over the window>>> MOUSE "BUTTON CLICK and HOLD down" then release,BUTTON , stay STILL , Then Move the Mouse alexfish Attachments:
|
|
|
Post by vovchik on May 28, 2012 16:25:11 GMT 1
Dear guys, This is another great example of setting cursor XY using arrow keys. Both the above mouse dragging and this key positioning prog can be easily baconized and used in the RAD without recourse to external routines or libs (that goes for axelfish's nice Xlib find, too). Just define the imports and call the routines. For added comfort, they can be HUGified, too. In the attachment, it appears to do nothing. That is OK. Just move the arrow keys and you will see what it is all about. With kind regards, vovchik Attachments:
|
|
|
Post by alexfish on May 28, 2012 16:42:37 GMT 1
Dear guys, This is another great example of setting cursor XY using arrow keys. Both the above mouse dragging and this key positioning prog can be easily baconized and used in the RAD without recourse to external routines or libs (that goes for axelfish's nice Xlib find, too). Just define the imports and call the routines. For added comfort, they can be HUGified, too. In the attachment, it appears to do nothing. That is OK. Just move the arrow keys and you will see what it is all about. With kind regards, vovchik Just added some test code to the post,, But can use exec getcurpos by EVENTS This is something missing from most of the codes I have Seen IE : REPEAT window event IF some_event do_something END IF UNTIL window event does_something Look like an empty tar-file (0 0 KB)
|
|
|
Post by vovchik on May 28, 2012 16:48:36 GMT 1
Sorry, The last archive I uploaded was empty This is the real one. With kind regards, vovchik Attachments:
|
|
2lss
Full Member
Posts: 140
|
Post by 2lss on May 28, 2012 16:53:40 GMT 1
Here is an updated version of the RAD I posted earlier. This one supports resizing and renaming the widget. I will look into adding the 'mouse drag' and 'key' methods of moving the widgets. Can anyone translate vovchik's C programs into bacon? EDIT*** Updated to use 'g_signal_connect_object' in place of 'g_signal_connect_data' to avoid issues with HUG INCLUDE hug_imports.bac
CONST gtk$ = HUGLIB$("gtk") CONST gob$ = HUGLIB$("gobject") GLOBAL active_widget, X DECLARE widget_name$ ASSOC STRING DECLARE widget_x_pos ASSOC NUMBER DECLARE widget_y_pos ASSOC NUMBER DECLARE widget_x_size ASSOC NUMBER DECLARE widget_y_size ASSOC NUMBER
' Import GTK functions IMPORT "gtk_fixed_move(long,long,int,int)" FROM gtk$ TYPE void IMPORT "gtk_fixed_new" FROM gtk$ TYPE long 'IMPORT "gtk_label_set_text(long,char*)" FROM gtk$ TYPE void IMPORT "gtk_widget_set_size_request(long,int,int)" FROM gtk$ TYPE void
' Import GOBJECT functions IMPORT "g_signal_connect_object(long,char*,void*,long,int)" FROM gob$ TYPE long IMPORT "g_signal_handler_block(long,long)" FROM gob$ TYPE void IMPORT "g_signal_handler_unblock(long,long)" FROM gob$ TYPE void
' Add a button to gui builder and save x/y coordinates in associative arrays SUB Add_button_widget() INCR X button_widget = BUTTON(CONCAT$("Button ", STR$(X)), 80, 30) ATTACH(fixed_container, button_widget, 5, 15) widget_name$(STR$(button_widget)) = CONCAT$("Button ", STR$(X)) widget_x_pos(STR$(button_widget)) = 5 widget_y_pos(STR$(button_widget)) = 15 widget_x_size(STR$(button_widget)) = 80 widget_y_size(STR$(button_widget)) = 30 CALLBACK(button_widget, Register_properties) END SUB
' Bring up the Properties tab when the widget is clicked and set position in spin buttons SUB Register_properties(NUMBER widget) active_widget = widget SET(tabs, 1) g_signal_handler_block(spin_x_pos, x_pos_handler) g_signal_handler_block(spin_y_pos, y_pos_handler) g_signal_handler_block(spin_x_size, x_size_handler) g_signal_handler_block(spin_y_size, y_size_handler) TEXT(entry1, widget_name$(STR$(widget))) SET(spin_x_pos, widget_x_pos(STR$(widget))) SET(spin_y_pos, widget_y_pos(STR$(widget))) SET(spin_x_size, widget_x_size(STR$(widget))) SET(spin_y_size, widget_y_size(STR$(widget))) g_signal_handler_unblock(spin_x_pos, x_pos_handler) g_signal_handler_unblock(spin_y_pos, y_pos_handler) g_signal_handler_unblock(spin_x_size, x_size_handler) g_signal_handler_unblock(spin_y_size, y_size_handler) END SUB
' When text is entered into ENTRY, changet the text on widget SUB Change_text(NUMBER widget) widget_name$(STR$(active_widget)) = GRAB$(entry1) ' gtk_label_set_text(active_widget, GRAB$(entry1)) TEXT(active_widget, GRAB$(entry1)) END SUB
' When the X or Y position spin button is changed move the widget SUB Move_widget(NUMBER widget) widget_x_pos(STR$(active_widget)) = GET(spin_x_pos) widget_y_pos(STR$(active_widget)) = GET(spin_y_pos) gtk_fixed_move(fixed_container, active_widget, GET(spin_x_pos), GET(spin_y_pos)) END SUB
' When the X or Y size spin button is changed resize the widget SUB Resize_widget(NUMBER widget) widget_x_size(STR$(active_widget)) = GET(spin_x_size) widget_y_size(STR$(active_widget)) = GET(spin_y_size) gtk_widget_set_size_request(active_widget, GET(spin_x_size), GET(spin_y_size)) END SUB
INIT
' Position of the gui builder gui_x_pos = 280 gui_y_pos = 5 ' Size of the gui builder gui_x_size = 315 gui_y_size = 440
newwin = WINDOW("BaCon RAD", 600, 450)
frame1 = FRAME(gui_x_size, gui_y_size) ATTACH(newwin, frame1, gui_x_pos, gui_y_pos) TEXT(frame1, "GUI Preview")
fixed_container = gtk_fixed_new() REGISTER(fixed_container, gui_x_size, gui_y_size, "", 0, 0, 0, 0) ATTACH(newwin, fixed_container, gui_x_pos, gui_y_pos)
' Create Widgets tab--------- tabs = NOTEBOOK("Widgets", 270, 440) ATTACH(newwin, tabs, 5, 5)
frame2 = FRAME(255, 400) TEXT(frame2, "Click to add to GUI") ATTACH(tabs, frame2, 5, 5)
widget_button = BUTTON("Button", 60, 30) ATTACH(tabs, widget_button, 10, 40) CALLBACK(widget_button, Add_button_widget)
' Create Properties tab ------ TEXT(tabs, "Properties")
' Widget Text frame2 = FRAME(255, 60) TEXT(frame2, "Widget Text") ATTACH(tabs, frame2, 5, 5)
entry1 = ENTRY("", 245, 25) ATTACH(tabs, entry1, 10, 30) CALLBACK(entry1, Change_text)
' Widget Position frame3 = FRAME(255, 70) TEXT(frame3, "Postion") ATTACH(tabs, frame3, 5, 75)
mark1 = MARK("X:", 25, 25) ATTACH(tabs, mark1, 20, 105) spin_x_pos = SPIN(50, 30, 0, gui_x_pos + gui_x_size, 1) ATTACH(tabs, spin_x_pos, 50, 100) 'CALLBACK(spin_x_pos, Move_widget) x_pos_handler = g_signal_connect_object(spin_x_pos, "value-changed", Move_widget, 0, 0)
mark2 = MARK("Y:", 25, 25) ATTACH(tabs, mark2, 140, 105) spin_y_pos = SPIN(50, 30, 0, gui_y_pos + gui_y_size, 1) ATTACH(tabs, spin_y_pos, 170, 100) 'CALLBACK(spin_y_pos, Move_widget) y_pos_handler = g_signal_connect_object(spin_y_pos, "value-changed", Move_widget, 0, 0)
' Widget Size frame4 = FRAME(255, 70) TEXT(frame4, "Size") ATTACH(tabs, frame4, 5, 155)
mark3 = MARK("X:", 25, 25) ATTACH(tabs, mark3, 20, 185) spin_x_size = SPIN(50, 30, 0, gui_x_pos + gui_x_size, 1) ATTACH(tabs, spin_x_size, 50, 185) 'CALLBACK(spin_x_size, Resize_widget) x_size_handler = g_signal_connect_object(spin_x_size, "value-changed", Resize_widget, 0, 0)
mark4 = MARK("Y:", 25, 25) ATTACH(tabs, mark4, 140, 185) spin_y_size = SPIN(50, 30, 0, gui_y_pos + gui_y_size, 1) ATTACH(tabs, spin_y_size, 170, 185) 'CALLBACK(spin_y_size, Resize_widget) y_size_handler = g_signal_connect_object(spin_y_size, "value-changed", Resize_widget, 0, 0)
' Set the notebook to display first tab SET(tabs, 0)
DISPLAY Attachments:
|
|
|
Post by alexfish on May 28, 2012 17:35:58 GMT 1
I am getting this error
Line 19: IMPORT "g_signal_connect_data(long,char*,void*,long,long,int)" FROM gob$ TYPE long Cause: conflicting types for 'g_signal_connect_data'
regards
alexfish
|
|
|
Post by vovchik on May 28, 2012 17:41:30 GMT 1
@ 2lss and axelfish:
I am looking at the same and see the same problem. The first is that "g_signal_connect_data(long,char*,void*,long,long,int)" is imported twice - once via HUG and once explicitly in IMPORTs. Secondly, the casting is different. For one, g_signal_connect_data does not return a long but a void, so far as I understand the function - and I ahve used it a lot. Hence line 130 will not work, since the function does not return anything. Am I right? At least that is the HUG definition - but the Gobject raw function does (an unsigned long, I think).
With kind regards, vovchik
|
|
2lss
Full Member
Posts: 140
|
Post by 2lss on May 28, 2012 17:44:25 GMT 1
alexfish: HUG normally imports g_signal_connect_data as TYPE void where I needed TYPE long, so I re-imported it. However, I was using HUG as a shared object and this wasn't a problem. Try creating hug.so (bacon -f hug.bac) and download basic-converter.org/hug_imports.bac. Then replace 'INCLUDE hug.bac' with 'INCLUDE hug_imports.bac.' I will try to find a work around for using hug.bac
|
|
|
Post by vovchik on May 28, 2012 17:47:59 GMT 1
Dear 2lss,
I wonder whether you couldn't import the "g_signal_connect_data(long,char*,void*,long,long,int) TYPE long" definition if you use an alias. I will try that now.
With kind regards, vovchik
|
|
2lss
Full Member
Posts: 140
|
Post by 2lss on May 28, 2012 17:55:31 GMT 1
vovchic, I had to re-import g_signal_connect_data as TYPE long so I could get the signal's 'handler.' This lets me block the callback using g_signal_handler_block developer.gnome.org/gobject/unstable/gobject-Signals.html#g-signal-handler-block I need to block the signal when calling the sub 'Register_properties' or else the spin buttons will activate their callback function when I use TEXT to set the value.. It is a bad work around. I was hoping someone more knowledgeable could figure out a better solution..
|
|
|
Post by vovchik on May 28, 2012 18:35:30 GMT 1
Dear 2lss, No success with my ALIAS proposal. I think Peter could offer some very competent advice here. He is also the author of GTK server, and I think he knows his gobejct signals and what to do with them Let's just hope he finds a few moments to look over some of these last posts. With kind regards, vovchik
|
|
|
Post by alexfish on May 28, 2012 18:56:55 GMT 1
the only reference I have seen to the go object is in the demos . go
CONST Gobject = "libgobject-2.0.so.0"
IMPORT "g_signal_connect_data" FROM Gobject TYPE void
regards
alexfish
|
|