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.
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