dariolah / nim-iup-examples Goto Github PK
View Code? Open in Web Editor NEWNim GUI examples using IUP
Nim GUI examples using IUP
Versions:
niup #head
Nim 1.6.0
IUP 3.30
I want to try how a GetParam works. I took an example of GetParam usage from nim-iup-examples
from example4_*.nim
.
A minimal example
# simple_params.nim
import niup/niupc
import niup/niupext
proc show_params(ih: PIhandle): int =
var
width: int = 10
height: int = 20
if GetParam("Page Setup", nil, nil, "Width: %i\nHeight: %i\n", width, height, nil) != 0:
discard
return IUP_DEFAULT
proc mainProc =
niupext.Open()
when defined(Linux):
SetGlobal("UTF8MODE", "YES")
var button = Button("Params", nil)
SetCallback(button, "ACTION", show_params)
var dlg = Dialog(button)
SetAttribute(dlg, "TITLE", "simple_params")
SetAttribute(dlg, "SIZE", "HALFxHALF")
ShowXY(dlg, IUP_CENTER, IUP_CENTER)
MainLoop()
Close()
if isMainModule:
mainProc()
Run
nim c -r simple_params.nim
Next I click on the button and get a traceback
Traceback (most recent call last)
.../simple_params.nim(33) simple_params
.../simple_params.nim(29) mainProc
.../simple_params.nim(9) show_params
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Segmentation fault (core dumped)
Error: execution of an external program failed: '.../simple_params '
What could be the problem?
I am able to compile the modules dependent on 'iupcontrols.dll', however, during execution, I get the message that the DLL could not be loaded. Any advice? Thank you.
Trying to figure out what to use for an output, do I use a dialog box or show or something else?
I would like to create a box with a button that shows your own IP address. Also opacity works great I was able to use opacity on a full window.
I am getting illegal storage access when trying to compile and run the plot.nim program.
nim c -r plot.nim
Hint: used config file '/home/nixfreak/.choosenim/toolchains/nim-1.6.2/config/nim.cfg' [Conf]
Hint: used config file '/home/nixfreak/.choosenim/toolchains/nim-1.6.2/config/config.nims' [Conf]
Hint: gc: refc; opt: none (DEBUG BUILD, -d:release
generates faster code)
9878 lines; 0.035s; 8.652MiB peakmem; proj: /home/nixfreak/nim/gui/niup/nixfreak_fork/niupc/plot.nim; out: /home/nixfreak/nim/gui/niup/nixfreak_fork/niupc/plot [SuccessX]
Hint: /home/nixfreak/nim/gui/niup/nixfreak_fork/niupc/plot [Exec]
Traceback (most recent call last)
/home/nixfreak/nim/gui/niup/nixfreak_fork/niupc/plot.nim(597) plot
/home/nixfreak/nim/gui/niup/nixfreak_fork/niupc/plot.nim(591) mainProc
/home/nixfreak/nim/gui/niup/nixfreak_fork/niupc/plot.nim(584) PlotTest
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Error: execution of an external program failed: '/home/nixfreak/nim/gui/niup/nixfreak_fork/niupc/plot '
I'm sure this is pretty messed up but , I am not understanding the callbacks I guess.
Also setting the attributes is probably wrong. It compiles just fine but no callbacks work.
import std/[httpclient, strutils, strformat]
import niup
#import TempFormula
var
label_c: Label_t
label_f: Label_t
textLabel_c: Text_t
textLabel_f: Text_t
proc txt_celcius_cb(ih: PIhandle):cint {.cdecl.} =
var fahrenheit = GetDialogChild("Fahrenheit")
var value = float(value * (1.8) + 32)
return IUP_DEFAULT
proc txt_fahrenheit_cb(ih: PIhandle):cint {.cdecl.} =
var celcius = GetDialogChild("Celcius")
return IUP_DEFAULT
#proc button_show_ip(ih: PIhandle): cint {.cdecl.} = # every callback has cint as return value
#textLabel.value = Ip()
#return IUP_DEFAULT
# create main proc and open UIP application
proc mainProc =
Open()
# create 2 labels and 2 textLabels
textLabel_f.value =
label_c = Label("Celcius " & " = ")
SetAttribute(textLabel_c, "VALUE", "")
SetAttribute(textLabel_c, "NAME", "Celcius")
textLabel_c = Text("")
textLabel_c.alignment = IUP_ACENTER
label_f = Label("Fahrenheit")
SetAttribute(textLabel_f, "VALUE", "")
SetAttribute(textLabel_f, "NAME", "Fahrenheit")
textLabel_f = Text("")
textLabel_f.alignment = IUP_ACENTER
var
hbox = Hbox(textLabel_c, label_c, "=" ,textLabel_f, label_f)
hbox.alignment = IUP_ACENTER
hbox.gap(20)
hbox.margin(20, 20)
# add dialog box to show title of UIP application
var dlg_h = Dialog(hbox)
dlg_h.title = "Convert Temperature"
dlg_h.bgcolor = "#7f11e0"
# call backs
SetCallback(textLabel_c, "VALUECHANGED_CB", (ICallback(txt_celcius_cb)))
SetCallback(textLabel_f, "VALUECHANGED_CB", (ICallback(txt_fahrenheit_cb)))
# show UIP application
#ShowXY(dlg, IUP_CENTER, IUP_CENTER)
ShowXY(dlg_h , IUP_CENTER, IUP_CENTER)
MainLoop()
Close()
if isMainModule: # if main module than call mainProc()
mainProc()
Traceback (most recent call last)
/home/nixfreak/nim/gui/niup/nixfreak_fork/niupc/example4_2.nim(733) example4_2
/home/nixfreak/nim/gui/niup/nixfreak_fork/niupc/example4_2.nim(718) mainProc
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Error: execution of an external program failed: '/home/nixfreak/nim/gui/niup/nixfreak_fork/niupc/example4_2 '
After changing everything over to use the niupc library and niupext.
I'm probably wrong about this I get errors compiling the majority of the niupc examples.
Example "tree.nim" https://github.com/dariolah/nim-iup-examples/blob/master/niupc/tree.nim the code states.
import niup
import niupext
Shouldn't it be
import niup/niupc
import niup/niupext
Same with the webbrowser.nim example
import niup
import niupext
Shouldn't it be
import niup/niupc
import niup/niupext
If this is correct I could do pull request to help out , I really like this project. Thanks again.
I tried to compile & run example2_1.nim using the following command:
nim compile --run example2_1.nim
But it fails with error: could not load: libiup.dylib
I just installed nim with brew install nim
and niup nimble install niup
, so the packages should all be up to date. Any ideas why this is happening? Let me know if you need any additional info.
Could you please sync all examples with the latest release version of niup?
hello, I tried to compile the first example in Emacs but it failed with the following message:
nim c -r --app:gui example2_1.nim
nim c -r --app:gui example2_1.nim
Hint: used config file 'C:\nim-0.19.2\config\nim.cfg' [Conf]
Hint: system [Processing]
Hint: widestrs [Processing]
Hint: io [Processing]
Hint: example2_1 [Processing]
Hint: niup [Processing]
CC: stdlib_system.nim
CC: ../../../../../../C:/Users/Neil/.nimble/pkgs/niup-3.27.2/niup.nim
CC: example2_1.nim
Error: execution of an external compiler program 'C:\MinGW\mingw64\bin\gcc.exe -c -w -mno-ms-bitfields -IC:\nim-0.19.2\lib -I"c:\Users\Neil\Documents\Nim Files\nim-iup-examples-master" -o C:\Users\Neil\nimcache\example2_1_d_7_7_7_7_7_7C87Users7Neil7.nimble7pkgs7niup-3.277.27niup.nim.c.o C:\Users\Neil\nimcache\example2_1_d_7_7_7_7_7_7C87Users7Neil7.nimble7pkgs7niup-3.277.27niup.nim.c' failed with exit code: 1
C:\Users\Neil\nimcache\example2_1_d_7_7_7_7_7_7C87Users7Neil7.nimble7pkgs7niup-3.277.27niup.nim.c:38:10: fatal error: dlfcn.h: No such file or directory
#include <dlfcn.h>
^~~~~~~~~
compilation terminated.
Trying to re-create tempConvert.c using niup library
I get errors trying to SetAtrribute
`ot <Text_t, string, string>
but expected one of:
proc SetAttribute(ih: PIhandle; name: cstring; value: cstring)
first type mismatch at position: 1
required type for ih: PIhandle
but expression 'textLabel_c' is of type: Text_t
expression: SetAttribute(textLabel_c, "value", "")
In the example do you have to SetStrf to convert to a string? or do I need to parseString? `
import std/[httpclient, strutils, strformat]
import niup
#import TempFormula
var
label_c: Label_t
label_f: Label_t
textLabel_c: Text_t
textLabel_f: Text_t
celsius: float
fahrenheit: float
proc txt_celcius_cb(ih: PIhandle):cint {.cdecl.} =
var fahrenheit = GetDialogChild(ih, "Fahrenheit")
var value = (celsius * 1.8) + 32
return IUP_DEFAULT
proc txt_fahrenheit_cb(ih: PIhandle):cint {.cdecl.} =
var celcius = GetDialogChild(ih, "Celcius")
var value = (fahrenheit - 32) / 1.8
return IUP_DEFAULT
#proc button_show_ip(ih: PIhandle): cint {.cdecl.} = # every callback has cint as return value
#textLabel.value = Ip()
#return IUP_DEFAULT
# create main proc and open UIP application
proc mainProc =
Open()
# create 2 labels and 2 textLabels
#textLabel_f.value =
label_c = Label("Celcius " & " = ")
textLabel_c = Text("")
SetAttribute(textLabel_c, "value", "")
SetAttribute(textLabel_c, "NAME", "Celcius")
textLabel_c.alignment = IUP_ACENTER
label_f = Label("Fahrenheit")
SetAttribute(textLabel_f, "value", "")
SetAttribute(textLabel_f, "NAME", "Fahrenheit")
textLabel_f = Text("")
textLabel_f.alignment = IUP_ACENTER
var
hbox = Hbox(textLabel_c, label_c, textLabel_f, label_f)
hbox.alignment = IUP_ACENTER
hbox.gap(20)
hbox.margin(20, 20)
# add dialog box to show title of UIP application
var dlg_h = Dialog(hbox)
dlg_h.title = "Convert Temperature"
dlg_h.bgcolor = "#7f11e0"
# call backs
SetCallback(textLabel_c, "VALUECHANGED_CB", (Icallback(txt_celcius_cb)))
SetCallback(textLabel_f, "VALUECHANGED_CB", (Icallback(txt_fahrenheit_cb)))
# show UIP application
#ShowXY(dlg, IUP_CENTER, IUP_CENTER)
ShowXY(dlg_h , IUP_CENTER, IUP_CENTER)
MainLoop()
Close()
if isMainModule: # if main module than call mainProc()
mainProc()
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.