Author Topic: Script BASIC IUP 3.16  (Read 4555 times)

Offline John

  • Forum Support / SB Dev
  • Posts: 3511
    • ScriptBasic Open Source Project
Script BASIC IUP 3.16
« on: November 03, 2015, 12:40:37 PM »
I just rebuilt the IUP extension module for the latest 3.16 release for Window 32 bit. Here is the traditional GUI toolkit Hello World we have been using.



Code: ScriptBasic
  1. IMPORT iup.bas
  2.  
  3. servers[0]="dict.org"
  4. servers[1]="dict1.us.dict.org"
  5. servers[2]="all.dict.org"
  6.  
  7. about="""This is a Demo
  8. of the IUP GUI Binding
  9. for Scriptbasic"""
  10.  
  11. ' Initialize IUP
  12. Iup::Open()
  13.  
  14. ' Create main window
  15.  
  16. win = Iup::Create("dialog")
  17.   Iup::SetAttributes(win, "TITLE=\"ScriptBasic IUP Online Dictionary\", SIZE=500x300")
  18.   Iup::SetCallback(win,"CLOSE_CB",ADDRESS(Win_exit()))
  19.  
  20. ' Create container to house ALL GUI objects
  21.  
  22. vbox = Iup::Create("vbox")
  23.   Iup::SetAttributes(vbox, "MARGIN=10x10")
  24.  
  25. ' Create server panel
  26.  
  27. topBox = Iup::Create("hbox")
  28.   Iup::SetAttributes(topBox, "GAP=10")
  29.   Iup::Append(vbox, topBox)
  30. serverFrame = Iup::Create("frame")
  31.   Iup::SetAttributes(serverFrame, "TITLE=Servers, EXPAND=YES")
  32.   Iup::Append(topBox, serverFrame)
  33. serverBox = Iup::Create("hbox")
  34.   Iup::SetAttributes(serverBox, "GAP=5")
  35.   Iup::Append(serverFrame, serverBox)
  36. serverCombo = Iup::Create("list")
  37.   Iup::SetAttributes(serverCombo, "DROPDOWN=YES, SIZE=120x, EXPAND=HORIZONTAL, VALUE=1")
  38.   Iup::Append(serverBox, serverCombo)
  39.   Iup::SetCallback(serverCombo, "ACTION", ADDRESS(serverCombo_selected()))
  40. btnFetch = Iup::Create("button")
  41.   Iup::SetAttributes(btnFetch, "TITLE=Fetch, SIZE = 50x")
  42.   Iup::Append(serverBox, btnFetch)
  43.   Iup::SetCallback(btnFetch, "ACTION", ADDRESS(btnFetch_clicked()))
  44.  
  45. ' Create control panel
  46.  
  47. controlFrame = Iup::Create("frame")
  48.   Iup::SetAttributes(controlFrame, "TITLE=Controls")
  49.   Iup::Append(topBox, controlFrame)
  50. controlBox = Iup::Create("hbox")
  51.   Iup::SetAttributes(controlBox, "GAP=5")
  52.   Iup::Append(controlFrame, controlBox)
  53. btnAbout = Iup::Create("button")
  54.   Iup::SetAttributes(btnAbout, "TITLE=About, SIZE = 50x")
  55.   Iup::Append(controlBox, btnAbout)
  56.   Iup::SetCallback(btnAbout, "ACTION", ADDRESS(btnAbout_clicked()))
  57. btnClear = Iup::Create("button")
  58.   Iup::SetAttributes(btnClear, "TITLE=Clear, SIZE = 50x")
  59.   Iup::Append(controlBox, btnClear)
  60.   Iup::SetCallback(btnClear, "ACTION", ADDRESS(btnClear_clicked()))
  61. btnExit = Iup::Create("button")
  62.   Iup::SetAttributes(btnExit, "TITLE=Exit, SIZE = 50x")
  63.   Iup::Append(controlBox, btnExit)
  64.   Iup::SetCallback(btnExit,"ACTION",ADDRESS(Win_exit()))
  65.  
  66. ' Create dictionary panel
  67.  
  68. dictFrame = Iup::Create("frame")
  69.   Iup::SetAttributes(dictFrame, "TITLE=Dictionaries")
  70.   Iup::Append(vbox, dictFrame)
  71. serverList = Iup::Create("list")
  72.   Iup::SetAttributes(serverList, "EXPAND=YES, VISIBLELINES=1")
  73.   Iup::Append(dictFrame, serverList)
  74.   Iup::SetCallback(serverList, "ACTION", ADDRESS(serverList_selected()))
  75.  
  76. ' Create text part
  77.  
  78. transFrame = IUP::Create("frame")
  79.   Iup::SetAttributes(transFrame, "TITLE=Translation")
  80.   Iup::Append(vbox, transFrame)
  81. text = Iup::Create("text")
  82.   Iup::SetAttributes(text, "MULTILINE=YES, EXPAND=YES")
  83.   Iup::Append(transFrame, text)
  84.  
  85. ' Create entry and search button
  86.  
  87. bottomBox = Iup::Create("hbox")
  88.   Iup::SetAttributes(bottomBox, "GAP=10")
  89.   Iup::Append(vbox, bottomBox)
  90. label = Iup::Create("label")
  91.   Iup::SetAttributes(label, "TITLE=\"Enter Word to Search For:\", SIZE=x12")
  92.   Iup::Append(bottomBox, label)
  93. entry = Iup::Create("text")
  94.   Iup::SetAttributes(entry, "EXPAND=HORIZONTAL")
  95.   Iup::Append(bottomBox, entry)
  96. btnSearch = Iup::Create("button")
  97.   Iup::SetAttributes(btnSearch,"TITLE=Search, SIZE=50x")
  98.   Iup::Append(bottomBox, btnSearch)
  99.   Iup::SetCallback(btnSearch, "ACTION", ADDRESS(btnSearch_clicked()))
  100. chkAll = Iup::Create("toggle")
  101.   Iup::SetAttributes(chkAll, "TITLE=ALL, SIZE=x12")
  102.   Iup::Append(bottomBox, chkAll)
  103. chkUTF = Iup::Create("toggle")
  104.   Iup::SetAttributes(chkUTF, "TITLE=UTF-8, SIZE=x12")
  105.   Iup::Append(bottomBox, chkUTF)
  106.  
  107. ' Add the main GUI container to the Window
  108.  
  109. Iup::Append(win, vbox)
  110.  
  111. ' Setup dialog defaults
  112.  
  113. Iup::Show(win)
  114. Iup::SetFocus(btnFetch)
  115. FOR i = 0 TO UBOUND(servers)
  116.   Iup::SetAttribute(serverCombo, "APPENDITEM", servers[i])
  117. NEXT
  118. Iup::SetAttribute(serverCombo, "VALUE", "1")
  119. Iup::Update(serverCombo)
  120. server_selection = servers[0]
  121.  
  122. ' Main processing loop
  123.  
  124. Iup::MainLoop()
  125. Iup::Close()
  126. END
  127.  
  128. ' Callback routines
  129.  
  130. SUB Win_exit
  131.   Iup::ExitLoop = TRUE
  132. END SUB
  133.  
  134. SUB btnAbout_clicked
  135.   Iup::Message("ABOUT", about)
  136. END SUB
  137.  
  138. SUB serverCombo_selected
  139.   server_selection = Iup::GetListText()
  140. END SUB
  141.  
  142. SUB serverList_selected
  143.   whichDictionary = Iup::GetListText()
  144. END SUB
  145.  
  146. SUB btnFetch_clicked
  147.   LOCAL dat, total, count
  148.   ON ERROR GOTO G_NetError
  149.   OPEN server_selection & ":2628" FOR SOCKET AS #1
  150.   PRINT#1,"SHOW DB\n"
  151.   LINE INPUT#1, dat
  152.   LINE INPUT#1, dat
  153.   count = 0
  154.   WHILE LEFT(dat, 1) <> "."
  155.     LINE INPUT#1, dat
  156.     IF LEFT(dat, 1) <> "." THEN total[count] = TRIM(dat)
  157.     count+=1
  158.   WEND
  159.   PRINT#1,"QUIT\n"
  160.   CLOSE(#1)
  161.   FOR cnt = 0 TO count - 2
  162.     Iup::SetAttribute(serverList, "APPENDITEM", total[cnt])
  163.   NEXT
  164.   Iup::SetAttribute(serverList, "VALUE", "1")
  165.   Iup::Update(serverCombo)
  166.   whichDictionary = total[0]
  167.   EXIT SUB
  168.  
  169.   G_NetError:
  170.   PRINT "Server ",server_selection," not available. (",ERROR,")\n"
  171. END SUB
  172.  
  173. SUB btnClear_clicked
  174.   Iup::ClearList(serverList)
  175.   Iup::SetAttribute(text, "VALUE", "")
  176.   Iup::SetAttribute(entry, "VALUE", "")
  177. END SUB
  178.  
  179. SUB btnSearch_clicked
  180.   LOCAL dict, dat, total, info
  181.   IUP::SetAttribute(text, "VALUE","Fetching....")
  182.   ON ERROR GOTO L_NetError
  183.   dict = LEFT(whichDictionary, INSTR(whichDictionary, " "))
  184.   OPEN server_selection & ":2628" FOR SOCKET AS 1
  185.   IF Iup::GetAttribute(chkAll, "VALUE") THEN
  186.     PRINT#1,"DEFINE * " & Iup::GetAttribute(entry,"VALUE") & "\n"
  187.   ELSE
  188.     PRINT#1,"DEFINE " & dict & " " & Iup::GetAttribute(entry,"VALUE") & "\n"
  189.   END IF
  190.   REPEAT
  191.     LINE INPUT#1, dat
  192.     IF LEFT(dat, 3) = "151" THEN
  193.       total$ &= "------------------------------\r\n"
  194.       total$ &= RIGHT(dat, LEN(dat) - LEN(Iup::GetAttribute(entry, "VALUE")) - LEN(dict))
  195.       total$ &= "------------------------------\r\n"
  196.       REPEAT
  197.         LINE INPUT#1, info
  198.         info = REPLACE(info, CHR(34), CHR(92) & CHR(34))
  199.         IF LEFT(info, 1) <> "." THEN total &= TRIM(info) & "\n"
  200.       UNTIL LEFT(info, 1) = "."
  201.       total &= "\n"
  202.     END IF
  203.   UNTIL LEFT(dat, 3) = "250" OR VAL(LEFT(dat, 3)) > 499
  204.   PRINT#1,"QUIT\n"
  205.   CLOSE(#1)
  206.   IF LEFT(dat, 3) = "552" THEN
  207.     total = "No match found."
  208.   ELSE IF LEFT(dat, 3) = "501" THEN
  209.     total = "Select a dictionary first!"
  210.   ELSE IF LEFT(dat, 3) = "550" THEN
  211.     total = "Invalid database!"
  212.   END IF
  213.   Iup::SetAttribute(text, "VALUE", total)
  214. EXIT SUB
  215.  
  216. L_NetError:
  217.   dat[0] = "Could not lookup word! (" & ERROR & ")"
  218.   Iup::SetAttribute(text, "VALUE", dat)
  219. END SUB
  220.  
« Last Edit: November 03, 2015, 12:42:30 PM by John »

Offline John

  • Forum Support / SB Dev
  • Posts: 3511
    • ScriptBasic Open Source Project
Re: Script BASIC IUP 3.16
« Reply #1 on: November 03, 2015, 04:21:39 PM »
Here is another IUP example using the SBx wrapper I started on to make IUP easier to use.



Code: ScriptBasic
  1. ' SBx_buttons Example
  2.  
  3. INCLUDE "SBx"
  4.  
  5. SUB Btn1_clicked
  6.   PRINT "BUTTON 1 Event\n"
  7. END SUB
  8.  
  9. SUB Btn2_clicked
  10.   PRINT "BUTTON 2 Event\n"
  11. END SUB
  12.  
  13. SUB Btn3_clicked
  14.   PRINT "BUTTON 3 Event\n"
  15. END SUB
  16.  
  17. SUB Win_exit
  18.   Iup::ExitLoop = TRUE
  19. END SUB
  20.  
  21.  
  22. win = WINDOW()
  23. SETPROPERTY(win, "TITLE=\"SBx Buttons\", SIZE=300x")
  24. horzbox = HBOX()
  25. SETPROPERTY(horzbox, "GAP=5")
  26. btn1 = BUTTON()
  27. SETPROPERTY(btn1, "TITLE=Button1, EXPAND=HORIZONTAL")
  28. btn2 = BUTTON()
  29. SETPROPERTY(btn2, "TITLE=Button2, EXPAND=HORIZONTAL")
  30. btn3 = BUTTON()
  31. SETPROPERTY(btn3, "TITLE=Button3, EXPAND=HORIZONTAL")
  32. APPEND(horzbox, btn1)
  33. APPEND(horzbox, btn2)
  34. APPEND(horzbox, btn3)
  35. APPEND(win, horzbox)
  36. EVENT(win,"CLOSE_CB",ADDRESS(Win_exit()))
  37. EVENT(btn1,"ACTION",ADDRESS(Btn1_clicked()))
  38. EVENT(btn2,"ACTION",ADDRESS(Btn2_clicked()))
  39. EVENT(btn3,"ACTION",ADDRESS(Btn3_clicked()))
  40. SHOW(win)
  41.  

SBx Include
Code: ScriptBasic
  1. ' ScriptBasic IUP Interface
  2.  
  3. IMPORT iup.bas
  4.  
  5. Iup::Open()
  6.  
  7. FUNCTION WINDOW
  8.   WINDOW = Iup::Create("dialog")
  9. END FUNCTION
  10.  
  11. SUB SETPROPERTY(ih, propstr)
  12.   Iup::SetAttributes(ih, propstr)
  13. END SUB
  14.  
  15. FUNCTION HBOX
  16.   HBOX = Iup::Create("hbox")
  17. END FUNCTION
  18.  
  19. FUNCTION BUTTON
  20.   BUTTON = Iup::Create("button")
  21. END FUNCTION
  22.  
  23. SUB APPEND(ih_to, ih_from)
  24.   Iup::Append(ih_to, ih_from)
  25. END SUB
  26.  
  27. SUB EVENT(ih, class, funcaddr)
  28.   Iup::SetCallback(ih, class,  funcaddr)
  29. END SUB
  30.  
  31. FUNCTION SHOW(ih)
  32.   Iup::Show(ih)
  33.   Iup::MainLoop
  34.   Iup::Close
  35. END FUNCTION  
  36.  

Output

C:\scriptbasic\examples>sbiup SBx_buttons
BUTTON 1 Event
BUTTON 2 Event
BUTTON 3 Event

C:\scriptbasic\examples>