added gsettings example
This commit is contained in:
parent
fd6cda7fe8
commit
e6fccd33a8
3 changed files with 181 additions and 1 deletions
32
examples/gtk3/gsettings.nim
Normal file
32
examples/gtk3/gsettings.nim
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
# gsettings.nim -- basic use of gsettings
|
||||
# nim c gsettings.nim
|
||||
# https://blog.gtk.org/2017/05/01/first-steps-with-gsettings/
|
||||
import gintro/[gtk, glib, gobject, gio]
|
||||
|
||||
# unused
|
||||
proc toggle(b: CheckButton) =
|
||||
echo b.active
|
||||
let s = newSettings("org.gnome.Recipes")
|
||||
discard s.setBoolean("like-nim", b.active)
|
||||
|
||||
proc appActivate(app: Application) =
|
||||
let window = newApplicationWindow(app)
|
||||
window.title = "GTK3, Nim and GSettings"
|
||||
window.defaultSize = (200, 200)
|
||||
let b = newCheckButton()
|
||||
b.halign = Align.center
|
||||
b.label = "I like Nim"
|
||||
#b.connect("toggled", toggle) # we don't need this for plain binding!
|
||||
let s = newSettings("org.gnome.Recipes")
|
||||
if s.getBoolean("like-nim"):
|
||||
echo "I like Nim language"
|
||||
`bind`(s, "like-nim", b, "active", {SettingsBindFlag.get, SettingsBindFlag.set})
|
||||
window.add(b)
|
||||
showAll(window)
|
||||
|
||||
proc main =
|
||||
let app = newApplication("org.gtk.example")
|
||||
connect(app, "activate", appActivate)
|
||||
discard run(app)
|
||||
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue