Hello everybody,
i want to create an app with gui. Therefore i use th uing-Library. In my gui there is a button which opens the openfile dialog and a Table with 1 column. As "template" i used the "tables.nim" file from the examples folder in the uing.
My application starts and because i haven't data in my string sequence, the table is initialised with a colmn-header and one "dummy" data. If i click on the button, the open file dialog pops up, i choose a file and read the words in my data-sequence. so far - so good.
How can i then get the values of the data-sequence into the table? I've read the docs - and it's confusing... I've read, that i had to "insertRows" but before i have to add the data to the model and i don't know how i can do this :(
Can anybody help me please?
Bests Beckx
i am sorry to steal your time with ask without code! Here's my code - i wanna change the content of my sequence data - but it does not show in my table...
from uing/rawui import nil
import uing
var list: seq[string] = @["dummy"]
proc modelNumColumns(mh: ptr TableModelHandler, m: ptr rawui.TableModel): cint {.cdecl.} = 0
proc modelNumRows(mh: ptr TableModelHandler, m: ptr rawui.TableModel): cint {.cdecl.} =
result = cint(list.len())
proc modelColumnType(mh: ptr TableModelHandler, m: ptr rawui.TableModel, col: cint): TableValueType {.cdecl.} =
result = TableValueTypeString
proc modelCellValue(mh: ptr TableModelHandler, m: ptr rawui.TableModel, row, col: cint): ptr rawui.TableValue {.cdecl.} =
result = newTableValue(list[row]).impl
proc modelSetCellValue(mh: ptr TableModelHandler, m: ptr rawui.TableModel, row, col: cint, val: ptr rawui.TableValue) {.cdecl.} =
rawui.tableModelRowChanged(m, row)
proc main() =
var mainwin: Window
let menu = newMenu("File")
menu.addQuitItem(
proc(): bool =
mainwin.destroy()
return true
)
mainwin = newWindow("Table", 640, 480, true)
mainwin.margined = true
let box = newVerticalBox(true)
mainwin.child = box
var mh: TableModelHandler
mh.numColumns = modelNumColumns
mh.columnType = modelColumnType
mh.numRows = modelNumRows
mh.cellValue = modelCellValue
mh.setCellValue = modelSetCellValue
var p: TableParams
p.model = newTableModel(addr mh).impl
p.rowBackgroundColorModelColumn = -1
let table = newTable(addr p)
table.addTextColumn("My Header", 0, TableModelColumnNeverEditable)
let btn = newButton("click me...", proc(sender: Button)=
list = @[]
list.add(@["one", "two", "three", "four"])
echo list.len()
# now update the tabel... but how ;(
mh.numColumns = modelNumColumns
mh.columnType = modelColumnType
mh.numRows = modelNumRows
mh.cellValue = modelCellValue
mh.setCellValue = modelSetCellValue
)
box.add btn, false
box.add table, true
show mainwin
mainLoop()
init()
main()
Thx
Thank you very much for reply on my question! You're the maintainer of the module "uing", isn't it? Thanx for your work!
Back to topic: i've looked at your new example with csv file. And i read yout first answer feeled a hundred times... but i'am ashamed - i don't get it to work :(
you mentioned, to alter the "list" sequence, to take effect on the table... I think i've done it in the proc of the button.
I' done some corrections but it does not alter the table: i see the values "dummy 1" and "dummy 2" as the init values of my "list", but when i click the button, the new values were added to the "list" value, but the new values do not append to the tabel :( what i'm doing wrong? Am i such stupid ;(
from uing/rawui import nil
import uing
var list: seq[string] = @["dummy1", "dummy2"]
proc modelNumColumns(mh: ptr TableModelHandler, m: ptr rawui.TableModel): cint {.cdecl.} = 0
proc modelNumRows(mh: ptr TableModelHandler, m: ptr rawui.TableModel): cint {.cdecl.} =
result = cint(list.len())
proc modelColumnType(mh: ptr TableModelHandler, m: ptr rawui.TableModel, col: cint): TableValueType {.cdecl.} =
result = TableValueTypeString
proc modelCellValue(mh: ptr TableModelHandler, m: ptr rawui.TableModel, row, col: cint): ptr rawui.TableValue {.cdecl.} =
return newTableValue(list[row]).impl
proc modelSetCellValue(mh: ptr TableModelHandler, m: ptr rawui.TableModel, row, col: cint, val: ptr rawui.TableValue) {.cdecl.} =
rawui.tableModelRowChanged(m, row)
proc main() =
var mainwin: Window
let menu = newMenu("File")
menu.addQuitItem(
proc(): bool =
mainwin.destroy()
return true
)
mainwin = newWindow("Table", 640, 480, true)
mainwin.margined = true
let box = newVerticalBox(true)
mainwin.child = box
var mh: TableModelHandler
mh.numColumns = modelNumColumns
mh.columnType = modelColumnType
mh.numRows = modelNumRows
mh.cellValue = modelCellValue
mh.setCellValue = modelSetCellValue
var p: TableParams
p.model = newTableModel(addr mh).impl
p.rowBackgroundColorModelColumn = -1
let table = newTable(addr p)
table.addTextColumn("My Header", 0, TableModelColumnNeverEditable)
let btn = newButton("click me...", proc(sender: Button)=
list.add(@["one", "two", "three", "four"])
echo list.len()
)
box.add btn, false
box.add table, true
show mainwin
mainLoop()
init()
main()
Perhaps you have time and want push me to the right way?
hurra - i've found a solution - don't no if it is correct - but it works:
let btn = newButton("click me...", proc(sender: Button)=
let ls = @["one", "two", "three", "four"]
for i, v in ls:
list.add(v)
model.rowInserted(i)
)
for each new row i've done a model.rowInserted(i) in a for-loop :) and now the new values are in the table :)