Mental math of GUI placement + widget tutorial
Mar 10, 2013 1:25:55 GMT 1
Post by alexfish on Mar 10, 2013 1:25:55 GMT 1
Here is part of your request Joe
DATA BASE / GRID
Requires sql3.bac from main download site
First run only writes the data so
run the program , then exit
then re run the prog
BR and Enjoy
Alex
DATA BASE / GRID
Requires sql3.bac from main download site
First run only writes the data so
run the program , then exit
then re run the prog
INCLUDE "hug.bac"
lib$ = HUGLIB$("gtk")
IMPORT "gtk_tree_view_column_cell_get_position(long,long,int*,int*)" FROM lib$ TYPE int
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
IMPORT "gtk_tree_view_get_column(long,int)" FROM lib$ TYPE long
IMPORT "gtk_tree_view_get_columns(long)" FROM lib$ TYPE int
'@ GLOBALS FOR EDITABLE GRIDLIST
LIST_SIGNAL=0
LIST_COL=0
HUGOPTIONS ("TABLE 1 1")
'=======================================================
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
'gboolean gtk_tree_view_column_cell_get_position (GtkTreeViewColumn *tree_column,GtkCellRenderer *cell_renderer, gint *x_offset, gint *width);
IF LIST_SIGNAL=1 THEN LIST_COL=hug_widget
LOCAL treeview,col2
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
'gtk_tree_view_get_column(long,int)
'treeview=hug_widget_font(STR$(hug_widget))
'col2=gtk_tree_view_get_column( treeview,int)
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
'=======================================================
' ***********************************************************
' PROGRAM: sql-mozart.bac
' PURPOSE: demo of BaCon sqlite3 commands
' AUTHOR: vovchik (Puppy Linux forum)
' DEPENDS: bash, bacon, slqite3
' PLATFORM: Puppy Linux (actually, any *nix)
' DATE: 14-05-2010
' VERSION: 0.1a
' MOD by Alexfish (BaCon Forums)
' ***********************************************************
' *****************
' INCLUDES
' *****************
'INCLUDE "sql3.bac"
INCLUDE "sqlite3.bac
GLOBAL MYSTR$[10] TYPE STRING
'---------------
FUNCTION CREATE_DB(STRING DBName$)
'---------------
' open sql database
mydb = DB_OPEN(DBName$)
' create table one of the two lines below will work.
' SQLITE_CREATE_TABLE(mydb, "CREATE TABLE Works(ID INTEGER PRIMARY KEY , Title TEXT, Date TEXT, Place TEXT);")
DB_SQL(mydb, "CREATE TABLE Works(ID INTEGER PRIMARY KEY , Title TEXT, Date TEXT, Place TEXT);")
DB_SQL(mydb, "COMMIT;")
RETURN mydb
END FUNCTION
'---------------
SUB CREATE_RECORDS()
'---------------
' write data to sql database
FOR i = 0 TO 9
DB_SQL(mydb, MYSTR$[i])
NEXT i
DB_SQL(mydb, "COMMIT;")
'@ can delete records like so
' DB_SQL(mydb, "DELETE from Works WHERE ID = 3")
' DB_SQL(mydb, "COMMIT;")
END SUB
SUB DELETE ()
DB_SQL(mydb, "COMMIT;")
END SUB
'---------------
FUNCTION SQLITE_GET_RECORD_COUNT()
LOCAL count
DB_SQL(mydb, "SELECT COUNT(*) FROM Works;")
DB_RESULT$ = CHOP$(DB_RESULT$)
SPLIT DB_RESULT$ BY ")" TO bit$ SIZE bits
IF bits > 0 THEN
count = VAL(CHOP$(bit$[1]))
RETURN count
END IF
RETURN 0
END FUNCTION
SUB READ_RECORDS()
'---------------
LOCAL i, j TYPE NUMBER
LOCAL FieldName$ TYPE STRING
res = DB_SQL(mydb, "SELECT * FROM Works;")
IF res IS 0 THEN
SPLIT CHOP$(DB_RESULT$) BY NL$ TO MYDATA$ SIZE RECORDS
FOR i = 1 TO RECORDS - 1
SPLIT MYDATA$[i] BY TAB$(1) TO colm$ SIZE dataCOLUMNS
PRINT "COLS :",dataCOLUMNS
MYDAT$=""
FOR n = 0 TO dataCOLUMNS -2
PRINT colm$[n]
MYDAT$=CONCAT$(MYDAT$,colm$[n],",")
NEXT n
MYDAT$=CONCAT$(MYDAT$,colm$[n])
TEXT_EDITABLE_GRIDVIEW(grid1,MYDAT$)
NEXT i
ELSE
PRINT DB_ERROR$
ENDIF
END SUB
'---------------
SUB CLOSE_DB
'---------------
res = DB_CLOSE(mydb)
END SUB
SUB PREPARE_DATA()
'---------------
' fill aray with data
LOCAL STR1$
STR1$ = "INSERT INTO Works(ID, Title, Date, Place) VALUES "
MYSTR$[0] = CONCAT$(STR1$,"(0, '8 Variations in G on Laat ons Juichen', 'January 1766', 'The Hague');")
MYSTR$[1] = CONCAT$(STR1$,"(1, 'Variations in D on Willem van Nassau', 'February 1766', 'Amsterdam');")
MYSTR$[2] = CONCAT$(STR1$,"(3, 'Sonata in E-flat for Violin and Keyboard', 'February 1766', 'The Hague');")
MYSTR$[3] = CONCAT$(STR1$,"(4, 'Sonata in G for Violin and Keyboard', 'February 1766', 'The Hague');")
MYSTR$[4] = CONCAT$(STR1$,"(5, 'Sonata in C for Violin and Keyboard', 'February 1766', 'The Hague');")
MYSTR$[5] = CONCAT$(STR1$,"(6, 'Sonata in D for Violin and Keyboard', 'February 1766', 'The Hague');")
MYSTR$[6] = CONCAT$(STR1$,"(7, 'Sonata in F for Violin and Keyboard', 'February 1766', 'The Hague');")
MYSTR$[7] = CONCAT$(STR1$,"(8, 'Sonata in B-flat for Violin and Keyboard', 'February 1766', 'The Hague');")
MYSTR$[8] = CONCAT$(STR1$,"(9, 'Gallimathias Musicum (Quodlibet)', 'March 1766', 'The Hague');")
MYSTR$[9] = CONCAT$(STR1$,"(10, 'Kyrie in F', 'June 1766', 'Paris');")
END SUB
PREPARE_DATA
MY_DB$="/tmp/vovchik-demo.sdb"
IF NOT(FILEEXISTS(MY_DB$)) THEN
mydb=CREATE_DB(MY_DB$)
ELSE
mydb = DB_OPEN(MY_DB$)
a=SQLITE_GET_RECORD_COUNT()
IF a = 0 THEN
CREATE_RECORDS
END IF
END IF
win=WINDOW("Four column multi list ",300,300)
grid1=EDITABLE_GRIDVIEW("ID,Name of Composition: ,Composed during (date),Composed at (location)",1,1,3)
ATTACH(win,grid1,0,0)
READ_RECORDS
'@ DISPLAY FOREVER
DISPLAY
BR and Enjoy
Alex