module Iup

Iup is the main module, in which all controls and widgets are named.

The module also provides constants and supporting methods.

Constants

predefined colours

operations on vertical scrollbar (ScrollBarAttributes#scroll_cb)

operations on horizontal scrollbar (ScrollBarAttributes#scroll_cb)

line style

line join

line cap

mark type

background opacity mode

fill mode

hatch type

interior style

path actions

polygon mode (begin…end)

write mode

text alignment

text styles

Constants

BOTTOM
BUTTON1

Mouse Button Values and Macros

BUTTON2
BUTTON3
BUTTON4
BUTTON5
CD_CLIPAREA
CD_CLIPOFF

clip mode

CD_CLIPPOLYGON
CD_CLIPREGION
CD_COLORS
CD_DEG2RAD
CD_DIFFERENCE
CD_ERROR

status report

CD_FORCE
CD_IALPHA
CD_IBLUE
CD_IGREEN
CD_INDEX
CD_INTERSECT
CD_IRED

bitmap data

CD_MAP
CD_MM2PT

some useful conversion factors

CD_NOTINTERSECT
CD_OK
CD_POLITE

color allocation mode (palette)

CD_QUERY

– from CD library

CD_RAD2DEG
CD_RGB

bitmap type these definitions are compatibility with the IM library

CD_RGBA
CD_UNION

region combine mode

CENTER

IupPopup and IupShowXY Parameter Values

CENTERPARENT
CLOSE
CONTINUE
CURRENT
ColourBar

Colour bar

DEFAULT
ERROR

Common Flags and Return Values

GETPARAM_CANCEL
GETPARAM_HELP
GETPARAM_INIT
GETPARAM_OK

IupGetParam Callback situations

IGNORE

Callback Return Values

INVALID
INVALID_ID
IUP_HIDE
IUP_MAXIMIZE
IUP_MINIMIZE
IUP_PRIMARY

used by ColourBar

IUP_RESTORE
IUP_SECONDARY
IUP_SHOW

SHOW_CB Callback Values

K_0
K_1
K_2
K_3
K_4
K_5
K_6
K_7
K_8
K_9
K_A
K_B
K_BS

also define the escape sequences that have keys associated

K_C
K_CAPS
K_CR
K_Ccedilla
K_D
K_DEL
K_DOWN
K_E
K_END
K_ESC
K_F
K_F1
K_F10
K_F11
K_F12
K_F2
K_F3
K_F4
K_F5
K_F6
K_F7
K_F8
K_F9
K_G
K_H
K_HOME
K_I
K_INS
K_J
K_K
K_L
K_LALT
K_LCTRL
K_LEFT
K_LF
K_LSHIFT

no Shift/Ctrl/Alt */

K_M
K_MIDDLE
K_Menu
K_N
K_NUM
K_O
K_P
K_PAUSE

These use the same definition as X11 and GDK.

This also means that any X11 or GDK definition can also be used.
K_PGDN
K_PGUP
K_Print
K_Q
K_R
K_RALT
K_RCTRL
K_RIGHT
K_RSHIFT
K_S
K_SCROLL
K_SP

from 32 to 126, all character sets are equal, the key code is the same as the ASCii character code.

K_T
K_TAB
K_U
K_UP
K_V
K_W
K_X
K_Y
K_Z
K_a
K_acute
K_ampersand
K_apostrophe
K_asterisk
K_at
K_b
K_backslash
K_bar
K_braceleft
K_braceright
K_bracketleft
K_bracketright
K_c
K_ccedilla

Also, these are the same as the Latin-1 definition */

K_circum
K_colon
K_comma
K_d
K_diaeresis
K_dollar
K_e
K_equal
K_exclam
K_f
K_g
K_grave
K_greater
K_h
K_i
K_j
K_k
K_l
K_less
K_m
K_minus
K_n
K_numbersign
K_o
K_p
K_parentleft
K_parentright
K_percent
K_period
K_plus
K_q
K_question
K_quotedbl
K_r
K_s
K_semicolon
K_slash
K_t
K_tilde
K_u
K_underscore
K_v
K_w
K_x
K_y
K_z
LEFT
MASK_EFLOAT
MASK_FLOAT

Pre-Defined Masks

MASK_INT
MASK_UFLOAT
MASK_UINT
MOUSEPOS
NOERROR
OPENED
TOP

Public Class Methods

LoadImage(filename) click to toggle source

Loads an image from file and returns an appropriate ruby class

# File lib/wrapped/image.rb, line 4
def Iup.LoadImage filename
  handle = ImLib.IupLoadImage filename
  image = ImageWidget.new
  image.instance_eval do
    @handle = handle
  end
  return image
end

Public Instance Methods

alarm(title, msg, button1, button2=nil, button3=nil) click to toggle source

Creates and shows an AlarmDialog, returning the number of the button clicked.

mainloop do
  case alarm 'IupAlarm Example', 'File not saved!  Save it now?', 'Yes', 'No', 'Cancel'
  when 1
    message 'Save file', 'File saved successfully - leaving program'
  when 2
    message 'Save file', 'File not saved - leaving program anyway'
  when 3
    message 'Save file', 'Operation cancelled'
  end
  exit # needed, as we don't have a persistent dialog, so don't wish to run the   mainloop
end
title

the title of the dialog window

msg

the text to display within the dialog

button1

label for the first button

button2

label for the optional second button

button3

label for the optional third button

# File lib/wrapped/dialogs.rb, line 23
def alarm title, msg, button1, button2=nil, button3=nil
  IupLib.IupAlarm title, msg, button1, button2, button3
end
get_colour(x=0, y=0) click to toggle source

Shows a modal dialog allowing user to select a colour.

As input, provide the x,y coordinates to show dialog.

Returns r/g/b triple of selected colour, or nil if “cancel” clicked.

r, g, b = get_colour 150, 150
# File lib/wrapped/dialogs.rb, line 33
def get_colour x=0, y=0
  r = FFI::MemoryPointer.new(:int, 1, 0)
  g = FFI::MemoryPointer.new(:int, 1, 0)
  b = FFI::MemoryPointer.new(:int, 1, 0)
  code = IupLib.IupGetColor x, y, r, g, b
  if code == 0
    return nil, nil, nil
  else
    return r.read_int, g.read_int, b.read_int
  end
end
get_file(filter='') click to toggle source

Convenience function to show a modal dialog to select a filename. As input, accepts a path and filter for the file.

Returns the status code and selected filename.

Example, selecting a filename ending in “.txt” from current directory.

code, file = get_file './*.txt'
# File lib/wrapped/dialogs.rb, line 53
def get_file filter=''
  file = ' '*(256-filter.size) + filter
  code = IupLib.IupGetFile file
  case code
  when 0, 1
    filename = file[0...file.index("\0")]
    return code, filename
  else
    return code, ''
  end
end
global(name, val=nil) click to toggle source

Accesses the global variable 'name'. Provide a value for 'val' to set the variable, or leave as nil to get the variable.

# File lib/wrapped/iup-global.rb, line 30
def global name, val=nil
  if val.nil?
    IupLib.IupGetGlobal(name).first
  else
    IupLib.IupSetGlobal name, val
  end
end
idle(callback) click to toggle source

Sets the idle_action

# File lib/wrapped/iup-global.rb, line 39
def idle callback
  unless callback.nil? or callback.arity.zero? 
    raise ArgumentError 'callback to idle must take no arguments'
  end
  IupLib.IupSetFunction 'IDLE_ACTION', callback
end
listdialog(title, items) click to toggle source

show a list dialog. returns selected item, or nil if cancel clicked.

# File lib/wrapped/dialogs.rb, line 84
def listdialog title, items
  strptrs = []
  strptrs << nil
 
  items_ptr = FFI::MemoryPointer.new(:pointer, items.length)
  items.each_with_index do |item, i|
    items_ptr[i].put_pointer(0, FFI::MemoryPointer.from_string(item))
  end

  code = IupLib.IupListDialog 1, title, items.length, items_ptr, 1, 1, 10, nil

  return (code == -1 ? nil : items[code])
end
mainloop() { || ... } click to toggle source

All IUP GUI code must be called via a block passed to this method, as in this minimal example.

mainloop do

  label = Label.new("Hello World!")

  Dialog.new label do
    title ' ... from IUP'
    size '150x50'
  end.show
end
# File lib/wrapped/iup-global.rb, line 16
def mainloop 
  begin
    IupLib.IupOpen 0, nil
    ImgLib::IupImageLibOpen()
    yield
    IupLib.IupMainLoop
  ensure
    IupLib.IupClose
  end
end
message(title, msg) click to toggle source

Create a MessageDialog with given title and displayed message.

message "title of dialog", "text of message"
# File lib/wrapped/dialogs.rb, line 102
def message title, msg
  IupLib.IupMessage title, msg
end