added gearsmenu.nim example

This commit is contained in:
Stefan Salewski 2019-09-01 12:54:32 +02:00
commit c79299485c
3 changed files with 258 additions and 7 deletions

View file

@ -7,17 +7,17 @@ import gintro/[gtk, glib, gobject, gio]
from strutils import `%`, format
# https://github.com/GNOME/glib/blob/master/gio/tests/gapplication-example-actions.c
proc activateToggleAction(action: SimpleAction; parameter: Variant; app: Application) =
proc activateToggleAction(action: SimpleAction; parameter: Variant; app: Application) =
app.hold # hold/release taken over from C example, there may be reasons...
block:
echo format("action $1 activated", action.name)
let state: Variant = action.state
let b = state.getBoolean
action.state = newVariantBoolean(not b)
action.state = newVariantBoolean(not b)
echo format("state change $1 -> $2", b, not b)
app.release
proc activateStatefulAction(action: SimpleAction; parameter: Variant; app: Application) =
proc activateStatefulAction(action: SimpleAction; parameter: Variant; app: Application) =
app.hold
block:
echo format("action $1 activated", action.name)
@ -25,7 +25,7 @@ proc activateStatefulAction(action: SimpleAction; parameter: Variant; app: Appli
var l: uint64
let oldState = state.getString(l) # yes uint64 parameter is a bit ugly
let newState = parameter.getString(l)
action.state = newVariantString(newState)
action.state = newVariantString(newState)
echo format("state change $1 -> $2", oldState, newState)
app.release
@ -33,6 +33,7 @@ proc quitProgram(action: SimpleAction; parameter: Variant; app: Application) =
quit(app)
proc appStartup(app: Application) =
echo "appStartup"
let quit = newSimpleAction("quit") # here we create the actions for whole app
connect(quit, "activate", quitProgram, app)
app.addAction(quit)
@ -63,10 +64,11 @@ proc appStartup(app: Application) =
let section = gio.newMenu()
submenu.appendSection(nil, section)
section.append("Check", "win.toggleSpellCheck")
# finally add the menubar
# finally add the menubar
setMenuBar(app, menu)
proc appActivate(app: Application) =
echo "appActivate"
let window = newApplicationWindow(app)
window.title = "GTK3 App with Menubar"
window.defaultSize = (500, 200)
@ -87,7 +89,7 @@ proc appActivate(app: Application) =
#window.add(button) # do not add it here already: (menubar:10010): Gtk-WARNING **: 22:00:33.230: actionhelper:
# action win.justify can't be activated due to parameter type mismatch (parameter type s, target type NULL)
button.setDetailedActionName("win.justify::center")
#button.setActionName("app.quit") # for a stateless action
#button.setActionName("app.quit") # for a stateless action
setAccelsForAction(app, "win.justify::right", "<Control><Shift>R")
window.add(button)
showAll(window)