Open Forum > Business BASIC Migrations

ProvideX Linux 64 IUP

(1/1)

Support:
Here is an example of an online dictionary program written in ProvideX (PxBasic) for Ubuntu 64 bit and using the IUP (Portable User Interface) with an interface shared object I wrote.

Update: I included a screen shot of the Windows version of ProvideX and IUP. Theming isn't working but the goal was to show the same PVX code running native GUI on Linux and Windows.


--- Code: Text ---! Online Dictionary - Px* + IUP BEGIN lib = DLL(ADDR "/home/jrs/pxbasic/pxbiup.so") DIM servers$[0]servers$[0]="dict.org" about$ = "ProvideX IUP Binding" ! Initialize IUPok = DLL(lib, "IupOpen") ! Create main window win = DLL(lib, "IupCreate", "dialog"+$00$)  ok = DLL(lib, "IupSetAttributes", win, "TITLE="+QUO+"Online Dictionary - ProvideX/IUP"+QUO+", SIZE=500x300"+$00$)  ok = DLL(lib, "PxBSetCallback", win,"CLOSE_CB"+$00$) ! Create container to house ALL GUI objects vbox = DLL(lib, "IupCreate", "vbox"+$00$)  ok = DLL(lib, "IupSetAttributes", vbox, "MARGIN=10x10"+$00$) ! Create server panel topBox = DLL(lib, "IupCreate", "hbox"+$00$)  ok = DLL(lib, "IupSetAttributes", topBox, "GAP=10"+$00$)  ok = DLL(lib, "IupAppend", vbox, topBox)serverFrame = DLL(lib, "IupCreate", "frame"+$00$)  ok = DLL(lib, "IupSetAttributes", serverFrame, "TITLE=Servers, EXPAND=YES"+$00$)  ok = DLL(lib, "IupAppend", topBox, serverFrame)serverBox = DLL(lib, "IupCreate", "hbox"+$00$)  ok = DLL(lib, "IupSetAttributes", serverBox, "GAP=5"+$00$)  ok = DLL(lib, "IupAppend", serverFrame, serverBox)serverCombo = DLL(lib, "IupCreate", "list"+$00$)  ok = DLL(lib, "IupSetAttributes", serverCombo, "DROPDOWN=YES, SIZE=120x, EXPAND=HORIZONTAL, VALUE=1"+$00$)  ok = DLL(lib, "IupAppend", serverBox, serverCombo)  ok = DLL(lib, "PxBSetCallback", serverCombo, "ACTION"+$00$)btnFetch = DLL(lib, "IupCreate", "button"+$00$)  ok = DLL(lib, "IupSetAttributes", btnFetch, "TITLE=Fetch, SIZE = 50x"+$00$)  ok = DLL(lib, "IupAppend", serverBox, btnFetch)  ok = DLL(lib, "PxBSetCallback", btnFetch, "ACTION"+$00$) ! Create control panel controlFrame = DLL(lib, "IupCreate", "frame"+$00$)  ok = DLL(lib, "IupSetAttributes", controlFrame, "TITLE=Controls"+$00$)  ok = DLL(lib, "IupAppend", topBox, controlFrame)controlBox = DLL(lib, "IupCreate", "hbox"+$00$)  ok = DLL(lib, "IupSetAttributes", controlBox, "GAP=5"+$00$)  ok = DLL(lib, "IupAppend", controlFrame, controlBox)btnAbout = DLL(lib, "IupCreate", "button"+$00$)  ok = DLL(lib, "IupSetAttributes", btnAbout, "TITLE=About, SIZE = 50x"+$00$)  ok = DLL(lib, "IupAppend", controlBox, btnAbout)  ok = DLL(lib, "PxBSetCallback", btnAbout, "ACTION"+$00$)btnClear = DLL(lib, "IupCreate", "button"+$00$)  ok = DLL(lib, "IupSetAttributes", btnClear, "TITLE=Clear, SIZE = 50x"+$00$)  ok = DLL(lib, "IupAppend", controlBox, btnClear)  ok = DLL(lib, "PxBSetCallback", btnClear, "ACTION"+$00$)btnExit = DLL(lib, "IupCreate", "button"+$00$)  ok = DLL(lib, "IupSetAttributes", btnExit, "TITLE=Exit, SIZE = 50x"+$00$)  ok = DLL(lib, "IupAppend", controlBox, btnExit)  ok = DLL(lib, "PxBSetCallback", btnExit,"ACTION"+$00$) ! Create dictionary panel dictFrame = DLL(lib, "IupCreate", "frame"+$00$)  ok = DLL(lib, "IupSetAttributes", dictFrame, "TITLE=Dictionaries"+$00$)  ok = DLL(lib, "IupAppend", vbox, dictFrame)serverList = DLL(lib, "IupCreate", "list"+$00$)  ok = DLL(lib, "IupSetAttributes", serverList, "EXPAND=YES, VISIBLELINES=1"+$00$)  ok = DLL(lib, "IupAppend", dictFrame, serverList)  ok = DLL(lib, "PxBSetCallback", serverList, "ACTION"+$00$) ! Create text part transFrame = DLL(lib, "IupCreate", "frame"+$00$)  ok = DLL(lib, "IupSetAttributes", transFrame, "TITLE=Translation"+$00$)  ok = DLL(lib, "IupAppend", vbox, transFrame)text = DLL(lib, "IupCreate", "text"+$00$)  ok = DLL(lib, "IupSetAttributes", text, "MULTILINE=YES, EXPAND=YES"+$00$)  ok = DLL(lib, "IupAppend", transFrame, text) ! Create entry and search button bottomBox = DLL(lib, "IupCreate", "hbox"+$00$)  ok = DLL(lib, "IupSetAttributes", bottomBox, "GAP=10"+$00$)  ok = DLL(lib, "IupAppend", vbox, bottomBox)label = DLL(lib, "IupCreate", "label"+$00$)  ok = DLL(lib, "IupSetAttributes", label, "TITLE="+QUO+"Enter Word to Search For:"+QUO+", SIZE=x12"+$00$)  ok = DLL(lib, "IupAppend", bottomBox, label)entry = DLL(lib, "IupCreate", "text"+$00$)  ok = DLL(lib, "IupSetAttributes", entry, "EXPAND=HORIZONTAL"+$00$)  ok = DLL(lib, "IupAppend", bottomBox, entry)btnSearch = DLL(lib, "IupCreate", "button"+$00$)  ok = DLL(lib, "IupSetAttributes", btnSearch, "TITLE=Search, SIZE=50x"+$00$)  ok = DLL(lib, "IupAppend", bottomBox, btnSearch)  ok = DLL(lib, "PxBSetCallback", btnSearch, "ACTION"+$00$)chkAll = DLL(lib, "IupCreate","toggle"+$00$)  ok = DLL(lib, "IupSetAttributes", chkAll, "TITLE=ALL, SIZE=x12"+$00$)  ok = DLL(lib, "IupAppend", bottomBox, chkAll)chkUTF = DLL(lib, "IupCreate", "toggle"+$00$)  ok = DLL(lib, "IupSetAttributes", chkUTF, "TITLE=UTF-8, SIZE=x12"+$00$)  ok = DLL(lib, "IupAppend", bottomBox, chkUTF) ! Add the main GUI container to the Window ok = DLL(lib, "IupAppend", win, vbox) ! Setup dialog defaults ok = DLL(lib, "IupShow", win)ok = DLL(lib, "IupSetFocus", btnFetch)FOR i = 0 TO DIM(READ MAX(servers$))  ok = DLL(lib, "IupSetAttribute", serverCombo, "APPENDITEM"+$00$, servers$[i]+$00$)NEXTok = DLL(lib, "IupSetAttribute", serverCombo, "VALUE"+$00$, "1"+$00$)ok = DLL(lib, "IupUpdate", serverCombo)server_selection$ = servers$[0] ! Main processing loop REPEAT  WAIT: ok = DLL(lib, "IupLoopStepWait")  this_event = DLL(lib, "GetEvent")  IF NOT(this_event) THEN GOTO WAIT  SWITCH this_event    CASE serverCombo      GOSUB serverCombo_selected      BREAK    CASE btnFetch      GOSUB btnFetch_clicked      BREAK    CASE btnAbout      GOSUB btnAbout_clicked      BREAK    CASE btnClear      GOSUB btnClear_clicked      BREAK    CASE serverList      GOSUB serverList_selected      BREAK    CASE btnSearch      GOSUB btnSearch_clicked      BREAK  END SWITCHUNTIL this_event = win OR this_event = btnExitok = DLL(lib, "IupClose")ok = DLL(DROP lib)END ! Callback routines btnAbout_clicked:  ok = DLL(lib, "IupMessage", "ABOUT"+$00$, about$)RETURN serverCombo_selected:  DIM server_selection$(1024)  ok = DLL(lib, "GetListSelectedText", server_selection$)  server_selection$ = STP(server_selection$, 2)RETURN serverList_selected:  DIM whichDictionary$(1024)  ok = DLL(lib, "GetListSelectedText", whichDictionary$)  whichDictionary$ = STP(whichDictionary$, 2)RETURN btnFetch_clicked:  dat$ = ""  DIM _total$[*]  count = 1  OPEN (1,BSZ=16384)"[TCP]"+server_selection$+";2628;NoDelay;stream"  WRITE (1)"SHOW DB"+$0D0A$  REPEAT    READ(1)raw_data$    dat$ = dat$ + raw_data$  UNTIL POS("250 ok" = raw_data$)  WRITE(1)"QUIT"+$0D0A$  CLOSE(1)  REPEAT    eol = POS($0D0A$=dat$)    _total$[count] = dat$(1,eol - 1)    dat$ = dat$(eol + 2)    count += 1  UNTIL dat$ = ""  FOR cnt = 3 TO count - 3    ok = DLL(lib, "IupSetAttribute", serverList, "APPENDITEM"+$00$, _total$[cnt]+$00$)   NEXT cnt  ok = DLL(lib, "IupSetAttribute", serverList, "APPENDITEM"+$00$, _total$[3]+$00$)  ok = DLL(lib, "IupSetAttribute", serverList, "VALUE"+$00$, "1"+$00$)  ok = DLL(lib, "IupUpdate", serverCombo)  whichDictionary$ = _total$[3]RETURN G_NetError:  PRINT "Server ",server_selection$," not available. (",ERROR,")"RETURN btnClear_clicked:  ok = DLL(lib, "IupSetAttribute", serverList,"1"+$00$)  ok = DLL(lib, "IupSetAttribute", text, "VALUE"+$00$, ""+$00$)  ok = DLL(lib, "IupSetAttribute", entry, "VALUE"+$00$, ""+$00$)RETURN btnSearch_clicked:  dict$ = ""  dat$ = ""  total$ = ""  info$ = ""  ok = DLL(lib, "IupSetAttribute", text, "VALUE"+$00$, "Fetching...."+$00$)  dict$ = whichDictionary$(1, POS(" " = whichDictionary$) - 1)  OPEN (1,BSZ=16384)"[TCP]"+server_selection$+";2628;NoDelay;stream"  chkval$ = FNIupGetString$(DLL(lib, "IupGetAttribute", chkAll, "VALUE"+$00$))  IF chkval$ = "ON" THEN {    WRITE(1)"DEFINE * " + FNIupGetString$(DLL(lib, "IupGetAttribute", entry,"VALUE"+$00$)) + $0D0A$  } ELSE {    WRITE(1)"DEFINE " + dict$ + " " + FNIupGetString$(DLL(lib, "IupGetAttribute", entry,"VALUE"+$00$)) + $0D0A$  }  REPEAT    READ(1)raw_data$    data_str$ = data_str$ + raw_data$  UNTIL POS("250 ok [d/m/c =" = raw_data$)  WRITE(1)"QUIT"+$0D0A$  CLOSE(1)  ! Remove header  data_str$ = data_str$(POS($0D0A$=data_str$, 1, 2) + 2)  REPEAT    eol = POS($0D0A$=data_str$)    dat$ = data_str$(1,eol - 1)    data_str$ = data_str$(eol + 2)    IF dat$(1, 3) <> "151" THEN GOTO IT      entstr$ = FNIupGetString$(DLL(lib, "IupGetAttribute", entry, "VALUE"+$00$))      total$ = total$ + "------------------------------" + $0D0A$      total$ = total$ + dat$(2 + LEN(entstr$) + LEN(dict$)) + $0D0A$      total$ = total$ + "------------------------------"+ $0D0A$      REPEAT        eol = POS($0D0A$=data_str$)        info$ = data_str$(1,eol - 1)        data_str$ = data_str$(eol + 2)        info$ = SUB(info$, CHR(34), CHR(92) + CHR(34))        IF LEN(info$) AND info$(1, 1) <> "." THEN total$ += STP(info$, 2) + $0D0A$      UNTIL info$ > "" AND info$(1, 1) = "."      total$ += $0D0A$    IT:  UNTIL data_str$(1, 3) = "250" OR NUM(data_str$(1, 3)) > 499  IF dat$(1, 3) = "552" THEN total$ = "No match found."  IF dat$(1, 3) = "501" THEN total$ = "Select a dictionary first!"  IF dat$(1, 3) = "550" THEN total$ = "Invalid database!"  ok = DLL(lib, "IupSetAttribute", text, "VALUE"+$00$, total$+$00$)RETURN L_NetError:  dat$ = "Could not lookup word! (" + STR(ERR) + ")"  ok = DLL(lib, "IupSetAttribute", text, "VALUE"+$00$, dat$+$00$)RETURN ! DLL() return string emulator DEF FNIupGetString$(LOCAL i_ptr)  LOCAL strlen, pxbuff$  DIM pxbuff$(4096)  strlen = DLL(lib, "ptr2pxbstr", i_ptr, pxbuff$)  RETURN pxbuff$(1,strlen)END DEF 

Support:
This is the Online Dictionary example running under Script BASIC for Windows 64 bit. I used my IUP wrapper library to make the code easier to read.


--- Code: Script BASIC ---' SBx Online Dictionary servers[0]="dict.org"servers[1]="dict1.us.dict.org"servers[2]="all.dict.org" about="""This is a Demoof the IUP GUI Bindingfor Scriptbasic""" INCLUDE "SBx" ' Create main windowwin = DIALOG()  SETPROPERTIES win, "TITLE=\"Script BASIC/IUP 64 bit Online Dictionary\", SIZE = 500x300"  SETEVENT win, "CLOSE_CB", ADDRESS(Win_exit()) ' Create container to house ALL GUI objectsvbx = VBOX()  SETPROPERTIES vbx, "MARGIN=10x10" ' Create server paneltopBox = HBOX()  SETPROPERTIES topBox, "GAP=10"  APPEND vbx, topBoxserverFrame = FRAME()  SETPROPERTIES serverFrame, "TITLE=Servers, EXPAND=YES"  APPEND topBox, serverFrameserverBox = HBOX()  SETPROPERTIES serverBox, "GAP=5"  APPEND serverFrame, serverBoxserverCombo = 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 panelcontrolFrame = FRAME()  SETPROPERTIES controlFrame, "TITLE=Controls"  APPEND topBox, controlFramecontrolBox = HBOX()  SETPROPERTIES controlBox, "GAP=5"  APPEND controlFrame, controlBoxbtnAbout = 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 paneldictFrame = FRAME()  SETPROPERTIES dictFrame, "TITLE=\"Dictionaries\""  APPEND vbx, dictFrameserverList = LIST()  SETPROPERTIES serverList, "EXPAND=YES, VISIBLELINES=1"  APPEND dictFrame, serverList  SETEVENT serverList, "ACTION", ADDRESS(serverList_selected()) ' Create text parttransFrame = FRAME()  SETPROPERTIES transFrame, "TITLE=\"Translation\""  APPEND vbx, transFrametxt = TEXT()  SETPROPERTIES txt, "MULTILINE=YES, EXPAND=YES"  APPEND transFrame, txt  ' Create entry and search buttonbottomBox = HBOX()  SETPROPERTIES bottomBox, "GAP=10"  APPEND vbx, bottomBoxlbl = LABEL()  SETPROPERTIES lbl, "TITLE=\"Enter Word to Search For:\", SIZE=x12"  APPEND bottomBox, lblentry = TEXT()  SETPROPERTIES entry, "EXPAND=HORIZONTAL"  APPEND bottomBox, entrybtnSearch = 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, chkAllchkUTF = TOGGLE()  SETPROPERTIES chkUTF, "TITLE=UTF-8, SIZE=x12"  APPEND bottomBox, chkUTF ' Add the main GUI container to the WindowAPPEND win, vbx ' Setup dialog defaultsSHOW winFOCUS btnFetchFOR i = 0 TO UBOUND(servers)  SETPROPERTY serverCombo, "APPENDITEM", servers[i]NEXTSETPROPERTY serverCombo, "VALUE", "1"UPDATE serverComboserver_selection = servers[0]GETEVENT()END  ' Callback routines SUB Win_exit  Iup::ExitLoop = TRUEEND SUB SUB btnAbout_clicked  MESSAGE "ABOUT", aboutEND 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", totalEXIT SUB L_NetError:  dat[0] = "Could not lookup word! (" & ERROR & ")"  SETPROPERTY txt, "VALUE", datEND SUB 

Navigation

[0] Message Index

Go to full version