-
Notifications
You must be signed in to change notification settings - Fork 42
/
gtk-tree-store.js
96 lines (69 loc) · 1.8 KB
/
gtk-tree-store.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* gtk-tree-store.js
*/
const path = require('path')
const gi = require('../')
const Gtk = gi.require('Gtk', '3.0')
const GdkPixbuf = gi.require('GdkPixbuf')
const GObject = gi.require('GObject')
gi.startLoop()
Gtk.init()
const TYPE_FLOAT = GObject.typeFromName('gfloat')
const TYPE_STRING = GObject.typeFromName('gchararray')
const TYPE_PIXBUF = GObject.typeFromName('GdkPixbuf') // Gtk.ImageType.PIXBUF
const store = new Gtk.TreeStore()
store.setColumnTypes([TYPE_STRING, TYPE_PIXBUF])
addRow()
addRow()
addRow()
function addRow() {
const iter = store.append()
{
// Add string
const value = new GObject.Value()
value.init(TYPE_STRING)
value.setString('Image:')
store.setValue(iter, 0, value)
}
{
// Add Pixbuf
const pixbuf = GdkPixbuf.Pixbuf.newFromFile(path.join(__dirname, 'logo.png'))
const value = new GObject.Value()
value.init(TYPE_PIXBUF)
value.setObject(pixbuf)
store.setValue(iter, 1, value)
}
}
// View
const treeView = new Gtk.TreeView({ model: store })
{
const column = new Gtk.TreeViewColumn({ title: 'Caption' })
const caption = new Gtk.CellRendererText()
column.packStart(caption, true)
column.addAttribute(caption, 'text', 0)
treeView.appendColumn(column)
}
{
const column = new Gtk.TreeViewColumn({ title: 'Image' })
const image = new Gtk.CellRendererPixbuf()
column.packStart(image, true)
column.addAttribute(image, 'pixbuf', 1)
treeView.appendColumn(column)
}
// configure main window
const window = new Gtk.Window({ type : Gtk.WindowType.TOPLEVEL })
window.setDefaultSize(500, 300)
window.setResizable(true)
window.add(treeView)
window.on('show', () => {
Gtk.main()
})
window.on('destroy', () => Gtk.mainQuit())
window.on('delete-event', () => false)
/*
* Main
*/
main()
function main() {
window.showAll()
}