Add tasks for all the new languages
This commit is contained in:
parent
9dc3c2bb62
commit
bba7bfd280
13208 changed files with 134745 additions and 0 deletions
|
|
@ -0,0 +1,71 @@
|
|||
import
|
||||
gtk2, gdk2, glib2, strutils, math
|
||||
|
||||
import
|
||||
gtk2, gdk2, glib2, strutils, math
|
||||
|
||||
var valu: int = 0
|
||||
var chngd_txt_hndler: gulong = 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()
|
||||
if response == RESPONSE_YES:
|
||||
result = true
|
||||
elif response == RESPONSE_NO:
|
||||
result = false
|
||||
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 = random(20)
|
||||
entry_fld.set_text($valu)
|
||||
|
||||
proc thisTextChanged(widget: PWidget, data: Pgpointer) {.cdecl.} =
|
||||
#signal_handler_block(entry_fld, chngd_txt_hndler)
|
||||
try:
|
||||
valu = parseInt($entry_fld.get_text())
|
||||
except EInvalidValue:
|
||||
valu = 0
|
||||
entry_fld.set_text($valu)
|
||||
#signal_handler_unblock(entry_fld, chngd_txt_hndler)
|
||||
#signal_emit_stop(entry_fld, signal_lookup("changed",TYPE_EDITABLE()),0)
|
||||
|
||||
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)
|
||||
chngd_txt_hndler = signal_connect(entry_fld, "changed", SIGNAL_FUNC(thisTextChanged), nil)
|
||||
|
||||
win.show_all()
|
||||
main()
|
||||
|
|
@ -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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue