Author Topic: Question about IUP  (Read 23252 times)

0 Members and 1 Guest are viewing this topic.

Arnold

  • Guest
Re: Question about IUP
« Reply #30 on: June 18, 2015, 12:11:27 AM »
Hi Charles,

trying to use iup.h directly I encounter some problems. What is the difference between these two examples:

This code shows the correct result:

Code: OxygenBasic
  1. 'getcolor1.o2bas
  2.  
  3. include "$/inc/console.inc"
  4.  
  5. includepath "iup\"      
  6. extern lib "IUP/iup.dll" cdecl
  7. 'include "iup.h"  
  8.  
  9. ! IupOpen          (sys argc,argv) as int
  10. ! IupGetColor(int x, int y, byte* r, byte* g, byte* b) as int    
  11. ! IupClose         ()
  12.  
  13. end extern
  14.  
  15. extern cdecl
  16.  
  17.  
  18. sub GetColorTest()
  19.   byte r = 10, g = 100, b = 25
  20.   if IupGetColor(100, 100, &r, &g, &b) then
  21.     print "RGB = "  r  ","  g  ","  b  " Hex=["  hex(r)  ","  hex(g)  ","  hex(b)  "]" &
  22.              cr &"Enter ..."  & cr
  23.   end if
  24. end sub
  25.  
  26.  
  27. sub main()
  28.  
  29.   IupOpen(0,0)
  30.   GetColorTest()
  31.  
  32.   IupClose()
  33.  
  34. end sub
  35.  
  36. main()
  37.  
  38. waitkey()
  39.  
  40.  
  41.  
  42.   IupOpen(0,0)
  43.  
  44.   byte r = 10, g = 100, b = 25
  45.   int result=IupGetColor(100, 100, &r, &g, &b)
  46.   if result then
  47.     print "RGB = "  r  ","  g  ","  b  " Hex=["  hex(r)  ","  hex(g)  ","  hex(b)  "]" &
  48.              cr &"Enter ..."  & cr
  49.   end if
  50.   IupClose()
  51.  
  52.  
  53. waitkey()
  54.  

Following the same code with using iup.h. It does either not work at all or does not change the values of r,g,b. What should I do differently?

Roland

Code: [Select]
'getcolor2.o2bas

include "$/inc/console.inc"

includepath "iup\"     
extern lib "IUP/iup.dll" cdecl
include "iup.h"

'int       IupOpen          (int *argc, char ***argv);
'void      IupClose         (void);
'int  IupGetColor(int x, int y, unsigned char* r, unsigned char* g, unsigned char* b);

end extern
     
extern cdecl       
/*
' will not work at all
sub GetColorTest()
  byte r = 10, g = 100, b = 25
  if IupGetColor(100, 100, &r, &g, &b) then
    print "RGB = "  r  ","  g  ","  b  " Hex=["  hex(r)  ","  hex(g)  ","  hex(b)  "]" &
             cr &"Enter ..."  & cr
  end if
end sub


sub main()

  IupOpen(0,0)
  GetColorTest()

  IupClose()

end sub

main()

waitkey()
*/

' returns false result
  IupOpen(0,0)

  byte r = 10, g = 100, b = 25
  int result=IupGetColor(100, 100, &r, &g, &b)
  if result then
    print "RGB = "  r  ","  g  ","  b  " Hex=["  hex(r)  ","  hex(g)  ","  hex(b)  "]" &
             cr &"Enter ..."  & cr
  end if
  IupClose()

 
waitkey()

Charles Pegge

  • Guest
Re: Question about IUP
« Reply #31 on: June 18, 2015, 12:47:39 AM »
Hi Roland,

char is understood as a string, and byte is understood as an integer.

Here's the byval solution :)

Code: OxygenBasic
  1. 'getcolor2.o2bas
  2.  
  3. include "$/inc/console.inc"
  4.  
  5.   includepath "iup\"      
  6.   extern lib "IUP/iup.dll" cdecl
  7.   include "iup.h"
  8.   extern cdecl      
  9.  
  10.   IupOpen(null,null)
  11.  
  12.   byte r = 10, g = 100, b = 25
  13.   int result=IupGetColor(100, 100, byval &r, byval &g, byval &b)
  14.   if result then
  15.     print "RGB = "  r  ","  g  ","  b  " Hex=["  hex(r)  ","  hex(g)  ","  hex(b)  "]" &
  16.              cr &"Enter ..."  & cr
  17.   end if
  18.   IupClose()
  19.  
  20.  
  21. waitkey()
  22.  

Arnold

  • Guest
Re: Question about IUP
« Reply #32 on: June 18, 2015, 02:17:32 AM »
Hi Charles,

thank you for this solution. This will solve some more functions which use unsigned char*. And it seems I must deal a little bit more with byval and byref.

Roland

Arnold

  • Guest
Re: Question about IUP
« Reply #33 on: June 18, 2015, 02:48:06 AM »
And
typedef sys iHandle*
solved my second problem. I think I will now start seriously with using iup.h directly.

Roland

Code: OxygenBasic
  1. 'getcolor2.o2bas
  2. include "$/inc/console.inc"
  3.  
  4.   includepath "iup\"      
  5.   extern lib "IUP/iup.dll" cdecl
  6.   include "iup.h"
  7.   extern cdecl      
  8.  
  9. typedef sys iHandle*
  10.  
  11. sub GetColorTest()
  12.   byte r = 10, g = 100, b = 25
  13.   if IupGetColor(100, 100, byval &r, byval &g, byval &b) then
  14.     print "RGB = "  r  ","  g  ","  b  " Hex=["  hex(r)  ","  hex(g)  ","  hex(b)  "]" &
  15.              cr &"Enter ..."  & cr
  16.   end if
  17. end sub
  18.  
  19. sub main()
  20.  
  21.   IupOpen(0,0)
  22.   GetColorTest()
  23.  
  24.   IupClose()
  25.  
  26. end sub
  27.  
  28. main()
  29.  
  30. waitkey()
  31.  

Arnold

  • Guest
Re: Question about IUP
« Reply #34 on: July 04, 2015, 01:03:12 AM »
Hi Charles,

I noticed that you updated the Iup.dll to version 3.14 but still use the include files of version 3.06. In case you wish to update these files too the include files are added in the attached zip file. These are the original files of the Iup toolkit using the unix style of end line characters (LF). I have added two extra files (Iup_draw.h and Iup_key.h) which can be used for some more Iup api functions.

Also added are two demos (tabs.o2bas, zbox.o2bas) which use LED files. These are simple text files which can be used for creating dialogs and controls. The callback events are then handled in the main .o2bas files. Using LED files is indeed an interesting option.

I also included another opengl demo which is provided with the original Iup Toolkit.

There are two demos of projectB/Iup where I did some small modifications:

jfdemo1H.o2bas needs this modification:

  label = Create("label", `TITLE="Enter Word to Search For:" , SIZE=x12`, bottomBox)

The text of TITLE must be enclosed with quotes, therefore I used the alternative quoting too.

In pwdemo1.o2bas I used iup_draw.h directly to call the api functions. This works very nice.

I also found that there is no problem creating executables. On the whole I think that OxygenBasic can handle the Iup toolkit very well either wrapping the functions or (with some limitation) using the header files directly.

Should it be possible to use the 64bit dlls with the code too? (I did not yet try this).


Roland



.

JRS

  • Guest
Re: Question about IUP
« Reply #35 on: July 04, 2015, 11:01:15 AM »
Quote
Also added are two demos (tabs.o2bas, zbox.o2bas) which use LED files. These are simple text files which can be used for creating dialogs and controls. The callback events are then handled in the main .o2bas files. Using LED files is indeed an interesting option.

Thanks Roland for the LED file examples! I have been contemplating using the LED method as an alternative to my home brew SBx IUP wrapper. Just to let you know, I'm following your progress with IUP/O2 closely. 

Arnold

  • Guest
Re: Question about IUP
« Reply #36 on: July 05, 2015, 12:25:03 AM »
Hi John,

from my point of view, LED files could simplify the layout of dialogs and controls in IUP. Although they look a little bit strange at the first moment, they have a simple syntax:

From IUP Helpfile:
Quote
In LED, attributes and expressions follow this form:

elem = element[attribute1=value1,attribute2=value2,...](...expression...)

The names of the elements must not contain the “iup” prefix

I think the elements could be drawn on paper and then simply specified in a LED file. They can be loaded at run time with IupLoad. There is also a function IupLoadBuffer which loads a string with the LED specification. I have not yet tried this, but if it works a LED file could be loaded as a string in the main program or in an include file. There is also a LED compiler (ledc) which generates C modules from one or more LED files. Many combinations of using LED files are possible.

Roland

JRS

  • Guest
Re: Question about IUP
« Reply #37 on: July 05, 2015, 10:28:49 PM »
Sounds great Roland. I'll give LED a try in Script BASIC and post a link when I have something to show.


Arnold

  • Guest
Re: Question about IUP
« Reply #38 on: July 06, 2015, 02:00:47 AM »
This is an example which will also run in projectsB\IUP. It uses IupLoadBuffer to create the dialog and controls from a string with the LED specification. I used this routine to load the string:

Code: OxygenBasic
  1. $ filename "sample_w_led.exe"
  2. 'include "$/inc/RTL32.inc"
  3.  
  4. extern lib "IUP/iup.dll" cdecl
  5. includepath "IUP/"
  6. include "iup.h"
  7.  
  8. end extern  
  9.  
  10. extern cdecl
  11.  
  12. typedef sys Ihandle
  13.  
  14.  
  15. includepath ""
  16. include "sample.inc"
  17.  
  18. sub Load_LED_Dialog()
  19.   string err = NULL
  20.  
  21.   /* Initialization of IUP and its controls */
  22.  
  23.   err = IupLoadBuffer(sample_led)
  24.   if len(err) then
  25.     IupMessage("LED error", err)
  26.     'hasta la vista baby
  27.    terminate()
  28.     end
  29.   end if
  30.    
  31.   IupShow(IupGetHandle("dlg"))
  32.    
  33. end sub
  34.  
  35.  
  36. sub main()
  37.  
  38.    IupOpen(0,0)
  39.    Load_LED_Dialog()
  40.    IupMainLoop()
  41.    IupClose()
  42.  
  43. end sub
  44.  
  45. main()
  46.  

I like creating the dialogs this way. IupGetClassName in the Iup Helpfile indicates the elements which can be created with LED (expander should also work). By adding some callbacks for the events in the main .o2bas file the application could then be further developed.

Roland

.

JRS

  • Guest
Re: Question about IUP
« Reply #39 on: July 06, 2015, 04:51:43 PM »
Works Great!

Code: Script BASIC
  1. ' Script BASIC IUP/LED
  2.  
  3. IMPORT iup.bas
  4. sample_led = """
  5.  
  6. img1 = IMAGE[0="0 0 0",1="BGCOLOR",2="255 0 0"]
  7. (32,32
  8. ,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1
  9. ,1,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1
  10. ,1,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1
  11. ,1,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1
  12. ,1,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1
  13. ,1,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1
  14. ,1,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1
  15. ,1,1,1,1,1,1,1,1,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,1,1,1,1,1,1,1,1
  16. ,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
  17. ,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
  18. ,2,2,2,0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,3,3,3,3,3,3,3,3,3
  66. ,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
  67. ,3,3,3,3,3,3,3,3,3,3,3,3,3,3,1,1,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
  68. ,2,2,2,2,2,2,2,3,3,3,3,3,3,3,1,1,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2
  69. ,2,2,2,2,2,2,3,3,3,3,3,3,3,3,1,1,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2
  70. ,2,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2
  71. ,2,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2
  72. ,2,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
  73. ,2,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
  74. ,2,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
  75. ,3,3,3,3,3,3,3,3,3,3,3,3,3,3,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2
  76. )
  77.  
  78. mnu = MENU
  79. (
  80.  SUBMENU("IupSubMenu 1",
  81.    MENU
  82.    (
  83.      ITEM[VALUE=ON]("IupItem 1 Checked",myaction),
  84.      SEPARATOR(),
  85.      ITEM[ACTIVE="NO"]("IupItem 2 Disabled",myaction)
  86.    )
  87.  ),
  88.  ITEM("IupItem 3",myaction),
  89.  ITEM("IupItem 4",myaction)
  90. )
  91.  
  92. dlg = DIALOG[TITLE="IupDialog Title",MENU="mnu"]
  93. (
  94.  VBOX[GAP="5",ALIGNMENT="ARIGHT",MARGIN="5x5"]
  95.  (
  96.    HBOX
  97.    (
  98.      FRAME[TITLE="IupButton"]
  99.      (
  100.        VBOX
  101.        (
  102.          BUTTON("Button Text",myaction),
  103.          BUTTON[IMAGE=img1]("",myaction),
  104.          BUTTON[IMAGE=img1,IMPRESS=img2]("",myaction)
  105.        )
  106.      ),
  107.      FRAME[TITLE="IupLabel"]
  108.      (
  109.        VBOX
  110.        (
  111.          LABEL("Label Text"),
  112.          LABEL[SEPARATOR=HORIZONTAL](""),
  113.          LABEL[IMAGE=img1]("")
  114.        )
  115.      ),
  116.      FRAME[TITLE="IupToggle"]
  117.      (
  118.        VBOX
  119.        (
  120.          TOGGLE[VALUE="ON"]("Toggle Text",myaction),
  121.          TOGGLE[IMAGE=img1,IMPRESS=img2]("",myaction),
  122.          FRAME[TITLE="IupRadio"]
  123.          (
  124.            RADIO
  125.            (
  126.              VBOX
  127.              (
  128.                TOGGLE("Toggle Text",myaction),
  129.                TOGGLE("Toggle Text",myaction)
  130.              )
  131.            )
  132.          )
  133.        )
  134.      ),
  135.      FRAME[TITLE="IupText/IupMultiline"]
  136.      (
  137.        VBOX
  138.        (
  139.          TEXT[SIZE="80x",VALUE="IupText Text"](myaction),
  140.          MULTILINE[SIZE="80x60",EXPAND="YES",VALUE="IupMultiline Text\nSecond Line\nThird Line"](myaction)
  141.        )
  142.      ),
  143.      FRAME[TITLE="IupList"]
  144.      (
  145.        VBOX
  146.        (
  147.          LIST[EXPAND="YES",VALUE="1",1="Item 1 Text",2="Item 2 Text",3="Item 3 Text"](myaction),
  148.          LIST[DROPDOWN="YES",EXPAND="YES",VALUE="2",1="Item 1 Text",2="Item 2 Text",3="Item 3 Text"](myaction),
  149.          LIST[EDITBOX="YES",EXPAND="YES",VALUE="3",1="Item 1 Text",2="Item 2 Text",3="Item 3 Text"](myaction)
  150.        )
  151.      )
  152.    ),
  153.    CANVAS[BGCOLOR="128 255 0"](myaction)
  154.  )
  155. )
  156. """
  157.  
  158. Iup::Open()
  159. Iup::LoadBuffer(sample_led)
  160. Iup::Show(Iup::GetHandle("dlg"))
  161. Iup::MLoop()
  162. IUP::Close()
  163.  


.
« Last Edit: July 06, 2015, 06:01:58 PM by John »

Arnold

  • Guest
Re: Question about IUP
« Reply #40 on: July 07, 2015, 03:02:20 AM »
Hi John,

it seems that Scriptbasic can also handle IUP in Linux. This is of course a very nice feature. Is there a downloadable version of Scriptbasic for Windows too?

I do not know if this is the case in Scriptbasic but with OxygenBasic I have to take care for the case that there is an error in the LED file or in the string of the LED specification. Otherwise IupMainLoop will prevent gxo2 or the application to exit and release memory. I can do this in the main sub with using a simple return in case of an error. If I use IupLoad / IupLoadBuffer in a separate routine I use terminate() to force the exit of the program. (I did not find another way). When loading a faulty LED file an error message shows where the error occured in the LED file, loading the string only shows an error message with the LED file. For this reason it should be better to construct the dialogs in a separate LED file.

This would be jfdemo1_led.o2bas using LED:

Code: OxygenBasic
  1. $ filename "jfdemo1_led.exe"
  2. 'include "$/inc/RTL32.inc"
  3.  
  4. extern lib "IUP/iup.dll" cdecl
  5. includepath "IUP/"
  6. include "iup.h"
  7.  
  8. end extern  
  9.  
  10. extern cdecl
  11.  
  12. typedef sys Ihandle
  13.  
  14.  
  15. 'Exit Button Callback
  16. function quit_cb() as sys
  17.   function = %IUP_CLOSE
  18. end function
  19.  
  20.  
  21. sub Load_LED_Dialog()
  22.   string err = NULL
  23.  
  24.   err = IupLoad("jfdemo1.led")
  25.   if len(err) then
  26.     IupMessage("LED error", err)
  27.     terminate()
  28.     end
  29.   end if
  30.  
  31.     'SETUP CALLBACK FOR EXIT BUTTON
  32.  IupSetCallback(IupGetHandle("btnExit"), "ACTION", @quit_cb)
  33.  
  34.   IupShow(IupGetHandle("win"))
  35.  
  36.   IupSetFocus(IupGetHandle("btnFetch"))
  37.    
  38. end sub
  39.  
  40.  
  41. sub main()
  42.  
  43.    IupOpen(0,0)
  44.    Load_LED_Dialog()
  45.    IupMainLoop()  
  46.    IupClose()
  47.  
  48. end sub
  49.  
  50. main()
  51.  

And this would be the LED specification:

Code: [Select]
#jfdemo1H Example in LED

servercombo = LIST [DROPDOWN=YES, SIZE=120x, EXPAND=HORIZONTAL, VALUE=1] (NULL)
btnFetch = BUTTON [SIZE = 50x] ("Fetch",NULL)
btnAbout = BUTTON [SIZE = 50x] ("About",NULL)
btnClear = BUTTON [SIZE = 50x] ("Clear",NULL)
btnExit = BUTTON [SIZE = 50x] ("E&xit", quit_cb)
serverList = LIST [EXPAND=YES, VISIBLELINES=1] (NULL)
textbox = TEXT [MULTILINE=YES, EXPAND=YES] (NULL)
lable = LABEL [SIZE=x12] ("Enter Word to Search For:")
entry = TEXT [EXPAND=HORIZONTAL] (NULL)
btnSearch = BUTTON [SIZE=50x] ("Search", NULL)
chkAll = TOGGLE [VALUE=ON, SIZE=x12] ("ALL", NULL)
chkUTF = TOGGLE [SIZE=x12] ("UTF-8", NULL)
 

win = DIALOG [TITLE=Thesaurus, SIZE=500x300]
(
VBOX [MARGIN=10x10]
  (
   HBOX [GAP=10]
   ( FRAME [TITLE=Servers, EXPAND=YES]
     ( HBOX [GAP=5] ( servercombo, btnFetch ) ) ,
          FRAME [TITLE=Controls]
          ( HBOX [MARGIN=6x6, GAP=5] ( btnAbout, btnClear, btnExit ) )
   ) ,
 
   FRAME [TITLE=Dictionaries]
   ( serverList ) ,
 
   FRAME [TITLE=Translation]
   ( textbox) ,
 
   HBOX [GAP=10] ( lable, entry, btnSearch, chkAll, chkUTF )
  )

)


I am not sure if I could represent the vertical / horizontal flow of VBOX / HBOX a little bit better? Putting everything of HBOX in one line could be confusing at some time too.

Roland

.

JRS

  • Guest
Re: Question about IUP
« Reply #41 on: July 07, 2015, 03:10:59 AM »
Quote
it seems that Scriptbasic can also handle IUP in Linux. This is of course a very nice feature. Is there a downloadable version of Scriptbasic for Windows too?

You have two choices under Windows with Script BASIC and IUP. You can use my cross platform (32/64 bit) IUP extension module or use Charles's (32 bit) DLLC extension module which also lets you run IUP in multi-threaded mode. (IUP is not by default thread safe)

Here is the Script BASIC Windows 64 bit version of the dictionary example.



Code: Script BASIC
  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: July 07, 2015, 03:18:22 AM by John »

Charles Pegge

  • Guest
Re: Question about IUP
« Reply #42 on: July 07, 2015, 04:09:35 AM »
Thanks Roland,

I've merged your material into projectsB/IUP

An alternative way of handling a LED error:

Code: OxygenBasic
  1. $ filename "sample_w_led.exe"
  2. 'include "$/inc/RTL32.inc"
  3.  
  4. extern lib "IUP/iup.dll" cdecl
  5. includepath "IUP/"
  6. include "iup.h"
  7.  
  8. end extern  
  9.  
  10. extern cdecl
  11.  
  12. typedef sys Ihandle
  13.  
  14.  
  15. includepath ""
  16. include "sample.inc"
  17.  
  18. function Load_LED_Dialog() as sys
  19.   string err = NULL
  20.  
  21.   /* Initialization of IUP and its controls */
  22.  
  23.   err = IupLoadBuffer(sample_led)
  24.   if len(err) then
  25.     IupMessage("LED error", err)
  26.     return 0
  27.   end if
  28.    
  29.   IupShow(IupGetHandle("dlg"))
  30.   return 1
  31.    
  32. end function
  33.  
  34.  
  35. sub main()
  36.  
  37.    IupOpen(0,0)
  38.    if Load_LED_Dialog() then
  39.      IupMainLoop()
  40.    end if
  41.    IupClose()
  42.  
  43. end sub
  44.  
  45. main()
  46.  
« Last Edit: July 07, 2015, 04:19:33 AM by Charles Pegge »

JRS

  • Guest
Re: Question about IUP
« Reply #43 on: July 07, 2015, 05:00:05 AM »
FYI I rarely add error trapping support to the examples I post. I test what I post so what's the point?

Quote from: Antonio Scuri
Hi All,

  We just released IUP version 3.15.

  We would like to highlight some of the new features:

- New: "iup_class_cbs.hpp" header with macros to help creation of callbacks as methods in C++.
- New: global hot key (Alt+Ctrl+Shft+L) to show the current dialog layout in a IupLayoutDialog dialog.
- New: Tutorial section in the documentation. It is still under construction but already has several topics completed.
- New: IupFlatButton control that mimics a IupButton but does not have native system decorations.
- New: IupConfig support in Lua.

  You can find the complete list of changes and files for download at:

http://www.tecgraf.puc-rio.br/iup/
and
http://iup.sourceforge.net/

Best Regards,
Antonio Scuri
« Last Edit: July 07, 2015, 05:11:06 AM by John »

Mike Lobanovsky

  • Guest
Re: Question about IUP
« Reply #44 on: July 07, 2015, 06:01:07 AM »
The point is to know *how* to do it efficiently just in case. ;)