Git Product home page Git Product logo

nim-iup-examples's Introduction

Nim GUI examples using IUP

Rewrite of IUP examples in Nim. Code uses package 'niup' which contains generated FFI bindings for latest IUP.

For code explanation and more information visit https://www.tecgraf.puc-rio.br/iup/

Strong typed API using 'niup' module

  • button: Button, Text, Label, Vbox, Dialog, Image
  • text
  • textformat
  • multiline1
  • multiline2: MultiLine, List dropdown
  • list1: List, drag'n'drop
  • timer
  • dialog_ballon: window/dialog with irregular shape based on image dialogballon

C-like API examples using 'niupc' module

  • Hello World

    • example2_1.nim : Initialization
    • example2_2.nim : Creating a Dialog
    • example2_3.nim : Adding Interaction
    • example2_4.nim : Adding Layout Elements
    • example2_5.nim : Improving the Layout
    • example2_5_niupext.nim : Improving the Layout, using module niupext
  • Simple Notepad

    • example3_1.nim : Main Dialog
    • example3_2.nim : Adding a Menu
    • example3_3.nim : Using Pre-defined Dialogs
    • example3_4.nim : Custom Dialogs
    • example3_5.nim : Adding a Toolbar and a Statusbar
    • example3_6.nim : Defining Hot Keys
    • example3_7.nim : Recent Files Menu and a Configuration File
    • example3_8.nim : Clipboard Support
    • example3_9.nim : More File Management
    • example3_10.nim : Dynamic Layout
    • example3_11.nim : External Help
    • simple_notepad.nim : Final Considerations
    • simple_notepad_niupext.nim : Final Considerations, using module niupext simple notepad
    • scintilla_notepad.nim : Version with IupScintilla instead of IupText scintilla notepad
  • SimplePaint

    • example4_1 : Loading and Saving Images
    • example4_2 : Drawing with OpenGL
    • example4_3 : Drawing with CD and Printing
    • example4_4 : Interactive Zoom and Scrollbars
  • samples

    • list1: simple list, multiple list with callback and a drop-down list list1
    • list2: three frames with simple list, multiple list with callback and a drop-down list list2
    • list3 list3
    • matrixlist matrixlist
    • matrix matrix
    • tree tree
    • webbrowser webbrowser
    • plot plot

nim-iup-examples's People

Contributors

dariolah avatar nixfreak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

nim-iup-examples's Issues

Error compiling plot.nim

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 '

Error on niupc examples

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.

GetParam: SIGSEGV: Illegal storage access. (Attempt to read from nil?)

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?

Example TempConvert.c

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()

OSX Run Issue: could not load: libiup.dylib

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.

creating sample hbox output IP result

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.

Error compiling example4_2.nim (Illegal access storage)

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.

Try re-creating temp convert using nuip

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()

How to compile

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.

Could not load: iupcontrols.dll

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.