Author Topic: SBx  (Read 8213 times)

Support

  • Administrator
  • *****
  • Posts: 22
    • View Profile
SBx
« on: February 12, 2013, 07:16:54 PM »
I expanded on the SBx IUP wrapper library enough to convert the online dictionary example. (see attached - running on Ubuntu 64) The same code runs on Win7-64 (as a 32 bit application) untouched.

SBx_dict.sb
Code: [Select]
' SBx Online Dictionary

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

INCLUDE "SBx"

' Create main window
win = DIALOG()
  SETPROPERTIES win, "TITLE=\"SBx Dictionary\", SIZE = 500x300"
  SETEVENT win, "CLOSE_CB", ADDRESS(Win_exit())

' Create container to house ALL GUI objects
vbx = VBOX()
  SETPROPERTIES vbx, "MARGIN=10x10"

' Create server panel
topBox = HBOX()
  SETPROPERTIES topBox, "GAP=10"
  APPEND vbx, topBox
serverFrame = FRAME()
  SETPROPERTIES serverFrame, "TITLE=Servers, EXPAND=YES"
  APPEND topBox, serverFrame
serverBox = HBOX()
  SETPROPERTIES serverBox, "GAP=5"
  APPEND serverFrame, serverBox
serverCombo = LIST()
  SETPROPERTIES serverCombo, "DROPDOWN=YES, SIZE=120x, EXPAND=HORIZONTAL, VALUE=1"
  APPEND serverBox, serverCombo
  SETEVENT serverCombo, "ACTION", ADDRESS(serverCombo_selected())
btnFetch = BUTTON()
  SETPROPERTIES btnFetch, "TITLE=Fetch, SIZE = 50x"
  APPEND serverBox, btnFetch
  SETEVENT btnFetch, "ACTION", ADDRESS(btnFetch_clicked())

' Create control panel
controlFrame = FRAME()
  SETPROPERTIES controlFrame, "TITLE=Controls"
  APPEND topBox, controlFrame
controlBox = HBOX()
  SETPROPERTIES controlBox, "GAP=5"
  APPEND controlFrame, controlBox
btnAbout = BUTTON()
  SETPROPERTIES btnAbout, "TITLE=About, SIZE = 50x"
  APPEND controlBox, btnAbout
  SETEVENT btnAbout, "ACTION", ADDRESS(btnAbout_clicked())
btnClear = BUTTON()
  SETPROPERTIES btnClear, "TITLE=Clear, SIZE = 50x"
  APPEND controlBox, btnClear
  SETEVENT btnClear, "ACTION", ADDRESS(btnClear_clicked())
btnExit = BUTTON()
  SETPROPERTIES btnExit, "TITLE=Exit, SIZE = 50x"
  APPEND controlBox, btnExit
  SETEVENT btnExit,"ACTION",ADDRESS(Win_exit())

' Create dictionary panel
dictFrame = FRAME()
  SETPROPERTIES dictFrame, "TITLE=\"Dictionaries\""
  APPEND vbx, dictFrame
serverList = LIST()
  SETPROPERTIES serverList, "EXPAND=YES, VISIBLELINES=1"
  APPEND dictFrame, serverList
  SETEVENT serverList, "ACTION", ADDRESS(serverList_selected())

' Create text part
transFrame = FRAME()
  SETPROPERTIES transFrame, "TITLE=\"Translation\""
  APPEND vbx, transFrame
txt = TEXT()
  SETPROPERTIES txt, "MULTILINE=YES, EXPAND=YES"
  APPEND transFrame, txt


' Create entry and search button
bottomBox = HBOX()
  SETPROPERTIES bottomBox, "GAP=10"
  APPEND vbx, bottomBox
lbl = LABEL()
  SETPROPERTIES lbl, "TITLE=\"Enter Word to Search For:\", SIZE=x12"
  APPEND bottomBox, lbl
entry = TEXT()
  SETPROPERTIES entry, "EXPAND=HORIZONTAL"
  APPEND bottomBox, entry
btnSearch = BUTTON()
  SETPROPERTIES btnSearch,"TITLE=Search, SIZE=50x"
  APPEND bottomBox, btnSearch
  SETEVENT btnSearch, "ACTION", ADDRESS(btnSearch_clicked())
chkAll = TOGGLE()
  SETPROPERTIES chkAll, "TITLE=ALL, SIZE=x12"
  APPEND bottomBox, chkAll
chkUTF = TOGGLE()
  SETPROPERTIES chkUTF, "TITLE=UTF-8, SIZE=x12"
  APPEND bottomBox, chkUTF

' Add the main GUI container to the Window
APPEND win, vbx

' Setup dialog defaults
SHOW win
FOCUS btnFetch
FOR i = 0 TO UBOUND(servers)
  SETPROPERTY serverCombo, "APPENDITEM", servers[i]
NEXT
SETPROPERTY serverCombo, "VALUE", "1"
UPDATE serverCombo
server_selection = servers[0]
GETEVENT()
END


' Callback routines

SUB Win_exit
  Iup::ExitLoop = TRUE
END SUB

SUB btnAbout_clicked
  MESSAGE "ABOUT", about
END SUB

SUB serverCombo_selected
  server_selection = GETITEM()
END SUB

SUB serverList_selected
  whichDictionary = GETITEM()
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
    SETPROPERTY serverList, "APPENDITEM", total[cnt]
  NEXT
  SETPROPERTY serverList, "VALUE", "1"
  UPDATE serverCombo
  whichDictionary = total[0]
  EXIT SUB

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

SUB btnClear_clicked
  CLEAR serverList
  SETPROPERTY txt, "VALUE", ""
  SETPROPERTY entry, "VALUE", ""
END SUB

SUB btnSearch_clicked
  LOCAL dict, dat, total, info
  SETPROPERTY txt, "VALUE", "Fetching...."
  ON ERROR GOTO L_NetError
  dict = LEFT(whichDictionary, INSTR(whichDictionary, " "))
  OPEN server_selection & ":2628" FOR SOCKET AS 1
  IF GETPROPERTY(chkAll, "VALUE") THEN
    PRINT#1,"DEFINE * " & GETPROPERTY(entry, "VALUE") & "\n"
  ELSE
    PRINT#1,"DEFINE " & dict & " " & GETPROPERTY(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(GETPROPERTY(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
  SETPROPERTY txt, "VALUE", total
EXIT SUB

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

SBx
Code: [Select]
' ScriptBasic IUP Interface

IMPORT iup.bas

Iup::Open()

FUNCTION DIALOG
  DIALOG = Iup::Create("dialog")
END FUNCTION

SUB SETPROPERTIES(ih, propstr)
  Iup::SetAttributes(ih, propstr)
END SUB

SUB SETPROPERTY(ih, typ, value)
  Iup::SetAttribute(ih, typ, value)
END SUB

FUNCTION GETPROPERTY(ih, typ)
  GETPROPERTY = Iup::GetAttribute(ih, typ)
END FUNCTION

FUNCTION VBOX
  VBOX = Iup::Create("vbox")
END FUNCTION

FUNCTION HBOX
  HBOX = Iup::Create("hbox")
END FUNCTION

FUNCTION FRAME
  FRAME = Iup::Create("frame")
END FUNCTION

FUNCTION BUTTON
  BUTTON = Iup::Create("button")
END FUNCTION

FUNCTION LIST
  LIST = Iup::Create("list")
END FUNCTION

FUNCTION TEXT
  TEXT = Iup::Create("text")
END FUNCTION

FUNCTION LABEL
  LABEL = Iup::Create("label")
END FUNCTION

FUNCTION TOGGLE
  TOGGLE = Iup::Create("toggle")
END FUNCTION

SUB MESSAGE(title, body)
  Iup::Message(title, body)
END SUB

FUNCTION GETITEM
  GETITEM = Iup::GetListText()
END FUNCTION
 
SUB APPEND(ih_to, ih_from)
  Iup::Append(ih_to, ih_from)
END SUB

FUNCTION FOCUS(ih)
  FOCUS = Iup::SetFocus(ih)
END FUNCTION

FUNCTION UPDATE(ih)
  UPDATE = Iup::Update(ih)
END FUNCTION

SUB CLEAR(ih)
  Iup::ClearList(ih)
END SUB

SUB SETEVENT(ih, class, funcaddr)
  Iup::SetCallback(ih, class,  funcaddr)
END SUB

SUB SHOW(ih)
  Iup::Show(ih)
END SUB  

SUB GETEVENT
  Iup::MainLoop
  Iup::Close
END SUB
« Last Edit: February 12, 2013, 11:25:55 PM by support »