#!/usr/bin/gtkbasic002


//-- load  file and show the window
gins_glade("calc.glade")
gins_main()


//-- manipulate a widget, e.g. move the window
gins_set("window1" , "10" , "10" , "<uposition>")


//-- get information about a widget
a = gins_get("button1" , "label" , "<str>")
print a


mem = 0
op = ""
operands = {"+" , "-" , "*" , "/"}


//-- mainloop with eventhandling
while 1

  widget , event , pdata = gins_event()

  if widget != Nothing then
  '  print widget
    print event
  '  print pdata

    if event = "GDK_DELETE" then
      gins_exit()
      end
    end if


//    if event = "BUTTON_PRESS" then
    if event = "GDK_BUTTON_RELEASE" then
   ' print widget
   ' print event
   ' print pdata



    widget = replace(widget , "button" , "")
    widget = val(widget)

      select case widget
      case 0 to 9

        if op = "done" then
          gins_set("entry1" , "text" , "" , "<str>")
          op = ""
          mem = 0
        end if
        if op != "" then
          gins_set("entry1" , "text" , "" , "<str>")
          gins_set("entry1" , "text" , "" , "<str>")
        end if

        n = gins_get("entry1" , "text" , "<str>")
        gins_set("entry1" , "text" , n & widget , "<str>")


      case 10
        gins_set("entry1" , "text" , "" , "<str>")
        op = ""


      case 11

        n = gins_get("entry1" , "text" , "<str>")
        if op = "+" then
          gins_set("entry1" , "text" , mem + val(n) , "<str>")
        end if
        if op = "-" then
          gins_set("entry1" , "text" , mem - val(n) , "<str>")
        end if
        if op = "*" then
          gins_set("entry1" , "text" , mem * val(n) , "<str>")
        end if
        if op = "/" then
          gins_set("entry1" , "text" , mem / val(n) , "<str>")
        end if

        mem = 0
        op = "done"

      case 12 to 15
        setop(widget)

      end select

    end if


  end if

  xwin_usleep(10000)

wend

sub setop (button)

  button -= 11
  op = operands[button]
  n = gins_get("entry1" , "text" , "<str>")
  mem = val(n)

end sub