Extension Modules > IUP

IUP Linux and Windows

<< < (6/10) > >>

Support:
Here is the submenu.c example converted to ScriptBasic. It's too bad I can't show the multi-level menu in a screen capture.

C Version

ScriptBasic Version

--- Code: ---' IupSubmenu: Example in ScriptBasic
' Creates a dialog with a menu with three submenus.
' One of the submenus has a submenu, which has another submenu.

IMPORT iup.bas

GLOBAL CONST IUP_CENTER = 0xFFFF

'"""***************************************************************************
 * Function:                                                                  *
 * Item help callback                                                         *
 *                                                                            *
 * Description:                                                               *
 * Shows a message saying that only Help and Exit items performs an operation *
 *                                                                            *
 * Value returned:                                                            *
 * IUP_DEFAULT                                                                *
 ***************************************************************************"""
SUB item_help_cb

  Iup::Message ("Warning", "Only Help and Exit items performs an operation")

END SUB  

'"""***************************************************************************
 * Function:                                                                  *
 * Item exit callback                                                         *
 *                                                                            *
 * Description:                                                               *
 * Exits the program                                                          *
 *                                                                            *
 * Value returned:                                                            *
 * IUP_DEFAULT                                                                *
 ***************************************************************************"""
SUB item_exit_cb

  Iup::ExitLoop = TRUE

END SUB

' Main program
  
' Initializes IUP
Iup::Open()

' Program begin
  
' Creates a multiline
text = Iup::Text()
  
' Sets value of the text and turns on expand
Iup::SetAttributes(text, "VALUE = \"This text is here only to compose\", EXPAND = YES")
    
' Creates items of menu file
item_new = Iup::Item("New")
item_open = Iup::Item("Open")
item_close = Iup::Item("Close")
item_exit = Iup::Item("Exit", "item_exit_act")

' Creates items of menu edit
item_copy = Iup::Item("Copy")
item_paste = Iup::Item("Paste")

' Creates items for menu triangle
item_scalenus = Iup::Item("Scalenus")
item_isoceles = Iup::Item("Isoceles")
item_equilateral = Iup::Item("Equilateral")

' Create menu triangle
menu_triangle = Iup::Menu(item_equilateral, item_isoceles, item_scalenus)

' Creates submenu triangle
submenu_triangle = Iup::Submenu("Triangle", menu_triangle)

' Creates items for menu create
item_line = Iup::Item("Line")
item_circle = Iup::Item("Circle")

' Creates menu create
menu_create = Iup::Menu(item_line, item_circle, submenu_triangle)

' Creates submenu create
submenu_create = Iup::Submenu("Create", menu_create)

' Creates items of menu help
item_help = Iup::Item("Help", "item_help_act")
  
' Creates three menus
menu_file = Iup::Menu(item_new, item_open, item_close, Iup::Separator(), item_exit)
menu_edit = Iup::Menu(item_copy, item_paste, Iup::Separator(), submenu_create)
menu_help = Iup::Menu(item_help)

' Creates three submenus
submenu_file = Iup::Submenu("File", menu_file)
submenu_edit = Iup::Submenu("Edit", menu_edit)
submenu_help = Iup::Submenu("Help", menu_help)
  
' Creates main menu with file menu
menu = Iup::Menu(submenu_file, submenu_edit, submenu_help)

' Registers callbacks
Iup::SetCallback(item_help, "ACTION", ADDRESS(item_help_cb()))
Iup::SetCallback(item_exit, "ACTION", ADDRESS(item_exit_cb()))
 
' Associates handle "menu" with menu
Iup::SetHandle("menu", menu)
                                
' Creates dialog with a text
dlg = Iup::Dialog(text)

' Sets title and size of the dialog and associates a menu to it
Iup::SetAttributes(dlg, "TITLE=\"IupSubmenu Example\", SIZE = QUARTERxEIGHTH, MENU = menu")

' Shows dialog in the center of the screen
Iup::ShowXY(dlg, IUP_CENTER, IUP_CENTER)

' Initializes IUP main loop
Iup::MainLoop()

' Finishes IUP
Iup::Close()  

' Program finished successfully
END

--- End code ---

Support:
Thanks Ron for giving SB/IUP a try. I don't have the 'DOS' box/console issue with Linux if I insert the #! /usr/bin/scriba as the first line of the script or compile the application to C. The CIO Windows extension module has a Detach() function to kill the DOS box and run your application as a GUI program. I'm looking at adding a new command line switch for scriba to disable the console on startup.

Thanks for the menu screen shots! I'm trying to convert the C examples on the IUP site to help get folks going with IUP.

Are you running Windows 2000? If your running XP or greater, you should be seeing the current themed windows and controls with the IUP interface.

Support:

--- Quote ----If you can't get the dos window to close maybe you can get it to minimize as a work around?
--- End quote ---

You may be able to get rid of the console window start/close flash (using CIO::Detach) by setting the application to start minimized. (shortcut properties)

Update

The minimize trick solves the console flash issue but I was unable to get IUP to force the window to it's normal state under program control. (had to click on it in the taskbar)

Support:
I'm working on creating a scribaw for Windows that doesn't create a console window.

I'll post it to the downloads section when it's done.

Support:
Here is the IUP sample.c converted to ScriptBasic.

C Version


--- Code: ---' IUP sample.sb

IMPORT iup.bas

GLOBAL CONST IUP_CENTER = 0xFFFF
GLOBAL CONST IUP_TITLE = "TITLE"
GLOBAL CONST IUP_VALUE = "VALUE"
GLOBAL CONST IUP_SIZE = "SIZE"
GLOBAL CONST IUP_EXPAND = "EXPAND"
GLOBAL CONST IUP_DROPDOWN = "DROPDOWN"
GLOBAL CONST IUP_POSX = "POSX"
GLOBAL CONST IUP_POSY = "POSY"
GLOBAL CONST IUP_BGCOLOR = "BGCOLOR"
GLOBAL CONST IUP_MARGIN = "MARGIN"
GLOBAL CONST IUP_ALIGNMENT = "ALIGNMENT"
GLOBAL CONST IUP_GAP = "GAP"
GLOBAL CONST IUP_MENU = "MENU"

img_bits1 = """
 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1
,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1
,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1
,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1
,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1
,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1
,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1
,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,2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2,2,3,3,3,3,3,3,3,1,1,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2
,2,2,2,2,2,2,3,3,3,3,3,3,3,3,1,1,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
"""

SUB init_dialog

  img = Iup::Image(32,32, Iup::CreateImg(img_bits1))
  Iup::SetHandle ("img1", img)
  Iup::SetAttribute (img, "0", "0 0 0")
  Iup::SetAttribute (img, "1", "BGCOLOR")
  Iup::SetAttribute (img, "2", "255 0 0")

  img = Iup::Image(32,32, Iup::CreateImg(img_bits2))
  Iup::SetHandle ("img2", img)
  Iup::SetAttribute (img, "0", "0 0 0")
  Iup::SetAttribute (img, "1", "0 255 0")
  Iup::SetAttribute (img, "2", "BGCOLOR")
  Iup::SetAttribute (img, "3", "255 0 0")

  mnu = Iup::Menu( _
  Iup::Submenu("IupSubmenu 1",Iup::Menu( _
      Iup::SetAttributes(Iup::Item("IupItem 1 Checked"), "VALUE=ON"), _
      Iup::Separator(), _
      Iup::SetAttributes(Iup::Item("IupItem 2 Disabled"), "ACTIVE=NO"))), _
    Iup::Item("IupItem 3"), _
    Iup::Item("IupItem 4"))
  Iup::SetHandle("mnu",mnu)

  _frm_1 = Iup::Frame( _
    Iup::Vbox( _
      Iup::Button("Button Text"), _
      Iup::SetAttributes(Iup::Button(), "IMAGE=img1"), _
      Iup::SetAttributes(Iup::Button(), "IMAGE=img1,IMPRESS=img2")))
  Iup::SetAttribute(_frm_1,IUP_TITLE,"IupButton")

  _frm_2 = Iup::Frame( _
    Iup::Vbox( _
      Iup::Label("Label Text"), _
      Iup::SetAttributes(Iup::Label(""), "SEPARATOR=HORIZONTAL"), _
      Iup::SetAttributes(Iup::Label(""), "IMAGE=img1")))
  Iup::SetAttribute(_frm_2,IUP_TITLE,"IupLabel")

  _frm_3 = Iup::Frame( _
    Iup::Vbox( _
      Iup::SetAttributes(Iup::Toggle("Toggle Text"), "VALUE=ON"), _
      Iup::SetAttributes(Iup::Toggle(""), "IMAGE=img1,IMPRESS=img2"), _
      Iup::SetAttributes(Iup::Frame(Iup::Radio(Iup::Vbox( _
        Iup::Toggle("Toggle Text"), _
        Iup::Toggle("Toggle Text")))), "TITLE=IupRadio")))
  Iup::SetAttribute(_frm_3,IUP_TITLE,"IupToggle")

  _text_1 = Iup::Text()
  Iup::SetAttribute(_text_1,IUP_VALUE,"IupText Text")
  Iup::SetAttribute(_text_1,IUP_SIZE,"80x")

  _ml_1 = Iup::MultiLine()
  Iup::SetAttribute(_ml_1,IUP_VALUE,"IupMultiline Text\nSecond Line\nThird Line")
  Iup::SetAttribute(_ml_1,IUP_EXPAND,"YES")
  Iup::SetAttribute(_ml_1,IUP_SIZE,"80x60")

  _frm_4 = Iup::Frame(Iup::Vbox( _
    _text_1, _
    _ml_1))
  Iup::SetAttribute(_frm_4,IUP_TITLE,"IupText/IupMultiline")

  _list_1 = Iup::List()
  Iup::SetAttribute(_list_1,IUP_EXPAND,"YES")
  Iup::SetAttribute(_list_1,IUP_VALUE,"1")
  Iup::SetAttribute(_list_1,"1","Item 1 Text")
  Iup::SetAttribute(_list_1,"2","Item 2 Text")
  Iup::SetAttribute(_list_1,"3","Item 3 Text")

  _list_2 = Iup::List()
  Iup::SetAttribute(_list_2,IUP_DROPDOWN,"YES")
  Iup::SetAttribute(_list_2,IUP_EXPAND,"YES")
  Iup::SetAttribute(_list_2,IUP_VALUE,"2")
  Iup::SetAttribute(_list_2,"1","Item 1 Text")
  Iup::SetAttribute(_list_2,"2","Item 2 Text")
  Iup::SetAttribute(_list_2,"3","Item 3 Text")

  _list_3 = Iup::List()
  Iup::SetAttribute(_list_3,"EDITBOX","YES")
  Iup::SetAttribute(_list_3,IUP_EXPAND,"YES")
  Iup::SetAttribute(_list_3,IUP_VALUE,"3")
  Iup::SetAttribute(_list_3,"1","Item 1 Text")
  Iup::SetAttribute(_list_3,"2","Item 2 Text")
  Iup::SetAttribute(_list_3,"3","Item 3 Text")

  _frm_5 =  Iup::Frame(Iup::Vbox( _
      _list_1, _
      _list_2, _
      _list_3))
  Iup::SetAttribute(_frm_5,IUP_TITLE,"IupList")

  _hbox_1 = Iup::Hbox( _
    _frm_1, _
    _frm_2, _
    _frm_3, _
    _frm_4, _
    _frm_5)

  _cnv_1 = Iup::Canvas()
  Iup::SetAttribute(_cnv_1,IUP_POSX,"0.0")
  Iup::SetAttribute(_cnv_1,IUP_POSY,"0.0")
  Iup::SetAttribute(_cnv_1,IUP_BGCOLOR,"128 255 0")

  _vbox_1 = Iup::Vbox( _
    _hbox_1, _
    _cnv_1)
  Iup::SetAttribute(_vbox_1,IUP_MARGIN,"5x5")
  Iup::SetAttribute(_vbox_1,IUP_ALIGNMENT,"ARIGHT")
  Iup::SetAttribute(_vbox_1,IUP_GAP,"5")

  dlg = Iup::Dialog(_vbox_1)
  Iup::SetHandle("dlg",dlg)
  Iup::SetAttribute(dlg,IUP_MENU,"mnu")
  Iup::SetAttribute(dlg,IUP_TITLE,"IupDialog Title")

END SUB

' MAIN

  Iup::Open()
  init_dialog()
  Iup::Show(Iup::GetHandle("dlg"))
  Iup::MainLoop()
  Iup::Close()
 
  END

--- End code ---

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version