Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,60 @@
import
gtk2, glib2, strutils, random
var valu: int = 0
proc thisDestroy(widget: PWidget, data: Pgpointer) {.cdecl.} =
main_quit()
randomize()
nim_init()
var win = window_new(gtk2.WINDOW_TOPLEVEL)
var content = vbox_new(true,10)
var hbox1 = hbox_new(true,10)
var hbox2 = hbox_new(false,1)
var lbl = label_new("Value:")
var entry_fld = entry_new()
entry_fld.set_text("0")
var btn_quit = button_new("Quit")
var btn_inc = button_new("Increment")
var btn_rnd = button_new("Random")
add(hbox2,lbl)
add(hbox2,entry_fld)
add(hbox1,btn_inc)
add(hbox1,btn_rnd)
pack_start(content, hbox2, true, true, 0)
pack_start(content, hbox1, true, true, 0)
pack_start(content, btn_quit, true, true, 0)
set_border_width(win, 5)
add(win, content)
proc on_question_clicked: bool =
var dialog = win.message_dialog_new(0, MESSAGE_QUESTION,
BUTTONS_YES_NO, "Use a Random number?")
var response = dialog.run()
result = response == RESPONSE_YES
dialog.destroy()
proc thisInc(widget: PWidget, data: Pgpointer){.cdecl.} =
inc(valu)
entry_fld.set_text($valu)
proc thisRnd(widget: PWidget, data: Pgpointer){.cdecl.} =
if on_question_clicked():
valu = rand(20)
entry_fld.set_text($valu)
proc thisTextChanged(widget: PWidget, data: Pgpointer) {.cdecl.} =
try:
valu = parseInt($entry_fld.get_text())
except ValueError:
entry_fld.set_text($valu)
discard signal_connect(win, "destroy", SIGNAL_FUNC(thisDestroy), nil)
discard signal_connect(btn_quit, "clicked", SIGNAL_FUNC(thisDestroy), nil)
discard signal_connect(btn_inc, "clicked", SIGNAL_FUNC(thisInc), nil)
discard signal_connect(btn_rnd, "clicked", SIGNAL_FUNC(thisRnd), nil)
discard signal_connect(entry_fld, "changed", SIGNAL_FUNC(thisTextChanged), nil)
win.show_all()
main()

View file

@ -0,0 +1,95 @@
import random, strutils
import gintro/[glib, gobject, gtk, gio]
type Context = ref object
value: int
entry: Entry
#---------------------------------------------------------------------------------------------------
proc onQuestionClicked(): bool =
# As "gintro" doesn't provide "MessageDialog" yet, we will use a simple dialog.
let dialog = newDialog()
dialog.setModal(true)
let label = newLabel("Use a Random number?")
dialog.contentArea.add(label)
discard dialog.addButton("No", ord(ResponseType.no))
discard dialog.addButton("Yes", ord(ResponseType.yes))
dialog.showAll()
result = dialog.run() == ord(ResponseType.yes)
dialog.destroy()
#---------------------------------------------------------------------------------------------------
proc onQuit(button: Button; window: ApplicationWindow) =
window.destroy()
#---------------------------------------------------------------------------------------------------
proc onIncr(button: Button; ctx: Context) =
inc ctx.value
ctx.entry.setText($ctx.value)
#---------------------------------------------------------------------------------------------------
proc onRand(button: Button; ctx: Context) =
if onQuestionClicked():
ctx.value = rand(20)
ctx.entry.setText($ctx.value)
#---------------------------------------------------------------------------------------------------
proc onEntryChange(entry: Entry; ctx: Context) =
try:
ctx.value = entry.text().parseInt()
except ValueError:
entry.setText($ctx.value)
#---------------------------------------------------------------------------------------------------
proc activate(app: Application) =
## Activate the application.
let window = app.newApplicationWindow()
window.setTitle("Component interaction")
let content = newBox(Orientation.vertical, 10)
content.setHomogeneous(true)
let hbox1 = newBox(Orientation.horizontal, 10)
hbox1.setHomogeneous(true)
let hbox2 = newBox(Orientation.horizontal, 1)
hbox2.setHomogeneous(false)
let label = newLabel("Value:")
let entry = newEntry()
entry.setText("0")
let btnQuit = newButton("Quit")
let btnIncr = newButton("Increment")
let btnRand = newButton("Random")
hbox2.add(label)
hbox2.add(entry)
hbox1.add(btnIncr)
hbox1.add(btnRand)
content.packStart(hbox2, true, true, 0)
content.packStart(hbox1, true, true, 0)
content.packStart(btnQuit, true, true, 0)
window.setBorderWidth(5)
window.add(content)
let context = Context(value: 0, entry: entry)
discard btnQuit.connect("clicked", onQuit, window)
discard btnIncr.connect("clicked", onIncr, context)
discard btnRand.connect("clicked", onRand, context)
discard entry.connect("changed", onEntryChange, context)
window.showAll()
#———————————————————————————————————————————————————————————————————————————————————————————————————
let app = newApplication(Application, "Rosetta.ComponentInteraction")
discard app.connect("activate", activate)
discard app.run()

View file

@ -0,0 +1,63 @@
import
iup, strutils, math
# assumes you have the iup .dll or .so installed
randomize()
discard iup.open(nil,nil)
var lbl = Label("Value:")
setAttribute(lbl,"PADDING","2x2")
var valu = Text(nil)
SetAttribute(valu, "PADDING", "2x2")
SetAttribute(valu, "VALUE", "0")
proc toCB(fp: proc): ICallback =
return cast[ICallback](fp)
# Click handler for Click button
proc incClick(ih:PIhandle): cint {.cdecl.} =
var s: string = $(GetAttribute(valu,"VALUE"))
var x: int = 0
try:
x = 1 + parseInt(s)
except:
x = 1 # default to 1 if non-numeric entry
setAttribute(valu,"VALUE", $x)
return IUP_DEFAULT
# Click handler for Random button
proc randClick(ih:PIhandle): cint {.cdecl.} =
if Iup.Alarm("Random Value?", "Set value to a random numer < 100 ?","Yes","No",nil) == 1:
setAttribute(valu,"VALUE", $random(100))
return IUP_DEFAULT
# Key handler to check for Esc pressed
proc key_cb(ih:PIhandle, c: cint):cint {.cdecl.} =
#echo c
if (c == Iup.K_esc) and (Iup.Alarm("Exit?", "Had enough?","Yes","Keep going",nil) == 1):
return IUP_CLOSE # Exit application
return IUP_CONTINUE
var txtBox = Hbox(lbl, valu, nil)
SetAttribute(txtBox, "MARGIN", "10x10")
var incBtn = Button("&Increment", "")
var randBtn = Button("&Randomize", "")
var btnBox = Vbox(incBtn, randBtn, nil)
SetAttribute(btnBox, "MARGIN", "5x5")
var contents = Hbox(txtBox, btnBox, nil)
SetAttribute(contents, "MARGIN", "2x2")
discard setCallback(incBtn,"ACTION", toCB(incClick))
discard setCallback(randBtn,"ACTION", toCB(randClick))
discard setCallback(contents,"K_ANY", toCB(key_cb))
var dlg = Dialog(contents)
discard dlg.show()
discard mainloop()
iup.close()