Author Topic: IUP Linux and Windows  (Read 106365 times)

Support

  • Administrator
  • *****
  • Posts: 19
    • View Profile
IUP Linux and Windows
« on: November 03, 2011, 10:27:21 PM »
I'm glad that everyone is happy with GTK-Server but if you would have looked behind door #2, ...   ;)

The following is the status of the core IUP extension module. Functions that start with a * haven't been implemented yet. (stubs)

TODO List
  • Variable number of arguments for IUP functions that support it.
  • Return IUP name lists in an array. (like Iup::Info)
  • Bring callback handling internal to the extension module.
  • Add all the other IUP goodies (plot, GL, grids, ...)

IUP is an extensive library and wrapping it to work with ScriptBasic is going to take time. The SB macros help a lot but there is always something that crops up that puts the wagons in a circle.


System
Iup::Open
Iup::Close
Iup::Version
Iup::Load
Iup::LoadBuffer
Iup::SetLanguage
Iup::GetLanguage

Attribute
Iup::StoreAttribute
Iup::StoreGlobalAttribute
Iup::StoreAttributeId
Iup::StoreGlobalAttributeId
Iup::SetAttribute
Iup::SetGlobalAttribute
Iup::SetAttributeId
Iup::SetGlobalAttributeId
Iup::SetfAttribute
Iup::SetfAttributeId
Iup::SetfAttributeId2
Iup::SetAttributes
Iup::ResetAttribute
Iup::ResetGlobalAttribute
Iup::SetAtt
Iup::SetAttributeHandle
Iup::GetAttributeHandle
Iup::GetAttribute
Iup::GetAttributeId
Iup::GetAllAttributes
Iup::GetAttributes
Iup::GetFloat
Iup::GetFloatId
Iup::GetFloatId2
Iup::GetInt
Iup::GetInt2
* Iup::GetIntInt
Iup::GetIntId
Iup::GetIntId2
Iup::StoreGlobal
Iup::SetGlobal
Iup::GetGlobal

Events
GetEvent  (used internally)
Iup::MainLoop
Iup::MainLoopLevel
Iup::LoopStep
Iup::LoopStepWait
Iup::ExitLoop
Iup::Flush
Iup::GetCallback
Iup::SetCallback
* Iup::SetCallbacks
Iup::GetActionName
Iup::SetFunction
Iup::RecordInput
Iup::PlayInput

Layout
Iup::Create
Iup::Destroy
Iup::Map
Iup::Unmap
Iup::GetAllClasses
Iup::GetClassName
Iup::GetClassType
Iup::ClassMatch
Iup::GetClassAttributes
Iup::GetClassCallbacks
Iup::SaveClassAttributes
Iup::CopyClassAttributes
Iup::SetClassDefaultAttribute
Iup::Fill
Iup::Hbox
Iup::Vbox
Iup::Zbox
Iup::Radio
Iup::Normalizer
Iup::Cbox
Iup::Sbox
Iup::Split
Iup::Append
Iup::Detach
Iup::Insert
Iup::InsertTop
Iup::Reparent
Iup::GetParent
Iup::GetChild
Iup::GetChildPos
Iup::GetChildCount
Iup::GetNextChild
Iup::GetBrother
Iup::GetDialog
Iup::GetDialogChild
Iup::Refresh
Iup::RefreshChildren
Iup::Update
Iup::UpdateChildren
Iup::Redraw
Iup::ConvertXYToPos

Dialog
Iup::Dialog
Iup::Popup
Iup::Show
Iup::ShowXY
Iup::Hide
Iup::FileDlg
Iup::MessageDlg
Iup::ColorDlg
Iup::FontDlg
Iup::Alarm
Iup::GetFile
Iup::GetColor
* Iup::GetParam
Iup::GetText
* Iup::ListDialog
Iup::Message
Iup::LayoutDialog
Iup::ElementPropertiesDialog

Controls
Iup::Button
Iup::Canvas
Iup::Frame
Iup::Label
Iup::List
Iup::MultiLine
Iup::ProgressBar
Iup::Spin
Iup::Tabs
* Iup::Tabsv
Iup::Text
Iup::Toggle
Iup::Tree
Iup::Val

Resources
Iup::Image
Iup::ImageRGB
Iup::ImageRGBA
Iup::NextField
Iup::PreviousField
Iup::GetFocus
Iup::SetFocus
Iup::Item
Iup::Menu
* Iup::Menuv
Iup::Separator
Iup::Submenu
Iup::SetHandle
Iup::GetHandle
Iup::GetName
Iup::GetAllNames
Iup::GetAllDialogs
Iup::Clipboard
Iup::Timer
Iup::User
Iup::Help

Helper Functions
Iup::GetListText
Iup::Info


IUP Control Gallery

IUP Project Site
« Last Edit: December 31, 2011, 04:00:42 PM by support »

Support

  • Administrator
  • *****
  • Posts: 19
    • View Profile
Re: IUP Linux and Windows
« Reply #1 on: December 07, 2011, 11:53:54 AM »
Status Update

I have the controls and attribute IUP functions pretty much done. I'm working on the event section so callbacks call SB FUNCTION/SUB script routines to process events. There is still work to be done after events to allow passing multiple control IDs to a IUP function. (handled internally with IupAppend)

Won't be long now ...

P.S.

If you have any interest in this, now would be a good time to start reviewing the IUP API documentation.
« Last Edit: December 07, 2011, 11:56:38 AM by support »

Support

  • Administrator
  • *****
  • Posts: 19
    • View Profile
Re: IUP Linux and Windows
« Reply #2 on: December 16, 2011, 05:09:03 PM »
I'm making progress and have a quick example to show. I hope to have a beta soon.

Code: [Select]
' MAIN

IMPORT iup.bas

SUB Btn1_clicked
  PRINT "BUTTON 1 Event\n"
END SUB

SUB Btn2_clicked
  PRINT "BUTTON 2 Event\n"
END SUB

SUB Btn3_clicked
  PRINT "BUTTON 3 Event\n"
END SUB

SUB Win_exit
  Iup::ExitLoop = TRUE
END SUB

Iup::Open()

win = Iup::Create("dialog")
Iup::SetAttributes(win, "TITLE=\"Test Dialog\", SIZE=300x200")
horzbox = Iup::Create("hbox")
Iup::SetAttributes(horzbox, "GAP=5")
btn1 = Iup::Create("button")
Iup::SetAttributes(btn1, "TITLE=Button1, EXPAND=HORIZONTAL")
btn2 = Iup::Create("button")
Iup::SetAttributes(btn2, "TITLE=Button2, EXPAND=HORIZONTAL")
btn3 = Iup::Create("button")
Iup::SetAttributes(btn3, "TITLE=Button3, EXPAND=HORIZONTAL")

Iup::Append(horzbox, btn1)
Iup::Append(horzbox, btn2)
Iup::Append(horzbox, btn3)
Iup::Append(win, horzbox)

Iup::SetCallback(win,"CLOSE_CB",ADDRESS(Win_exit()))
Iup::SetCallback(btn1,"ACTION",ADDRESS(Btn1_clicked()))
Iup::SetCallback(btn2,"ACTION",ADDRESS(Btn2_clicked()))
Iup::SetCallback(btn3,"ACTION",ADDRESS(Btn3_clicked()))

Iup::Show(win)

Iup::MainLoop()

Iup::Close()

END

jrs@laptop:~/sb/test$ scriba puitest.sb
BUTTON 1 Event
BUTTON 2 Event
BUTTON 3 Event
jrs@laptop:~/sb/test$

« Last Edit: December 17, 2011, 08:48:17 PM by support »

Support

  • Administrator
  • *****
  • Posts: 19
    • View Profile
Re: IUP Linux and Windows
« Reply #3 on: December 17, 2011, 08:55:24 PM »
I'm going to give this a try in Windows and if all goes well, I will release a work in progress beta that should allow you to create dialogs and play with controls. I still have some convenience features to add but it's getting pretty close to a version 1.0 release.

Support

  • Administrator
  • *****
  • Posts: 19
    • View Profile
Re: IUP Linux and Windows
« Reply #4 on: December 19, 2011, 12:32:47 AM »
Here is a more meaningful example. It seems Peter's Thesaurus program has become the Hello World for Basic GUI toolkit integrators.  :D

Code: [Select]
IMPORT iup.bas

servers[0]="dict.org"
servers[1]="dict1.us.dict.org"
servers[2]="all.dict.org"

about="""This is a Demo
of the IUP GUI Binding
for Scriptbasic"""

' Initialize IUP
Iup::Open()

' Create main window

win = Iup::Create("dialog")
  Iup::SetAttributes(win, "TITLE=Thesaurus, SIZE=500x300")
  Iup::SetCallback(win,"CLOSE_CB",ADDRESS(Win_exit()))

' Create container to house ALL GUI objects

vbox = Iup::Create("vbox")
  Iup::SetAttributes(vbox, "MARGIN=10x10")

' Create server panel

topBox = Iup::Create("hbox")
  Iup::SetAttributes(topBox, "GAP=10")
  Iup::Append(vbox, topBox)
serverFrame = Iup::Create("frame")
  Iup::SetAttributes(serverFrame, "TITLE=Servers, EXPAND=YES")
  Iup::Append(topBox, serverFrame)
serverBox = Iup::Create("hbox")
  Iup::SetAttributes(serverBox, "GAP=5")
  Iup::Append(serverFrame, serverBox)
serverCombo = Iup::Create("list")
  Iup::SetAttributes(serverCombo, "DROPDOWN=YES, SIZE=120x, EXPAND=HORIZONTAL, VALUE=1")
  Iup::Append(serverBox, serverCombo)
  Iup::SetCallback(serverCombo, "ACTION", ADDRESS(serverCombo_selected()))
btnFetch = Iup::Create("button")
  Iup::SetAttributes(btnFetch, "TITLE=Fetch, SIZE = 50x")
  Iup::Append(serverBox, btnFetch)
  Iup::SetCallback(btnFetch, "ACTION", ADDRESS(btnFetch_clicked()))

' Create control panel

controlFrame = Iup::Create("frame")
  Iup::SetAttributes(controlFrame, "TITLE=Controls")
  Iup::Append(topBox, controlFrame)
controlBox = Iup::Create("hbox")
  Iup::SetAttributes(controlBox, "GAP=5")
  Iup::Append(controlFrame, controlBox)
btnAbout = Iup::Create("button")
  Iup::SetAttributes(btnAbout, "TITLE=About, SIZE = 50x")
  Iup::Append(controlBox, btnAbout)
  Iup::SetCallback(btnAbout, "ACTION", ADDRESS(btnAbout_clicked()))
btnClear = Iup::Create("button")
  Iup::SetAttributes(btnClear, "TITLE=Clear, SIZE = 50x")
  Iup::Append(controlBox, btnClear)
  Iup::SetCallback(btnClear, "ACTION", ADDRESS(btnClear_clicked()))
btnExit = Iup::Create("button")
  Iup::SetAttributes(btnExit, "TITLE=Exit, SIZE = 50x")
  Iup::Append(controlBox, btnExit)
  Iup::SetCallback(btnExit,"ACTION",ADDRESS(Win_exit()))

' Create dictionary panel

dictFrame = Iup::Create("frame")
  Iup::SetAttributes(dictFrame, "TITLE=Dictionaries")
  Iup::Append(vbox, dictFrame)
serverList = Iup::Create("list")
  Iup::SetAttributes(serverList, "EXPAND=YES, VISIBLELINES=1")
  Iup::Append(dictFrame, serverList)
  Iup::SetCallback(serverList, "ACTION", ADDRESS(serverList_selected()))

' Create text part

transFrame = IUP::Create("frame")
  Iup::SetAttributes(transFrame, "TITLE=Translation")
  Iup::Append(vbox, transFrame)
text = Iup::Create("text")
  Iup::SetAttributes(text, "MULTILINE=YES, EXPAND=YES")
  Iup::Append(transFrame, text)

' Create entry and search button

bottomBox = Iup::Create("hbox")
  Iup::SetAttributes(bottomBox, "GAP=10")
  Iup::Append(vbox, bottomBox)
label = Iup::Create("label")
  Iup::SetAttributes(label, "TITLE=\"Enter Word to Search For:\", SIZE=x12")
  Iup::Append(bottomBox, label)
entry = Iup::Create("text")
  Iup::SetAttributes(entry, "EXPAND=HORIZONTAL")
  Iup::Append(bottomBox, entry)
btnSearch = Iup::Create("button")
  Iup::SetAttributes(btnSearch,"TITLE=Search, SIZE=50x")
  Iup::Append(bottomBox, btnSearch)
  Iup::SetCallback(btnSearch, "ACTION", ADDRESS(btnSearch_clicked()))
chkAll = Iup::Create("toggle")
  Iup::SetAttributes(chkAll, "TITLE=ALL, SIZE=x12")
  Iup::Append(bottomBox, chkAll)
chkUTF = Iup::Create("toggle")
  Iup::SetAttributes(chkUTF, "TITLE=UTF-8, SIZE=x12")
  Iup::Append(bottomBox, chkUTF)

' Add the main GUI container to the Window

Iup::Append(win, vbox)

' Setup dialog defaults

Iup::Show(win)
Iup::SetFocus(btnFetch)
FOR i = 0 TO UBOUND(servers)
  Iup::SetAttribute(serverCombo, "APPENDITEM", servers[i])
NEXT
Iup::SetAttribute(serverCombo, "VALUE", "1")
Iup::Update(serverCombo)
server_selection = servers[0]

' Main processing loop

Iup::MainLoop()
Iup::Close()
END

' Callback routines

SUB Win_exit
  Iup::ExitLoop = TRUE
END SUB

SUB btnAbout_clicked
  Iup::Message("ABOUT", about)
END SUB

SUB serverCombo_selected
  server_selection = Iup::GetListText()
END SUB

SUB serverList_selected
  whichDictionary = Iup::GetListText()
END SUB

SUB btnFetch_clicked
  LOCAL dat, total, count
  ON ERROR GOTO G_NetError
  OPEN server_selection & ":2628" FOR SOCKET AS #1
  PRINT#1,"SHOW DB\n"
  LINE INPUT#1, dat
  LINE INPUT#1, dat
  count = 0
  WHILE LEFT(dat, 1) <> "."
    LINE INPUT#1, dat
    IF LEFT(dat, 1) <> "." THEN total[count] = TRIM(dat)
    count+=1
  WEND
  PRINT#1,"QUIT\n"
  CLOSE(#1)
  FOR cnt = 0 TO count - 2
    Iup::SetAttribute(serverList, "APPENDITEM", total[cnt])
  NEXT
  Iup::SetAttribute(serverList, "VALUE", "1")
  Iup::Update(serverCombo)
  whichDictionary = total[0]
  EXIT SUB

  G_NetError:
  PRINT "Server ",server_selection," not available. (",ERROR,")\n"
END SUB

SUB btnClear_clicked
  Iup::ClearList(serverList)
  Iup::SetAttribute(text, "VALUE", "")
  Iup::SetAttribute(entry, "VALUE", "")
END SUB

SUB btnSearch_clicked
  LOCAL dict, dat, total, info
  IUP::SetAttribute(text, "VALUE","Fetching....")
  ON ERROR GOTO L_NetError
  dict = LEFT(whichDictionary, INSTR(whichDictionary, " "))
  OPEN server_selection & ":2628" FOR SOCKET AS 1
  IF Iup::GetAttribute(chkAll, "VALUE") THEN
    PRINT#1,"DEFINE * " & Iup::GetAttribute(entry,"VALUE") & "\n"
  ELSE
    PRINT#1,"DEFINE " & dict & " " & Iup::GetAttribute(entry,"VALUE") & "\n"
  END IF
  REPEAT
    LINE INPUT#1, dat
    IF LEFT(dat, 3) = "151" THEN
      total$ &= "------------------------------\r\n"
      total$ &= RIGHT(dat, LEN(dat) - LEN(Iup::GetAttribute(entry, "VALUE")) - LEN(dict))
      total$ &= "------------------------------\r\n"
      REPEAT
        LINE INPUT#1, info
        info = REPLACE(info, CHR(34), CHR(92) & CHR(34))
        IF LEFT(info, 1) <> "." THEN total &= TRIM(info) & "\n"
      UNTIL LEFT(info, 1) = "."
      total &= "\n"
    END IF
  UNTIL LEFT(dat, 3) = "250" OR VAL(LEFT(dat, 3)) > 499
  PRINT#1,"QUIT\n"
  CLOSE(#1)
  IF LEFT(dat, 3) = "552" THEN
    total = "No match found."
  ELSE IF LEFT(dat, 3) = "501" THEN
    total = "Select a dictionary first!"
  ELSE IF LEFT(dat, 3) = "550" THEN
    total = "Invalid database!"
  END IF
  Iup::SetAttribute(text, "VALUE", total)
EXIT SUB

L_NetError:
  dat[0] = "Could not lookup word! (" & ERROR & ")"
  Iup::SetAttribute(text, "VALUE", dat)
END SUB

« Last Edit: January 01, 2012, 10:24:00 PM by support »

Support

  • Administrator
  • *****
  • Posts: 19
    • View Profile
Re: IUP Linux and Windows
« Reply #5 on: December 20, 2011, 11:54:29 PM »
I started working on controls that allow a variable number of child controls as arguments. Notice the difference between using Iup::Create("Hbox") and Iup::Hbox(child,child,...) in the two code blocks.  At this time I have limited the number of child controls to be passed as arguments to 16. I'm testing passing an array of control IDs as the first parameter which removes the 16 child control limit. So, if you have 16 or less child controls, pass them as arguments otherwise build an array and pass it as the first argument.

Code: [Select]
' Create control panel

controlFrame = Iup::Create("frame")
  Iup::SetAttributes(controlFrame, "TITLE=Controls")
  Iup::Append(topBox, controlFrame)
controlBox = Iup::Create("hbox")
  Iup::SetAttributes(controlBox, "GAP=5")
  Iup::Append(controlFrame, controlBox)
btnAbout = Iup::Create("button")
  Iup::SetAttributes(btnAbout, "TITLE=About, SIZE = 50x")
  Iup::Append(controlBox, btnAbout)
  Iup::SetCallback(btnAbout, "ACTION", ADDRESS(btnAbout_clicked()))
btnClear = Iup::Create("button")
  Iup::SetAttributes(btnClear, "TITLE=Clear, SIZE = 50x")
  Iup::Append(controlBox, btnClear)
  Iup::SetCallback(btnClear, "ACTION", ADDRESS(btnClear_clicked()))
btnExit = Iup::Create("button")
  Iup::SetAttributes(btnExit, "TITLE=Exit, SIZE = 50x")
  Iup::Append(controlBox, btnExit)
  Iup::SetCallback(btnExit,"ACTION",ADDRESS(Win_exit()))

Code: [Select]
' Create control panel

btnAbout = Iup::Create("button")
  Iup::SetAttributes(btnAbout, "TITLE=About, SIZE = 50x")
  Iup::SetCallback(btnAbout, "ACTION", ADDRESS(btnAbout_clicked()))
btnClear = Iup::Create("button")
  Iup::SetAttributes(btnClear, "TITLE=Clear, SIZE = 50x")
  Iup::SetCallback(btnClear, "ACTION", ADDRESS(btnClear_clicked()))
btnExit = Iup::Create("button")
  Iup::SetAttributes(btnExit, "TITLE=Exit, SIZE = 50x")
  Iup::SetCallback(btnExit,"ACTION",ADDRESS(Win_exit()))
controlFrame = Iup::Create("frame")
  Iup::SetAttributes(controlFrame, "TITLE=Controls")
  Iup::Append(topBox, controlFrame)
controlBox = Iup::Hbox(btnAbout, btnClear, btnExit)
  Iup::SetAttributes(controlBox, "GAP=5")
  Iup::Append(controlFrame, controlBox)
« Last Edit: December 21, 2011, 01:00:37 AM by support »

Support

  • Administrator
  • *****
  • Posts: 19
    • View Profile
Re: IUP Linux and Windows
« Reply #6 on: December 22, 2011, 01:13:55 PM »
BUILD 1

I was able to get a Windows version of the IUP.DLL compiled today. It only contains the core IUP library. (what's defined in iup.h) Check out the iup.bas INCLUDE module file for a list of the functions.

FYI The same ScriptBasic C interface program for IUP and dictionary example I created on Linux 64 compiled/ran untouched under Windows XP. I would say that pretty much defines what portability means.  8)

If you don't have a copy of ScriptBasic for Windows, here is the runtime for the MinGW32-TDM compiled version.  

ScriptBasic 3.0 Windows 32 bit

Note The IUP extension module in the zip is based on Armando's first pass at IUP for SB. Replace them with the download attached.
« Last Edit: December 23, 2011, 05:54:49 PM by support »

Support

  • Administrator
  • *****
  • Posts: 19
    • View Profile
Re: IUP Linux and Windows
« Reply #7 on: December 23, 2011, 01:26:50 PM »
BUILD 2

I have added / fixed a few things so here is a new build.

  • Iup::LoadBuffer was added back in. (my typo caused a ref. not found at compile time)
  • Vbox now accepts up to 16 child controls like Hbox.
  • Added Iup::Info() - This function is the foundation for passing IUP name lists back to SB in an argument variable.

Windows - Iup::Info
C:\SB3\test>sb3 iupinfo.sb
SYSTEMLANGUAGE: English (United States)
DRIVER: Win32
SYSTEM: WinXP
SYSTEMLOCALE: 1252  (ANSI - Latin I)
COMPUTERNAME: JRS-C997F91780C
USERNAME: John
MONITORSINFO: 0 0 1280 800

SCREENSIZE: 1280x766
SCREENDEPTH: 32
VIRTUALSCREEN: 0 0 1280 800
DLGFGCOLOR:   0   0   0
DLGBGCOLOR: 236 233 216
DEFAULTFONT: Tahoma,  8
DEFAULTFONTSIZE: 8
TXTFGCOLOR:   0   0   0
TXTBGCOLOR: 255 255 255
C:\SB3\test>

Linux - Iup::Info
jrs@laptop:~/sb/test$ scriba iupinfo.sb
SYSTEMLANGUAGE: en-us
DRIVER: GTK
SYSTEM: Linux
SYSTEMLOCALE: UTF-8
COMPUTERNAME: laptop
USERNAME: jrs
MONITORSINFO: 0 0 1280 800

SCREENSIZE: 1280x749
SCREENDEPTH: 24
VIRTUALSCREEN: 0 0 1280 800
DLGFGCOLOR:   0   0   0
DLGBGCOLOR: 220 218 213
DEFAULTFONT: Ubuntu 11
DEFAULTFONTSIZE: 11
TXTFGCOLOR:   0   0   0
TXTBGCOLOR: 255 255 255
jrs@laptop:~/sb/test$


Code: [Select]
IMPORT iup.bas
IUP::Open()

IUP::Info(INFO)

PRINT "SYSTEMLANGUAGE: ",INFO{"SYSTEMLANGUAGE"},"\n"
PRINT "DRIVER: ",INFO{"DRIVER"},"\n"
PRINT "SYSTEM: ",INFO{"SYSTEM"},"\n"
PRINT "SYSTEMLOCALE: ",INFO{"SYSTEMLOCALE"},"\n"
PRINT "COMPUTERNAME: ",INFO{"COMPUTERNAME"},"\n"
PRINT "USERNAME: ", INFO{"USERNAME"},"\n"
PRINT "MONITORSINFO: ",INFO{"MONITORSINFO"},"\n"
PRINT "SCREENSIZE: ",INFO{"SCREENSIZE"},"\n"
PRINT "SCREENDEPTH: ",INFO{"SCREENDEPTH"},"\n"
PRINT "VIRTUALSCREEN: ",INFO{"VIRTUALSCREEN"},"\n"
PRINT "DLGFGCOLOR: ",INFO{"DLGFGCOLOR"},"\n"
PRINT "DLGBGCOLOR: ",INFO{"DLGBGCOLOR"},"\n"
PRINT "DEFAULTFONT: ",INFO{"DEFAULTFONT"},"\n"
PRINT "DEFAULTFONTSIZE: ",INFO{"DEFAULTFONTSIZE"},"\n"
PRINT "TXTFGCOLOR: ",INFO{"TXTFGCOLOR"},"\n"
PRINT "TXTBGCOLOR: ",INFO{"TXTBGCOLOR"},"\n"
« Last Edit: December 23, 2011, 01:43:03 PM by support »

Support

  • Administrator
  • *****
  • Posts: 19
    • View Profile
Re: IUP Linux and Windows
« Reply #8 on: December 23, 2011, 10:11:20 PM »
BUILD 3

I thought I would give some of the other IUP functions a try so I substituted the Iup::Create() calls with their control equivalent. I like the Iup::Create() method better. It allows me to use Iup::SetAttributes() to define the control properties and not force me to use specific attributes on the create. For example, Iup::Button() requires you pass the title and action class on create. Using Iup::Create("button"), I set attributes and callbacks with two functions and I'm done. Why should I be forced to set control actions if i have no plans to define a callback for it?

The other issue is passing a NULL for optional arguments. The Iup::Dialog() has and option for passing one child or a NULL. The main purpose is to return a handle for the dialog. I'm not sure why Iup::Dialog() only allows one child when Hbox & Vbox allow as many children as you wish. At this time, the control create main purpose is to return a handle. Use Iup::Append() in a loop to load up a parent with the kids.

Here is the modified dictionary program using IUP control creation functions rather that the generic Iup::Create() function. Build 3 handles the NULL issues internally.

I think the best thing to do is solve the null argument issue as it keeps cropping up as I move forward. The next update will have this resolved so the SB IUP API follows the original as best as possible. I could pass a "NULL" and convert it to a C NULL internally.


Code: [Select]
IMPORT iup.bas

servers[0]="dict.org"
servers[1]="dict1.us.dict.org"
servers[2]="all.dict.org"

about="""This is a Demo
of the IUP GUI Binding
for Scriptbasic"""

' Initialize IUP
Iup::Open()

' Create main window

win = Iup::Dialog()
  Iup::SetAttributes(win, "TITLE=Thesaurus, SIZE=500x300")
  Iup::SetCallback(win,"CLOSE_CB",ADDRESS(Win_exit()))

' Create container to house ALL GUI objects

vbox = Iup::Vbox()
  Iup::SetAttributes(vbox, "MARGIN=10x10")

' Create server panel

topBox = Iup::Hbox()
  Iup::SetAttributes(topBox, "GAP=10")
  Iup::Append(vbox, topBox)
serverFrame = Iup::Frame()
  Iup::SetAttributes(serverFrame, "TITLE=Servers, EXPAND=YES")
  Iup::Append(topBox, serverFrame)
serverBox = Iup::Hbox()
  Iup::SetAttributes(serverBox, "GAP=5")
  Iup::Append(serverFrame, serverBox)
serverCombo = Iup::List("ACTION")
  Iup::SetAttributes(serverCombo, "DROPDOWN=YES, SIZE=120x, EXPAND=HORIZONTAL, VALUE=1")
  Iup::Append(serverBox, serverCombo)
  Iup::SetCallback(serverCombo, "ACTION", ADDRESS(serverCombo_selected()))
btnFetch = Iup::Button("Fetch","ACTION")
  Iup::SetAttributes(btnFetch, "SIZE = 50x")
  Iup::Append(serverBox, btnFetch)
  Iup::SetCallback(btnFetch, "ACTION", ADDRESS(btnFetch_clicked()))

' Create control panel

btnAbout = Iup::Button("About","ACTION")
  Iup::SetAttributes(btnAbout, "SIZE = 50x")
  Iup::SetCallback(btnAbout, "ACTION", ADDRESS(btnAbout_clicked()))
btnClear = Iup::Button("Clear","ACTION")
  Iup::SetAttributes(btnClear, "SIZE = 50x")
  Iup::SetCallback(btnClear, "ACTION", ADDRESS(btnClear_clicked()))
btnExit = Iup::Button("Exit","ACTION")
  Iup::SetAttributes(btnExit, "SIZE = 50x")
  Iup::SetCallback(btnExit,"ACTION",ADDRESS(Win_exit()))
controlFrame = Iup::Frame()
  Iup::SetAttributes(controlFrame, "TITLE=Controls")
  Iup::Append(topBox, controlFrame)
controlBox = Iup::Hbox(btnAbout, btnClear, btnExit)
  Iup::SetAttributes(controlBox, "GAP=5")
  Iup::Append(controlFrame, controlBox)

' Create dictionary panel

dictFrame = Iup::Frame()
  Iup::SetAttributes(dictFrame, "TITLE=Dictionaries")
  Iup::Append(vbox, dictFrame)
serverList = Iup::List("ACTION")
  Iup::SetAttributes(serverList, "EXPAND=YES, VISIBLELINES=1")
  Iup::Append(dictFrame, serverList)
  Iup::SetCallback(serverList, "ACTION", ADDRESS(serverList_selected()))

' Create text part

transFrame = IUP::Frame()
  Iup::SetAttributes(transFrame, "TITLE=Translation")
  Iup::Append(vbox, transFrame)
text = Iup::Text("ACTION")
  Iup::SetAttributes(text, "MULTILINE=YES, EXPAND=YES")
  Iup::Append(transFrame, text)

' Create entry and search button

bottomBox = Iup::Hbox()
  Iup::SetAttributes(bottomBox, "GAP=10")
  Iup::Append(vbox, bottomBox)
label = Iup::Label("Enter Word to Search For:")
  Iup::SetAttributes(label, "SIZE=x12")
  Iup::Append(bottomBox, label)
entry = Iup::Text("ACTION")
  Iup::SetAttributes(entry, "EXPAND=HORIZONTAL")
  Iup::Append(bottomBox, entry)
btnSearch = Iup::Button("Search","ACTION")
  Iup::SetAttributes(btnSearch,"SIZE=50x")
  Iup::Append(bottomBox, btnSearch)
  Iup::SetCallback(btnSearch, "ACTION", ADDRESS(btnSearch_clicked()))
chkAll = Iup::Toggle("ALL","ACTION")
  Iup::SetAttributes(chkAll, "SIZE=x12")
  Iup::Append(bottomBox, chkAll)
chkUTF = Iup::Toggle("UTF-8","ACTION")
  Iup::SetAttributes(chkUTF, "SIZE=x12")
  Iup::Append(bottomBox, chkUTF)

' Add the main GUI container to the Window

Iup::Append(win, vbox)

' Setup dialog defaults


Iup::Show(win)
Iup::SetFocus(btnFetch)
FOR i = 0 TO UBOUND(servers)
  Iup::SetAttribute(serverCombo, "APPENDITEM", servers[i])
NEXT
Iup::SetAttribute(serverCombo, "VALUE", "1")
Iup::Update(serverCombo)
server_selection = servers[0]

' Main processing loop

Iup::MainLoop()
Iup::Close()
END

' Callback routines

SUB Win_exit
  Iup::ExitLoop = TRUE
END SUB

SUB btnAbout_clicked
  Iup::Message("ABOUT", about)
END SUB

SUB serverCombo_selected
  server_selection = Iup::GetListText()
END SUB

SUB serverList_selected
  whichDictionary = Iup::GetListText()
END SUB

SUB btnFetch_clicked
  LOCAL dat, total, count
  ON ERROR GOTO G_NetError
  OPEN server_selection & ":2628" FOR SOCKET AS #1
  PRINT#1,"SHOW DB\n"
  LINE INPUT#1, dat
  LINE INPUT#1, dat
  count = 0
  WHILE LEFT(dat, 1) <> "."
    LINE INPUT#1, dat
    IF LEFT(dat, 1) <> "." THEN total[count] = TRIM(dat)
    count+=1
  WEND
  PRINT#1,"QUIT\n"
  CLOSE(#1)
  FOR cnt = 0 TO count - 2
    Iup::SetAttribute(serverList, "APPENDITEM", total[cnt])
  NEXT
  Iup::SetAttribute(serverList, "VALUE", "1")
  Iup::Update(serverCombo)
  whichDictionary = total[0]
  EXIT SUB

  G_NetError:
  PRINT "Server ",server_selection," not available. (",ERROR,")\n"
END SUB

SUB btnClear_clicked
  Iup::ClearList(serverList)
  Iup::SetAttribute(text, "VALUE", "")
  Iup::SetAttribute(entry, "VALUE", "")
END SUB

SUB btnSearch_clicked
  LOCAL dict, dat, total, info
  IUP::SetAttribute(text, "VALUE","Fetching....")
  ON ERROR GOTO L_NetError
  dict = LEFT(whichDictionary, INSTR(whichDictionary, " "))
  OPEN server_selection & ":2628" FOR SOCKET AS 1
  IF Iup::GetAttribute(chkAll, "VALUE") THEN
    PRINT#1,"DEFINE * " & Iup::GetAttribute(entry,"VALUE") & "\n"
  ELSE
    PRINT#1,"DEFINE " & dict & " " & Iup::GetAttribute(entry,"VALUE") & "\n"
  END IF
  REPEAT
    LINE INPUT#1, dat
    IF LEFT(dat, 3) = "151" THEN
      total$ &= "------------------------------\r\n"
      total$ &= RIGHT(dat, LEN(dat) - LEN(Iup::GetAttribute(entry, "VALUE")) - LEN(dict))
      total$ &= "------------------------------\r\n"
      REPEAT
        LINE INPUT#1, info
        info = REPLACE(info, CHR(34), CHR(92) & CHR(34))
        IF LEFT(info, 1) <> "." THEN total &= TRIM(info) & "\n"
      UNTIL LEFT(info, 1) = "."
      total &= "\n"
    END IF
  UNTIL LEFT(dat, 3) = "250" OR VAL(LEFT(dat, 3)) > 499
  PRINT#1,"QUIT\n"
  CLOSE(#1)
  IF LEFT(dat, 3) = "552" THEN
    total = "No match found."
  ELSE IF LEFT(dat, 3) = "501" THEN
    total = "Select a dictionary first!"
  ELSE IF LEFT(dat, 3) = "550" THEN
    total = "Invalid database!"
  END IF
  Iup::SetAttribute(text, "VALUE", total)
EXIT SUB

L_NetError:
  dat[0] = "Could not lookup word! (" & ERROR & ")"
  Iup::SetAttribute(text, "VALUE", dat)
END SUB

« Last Edit: December 23, 2011, 10:40:38 PM by support »

Support

  • Administrator
  • *****
  • Posts: 19
    • View Profile
Re: IUP Linux and Windows
« Reply #9 on: December 23, 2011, 11:31:55 PM »
I solved my NULL problem. The SB macro for argument processing allows optional parameters if you enclose them with [] brackets. As luck would have it, a NULL argument is passed to the IupButton() as required.

Ihandle* IupButton(const char *title, const char *action);

Quote
title: Text to be shown to the user. It can be NULL. It will set the TITLE attribute.
action: Name of the action generated when the button is selected. It can be NULL.

Code: [Select]
besFUNCTION(PuiButton)
  Ihandle *ih;
  const char *title, *action;

  besARGUMENTS("[z][z]")
    &title, &action
  besARGEND

  ih = IupButton(title, action);
  besRETURN_POINTER(ih);
besEND

I can now pass what I want as the API intended.

btnAbout = Iup::Button()
  Iup::SetAttributes(btnAbout, "TITLE=About, SIZE = 50x")
  Iup::SetCallback(btnAbout, "ACTION", ADDRESS(btnAbout_clicked()))

btnAbout = Iup::Button("About")
  Iup::SetAttributes(btnAbout, "SIZE = 50x")
  Iup::SetCallback(btnAbout, "ACTION", ADDRESS(btnAbout_clicked()))

btnAbout = Iup::Button("About","ACTION")
  Iup::SetAttributes(btnAbout, "SIZE = 50x")
  Iup::SetCallback(btnAbout, "ACTION", ADDRESS(btnAbout_clicked()))

This worked.

btnAbout = Iup::Button("","ACTION")
  Iup::SetAttributes(btnAbout, "TITLE=About, SIZE = 50x")
  Iup::SetCallback(btnAbout, "ACTION", ADDRESS(btnAbout_clicked()))

This didn't.  :(

btnAbout = Iup::Button(,"ACTION")
  Iup::SetAttributes(btnAbout, "TITLE=About, SIZE = 50x")
  Iup::SetCallback(btnAbout, "ACTION", ADDRESS(btnAbout_clicked()))

By enabling the optional argument feature in the SB API, it seems to produce the desired results. I thought at first that I needed to pass a NULL from the SB script but I can't find a good reason to at this point. In the above example, who is going to set the second action argument without setting the title as well?  Skipping optional arguments with a NULL placeholder doesn't seem to be what the author intended. IMHO
« Last Edit: December 24, 2011, 05:19:48 PM by support »

Support

  • Administrator
  • *****
  • Posts: 19
    • View Profile
Re: IUP Linux and Windows
« Reply #10 on: December 25, 2011, 12:47:00 AM »
I think I solved the optional parameters and NULL passing issues I was having. Global attribute functions were the only offender for the most part with needing to pass a NULL for a control handle to make the function use a global attribute. I created a new set of global attribute functions and handled the NULL handle pointer internally.

  • Iup::StoreGlobalAttribute
  • Iup::StoreGlobalAttributeId
  • Iup::SetGlobalAttribute
  • Iup::SetGlobalAttributeId
  • Iup::ResetGlobalAttribute
  • Iup::GetGlobalAttribute
  • Iup::GetGlobalAttributeId
  • Iup::InsertTop


I rewrote the dictionary program to show optional arguments, embedding IUP functions within themselves and multiple children with Vbox & Hbox.

Code: [Select]
IMPORT iup.bas

servers[0]="dict.org"
servers[1]="dict1.us.dict.org"
servers[2]="all.dict.org"

about="""This is a Demo
of the IUP GUI Binding
for Scriptbasic"""

' Initialize IUP
Iup::Open()

' Create main window

win = Iup::SetAttributes(Iup::Dialog(), "TITLE=Thesaurus, SIZE=500x300")
  Iup::SetCallback(win,"CLOSE_CB",ADDRESS(Win_exit()))

' Create server panel

serverCombo = Iup::SetAttributes(Iup::List(), "DROPDOWN=YES, SIZE=120x, EXPAND=HORIZONTAL, VALUE=1")
  Iup::SetCallback(serverCombo, "ACTION", ADDRESS(serverCombo_selected()))
btnFetch = Iup::SetAttributes(Iup::Button(), "TITLE=Fetch, SIZE=50x")
  Iup::SetCallback(btnFetch, "ACTION", ADDRESS(btnFetch_clicked()))
serverFrame = Iup::SetAttributes(Iup::Frame(), "TITLE=Servers, EXPAND=YES")
serverBox = Iup::SetAttributes(Iup::Hbox(serverCombo, btnFetch), "GAP=5")
  Iup::Append(serverFrame, serverBox)
topBox = Iup::SetAttributes(Iup::Hbox(serverFrame), "GAP=10")

' Create control panel

btnAbout = Iup::SetAttributes(Iup::Button(), "TITLE=About, SIZE=50x")
  Iup::SetCallback(btnAbout, "ACTION", ADDRESS(btnAbout_clicked()))
btnClear = Iup::SetAttributes(Iup::Button(), "TITLE=Clear, SIZE=50x")
  Iup::SetCallback(btnClear, "ACTION", ADDRESS(btnClear_clicked()))
btnExit = Iup::SetAttributes(Iup::Button(), "TITLE=Exit, SIZE=50x")
  Iup::SetCallback(btnExit,"ACTION",ADDRESS(Win_exit()))
controlFrame = Iup::SetAttributes(Iup::Frame(), "TITLE=Controls")
  Iup::Append(topBox, controlFrame)
controlBox = Iup::SetAttributes(Iup::Hbox(btnAbout, btnClear, btnExit), "GAP=5")
  Iup::Append(controlFrame, controlBox)

' Create dictionary panel

dictFrame = Iup::SetAttributes(Iup::Frame(), "TITLE=Dictionaries")
serverList = Iup::SetAttributes(Iup::List(), "EXPAND=YES, VISIBLELINES=1")
  Iup::Append(dictFrame, serverList)
  Iup::SetCallback(serverList, "ACTION", ADDRESS(serverList_selected()))

' Create text part

transFrame = Iup::SetAttributes(IUP::Frame(), "TITLE=Translation")
text =   Iup::SetAttributes(Iup::Text(), "MULTILINE=YES, EXPAND=YES")
  Iup::Append(transFrame, text)

' Create entry and search button

label = Iup::SetAttributes(Iup::Label("Enter Word to Search For:"), "SIZE=x12")
entry = Iup::SetAttributes(Iup::Text(), "EXPAND=HORIZONTAL")
btnSearch = Iup::SetAttributes(Iup::Button(),"TITLE=Search, SIZE=50x")
  Iup::SetCallback(btnSearch, "ACTION", ADDRESS(btnSearch_clicked()))
chkAll = Iup::SetAttributes(Iup::Toggle(), "TITLE=ALL, SIZE=x12")
chkUTF = Iup::SetAttributes(Iup::Toggle(), "TITLE=UTF-8, SIZE=x12")
bottomBox = Iup::SetAttributes(Iup::Hbox(label, entry, btnSearch, chkAll, chkUTF), "GAP=10")

' Create container to house ALL GUI objects and add it to the main dialog
vbox = Iup::SetAttributes(Iup::Vbox(topBox, dictFrame, transFrame, bottomBox), "MARGIN=10x10")
Iup::Append(win, vbox)

' Setup dialog defaults

Iup::Show(win)
Iup::SetFocus(btnFetch)
FOR i = 0 TO UBOUND(servers)
  Iup::SetAttribute(serverCombo, "APPENDITEM", servers[i])
NEXT
Iup::SetAttribute(serverCombo, "VALUE", "1")
Iup::Update(serverCombo)
server_selection = servers[0]

' Main processing loop

Iup::MainLoop()
Iup::Close()
END

' Callback routines

SUB Win_exit
  Iup::ExitLoop = TRUE
END SUB

SUB btnAbout_clicked
  Iup::Message("ABOUT", about)
END SUB

SUB serverCombo_selected
  server_selection = Iup::GetListText()
END SUB

SUB serverList_selected
  whichDictionary = Iup::GetListText()
END SUB

SUB btnFetch_clicked
  LOCAL dat, total, count
  ON ERROR GOTO G_NetError
  OPEN server_selection & ":2628" FOR SOCKET AS #1
  PRINT#1,"SHOW DB\n"
  LINE INPUT#1, dat
  LINE INPUT#1, dat
  count = 0
  WHILE LEFT(dat, 1) <> "."
    LINE INPUT#1, dat
    IF LEFT(dat, 1) <> "." THEN total[count] = TRIM(dat)
    count+=1
  WEND
  PRINT#1,"QUIT\n"
  CLOSE(#1)
  FOR cnt = 0 TO count - 2
    Iup::SetAttribute(serverList, "APPENDITEM", total[cnt])
  NEXT
  Iup::SetAttribute(serverList, "VALUE", "1")
  Iup::Update(serverCombo)
  whichDictionary = total[0]
  EXIT SUB

  G_NetError:
  PRINT "Server ",server_selection," not available. (",ERROR,")\n"
END SUB

SUB btnClear_clicked
  Iup::ClearList(serverList)
  Iup::SetAttribute(text, "VALUE", "")
  Iup::SetAttribute(entry, "VALUE", "")
END SUB

SUB btnSearch_clicked
  LOCAL dict, dat, total, info
  IUP::SetAttribute(text, "VALUE","Fetching....")
  ON ERROR GOTO L_NetError
  dict = LEFT(whichDictionary, INSTR(whichDictionary, " "))
  OPEN server_selection & ":2628" FOR SOCKET AS 1
  IF Iup::GetAttribute(chkAll, "VALUE") THEN
    PRINT#1,"DEFINE * " & Iup::GetAttribute(entry,"VALUE") & "\n"
  ELSE
    PRINT#1,"DEFINE " & dict & " " & Iup::GetAttribute(entry,"VALUE") & "\n"
  END IF
  REPEAT
    LINE INPUT#1, dat
    IF LEFT(dat, 3) = "151" THEN
      total$ &= "------------------------------\r\n"
      total$ &= RIGHT(dat, LEN(dat) - LEN(Iup::GetAttribute(entry, "VALUE")) - LEN(dict))
      total$ &= "------------------------------\r\n"
      REPEAT
        LINE INPUT#1, info
        info = REPLACE(info, CHR(34), CHR(92) & CHR(34))
        IF LEFT(info, 1) <> "." THEN total &= TRIM(info) & "\n"
      UNTIL LEFT(info, 1) = "."
      total &= "\n"
    END IF
  UNTIL LEFT(dat, 3) = "250" OR VAL(LEFT(dat, 3)) > 499
  PRINT#1,"QUIT\n"
  CLOSE(#1)
  IF LEFT(dat, 3) = "552" THEN
    total = "No match found."
  ELSE IF LEFT(dat, 3) = "501" THEN
    total = "Select a dictionary first!"
  ELSE IF LEFT(dat, 3) = "550" THEN
    total = "Invalid database!"
  END IF
  Iup::SetAttribute(text, "VALUE", total)
EXIT SUB

L_NetError:
  dat[0] = "Could not lookup word! (" & ERROR & ")"
  Iup::SetAttribute(text, "VALUE", dat)
END SUB

I'll upload a new set of files tomorrow.

« Last Edit: December 25, 2011, 01:02:55 AM by support »

Support

  • Administrator
  • *****
  • Posts: 19
    • View Profile
Re: IUP Linux and Windows
« Reply #11 on: December 25, 2011, 10:58:47 AM »
BUILD 4

I have attached the latest IUP bindings for ScriptBasic Windows 32 and Linux 64. I feel that this version of the library is usable to start creating applications.

Your feedback is appreciated!
« Last Edit: December 25, 2011, 07:08:11 PM by support »

Support

  • Administrator
  • *****
  • Posts: 19
    • View Profile
Re: IUP Linux and Windows - Build 5
« Reply #12 on: December 26, 2011, 07:20:04 PM »
BUILD 5

I was able to get functions that supported a varying number of child controls working internally in C. (IUP Variadic functions) This version will allow the traditional nesting of functions you see commonly in C IUP examples.

Ihandle* IupButton(const char *title, const char *action);  // Support for optional arguments
Iup::Button()
Iup::Button("Button Title")
Iup::Button("Button Title", "ACTION")

Ihandle* IupHbox(Ihandle *child, ...);
Iup::Hbox()
Iup::Hbox(but1, but2, but3)  // Support for multiple children

Code: [Select]
IMPORT iup.bas

Iup::Open()

win = Iup::SetAttributes(Iup::Dialog( _
         Iup::Hbox( _
            Iup::SetAttributes(Iup::Button("Portable"),"EXPAND=HORIZONTAL"), _
            Iup::SetAttributes(Iup::Button("User"),"EXPAND=HORIZONTAL"), _
            Iup::SetAttributes(Iup::Button("Interface"),"EXPAND=HORIZONTAL") _
                  ) _
                                     ),"TITLE=IUP, SIZE=200x40")


Iup::SetCallback(win,"CLOSE_CB",ADDRESS(Win_exit()))

Iup::Show(win)

Iup::MainLoop()
Iup::Close()
END

SUB Win_exit
  Iup::ExitLoop = TRUE
END SUB


« Last Edit: December 28, 2011, 06:27:55 PM by support »

Support

  • Administrator
  • *****
  • Posts: 19
    • View Profile
Re: IUP Linux and Windows
« Reply #13 on: December 28, 2011, 08:54:48 PM »
I was playing around with the IUP control attributes and noticed the FLAT attribute for buttons. With this attribute set to YES, the button looks like a label until you mouse over it.






I'm looking forward to finishing this up and becoming a SB user again. I have a deeper appreciation for all the hard work Peter Verhas put into ScriptBasic after creating this extension module. It didn't hit me how extensive the IUP API was until I already lost site of shore.  :o
« Last Edit: December 28, 2011, 09:01:49 PM by support »

Support

  • Administrator
  • *****
  • Posts: 19
    • View Profile
Re: IUP Linux and Windows
« Reply #14 on: December 29, 2011, 11:49:35 PM »
I was able to get the IUP functions that return lists (C string arrays) to return in a ScriptBasic array. Note that I didn't initialize the variable I passed to the Iup::GetAllNames() function and it returned as a populated SB array. That's another one off the TODO list. I'll post BUILD 6 after a bit more testing of other list baring functions.

Quote
int IupGetAllNames(char** names, int max_n);

Returns the names of all interface elements that have an associated name using IupSetHandle or using LED.

Code: [Select]
num_names = Iup::GetAllNames(names, 0)

FOR x = 0 TO num_names-1
  PRINT names[x],"\n"
NEXT x
PRINT "Number of Names: ",num_names,"\n"

jrs@laptop:~/sb/test$ scriba iupdict.sb
IMGPAPER
IMGCOLLAPSED
Servers  <-- Me
Fetch  <-- Me
IMGEXPANDED
Window  <-- Me
IupSpinDownImage
IUP About  <-- Me
IMGBLANK
IMGLEAF
IupSpinUpImage
Number of Names: 11
jrs@laptop:~/sb/test$


Quote
int IupGetAllClasses(char** names, int max_n);


Returns the names of all registered classes.


jrs@laptop:~/sb/test$ scriba iupdict.sb
dialog
radio
vbox
imagergb
label
tree
sbox
messagedlg
list
fill
image
imagergba
canvas
split
text
submenu
spin
fontdlg
tabs
hbox
val
menu
clipboard
item
frame
timer
multiline
user
normalizer
cbox
button
filedlg
spinbox
colordlg
zbox
separator
toggle
progressbar
Number of Names: 38
jrs@laptop:~/sb/test$

« Last Edit: December 31, 2011, 04:11:29 PM by support »