Have just send out v0.6 with the requested gstreamer support, so I need a break of a few days at least.
Unfortunately I do know not much about all the treeview stuff, and treeview is the most difficult in GTK. I read about it ten years ago in the book of A.Krause, but can not remember details. We have some examples about listview in gintro, but that is mostly only converted and cleaned C code.
Do you have a small but complete C code example which I can use for your problem?
@Stefan_Salewski
no problem at the moment I did differently, for the validity checks, and I advance on the implementation to make for example billing ...... to give the sense of the application the goal is to make a kind of excel finally;) just to make an evaluation of an article price for example
I'm going to update my studies finally to help because I have time to resell I'm retired so the computer is only for fun and I have lots of ideas;)
like that there will be a model where we will find the majority of the problem in the management ... .. in interactive
Know that I used a lot of what you did with a lot of different order from your examples ;) just to search, and test; THEREFORE lots of great news
when to order for the function, I have several worries the first I will solve it is how this serve a function
the second is the parameters that I can touch to see in GINTRO to get to answer (return to the basic model for the parameters) if it works I would say it on the same post
I have an idea already about the source of the problem.
It is basically an callback issue as we had for g_signal_collect() -- we solved that with Nim macros which generates trampoline functions. I came to this idea by
grep -A3 "TreeCellDataFunc\*" ~/.nimble/pkgs/gintro-0.6.0/gintro/*
TreeCellDataFunc* = proc (treeColumn: ptr TreeViewColumn00; cell: ptr CellRenderer00;
treeModel: ptr TreeModel00;iter: TreeIter; data: pointer) {.cdecl.}
That is the low level interface which GTK needs for calls, but we want to work with the high level Nim objects of course.
I will have to find a small working C example which uses TreeCellDataFunc and then think about how we can make it work in Nim. Should be some work :-)
OK, I found a CellDataFunc example code from A. Krause. I will add that needed macro to the package eventually. But as I have just shipped v0.6.0 I hesitate to ship a new version just for this macro -- CellDataFunc is not used often, and maybe you can not use it at all as you have still old gtk 3.22 which seems not to work that fine with latest gintro.
You have asked at Stackoverflow also, so please copy this example to that page, or at least paste there a link to this forum thread.
# C example code was provided by A.Krause in chapter 8 of his book
# This example shows why applying a CellDataFunc to a GtkTreeView
# does not work out of the box with Gintro <= 0.6.0
# GTK calls the provided CellDataFunc, so that function must have the
# well defined C interface.
# Generally we would provide that interface by a Nim Macro, but that
# is not yet available. So we fake it manually for now. Basically we just
# use g_object_get_qdata() to get the Nim proxy objects from the plain
# C objects that GTK uses internally. This is similar as connect() Macro
# in file gimpl.nim does it.
import gintro/[gtk, gobject, glib]
const
Color = 0
Columns = 1
clr = ["00", "33", "66", "99", "CC", "FF"]
proc bye(w: Window) =
mainQuit()
echo "Bye..."
proc toStringVal(s: string): Value =
let gtype = typeFromName("gchararray")
discard init(result, gtype)
setString(result, s)
proc toBoolVal(b: bool): Value =
let gtype = typeFromName("gboolean")
discard init(result, gtype)
setBoolean(result, b)
# our Nim function
proc cellDataFuncN(column: TreeViewColumn; renderer: CellRenderer;
model: TreeModel; iter: TreeIter; data: pointer) =
## Get the color string stored by the column and make it the foreground color.
var val: Value
model.getValue(iter, Color, val)
let text = val.getString
val.unset
setProperty(renderer, "foreground", toStringVal("#FFFFFF"))
setProperty(renderer, "foreground-set", toBoolVal(true))
setProperty(renderer, "background", toStringVal(text))
setProperty(renderer, "background-set", toBoolVal(true))
setProperty(renderer, "text", toStringVal(text))
# the low level tampoline which GTK can call
proc cellDataFunc(column00: ptr TreeViewColumn00; renderer00: ptr CellRenderer00;
model00: ptr TreeModel00; iter: TreeIter; data: pointer) {.cdecl.} =
let column = cast[TreeViewColumn](g_object_get_qdata(column00, Quark))
let renderer = cast[CellRenderer](g_object_get_qdata(renderer00, Quark))
let model = cast[TreeModel](g_object_get_qdata(model00, Quark))
cellDataFuncN(column, renderer, model, iter, data)
## Add three columns to the GtkTreeView. All three of the columns will be
## displayed as text, although one is a gboolean value and another is
## an integer.
proc setupTreeView(treeview: TreeView) =
let renderer = gtk.newCellRendererText()
let column = newTreeViewColumn()
column.title = "Standard Colors"
column.packStart(renderer, expand = true) # what is the true?
column.addAttribute(renderer, "text", Color)
discard treeview.appendColumn(column)
column.setCellDataFunc(renderer, cellDataFunc, nil, nil)
proc main =
var iter: TreeIter
gtk.init()
let window = newWindow()
window.setTitle("Color List")
window.setBorderWidth(10)
window.setSizeRequest(250, 175)
window.connect("destroy", bye)
let treeview = newTreeView()
setupTreeView(treeview)
let gtype = typeFromName("gchararray")
let store = newListStore(Columns, cast[pointer](unsafeaddr gtype))
## Add all of the products to the GtkListStore.
for i in 0 ..< 6:
for j in 0 ..< 6:
for k in 0 ..< 6:
let color: string = "#" & clr[i] & clr[j] & clr[k]
store.append(iter)
store.setValue(iter, Color, toStringVal(color))
treeView.setModel(store)
let scrolledWin = newScrolledWindow(nil, nil)
scrolledWin.setPolicy(PolicyType.automatic, PolicyType.automatic)
scrolledWin.add(treeview)
window.add(scrolledWin)
window.showAll
gtk.main()
main()
thank you
cellDataFunc(column00: ptr TreeViewColumn00; renderer00: ptr CellRenderer00;
model00: ptr TreeModel00; iter: TreeIter; data: pointer) {.cdecl.}
that's where my mistake comes from
as I told you, I have also Manjaro (since 5 years) which is up to date, in fact the 0.6 version works perfectly, with the basic examples
your example will move me forward ....
As for Xubuntu (to which I feel sentimental), it will be necessary to wait until April 2020 (migration of the stable) to explore 0.6 so I'm going to use another strategy ..... see put it on my laptop and only keep Manjaro and win10 on my server, and rearrange all my disks
thanks again
it will be necessary to wait until April 2020 (migration of the stable) to explore 0.6
Sorry for that, but from
http://ftp.gnome.org/pub/gnome/sources/gtk+/3.24/
my impression is that GTK 3.24 is available for more than one year now. So when you still have only 3.22 your distribution is really slow.
I made the split of cairo into cairo.nim and cairoimpl.nim because the GTK devs told me I should use the g_boxed_free() whenever possible (https://developer.gnome.org/gobject/stable/gobject-Boxed-Types.html). Before I used free() or unref(), which was some guess work, which does not worked for a few data types.
I assume that you will be the only one with trouble with gintro 0.6 due to old gtk 3.22. For the case that you do no cairo drawing in your own programs, there may be a way to enable v0.6: Comment out or remove the line at the bottom of autogenerated file cairo.nim with content "include cairoimpl.nim". I would assume that plain GTK apps should compile then.
If at least 10 people should have issues with old gtk3.22 then I will try to fix that issue -- but it would be some work, basically a lot of additional when statements in cairoimpl.nim, and most importantly, I could not test it, as all my computers have gtk 3.24.
hello, I just tested code(example) with 3.22. it works perfectly
as for version 3.22 is that the "stable" at Ubuntu is very difficult to raise GTK if it is not proposed by Ubuntu (it is a problem that I understand) it protects the heart of their applications ... I can easily climb for the compiler or other but not GTK and the repository does not exist for GTK at Ubuntu and OpenSuze it's even worse apart from the rolling (Tumbleweed).