|
Post by bigbass on Jul 25, 2012 18:01:49 GMT 1
This one took me several hours to get working but it's worth it dynamic listbox widget Reads from a text file and generates the list It was kept simple for just the demo source the binary to see the selected from the list biglist2.txt basic-converter.proboards.com/index.cgi?action=downloadattachmentpage&board=doc&thread=263&post=2266*if for some reason the box is blank using a different file adjust this line FOR i = 0 TO dim - 4change the number in blue To compile faster I used INCLUDE "/usr/share/BaCon/hug.bac" But when you add more code use INCLUDE "hug.bac"
' bacon-listbox2.bac
' Include the files for making a GUI. INCLUDE "hug.bac" INIT
' we want to "echo out" which listbox_selected$ was pressed
SUB list_choices_demo() listbox_selected$ = GRAB$(list_choices) PRINT listbox_selected$ END SUB
' 1.) Create your main working window, 250 pixels wide x 130 pixels high Mainwin = WINDOW( "BaCon listbox", 250, 130 )
Menu_label = MARK("Select an option from the Menu" , 220, 30) ATTACH( Mainwin, Menu_label, 5, 0 )
result_input$ = EXEC$("cat /tmp/biglist2.txt")
'----------------- SUB MAKE_FILE_LIST '-----------------
SPLIT result_input$ BY NL$ TO words$ SIZE dim
FOR i = 0 TO dim - 4
list_choices_text$ = words$[i]
TEXT(list_choices, words$[i]) PRINT words$[i] PRINT i NEXT
END SUB
list_choices = LIST(180, 70 )
MAKE_FILE_LIST
ATTACH(Mainwin, list_choices,5, 30) CALLBACK(list_choices, list_choices_demo)
DISPLAY
|
|
|
Post by alexfish on Jul 26, 2012 23:35:47 GMT 1
Window FunPlaying with windowsclick the button , then click each window , also note the un-decorated window can be resized. could make a nice drop down Menu. INCLUDE "hug.bac" TRAP LOCAL INIT Gtk$ = HUGLIB$("gtk") IMPORT "gtk_decorated_window_move_resize_window(long,int,int,int,int)" FROM Gtk$ TYPE void
IMPORT "gtk_window_resize(long,int,int)" FROM Gtk$ TYPE void IMPORT "gtk_window_move(long,int,int)" FROM Gtk$ TYPE void IMPORT "gtk_window_set_keep_above(long,int)" FROM Gtk$ TYPE void SUB move_size gtk_decorated_window_move_resize_window(win,0,0,200,300) gtk_decorated_window_move_resize_window(win2,0,210,600,300) gtk_window_move(win3,210,0) END SUB win=WINDOW("Window-fun",300,300) but=BUTTON("Click-Move",1,1) CALLBACK(but,move_size) HUGOPTIONS ("TABLE 1 1") win2=WINDOW("Just fun",200,200) ATTACH(win2,but,0,0)
win3=WINDOW("can you size me ?",100,100) lab=MARK("<span font='8' foreground='#0000FF'>Size Me Up.</span>",1,1) ATTACH(win3,lab,0,0) gtk_window_set_keep_above(win3,TRUE) PROPERTY(win3, "decorated", FALSE) gtk_window_set_resizable(win3,TRUE) gtk_window_move(win3,600,0) DISPLAY Have fun alexfish
|
|
|
Post by bigbass on Jul 29, 2012 17:05:27 GMT 1
Well let's make an easy example ...first time I used it too Notes: named pipes will have a number added when you ls from a terminal but don't add the number
|
|
|
Post by bigbass on Aug 5, 2012 15:11:27 GMT 1
Easy Static Messages Pjot =Peter introduced a very simple way to compile static messages On page 3 of this thread I explained how a little Well I used his idea to make static compiled messages and they get called in a pure bash script I wanted to remove the Xdialog dependency in an app and have it use just bacon this is really easy to do ! unzip-error.bac after it's compiled call it by unzip-error & remember to place the compiled binary in the path the ampersand just runs the app in the background x = gtk_init(0, 0) x = gtk_dialog_run(gtk_message_dialog_new(0, 0, 3, 3 ,"ERROR a wrong format was used nothing done"))
'bacon -o "`pkg-config --cflags --libs gtk+-2.0`" unzip-error.bac
The way to compile it is included in the code unzip-ok.bacx = gtk_init(0, 0) x = gtk_dialog_run(gtk_message_dialog_new(0, 0, 0, 3 ,"Done your package is uncompressed in the same directory "))
'bacon -o "`pkg-config --cflags --libs gtk+-2.0`" unzip-ok.bac
Here is an example snippet how you would call it in 100% bash
|
|
|
Post by alexfish on Aug 11, 2012 2:39:42 GMT 1
IMAGE : svg hug / widget identfier
the Hug code is translated into screen array , using same code format as the hug-executor
save this in same directory as hug.bac as "test-svg"
<svg width='600px' height='400px'> <rect id=':HUG:BUTTON:button1,0,0,75,25:' x='0' y='0' width='75' height='25' ry='3' fill='#d0d0d0' stroke='black' stroke-width='1' style='display:1 ' /> <text x='8px' y='16px'>Button1</text> <rect id=':HUG:BUTTON:button2,15,0,75,25:' x='15' y='0' width='75' height='25' ry='3' fill='#d0d0d0' stroke='black' stroke-width='1' style='display:1 ' /> <text x='23px' y='16px'>Button2</text> <rect id=':HUG:BUTTON:button3,15,100,200,25:' x='15' y='100' width='200' height='25' ry='3' fill='#d0d0d0' stroke='black' stroke-width='1' style='display:1 ' /> <text x='90px' y='116px'>Click Me</text> </svg>
now the code
' Simple svg widget identify SYSTEM "mkdir /tmp/hugrad; chmod 777 /tmp/hugrad &" COPY "test-svg" TO "/tmp/hugrad/0" INCLUDE "hug.bac" HUGOPTIONS("NOSCALING")
FUNCTION EVENT_IMAGE(STRING hug_file$, int hug_xsize, int hug_ysize)
LOCAL image, ebox
image = gtk_image_new_from_file(hug_file$) ebox = gtk_event_box_new() gtk_container_add(ebox, image)
gtk_widget_queue_draw(image) 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_signal(STR$(ebox)) = 4 hug_widget_s_widget(STR$(ebox)) = ebox
hug_widget_type$(STR$(ebox)) = "image" hug_widget_font(STR$(ebox)) = image hug_widget_focus(STR$(ebox)) = image
hug_widget_image$(STR$(ebox)) = hug_file$
RETURN ebox
END FUNCTION REM --------------------------------------------------------- FUNCTION mouse IF MOUSE(0) > -1 THEN PRINT MOUSE(0)," : ",MOUSE(1) PRINT screen$[MOUSE(0)][MOUSE(1)] IF MOUSE(2) > -1 THEN CLEAR IF screen$[MOUSE(0)][MOUSE(1)] = "0" THEN RETURN TRUE PRINT screen$[MOUSE(0)][MOUSE(1)]," : Clicked" END IF END IF RETURN TRUE END FUNCTION REM -------------------------------------------------------------------------- win=WINDOW("Test-init",600,400) svg_screen1=EVENT_IMAGE("/tmp/hugrad/0",600,400) ATTACH(win,svg_screen1,0,0) DECLARE screen$[1000][1000] '@ format the screen to all 0 FOR y = 0 TO 400 : FOR x= 0 TO 600 screen$[x][y]="0" NEXT : NEXT
REM ------------------------------------------------------------------------- OPEN "/tmp/hugrad/0" FOR READING AS myfile WHILE NOT(ENDFILE(myfile)) DO IF NOT(ENDFILE(myfile)) THEN READLN txt$ FROM myfile IF (txt$ > "") THEN txt$=CHOP$(txt$) ck=INSTR(txt$,"HUG") IF (ck > 0) THEN SPLIT txt$ BY ":" TO hugcode$ SIZE hug data$= hugcode$[3] SPLIT data$ BY "," TO bitsize$ SIZE bits wid_x = VAL(bitsize$[1]) wid_y = VAL(bitsize$[2]) wid_wdth = VAL(bitsize$[3]) wd_ht= VAL(bitsize$[4]) name$=bitsize$[0] FOR y = wid_y TO wid_y + wd_ht : FOR x = wid_x TO wid_x + wid_wdth screen$[x][y]=name$ NEXT : NEXT END IF END IF END IF WEND CLOSE FILE myfile
REM --------------------------------------------------------------------------- TIMEOUT(20,mouse) DISPLAY
REM ----- End All That Stuff
Try experimenting with the svg code IE; add more + click all the widgets
ADDED: Almost forgot @ run in terminal mode
Have fun
and regards
alexfish
|
|
|
Post by bigbass on Dec 2, 2012 16:34:26 GMT 1
STATIC Multi list Gridview This is code is from alexfish (Thank you ) I adjusted the code so it could be used as a stand alone demo widget and added the callbacks to get the selected option to show in the terminal each window has its own scroll A great example that's why I added it to the widgets page we needed a multiple list widget ! Name this multi-list2.bac lib$ = HUGLIB$("gtk") IMPORT "gtk_tree_view_set_grid_lines(long,int)" FROM lib$ TYPE void
INCLUDE hug.bac INCLUDE gridview.bac
SUB list_choices() listbox_selected$ = GRAB$(list) PRINT listbox_selected$ END SUB
SUB list_choices2() listbox_selected2$ = GRAB$(list2) PRINT listbox_selected2$ END SUB
' Note gridview has a string then three arguments the last ' argument turns on or off the grid win=WINDOW("Multi List",200,200) list=GRIDVIEW("LIST",100,200,1) ATTACH(win,list,0,0) TEXT(list,"a") TEXT(list,"b") TEXT(list,"c") TEXT(list,"d") TEXT(list,"e") TEXT(list,"f") TEXT(list,"g") TEXT(list,"h") TEXT(list,"i") TEXT(list,"j") CALLBACK(list, list_choices)
list2=GRIDVIEW("LIST2",100,200,1) ATTACH(win,list2,100,0) TEXT(list2,"A") TEXT(list2,"B") TEXT(list2,"C") TEXT(list2,"D") TEXT(list2,"E") TEXT(list2,"F") TEXT(list2,"G") TEXT(list2,"H") TEXT(list2,"I") TEXT(list2,"J") CALLBACK(list2, list_choices2)
DISPLAY
name this gridview.bac it doesn't get compiled it is the include file FUNCTION GRIDVIEW (STRING header$,int hug_xsize, int hug_ysize,int gridlines)
LOCAL lst, tree, sel, cell, tc, win
lst = gtk_list_store_new(1, G_TYPE_STRING) tree = gtk_tree_view_new_with_model(lst) gtk_tree_view_set_grid_lines(tree,gridlines) gtk_tree_view_set_headers_visible(tree, 1)
sel = gtk_tree_view_get_selection(tree) gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE) cell = gtk_cell_renderer_text_new()
tc = gtk_tree_view_column_new_with_attributes( header$, cell, "text", 0, 0) gtk_tree_view_append_column(tree, tc)
win = gtk_scrolled_window_new(0, 0) gtk_scrolled_window_set_policy(win, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC) gtk_scrolled_window_set_shadow_type(win, GTK_SHADOW_ETCHED_IN) gtk_container_add(win, tree)
IF HUG_WIDGET_SHOW THEN gtk_widget_show_all(win)
hug_widget_xsize(STR$(win)) = hug_xsize hug_widget_ysize(STR$(win)) = hug_ysize hug_widget_signal(STR$(win)) = 5 hug_widget_s_widget(STR$(win)) = sel
hug_widget_type$(STR$(win)) = "list" hug_widget_attach(STR$(win)) = sel hug_widget_font(STR$(win)) = tree hug_widget_focus(STR$(win)) = lst
RETURN win
END FUNCTION
|
|
|
Post by bigbass on Dec 2, 2012 22:08:27 GMT 1
Dynamic-multi-listI combined alexfish's gridview with my dynamic list box code so now we have a Dynamic multi list I wanted something like this for a long time What does this mean ? A static list has to be compiled into the code and every time you want to edit the code you have to edit and recompile the binary However a dynamic list allows you to edit an external text file that gets read when the program is run therefore you don't have to recompile to edit your list making things easy to modify and update dynamic lists used for the example place them in /tmp bigbass-porteus.googlecode.com/files/girls-names.txtbigbass-porteus.googlecode.com/files/boys-names.txt
'dynamic-multi-list.bac
lib$ = HUGLIB$("gtk") IMPORT "gtk_tree_view_set_grid_lines(long,int)" FROM lib$ TYPE void INCLUDE hug.bac INCLUDE gridview.bac
' boys names ' get the list into a variable read from a file result_input$ = EXEC$("cat /tmp/boys-names.txt")
' girls-names ' get the list2 into a variable read from a file result_input2$ = EXEC$("cat /tmp/girls-names.txt")
'========================= SUB list_choices() '========================= listbox_selected$ = GRAB$(list) PRINT listbox_selected$ END SUB
'========================= SUB list_choices2() '========================= listbox_selected2$ = GRAB$(list2) PRINT listbox_selected2$ END SUB
' This is just to get a dynamic list read from a text file '========================= SUB MAKE_FILE_LIST '=========================
SPLIT result_input$ BY NL$ TO words$ SIZE dim
FOR i = 0 TO dim - 4
list_choices_text$ = words$[i]
TEXT(list, words$[i]) PRINT words$[i] PRINT i NEXT END SUB
' This is just to get a dynamic list read from a text file '========================= SUB MAKE_FILE_LIST2 '=========================
SPLIT result_input2$ BY NL$ TO words$ SIZE dim
FOR i = 0 TO dim - 4
list_choices_text2$ = words$[i]
TEXT(list2, words$[i]) PRINT words$[i] PRINT i NEXT END SUB
' Note gridview has a string then three arguments the last ' argument turns on or off the grid win=WINDOW("Dynamic Multi List ",300,200) list=GRIDVIEW("Boys Names",150,200,1) ATTACH(win,list,0,0) MAKE_FILE_LIST CALLBACK(list, list_choices)
list2=GRIDVIEW("Girls Names",150,200,1) ATTACH(win,list2,150,0) MAKE_FILE_LIST2 CALLBACK(list2, list_choices2)
DISPLAY
This is the gridview.bac include by alexfish FUNCTION GRIDVIEW (STRING header$,int hug_xsize, int hug_ysize,int gridlines)
LOCAL lst, tree, sel, cell, tc, win
lst = gtk_list_store_new(1, G_TYPE_STRING) tree = gtk_tree_view_new_with_model(lst) gtk_tree_view_set_grid_lines(tree,gridlines) gtk_tree_view_set_headers_visible(tree, 1)
sel = gtk_tree_view_get_selection(tree) gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE) cell = gtk_cell_renderer_text_new()
tc = gtk_tree_view_column_new_with_attributes( header$, cell, "text", 0, 0) gtk_tree_view_append_column(tree, tc)
win = gtk_scrolled_window_new(0, 0) gtk_scrolled_window_set_policy(win, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC) gtk_scrolled_window_set_shadow_type(win, GTK_SHADOW_ETCHED_IN) gtk_container_add(win, tree)
IF HUG_WIDGET_SHOW THEN gtk_widget_show_all(win)
hug_widget_xsize(STR$(win)) = hug_xsize hug_widget_ysize(STR$(win)) = hug_ysize hug_widget_signal(STR$(win)) = 5 hug_widget_s_widget(STR$(win)) = sel
hug_widget_type$(STR$(win)) = "list" hug_widget_attach(STR$(win)) = sel hug_widget_font(STR$(win)) = tree hug_widget_focus(STR$(win)) = lst
RETURN win
END FUNCTION
|
|
|
Post by alexfish on Dec 3, 2012 14:46:20 GMT 1
Hey Joe
have cleaned up the code for muti-column gridview
here is a example of four columns.
Have updated to enable grab$
'@ Example of four column gridview
INCLUDE hug.bac
lib$ = HUGLIB$("gtk") IMPORT "gtk_tree_view_set_grid_lines(long,int)" FROM lib$ TYPE void
FUNCTION TEXT_GRIDVIEW(NUMBER hug_widget,STRING text$) LOCAL bits SPLIT text$ BY "," TO hug_text$ SIZE bits IF bits < 4 THEN PRINT "need 4 values , exiting text_gridview" RETURN FALSE END IF LOCAL dim, i, layer, lab, buffer, lst, image LOCAL which TYPE int LOCAL (*hug_func)(long,char*) TYPE void RECORD iter LOCAL stamp TYPE int LOCAL user_data TYPE void* LOCAL user_data2 TYPE void* LOCAL user_data3 TYPE void* END RECORD lst = hug_widget_focus(STR$(hug_widget)) gtk_list_store_append(lst, ADDRESS(iter)) gtk_list_store_set(lst, ADDRESS(iter),0, hug_text$[0] , 1, hug_text$[1], 2, hug_text$[2] , 3, hug_text$[3] ,-1) RETURN TRUE END FUNCTION
SUB SET_GRID_ROW(NUMBER hug_widget, int hug_value) LOCAL buffer, view, iter, mark, sel, path LOCAL nr TYPE FLOATING LOCAL (*hug_func)(long,long) TYPE void SELECT hug_widget_type$(STR$(hug_widget)) CASE "gridview" sel = hug_widget_attach(STR$(hug_widget)) PRINT sel path = gtk_tree_path_new_from_string(STR$(hug_value)) gtk_tree_selection_select_path(sel, path) gtk_tree_path_free(path) END SELECT END SUB
FUNCTION GRIDVIEW(STRING header$,int hug_xsize, int hug_ysize,int gridlines) LOCAL cols SPLIT header$ BY "," TO colheader$ SIZE cols IF cols < 4 THEN PRINT "need 4 values , exiting text_gridview" RETURN FALSE END IF cols=cols-1 LOCAL lst, tree, sel, cell, tc, win '@ set colums to 4 + 4types of data . here the four columns are all strings lst = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING) tree = gtk_tree_view_new_with_model(lst) gtk_tree_view_set_grid_lines(tree,gridlines) gtk_tree_view_set_headers_visible(tree, 1) sel = gtk_tree_view_get_selection(tree) ' populate the tree with the columns FOR t = 0 TO cols cell = gtk_cell_renderer_text_new() tc = gtk_tree_view_column_new_with_attributes( colheader$[t], cell, "text", t, 0) gtk_tree_view_append_column(tree, tc) NEXT
win = gtk_scrolled_window_new(0, 0) gtk_scrolled_window_set_policy(win, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC) gtk_scrolled_window_set_shadow_type(win, GTK_SHADOW_ETCHED_IN) gtk_container_add(win, tree)
IF HUG_WIDGET_SHOW THEN gtk_widget_show_all(win)
hug_widget_xsize(STR$(win)) = hug_xsize hug_widget_ysize(STR$(win)) = hug_ysize hug_widget_signal(STR$(win)) = 5 hug_widget_s_widget(STR$(win)) = sel
hug_widget_type$(STR$(win)) = "gridview" hug_widget_attach(STR$(win)) = sel hug_widget_font(STR$(win)) = tree hug_widget_focus(STR$(win)) = lst
RETURN win
END FUNCTION
FUNCTION GRAB_GRID$(NUMBER hug_widget, int col)
IF col > 3 THEN PRINT "column ",col," not exist , exiting" RETURN FALSE END IF LOCAL iter1, iter2, slist LOCAL hug_text$ LOCAL ptr TYPE STRING LOCAL (*hug_func)(long) TYPE char* LOCAL ctr TYPE int
RECORD iter LOCAL stamp TYPE int LOCAL user_data TYPE void* LOCAL user_data2 TYPE void* LOCAL user_data3 TYPE void* END RECORD SELECT hug_widget_type$(STR$(hug_widget)) CASE "gridview" result = gtk_tree_selection_get_selected(hug_widget_attach(STR$(hug_widget)), 0, ADDRESS(iter)) IF ISTRUE(result) THEN gtk_tree_model_get(hug_widget_focus(STR$(hug_widget)), ADDRESS(iter), col, ADDRESS(hug_text$), -1) ELSE hug_text$ = "" END IF DEFAULT hug_text$ = "" END SELECT RETURN hug_text$ END FUNCTION
win=WINDOW("test",600,300) '@ make two grids so can check selections grid1=GRIDVIEW("Name,Age,Sex,Member",300,300,3) ATTACH(win,grid1,0,0) grid2=GRIDVIEW("col1,col2,col3,col4",300,300,3) ATTACH(win,grid2,300,0) '@ text two lines to the grids 1 and two TEXT_GRIDVIEW(grid1,"Joe,young at heart,male,yes") TEXT_GRIDVIEW(grid1,"Alex,young at heart,male,yes")
TEXT_GRIDVIEW(grid2,"one,two, three, four") TEXT_GRIDVIEW(grid2,"Five,Six ,7,8") ' set the grid row SET_GRID_ROW(grid1,1) ' print data from column 1 PRINT GRAB_GRID$(grid1,1)
DISPLAY
ADDED: can change auto expand column To Resizing column by changing code in "populate the tree with the columns" IE:
' populate the tree with the columns FOR t = 0 TO cols cell = gtk_cell_renderer_text_new() tc = gtk_tree_view_column_new_with_attributes( colheader$[t], cell, "text", t, 0) gtk_tree_view_column_set_resizable(tc,1) gtk_tree_view_append_column(tree, tc) NEXT
Change the Header Imports to
INCLUDE hug.bac
lib$ = HUGLIB$("gtk") IMPORT "gtk_tree_view_set_grid_lines(long,int)" FROM lib$ TYPE void IMPORT "gtk_tree_view_column_set_resizable(long,int)" FROM lib$ TYPE void
To omit render of a cell : best explained by this bit of code
TEXT_GRIDVIEW(grid1,"Joe,young at heart ,male,yes") TEXT_GRIDVIEW(grid1,"Alex,,male,yes") note the two ",," after Alex = nothing in the cell in col 1
Regards
Alex
|
|
|
Post by bigbass on Dec 4, 2012 17:22:06 GMT 1
Hey alexfish I love it I just added the callbacks to your code and some small adjustments just for a static example widget this is great we will have more widgets ! Note there is some info in the previous post how to edit the columns in alexfish's post don't miss it *I will think about how to get this as dynamic widget later this one is much more complex so it will take several cups of coffee Four column multi list staticfour-column-multi-list .bac'---Example of four column gridview with callbacks BaCon HUG four-column-multi-list .bac
INCLUDE hug.bac
lib$ = HUGLIB$("gtk") IMPORT "gtk_tree_view_set_grid_lines(long,int)" FROM lib$ TYPE void
'--- lets keep all GTK code as include files to simplify the BaCon code reading INCLUDE gridview-four-include.bac
'========================= SUB list_choices() '========================= PRINT GRAB_GRID$(grid1,0) ,",", GRAB_GRID$(grid1,1) ,",", GRAB_GRID$(grid1,2) ,",", GRAB_GRID$(grid1,3) END SUB
'========================= SUB list_choices2() '========================= PRINT GRAB_GRID$(grid2,0) ,",", GRAB_GRID$(grid2,1) ,",", GRAB_GRID$(grid2,2) ,",", GRAB_GRID$(grid2,3) END SUB
win=WINDOW("Four column multi list ",500,150) '---make two grids so can check selections
grid1=GRIDVIEW("Name,Age,Sex,Member",300,300,3) ATTACH(win,grid1,0,0)
grid2=GRIDVIEW("col1,col2,col3,col4",300,300,3) ATTACH(win,grid2,300,0)
'---text two lines to the grid 1 TEXT_GRIDVIEW(grid1,"Joe,young at heart,male,yes") TEXT_GRIDVIEW(grid1,"Alex,young at heart,male,yes")
'---text two lines to the grid 2 TEXT_GRIDVIEW(grid2,"one,two,three,four") TEXT_GRIDVIEW(grid2,"Five,Six,7,8")
'---set the grid row SET_GRID_ROW(grid1,1) '---print data from column 1
CALLBACK(grid1, list_choices) CALLBACK(grid2, list_choices2) DISPLAY
This is the include file all GTK functions will be a separate include file so that the BaCon coding is easy to read the same idea as HUG gridview-four-include.bac
'======================================================= FUNCTION TEXT_GRIDVIEW(NUMBER hug_widget,STRING text$) '======================================================= LOCAL bits SPLIT text$ BY "," TO hug_text$ SIZE bits IF bits < 4 THEN PRINT "need 4 values , exiting text_gridview" RETURN FALSE END IF LOCAL dim, i, layer, lab, buffer, lst, image LOCAL which TYPE int LOCAL (*hug_func)(long,char*) TYPE void RECORD iter LOCAL stamp TYPE int LOCAL user_data TYPE void* LOCAL user_data2 TYPE void* LOCAL user_data3 TYPE void* END RECORD lst = hug_widget_focus(STR$(hug_widget)) gtk_list_store_append(lst, ADDRESS(iter)) gtk_list_store_set(lst, ADDRESS(iter),0, hug_text$[0] , 1, hug_text$[1], 2, hug_text$[2] , 3, hug_text$[3] ,-1) RETURN TRUE END FUNCTION
'======================================================= SUB SET_GRID_ROW(NUMBER hug_widget, int hug_value) '======================================================= LOCAL buffer, view, iter, mark, sel, path LOCAL nr TYPE FLOATING LOCAL (*hug_func)(long,long) TYPE void SELECT hug_widget_type$(STR$(hug_widget)) CASE "gridview" sel = hug_widget_attach(STR$(hug_widget)) PRINT sel path = gtk_tree_path_new_from_string(STR$(hug_value)) gtk_tree_selection_select_path(sel, path) gtk_tree_path_free(path) END SELECT END SUB '======================================================= FUNCTION GRIDVIEW(STRING header$,int hug_xsize, int hug_ysize,int gridlines) '======================================================= LOCAL cols SPLIT header$ BY "," TO colheader$ SIZE cols IF cols < 4 THEN PRINT "need 4 values , exiting text_gridview" RETURN FALSE END IF cols=cols-1 LOCAL lst, tree, sel, cell, tc, win '@ set colums to 4 + 4types of data . here the four columns are all strings lst = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING) tree = gtk_tree_view_new_with_model(lst) gtk_tree_view_set_grid_lines(tree,gridlines) gtk_tree_view_set_headers_visible(tree, 1) sel = gtk_tree_view_get_selection(tree) ' populate the tree with the columns FOR t = 0 TO cols cell = gtk_cell_renderer_text_new() tc = gtk_tree_view_column_new_with_attributes( colheader$[t], cell, "text", t, 0) gtk_tree_view_append_column(tree, tc) NEXT
win = gtk_scrolled_window_new(0, 0) gtk_scrolled_window_set_policy(win, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC) gtk_scrolled_window_set_shadow_type(win, GTK_SHADOW_ETCHED_IN) gtk_container_add(win, tree)
IF HUG_WIDGET_SHOW THEN gtk_widget_show_all(win)
hug_widget_xsize(STR$(win)) = hug_xsize hug_widget_ysize(STR$(win)) = hug_ysize hug_widget_signal(STR$(win)) = 5 hug_widget_s_widget(STR$(win)) = sel
hug_widget_type$(STR$(win)) = "gridview" hug_widget_attach(STR$(win)) = sel hug_widget_font(STR$(win)) = tree hug_widget_focus(STR$(win)) = lst
RETURN win
END FUNCTION
'======================================================= FUNCTION GRAB_GRID$(NUMBER hug_widget, int col) '=======================================================
IF col > 3 THEN PRINT "column ",col," not exist , exiting" RETURN FALSE END IF LOCAL iter1, iter2, slist LOCAL hug_text$ LOCAL ptr TYPE STRING LOCAL (*hug_func)(long) TYPE char* LOCAL ctr TYPE int
RECORD iter LOCAL stamp TYPE int LOCAL user_data TYPE void* LOCAL user_data2 TYPE void* LOCAL user_data3 TYPE void* END RECORD SELECT hug_widget_type$(STR$(hug_widget)) CASE "gridview" result = gtk_tree_selection_get_selected(hug_widget_attach(STR$(hug_widget)), 0, ADDRESS(iter)) IF ISTRUE(result) THEN gtk_tree_model_get(hug_widget_focus(STR$(hug_widget)), ADDRESS(iter), col, ADDRESS(hug_text$), -1) ELSE hug_text$ = "" END IF DEFAULT hug_text$ = "" END SELECT RETURN hug_text$ END FUNCTION
|
|
|
Post by alexfish on Dec 5, 2012 16:29:22 GMT 1
Hey Joe
to delete the info Gridview > "Clear"
For the INCLUDE file
'@ for the INCLUDE file SUB GRIDVIEW_CLEAR(NUMBER hug_widget) lst = hug_widget_focus(STR$(hug_widget)) gtk_list_store_clear( lst) END SUB '----------------------------------------------------------------------- for the BACON code
'@ for the bacon code ' Example to clear grid1
SUB clear_grid1 GRIDVIEW_CLEAR(grid1) END SUB '----------------------------------------------------------------------------------------
EG: can have a button with callback to the "clear_grid1"
ADDED:
EDIT SELECTED ROW:
The Function for the INCLUDE file
'======================================================= FUNCTION RE_TEXT_GRIDVIEW(NUMBER hug_widget, STRING text$, int row) '======================================================= LOCAL bits SPLIT text$ BY "," TO hug_text$ SIZE bits IF bits < 4 THEN PRINT "need 4 values , exiting text_gridview" RETURN FALSE END IF ' SET THE ROW sel = hug_widget_attach(STR$(hug_widget)) PRINT sel path = gtk_tree_path_new_from_string(STR$(row)) gtk_tree_selection_select_path(sel, path) gtk_tree_path_free(path) '-------------------------------------------------------------------------------------------------------------------------- RECORD iter LOCAL stamp TYPE int LOCAL user_data TYPE void* LOCAL user_data2 TYPE void* LOCAL user_data3 TYPE void* END RECORD lst = hug_widget_focus(STR$(hug_widget)) result = gtk_tree_selection_get_selected(hug_widget_attach(STR$(hug_widget)), 0, ADDRESS(iter)) IF ISTRUE(result) THEN gtk_list_store_set(lst, ADDRESS(iter),0, hug_text$[0] , 1, hug_text$[1], 2, hug_text$[2] , 3, hug_text$[3] ,-1) ELSE PRINT " No Ref" RETURN FALSE END IF RETURN TRUE END FUNCTION
The bacon code Example
' edit or add text to grid1 row 1 SUB retext RE_TEXT_GRIDVIEW(grid1,"Joe,secret,male,yes",1) END SUB
TO EDIT ONE CELL
Example for the INCLUDE file
'======================================================= FUNCTION RE_TEXT_GRIDVIEW_COL_ROW(NUMBER hug_widget, STRING text$, int col,int row) '======================================================= IF col > 3 THEN PRINT "column does not exit , exiting" RETURN FALSE ENDIF
' SET THE ROW sel = hug_widget_attach(STR$(hug_widget)) PRINT sel path = gtk_tree_path_new_from_string(STR$(row)) gtk_tree_selection_select_path(sel, path) gtk_tree_path_free(path) '-------------------------------------------------------------------------------------------------------------------------- RECORD iter LOCAL stamp TYPE int LOCAL user_data TYPE void* LOCAL user_data2 TYPE void* LOCAL user_data3 TYPE void* END RECORD lst = hug_widget_focus(STR$(hug_widget)) result = gtk_tree_selection_get_selected(hug_widget_attach(STR$(hug_widget)), 0, ADDRESS(iter)) IF ISTRUE(result) THEN gtk_list_store_set(lst, ADDRESS(iter),col, text$ ,-1) ELSE PRINT " No Ref" RETURN FALSE END IF RETURN TRUE END FUNCTION
bacon code example
'EDIT CELL @ COLUMN 1 , ROW ONE SUB retext_col_row RE_TEXT_GRIDVIEW_COL_ROW(grid1,"EDIT",1,1) END SUB again should use a callback feature to the SUB
TEXT TO WIDGET can act as prepend by omiting data Example:
TEXT_GRIDVIEW(grid2,",,,") same method should also work for blanking a cell in "FUNCTION RE_TEXT_GRIDVIEW_COL_ROW()" or for blanking full rows of data etc etc :Experimenting = (hacking)
Regards
Alex
|
|
|
Post by bigbass on Dec 5, 2012 19:44:20 GMT 1
dynamic-four-column-multi-list.bac This was easier than I expected Only a cup of black tea was needed depends on gridview-four-include.bac '---Example of dynamic four column gridview with callbacks BaCon HUG 'dynamic-four-column-multi-list.bac
INCLUDE hug.bac
lib$ = HUGLIB$("gtk") IMPORT "gtk_tree_view_set_grid_lines(long,int)" FROM lib$ TYPE void
'--- lets keep all GTK code as include files to simplify the BaCon code reading INCLUDE gridview-four-include.bac
'--- a text file with commas separating four variables '--- get the list into a variable read from a file result_input$ = EXEC$("cat /tmp/names4.txt")
' This is just to get a dynamic list read from a text file '========================= SUB MAKE_FILE_LIST '=========================
SPLIT result_input$ BY NL$ TO words$ SIZE dim
FOR i = 0 TO dim - 4
list_choices_text$ = words$[i] TEXT_GRIDVIEW(grid1,words$[i]) PRINT words$[i] PRINT i NEXT END SUB
'========================= SUB list_choices() '========================= PRINT GRAB_GRID$(grid1,0) ,",", GRAB_GRID$(grid1,1) ,",", GRAB_GRID$(grid1,2) ,",", GRAB_GRID$(grid1,3) END SUB
'========================= SUB list_choices2() '========================= PRINT GRAB_GRID$(grid2,0) ,",", GRAB_GRID$(grid2,1) ,",", GRAB_GRID$(grid2,2) ,",", GRAB_GRID$(grid2,3) END SUB
win=WINDOW("Four column multi list ",500,200) '---make two grids so can check selections
grid1=GRIDVIEW("Name,Age,Sex,Member",300,200,3) ATTACH(win,grid1,0,0)
grid2=GRIDVIEW("col1,col2,col3,col4",300,200,3) ATTACH(win,grid2,300,0)
'---text two lines to the grid 1 '--- will use a dynamic list comma delimiter reading an external file MAKE_FILE_LIST
'---text two lines to the grid 2 TEXT_GRIDVIEW(grid2,"one,two,three,four") TEXT_GRIDVIEW(grid2,"Five,Six,7,8")
'---set the grid row SET_GRID_ROW(grid1,1) '---print data from column 1
CALLBACK(grid1, list_choices) CALLBACK(grid2, list_choices2) DISPLAY
place this file in /tmp and call it names4.txtit is the dynamic list modify it to see the changes without recompiling Bill,40,male,no Benjamin,30,male,yes Frank,40,male,no Sam,30,male,yes David,40,male,no Ben,30,male,yes John,40,male,no
|
|
|
Post by alexfish on Mar 9, 2013 15:37:21 GMT 1
EDITABLE LISTVEW This is a Single Listview with editable cells use Latest BaCon + Latest Hug click on the list untill the editable shows , type in new data Perhaps Joe could add some magic , dynamically INCLUDE "hug.bac"
'@ should put these to FUNCTIONS in an Include '======================================================= FUNCTION EDITABLE_LIST(int hug_xsize, int hug_ysize) '======================================================= LOCAL lst, tree, sel, cell, tc, win
lst = gtk_list_store_new(1, G_TYPE_STRING) tree = gtk_tree_view_new_with_model(lst) gtk_tree_view_set_headers_visible(tree, 0)
sel = gtk_tree_view_get_selection(tree) gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE) cell = gtk_cell_renderer_text_new() '@ set the header visable gtk_tree_view_set_headers_visible(tree, 1) tc = gtk_tree_view_column_new_with_attributes("editable-grid", cell, "text", 0, 0) gtk_tree_view_append_column(tree, tc) win = gtk_scrolled_window_new(0, 0) '@ SET EDITABLE g_object_set(cell, "editable",TRUE,"editable-set",TRUE,NULL) '@ SET CALLBACK HERE FOR THE CELL / returning the win id for HUG / hug_widget g_signal_connect_data(cell, "edited",UPDATE_LIST,win,0,0) gtk_scrolled_window_set_policy(win, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC) gtk_scrolled_window_set_shadow_type(win, GTK_SHADOW_ETCHED_IN) gtk_container_add(win, tree) '@ HUG IT IF HUG_WIDGET_SHOW THEN gtk_widget_show_all(win)
hug_widget_xsize(STR$(win)) = hug_xsize hug_widget_ysize(STR$(win)) = hug_ysize hug_widget_signal(STR$(win)) = 5 hug_widget_s_widget(STR$(win)) = sel
hug_widget_type$(STR$(win)) = "list" hug_widget_attach(STR$(win)) = sel hug_widget_font(STR$(win)) = tree hug_widget_focus(STR$(win)) = lst RETURN win END FUNCTION
REM ------------------------------------------------------------------------------------------------------------------------------------------ FUNCTION UPDATE_LIST(NUMBER *cell,char *path_string,STRING new_text$,int hug_widget)
RECORD iter LOCAL stamp TYPE int LOCAL user_data TYPE void* LOCAL user_data2 TYPE void* LOCAL user_data3 TYPE void* END RECORD
result = gtk_tree_selection_get_selected(hug_widget_attach(STR$(hug_widget)), 0, ADDRESS(iter)) IF ISTRUE(result) THEN gtk_list_store_set(hug_widget_focus(STR$(hug_widget)), ADDRESS(iter),0, new_text$ ,-1) ELSE RETURN FALSE END IF
RETURN TRUE END FUNCTION
'@ END OF NEW include FUNCTIONS -------------------------------------------------------------------
win=WINDOW("Editable-Listview ",700,500)
editable_list= EDITABLE_LIST(300,300) ATTACH(win,editable_list,0,0) '@ Populate the list for testing
FOR t = 1 TO 20 TEXT(editable_list,STR$(t)) NEXT '@ DISPLAY FOREVER DISPLAY Have Fun + BR Alex
|
|
|
Post by bigbass on Mar 9, 2013 19:52:01 GMT 1
Hey Alex Excellent! ;D I love the new widget you did! and it was a pleasure to add the dynamic list and callback that you suggested This is really great news that we can get more widgets I hope to some day figure out the GTK part till then I'll learn by all the new great examples you guys post P.S The next step is to have an option to edit the original file or save a new file with changes great for a simple data base app Joe biglist2.txt place it in /tmp uncompresed basic-converter.proboards.com/index.cgi?action=downloadattachmentpage&board=doc&thread=263&post=2266 INCLUDE "hug.bac"
'@ should put these to FUNCTIONS in an Include '======================================================= FUNCTION EDITABLE_LIST(int hug_xsize, int hug_ysize) '======================================================= LOCAL lst, tree, sel, cell, tc, win
lst = gtk_list_store_new(1, G_TYPE_STRING) tree = gtk_tree_view_new_with_model(lst) gtk_tree_view_set_headers_visible(tree, 0)
sel = gtk_tree_view_get_selection(tree) gtk_tree_selection_set_mode(sel, GTK_SELECTION_SINGLE) cell = gtk_cell_renderer_text_new() '@ set the header visable gtk_tree_view_set_headers_visible(tree, 1) tc = gtk_tree_view_column_new_with_attributes("editable-grid double click item to edit ", cell, "text", 0, 0) gtk_tree_view_append_column(tree, tc) win = gtk_scrolled_window_new(0, 0) '@ SET EDITABLE g_object_set(cell, "editable",TRUE,"editable-set",TRUE,NULL) '@ SET CALLBACK HERE FOR THE CELL / returning the win id for HUG / hug_widget g_signal_connect_data(cell, "edited",UPDATE_LIST,win,0,0) gtk_scrolled_window_set_policy(win, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC) gtk_scrolled_window_set_shadow_type(win, GTK_SHADOW_ETCHED_IN) gtk_container_add(win, tree) '@ HUG IT IF HUG_WIDGET_SHOW THEN gtk_widget_show_all(win)
hug_widget_xsize(STR$(win)) = hug_xsize hug_widget_ysize(STR$(win)) = hug_ysize hug_widget_signal(STR$(win)) = 5 hug_widget_s_widget(STR$(win)) = sel
hug_widget_type$(STR$(win)) = "list" hug_widget_attach(STR$(win)) = sel hug_widget_font(STR$(win)) = tree hug_widget_focus(STR$(win)) = lst RETURN win END FUNCTION
REM ------------------------------------------------------------------------------------------------------------------------ ------------------ FUNCTION UPDATE_LIST(NUMBER *cell,char *path_string,STRING new_text$,int hug_widget)
RECORD iter LOCAL stamp TYPE int LOCAL user_data TYPE void* LOCAL user_data2 TYPE void* LOCAL user_data3 TYPE void* END RECORD
result = gtk_tree_selection_get_selected(hug_widget_attach(STR$(hug_widget)), 0, ADDRESS(iter)) IF ISTRUE(result) THEN gtk_list_store_set(hug_widget_focus(STR$(hug_widget)), ADDRESS(iter),0, new_text$ ,-1) ELSE RETURN FALSE END IF
RETURN TRUE
END FUNCTION
'@ END OF NEW include FUNCTIONS -------------------------------------------------------------------
' we want to "echo out" which line was pressed
'========================= SUB list_choices_demo() '========================= listbox_selected$ = GRAB$(editable_list) PRINT listbox_selected$ END SUB
' (1) first step modify '--- setup the file to be read in and edited on the fly!
'--- a text file with new lines separating variables '--- get the list into a variable read in from a file result_input$ = EXEC$("cat /tmp/biglist2.txt")
' (2) second step modify ' This is just to get a dynamic list read from a text file into the list '========================= SUB MAKE_FILE_LIST '=========================
SPLIT result_input$ BY NL$ TO words$ SIZE dim
FOR i = 0 TO dim - 4
list_choices_text$ = words$[i] TEXT(editable_list, words$[i]) PRINT words$[i] PRINT i NEXT END SUB
win=WINDOW("Editable-Listview-Dynamic",300,300)
editable_list= EDITABLE_LIST(300,300) ATTACH(win,editable_list,0,0) '--- call the sub so we get the dynamic list read from a file MAKE_FILE_LIST '--- add a callback so we can see what was selected or edited CALLBACK(editable_list, list_choices_demo) DISPLAY
|
|
|
Post by alexfish on Mar 9, 2013 22:15:37 GMT 1
EDITABLE GRIDLIST With Resizable Columns Need Help with this one again Joe INCLUDE "hug.bac"
lib$ = HUGLIB$("gtk") IMPORT "gtk_tree_view_column_set_resizable(long,int)" FROM lib$ TYPE void IMPORT "gtk_tree_view_set_grid_lines(long,int)" FROM lib$ TYPE void '@ GLOBALS FOR EDITABLE GRIDLIST LIST_SIGNAL=0 LIST_COL=0 '======================================================= FUNCTION EDITABLE_GRIDVIEW(STRING header$,int hug_xsize, int hug_ysize,int gridlines) '======================================================= LOCAL cols SPLIT header$ BY "," TO colheader$ SIZE cols IF cols < 4 THEN PRINT "need 4 values , exiting text_gridview" RETURN FALSE END IF cols=cols-1 LOCAL lst, tree, sel, cell, tc, win,model,t '@ set colums to 4 + 4types of data . here the four columns are all strings lst = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING) tree = gtk_tree_view_new_with_model(lst)
gtk_tree_view_set_grid_lines(tree,gridlines) gtk_tree_view_set_headers_visible(tree, 1) sel = gtk_tree_view_get_selection(tree) 'model = gtk_tree_view_get_model(tree) win = gtk_scrolled_window_new(0, 0) ' populate the tree with the columns FOR t = 0 TO cols cell = gtk_cell_renderer_text_new() g_object_set(cell, "editable",TRUE,"editable-set",TRUE,NULL) tc = gtk_tree_view_column_new_with_attributes( colheader$[t], cell, "text", t, 0) '@ send column number first g_signal_connect_data(cell, "edited",UPDATE_LIST,t,0,0) '@ SET CALLBACK HERE FOR THE CELL / returning the win id for HUG / hug_widget g_signal_connect_data(cell, "edited",UPDATE_LIST,win,0,0)
gtk_tree_view_column_set_resizable(tc,1) 'gtk_tree_view_column_set_clickable(tc,1) gtk_tree_view_append_column(tree, tc) NEXT
gtk_scrolled_window_set_policy(win, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC) gtk_scrolled_window_set_shadow_type(win, GTK_SHADOW_ETCHED_IN) gtk_container_add(win, tree)
IF HUG_WIDGET_SHOW THEN gtk_widget_show_all(win)
hug_widget_xsize(STR$(win)) = hug_xsize hug_widget_ysize(STR$(win)) = hug_ysize hug_widget_signal(STR$(win)) = 5 hug_widget_s_widget(STR$(win)) = sel hug_widget_type$(STR$(win)) = "gridview" hug_widget_attach(STR$(win)) = sel hug_widget_font(STR$(win)) = tree TREE=tree hug_widget_focus(STR$(win)) = lst
RETURN win
END FUNCTION '======================================================= FUNCTION UPDATE_LIST(NUMBER *cell,char *path_string,STRING new_text$,int hug_widget) '======================================================= INCR LIST_SIGNAL
IF LIST_SIGNAL=1 THEN LIST_COL=hug_widget
RECORD iter LOCAL stamp TYPE int LOCAL user_data TYPE void* LOCAL user_data2 TYPE void* LOCAL user_data3 TYPE void* END RECORD '@ TODO Find way of editable in 4 or more coulms this is only updata col 0 IF LIST_SIGNAL = 2 THEN result = gtk_tree_selection_get_selected(hug_widget_attach(STR$(hug_widget)), 0, ADDRESS(iter)) IF ISTRUE(result) THEN gtk_list_store_set(hug_widget_focus(STR$(hug_widget)), ADDRESS(iter),LIST_COL, new_text$ ,-1) LIST_SIGNAL=0 ELSE LIST_SIGNAL=0 RETURN FALSE END IF END IF RETURN TRUE END FUNCTION '======================================================= FUNCTION TEXT_EDITABLE_GRIDVIEW(NUMBER hug_widget,STRING text$) '======================================================= LOCAL bits SPLIT text$ BY "," TO hug_text$ SIZE bits IF bits < 4 THEN PRINT "need 4 values , exiting text_gridview" RETURN FALSE END IF
RECORD iter LOCAL stamp TYPE int LOCAL user_data TYPE void* LOCAL user_data2 TYPE void* LOCAL user_data3 TYPE void* END RECORD lst = hug_widget_focus(STR$(hug_widget)) gtk_list_store_append(lst, ADDRESS(iter)) gtk_list_store_set(lst, ADDRESS(iter),0, hug_text$[0] , 1, hug_text$[1], 2, hug_text$[2] , 3, hug_text$[3] ,-1) RETURN TRUE END FUNCTION '=======================================================
win=WINDOW("Four column multi list ",700,500)
grid1=EDITABLE_GRIDVIEW("Name,Age,Sex,Member",700,500,3) ATTACH(win,grid1,0,5) TEXT_EDITABLE_GRIDVIEW(grid1,"Joe,young at heart,male,yes") TEXT_EDITABLE_GRIDVIEW(grid1,"1,2,3,4") a$=CONCAT$("one",NL$,"and one make two,two,three,four") TEXT_EDITABLE_GRIDVIEW(grid1,a$) '@ DISPLAY FOREVER
DISPLAY EDIT:: this may look better using TABLE can use this code HUGOPTIONS ("TABLE 1 1") Just under the "IMPORT "hug.bac" Have Fun + BR Alex
|
|
|
Post by bigbass on Mar 10, 2013 0:51:35 GMT 1
Hey Alex Thanks for another great widget! *Added two GTK functions from your old include file to grab and set Then added the dynamic part and callback Double click on a name to edit it It needs to be sourced to see the output in the terminal as you click and edit Joe name this girls-names4.txt and place it in /tmp edit4grid-dynamic.bac
INCLUDE "hug.bac"
lib$ = HUGLIB$("gtk") IMPORT "gtk_tree_view_column_set_resizable(long,int)" FROM lib$ TYPE void IMPORT "gtk_tree_view_set_grid_lines(long,int)" FROM lib$ TYPE void '@ GLOBALS FOR EDITABLE GRIDLIST LIST_SIGNAL=0 LIST_COL=0 '======================================================= FUNCTION EDITABLE_GRIDVIEW(STRING header$,int hug_xsize, int hug_ysize,int gridlines) '======================================================= LOCAL cols SPLIT header$ BY "," TO colheader$ SIZE cols IF cols < 4 THEN PRINT "need 4 values , exiting text_gridview" RETURN FALSE END IF
cols=cols-1
LOCAL lst, tree, sel, cell, tc, win,model,t '@ set colums to 4 + 4types of data . here the four columns are all strings lst = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING,G_TYPE_STRING,G_TYPE_STRING) tree = gtk_tree_view_new_with_model(lst)
gtk_tree_view_set_grid_lines(tree,gridlines) gtk_tree_view_set_headers_visible(tree, 1) sel = gtk_tree_view_get_selection(tree) 'model = gtk_tree_view_get_model(tree) win = gtk_scrolled_window_new(0, 0) ' populate the tree with the columns FOR t = 0 TO cols cell = gtk_cell_renderer_text_new() g_object_set(cell, "editable",TRUE,"editable-set",TRUE,NULL) tc = gtk_tree_view_column_new_with_attributes( colheader$[t], cell, "text", t, 0) '@ send column number first g_signal_connect_data(cell, "edited",UPDATE_LIST,t,0,0) '@ SET CALLBACK HERE FOR THE CELL / returning the win id for HUG / hug_widget g_signal_connect_data(cell, "edited",UPDATE_LIST,win,0,0)
gtk_tree_view_column_set_resizable(tc,1) 'gtk_tree_view_column_set_clickable(tc,1) gtk_tree_view_append_column(tree, tc) NEXT
gtk_scrolled_window_set_policy(win, GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC) gtk_scrolled_window_set_shadow_type(win, GTK_SHADOW_ETCHED_IN) gtk_container_add(win, tree)
IF HUG_WIDGET_SHOW THEN gtk_widget_show_all(win)
hug_widget_xsize(STR$(win)) = hug_xsize hug_widget_ysize(STR$(win)) = hug_ysize hug_widget_signal(STR$(win)) = 5 hug_widget_s_widget(STR$(win)) = sel hug_widget_type$(STR$(win)) = "gridview" hug_widget_attach(STR$(win)) = sel hug_widget_font(STR$(win)) = tree TREE=tree hug_widget_focus(STR$(win)) = lst
RETURN win
END FUNCTION
'======================================================= SUB SET_GRID_ROW(NUMBER hug_widget, int hug_value) '======================================================= LOCAL buffer, view, iter, mark, sel, path LOCAL nr TYPE FLOATING LOCAL (*hug_func)(long,long) TYPE void SELECT hug_widget_type$(STR$(hug_widget)) CASE "gridview" sel = hug_widget_attach(STR$(hug_widget)) PRINT sel path = gtk_tree_path_new_from_string(STR$(hug_value)) gtk_tree_selection_select_path(sel, path) gtk_tree_path_free(path) END SELECT END SUB
'======================================================= FUNCTION GRAB_GRID$(NUMBER hug_widget, int col) '=======================================================
IF col > 3 THEN PRINT "column ",col," not exist , exiting" RETURN FALSE END IF LOCAL iter1, iter2, slist LOCAL hug_text$ LOCAL ptr TYPE STRING LOCAL (*hug_func)(long) TYPE char* LOCAL ctr TYPE int
RECORD iter LOCAL stamp TYPE int LOCAL user_data TYPE void* LOCAL user_data2 TYPE void* LOCAL user_data3 TYPE void* END RECORD SELECT hug_widget_type$(STR$(hug_widget)) CASE "gridview" result = gtk_tree_selection_get_selected(hug_widget_attach(STR$(hug_widget)), 0, ADDRESS(iter)) IF ISTRUE(result) THEN gtk_tree_model_get(hug_widget_focus(STR$(hug_widget)), ADDRESS(iter), col, ADDRESS(hug_text$), -1) ELSE hug_text$ = "" END IF DEFAULT hug_text$ = "" END SELECT RETURN hug_text$ END FUNCTION
'======================================================= FUNCTION UPDATE_LIST(NUMBER *cell,char *path_string,STRING new_text$,int hug_widget) '======================================================= INCR LIST_SIGNAL
IF LIST_SIGNAL=1 THEN LIST_COL=hug_widget
RECORD iter LOCAL stamp TYPE int LOCAL user_data TYPE void* LOCAL user_data2 TYPE void* LOCAL user_data3 TYPE void* END RECORD '@ TODO Find way of editable in 4 or more coulms this is only updata col 0 IF LIST_SIGNAL = 2 THEN result = gtk_tree_selection_get_selected(hug_widget_attach(STR$(hug_widget)), 0, ADDRESS(iter)) IF ISTRUE(result) THEN gtk_list_store_set(hug_widget_focus(STR$(hug_widget)), ADDRESS(iter),LIST_COL, new_text$ ,-1) LIST_SIGNAL=0 ELSE LIST_SIGNAL=0 RETURN FALSE END IF END IF RETURN TRUE
END FUNCTION '======================================================= FUNCTION TEXT_EDITABLE_GRIDVIEW(NUMBER hug_widget,STRING text$) '======================================================= LOCAL bits SPLIT text$ BY "," TO hug_text$ SIZE bits IF bits < 4 THEN PRINT "need 4 values , exiting text_gridview" RETURN FALSE END IF
RECORD iter LOCAL stamp TYPE int LOCAL user_data TYPE void* LOCAL user_data2 TYPE void* LOCAL user_data3 TYPE void* END RECORD lst = hug_widget_focus(STR$(hug_widget)) gtk_list_store_append(lst, ADDRESS(iter)) gtk_list_store_set(lst, ADDRESS(iter),0, hug_text$[0] , 1, hug_text$[1], 2, hug_text$[2] , 3, hug_text$[3] ,-1)
RETURN TRUE END FUNCTION '=======================================================
'--- a text file with commas separating four variables '--- get the list into a variable read from a file result_input$ = EXEC$("cat /tmp/girls-names4.txt")
' This is just to get a dynamic list read from a text file '========================= SUB MAKE_FILE_LIST '=========================
SPLIT result_input$ BY NL$ TO words$ SIZE dim
FOR i = 0 TO dim - 4
list_choices_text$ = words$[i] TEXT_EDITABLE_GRIDVIEW(grid1,words$[i]) PRINT words$[i] PRINT i NEXT END SUB
'========================= SUB list_choices() '========================= PRINT GRAB_GRID$(grid1,0) ,",", GRAB_GRID$(grid1,1) ,",", GRAB_GRID$(grid1,2) ,",", GRAB_GRID$(grid1,3) END SUB
win=WINDOW("Four column multi list editable",300,200)
grid1=EDITABLE_GRIDVIEW("1 ,2 ,3 ,4 ",300,200,3) ATTACH(win,grid1,0,5) '---text lines to the grid 1 '--- will use a dynamic list comma delimiter reading an external file MAKE_FILE_LIST '---set the grid row SET_GRID_ROW(grid1,1) '---print data from column 1
CALLBACK(grid1, list_choices) DISPLAY
|
|