Open Forum > What's New

SBT - Script BASIC Tutorial API extension module

<< < (2/2)

Support:
The solution to my unstable IUP start-up issues were resolved with creating an IUP dialog in the parent script before creating threaded children dialogs.  I moved the Iup::MainLoop and Iup::GetThreadCallback routines into the main script from the IUP extension module. At this point everything is working as expected and I couldn't be happier.

Moral: How can you have well behaved children if you don't have a mature parent in charge?  ::)

SBx_Main

--- Code: Script BASIC ---' SBT IUP Theaded Example IMPORT mt.basIMPORT sbt.incIMPORT iup.basIMPORT "SBx" Iup::Open() SUB SB_Wait(mtvar)  WHILE mt::GetVariable(mtvar) <> "OK"    SB_msSleep(5000)  WENDEND SUB SUB btn1_clicked  PRINT "Main 0 Button 1 Pressed\n"  PRINT "Which Mouse Button: ",CHR(Iup::GetBtnPressed()),"\n"  PRINT "Button Up/Dn State: ",Iup::GetBtnState(),"\n"END SUB SUB btn2_clicked  PRINT "Main 0 Button 2 Pressed\n"END SUB SUB btn3_clicked  PRINT "Main 0 Button 3 Pressed\n"END SUB SUB win_exit  ' Good-ByeEND SUB win = DIALOG()SETPROPERTIES win, "TITLE=\"SBx Main 0\", SIZE=300x"horzbox = HBOX()SETPROPERTIES horzbox, "GAP=5"btn1 = BUTTON()SETPROPERTIES btn1, "TITLE=\"Button 1\", EXPAND=HORIZONTAL"btn2 = BUTTON()SETPROPERTIES btn2, "TITLE=\"Button 2\", EXPAND=HORIZONTAL"btn3 = BUTTON()SETPROPERTIES btn3, "TITLE=\"Button 3\", EXPAND=HORIZONTAL"APPEND horzbox, btn1APPEND horzbox, btn2APPEND horzbox, btn3APPEND win, horzboxIup::SetThreadCallback(win, "CLOSE_CB", ADDRESS(win_exit()), 0)Iup::SetThreadCallback(btn1, "BUTTON_CB", ADDRESS(btn1_clicked()), 0)Iup::SetThreadCallback(btn2, "ACTION", ADDRESS(btn2_clicked()), 0)Iup::SetThreadCallback(btn3, "ACTION", ADDRESS(btn3_clicked()), 0)SHOW win ' Puppet Show sb1 = SB_ThreadStart("SBx_T1",undef,"/etc/scriba/basic.conf")SB_Wait("sb1_loaded")sb1_rtn = SB_CallSubArgs(sb1, "main::main", sb1) sb2 = SB_ThreadStart("SBx_T2",undef,"/etc/scriba/basic.conf")SB_Wait("sb2_loaded")sb2_rtn = SB_CallSubArgs(sb2, "main::main", sb2) threads = 3 t_event = mt::GetVariable("Callback_Map")SPLITA t_event BY "\n" TO e_listFOR x = 0 TO UBOUND(e_list)  SPLITA e_list[x] BY "|" TO e_array  event{e_array[0]}[0] = e_array[0]  event{e_array[0]}[1] = e_array[1]  event{e_array[0]}[2] = e_array[2]NEXT WHILE threads  Iup::LoopStep()  this_event = Iup::GetEvent()  hex_event = Iup::BB_HTA(this_event)  IF hex_event = event{hex_event}[0] THEN    IF event{hex_event}[2] = 0 THEN      ICALL event{hex_event}[1]    ELSE IF event{hex_event}[2] = 1 THEN      SB_CallSub(main::sb1, event{hex_event}[1])    ELSE IF event{hex_event}[2] = 2 THEN      SB_CallSub(main::sb2, event{hex_event}[1])    END IF    IF Iup::GetActionName() = "CLOSE_CB" THEN threads -= 1  END IF    SB_msSleep(250)WEND Iup::Close()SB_Destroy(sb2)SB_Destroy(sb1) 
SBx_T1 - T2 is the same

--- Code: Script BASIC ---' SBx_buttons Example (Thread 1) IMPORT mt.basIMPORT iup.basIMPORT "SBx" SUB btn1_clicked  PRINT "Thread 1 Button 1 Pressed\n"  PRINT "Which Mouse Button: ",CHR(Iup::GetBtnPressed()),"\n"  PRINT "Button Up/Dn State: ",Iup::GetBtnState(),"\n"END SUB SUB btn2_clicked  PRINT "Thread 1 Button 2 Pressed\n"END SUB SUB btn3_clicked  PRINT "Thread 1 Button 3 Pressed\n"END SUB SUB win_exit  ' Good-ByeEND SUB SUB main  win = DIALOG()  SETPROPERTIES win, "TITLE=\"SBx Thread 1\", SIZE=300x"  horzbox = HBOX()  SETPROPERTIES horzbox, "GAP=5"  btn1 = BUTTON()  SETPROPERTIES btn1, "TITLE=\"Button 1\", EXPAND=HORIZONTAL"  btn2 = BUTTON()  SETPROPERTIES btn2, "TITLE=\"Button 2\", EXPAND=HORIZONTAL"  btn3 = BUTTON()  SETPROPERTIES btn3, "TITLE=\"Button 3\", EXPAND=HORIZONTAL"  APPEND horzbox, btn1  APPEND horzbox, btn2  APPEND horzbox, btn3  APPEND win, horzbox  Iup::SetThreadCallback(win, "CLOSE_CB", "main::win_exit", 1)  Iup::SetThreadCallback(btn1, "BUTTON_CB", "main::btn1_clicked", 1)   Iup::SetThreadCallback(btn2, "ACTION", "main::btn2_clicked", 1)  Iup::SetThreadCallback(btn3, "ACTION", "main::btn3_clicked", 1)  SHOW winEND SUBmt::SetVariable("sb1_loaded","OK") 
SBx (Experimental IUP Wrapper)

--- Code: Script BASIC ---' ScriptBasic IUP Interface 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 

Support:
As it turns out, you really don't need threading to achieve multiple window support. As I see it threading of a IUP dialog would be a special use case. It's good to know it can be done.


--- Code: Script BASIC ---' SBx_buttons Example (3 Form Version) IMPORT iup.basIMPORT sbt.incIMPORT "SBx" ' Form 1 Callback RoutinesSUB frm1_btn1_clicked  PRINT "Form 1 Button 1 Pressed\n"  PRINT "Which Mouse Button: ",CHR(Iup::GetBtnPressed()),"\n"  PRINT "Button Up/Dn State: ",Iup::GetBtnState(),"\n"END SUB SUB frm1_btn2_clicked  PRINT "Form 1 Button 2 Pressed\n"END SUB SUB frm1_btn3_clicked  PRINT "Form 1 Button 3 Pressed\n"END SUB ' Form 2  Callback RoutinesSUB frm2_btn1_clicked  PRINT "Form 2 Button 1 Pressed\n"  PRINT "Which Mouse Button: ",CHR(Iup::GetBtnPressed()),"\n"  PRINT "Button Up/Dn State: ",Iup::GetBtnState(),"\n"END SUB SUB frm2_btn2_clicked  PRINT "Form 2 Button 2 Pressed\n"END SUB SUB frm2_btn3_clicked  PRINT "Form 2 Button 3 Pressed\n"END SUB ' Form 3 Callback RoutinesSUB frm3_btn1_clicked  PRINT "Form 3 Button 1 Pressed\n"  PRINT "Which Mouse Button: ",CHR(Iup::GetBtnPressed()),"\n"  PRINT "Button Up/Dn State: ",Iup::GetBtnState(),"\n"END SUB SUB frm3_btn2_clicked  PRINT "Form 3 Button 2 Pressed\n"END SUB SUB frm3_btn3_clicked  PRINT "Form 3 Button 3 Pressed\n"END SUB SUB win_exit  ' Good-ByeEND SUB Iup::Open() ' Form 1 Dialogwin1 = DIALOG()SETPROPERTIES(win1, "TITLE=\"SBx Form 1\", SIZE=300x")horzbox1 = HBOX()SETPROPERTIES horzbox1, "GAP=5"btn1_1 = BUTTON()SETPROPERTIES btn1_1, "TITLE=\"Button 1\", EXPAND=HORIZONTAL"btn1_2 = BUTTON()SETPROPERTIES btn1_2, "TITLE=\"Button 2\", EXPAND=HORIZONTAL"btn1_3 = BUTTON()SETPROPERTIES btn1_3, "TITLE=\"Button 3\", EXPAND=HORIZONTAL"APPEND horzbox1, btn1_1APPEND horzbox1, btn1_2APPEND horzbox1, btn1_3APPEND win1, horzbox1Iup::SetCallback win1, "CLOSE_CB", ADDRESS(win_exit())Iup::SetCallback btn1_1, "BUTTON_CB", ADDRESS(frm1_btn1_clicked())Iup::SetCallback btn1_2, "ACTION", ADDRESS(frm1_btn2_clicked())Iup::SetCallback btn1_3, "ACTION", ADDRESS(frm1_btn3_clicked())Iup::ShowXY(win1,500,200)   ' Form 2 Dialogwin2 = DIALOG()SETPROPERTIES win2, "TITLE=\"SBx Form 2\", SIZE=300x"horzbox2 = HBOX()SETPROPERTIES horzbox2, "GAP=5"btn2_1 = BUTTON()SETPROPERTIES btn2_1, "TITLE=\"Button 1\", EXPAND=HORIZONTAL"btn2_2 = BUTTON()SETPROPERTIES btn2_2, "TITLE=\"Button 2\", EXPAND=HORIZONTAL"btn2_3 = BUTTON()SETPROPERTIES btn2_3, "TITLE=\"Button 3\", EXPAND=HORIZONTAL"APPEND horzbox2, btn2_1APPEND horzbox2, btn2_2APPEND horzbox2, btn2_3APPEND win2, horzbox2Iup::SetCallback win2, "CLOSE_CB", ADDRESS(win_exit())Iup::SetCallback btn2_1, "BUTTON_CB", ADDRESS(frm2_btn1_clicked())Iup::SetCallback btn2_2, "ACTION", ADDRESS(frm2_btn2_clicked())Iup::SetCallback btn2_3, "ACTION", ADDRESS(frm2_btn3_clicked())Iup::ShowXY(win2,500,400) ' Form 3 Dialogwin3 = DIALOG()SETPROPERTIES win3, "TITLE=\"SBx Form 3\", SIZE=300x"horzbox3 = HBOX()SETPROPERTIES horzbox3, "GAP=5"btn3_1 = BUTTON()SETPROPERTIES btn3_1, "TITLE=\"Button 1\", EXPAND=HORIZONTAL"btn3_2 = BUTTON()SETPROPERTIES btn3_2, "TITLE=\"Button 2\", EXPAND=HORIZONTAL"btn3_3 = BUTTON()SETPROPERTIES btn3_3, "TITLE=\"Button 3\", EXPAND=HORIZONTAL"APPEND horzbox3, btn3_1APPEND horzbox3, btn3_2APPEND horzbox3, btn3_3APPEND win3, horzbox3Iup::SetCallback win3, "CLOSE_CB", ADDRESS(win_exit())Iup::SetCallback btn3_1, "BUTTON_CB", ADDRESS(frm3_btn1_clicked())Iup::SetCallback btn3_2, "ACTION", ADDRESS(frm3_btn2_clicked())Iup::SetCallback btn3_3, "ACTION", ADDRESS(frm3_btn3_clicked())Iup::ShowXY(win3,500,600)   ' Event Loopwindows = 3 WHILE windows  Iup::LoopStep()  this_event = Iup::GetEvent()  this_event = Iup::BB_HTA(this_event)  IF this_event = event{this_event}[0] THEN    ICALL event{this_event}[1]    IF Iup::GetActionName() = "CLOSE_CB" THEN windows -= 1  END IF    SB_msSleep(250)WEND Iup::Close 
iup.bas - I changed the Iup::SetCallback() to create the event array in the main namespace.

--- Code: Script BASIC ---FUNCTION SetCallback(ih, aname, fname)  main::event{BB_HTA(ih)}[0] = BB_HTA(ih)  main::event{BB_HTA(ih)}[1] = fname  SetCallback = __SetCallback(ih, aname)END FUNCTION 

Navigation

[0] Message Index

[*] Previous page

Go to full version