Extension Modules > IUP
IUP Linux and Windows
Support:
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
[/list]
I rewrote the dictionary program to show optional arguments, embedding IUP functions within themselves and multiple children with Vbox & Hbox.
--- Code: ---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
--- End code ---
I'll upload a new set of files tomorrow.
Support:
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!
Support:
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: ---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
--- End code ---
Support:
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
Support:
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.
--- End quote ---
--- Code: ---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"
--- End code ---
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.
--- End quote ---
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$
Navigation
[0] Message Index
[#] Next page
[*] Previous page
Go to full version