WeixiangYan/CodeTransOcean huggingface dataset:
Task: Mouse position




Go: package main

import (
    "fmt"
    "github.com/go-vgo/robotgo"
)

func isInside(x, y, w, h, mx, my int) bool {
    rx := x + w - 1
    ry := y + h - 1
    return mx >= x && mx <= rx && my >= y && my <= ry
}

func main() {
    name := "gedit" 
    fpid, err := robotgo.FindIds(name)
    if err == nil && len(fpid) > 0 {
        pid := fpid[0]
        robotgo.ActivePID(pid) 
        x, y, w, h := robotgo.GetBounds(pid)
        fmt.Printf("The active window's top left corner is at (%d, %d)\n", x, y)
        fmt.Printf("Its width is %d and its height is %d\n", w, h)
        mx, my := robotgo.GetMousePos()
        fmt.Printf("The screen location of the mouse cursor is (%d, %d)\n", mx, my)
        if !isInside(x, y, w, h, mx, my) {
            fmt.Println("The mouse cursor is outside the active window")
        } else {
            wx := mx - x
            wy := my - y
            fmt.Printf("The window location of the mouse cursor is (%d, %d)\n", wx, wy)
        }
    } else {
        fmt.Println("Problem when finding PID(s) of", name)
    }
}








Ada: with GLib;        use GLib;
with Gtk.Button;  use Gtk.Button;
with Gtk.Label;   use Gtk.Label;
with Gtk.Window;  use Gtk.Window;
with Gtk.Widget;  use Gtk.Widget;
with Gtk.Table;   use Gtk.Table;
 
with Gtk.Handlers;
with Gtk.Main;
 
procedure Tell_Mouse is
   Window : Gtk_Window;
   Grid   : Gtk_Table;
   Button : Gtk_Button;
   Label  : Gtk_Label;
 
   package Handlers is new Gtk.Handlers.Callback (Gtk_Widget_Record);
   package Return_Handlers is
      new Gtk.Handlers.Return_Callback (Gtk_Widget_Record, Boolean);
 
   function Delete_Event (Widget : access Gtk_Widget_Record'Class)
      return Boolean is
   begin
      return False;
   end Delete_Event;
 
   procedure Destroy (Widget : access Gtk_Widget_Record'Class) is
   begin
      Gtk.Main.Main_Quit;
   end Destroy;
 
   procedure Clicked (Widget : access Gtk_Widget_Record'Class) is
      X, Y : GInt;
   begin
      Get_Pointer (Window, X, Y);
      Set_Text (Label, "At" & GInt'Image (X) & GInt'Image (Y));
   end Clicked;
 
begin
   Gtk.Main.Init;
   Gtk.Window.Gtk_New (Window);
   Gtk_New (Grid, 1, 2, False);
   Add (Window, Grid);
   Gtk_New (Label);
   Attach (Grid, Label, 0, 1, 0, 1);
   Gtk_New (Button, "Click me");
   Attach (Grid, Button, 0, 1, 1, 2);
   Return_Handlers.Connect
   (  Window,
      "delete_event",
      Return_Handlers.To_Marshaller (Delete_Event'Access)
   );
   Handlers.Connect
   (  Window,
      "destroy",
      Handlers.To_Marshaller (Destroy'Access)
   );
   Handlers.Connect
   (  Button,
      "clicked",
      Handlers.To_Marshaller (Clicked'Access)
   );
   Show_All (Grid);
   Show (Window);
 
   Gtk.Main.Main;
end Tell_Mouse;
Task: Mouse position





Java: Point mouseLocation = MouseInfo.getPointerInfo().getLocation();







Ada: with GLib;        use GLib;
with Gtk.Button;  use Gtk.Button;
with Gtk.Label;   use Gtk.Label;
with Gtk.Window;  use Gtk.Window;
with Gtk.Widget;  use Gtk.Widget;
with Gtk.Table;   use Gtk.Table;
 
with Gtk.Handlers;
with Gtk.Main;
 
procedure Tell_Mouse is
   Window : Gtk_Window;
   Grid   : Gtk_Table;
   Button : Gtk_Button;
   Label  : Gtk_Label;
 
   package Handlers is new Gtk.Handlers.Callback (Gtk_Widget_Record);
   package Return_Handlers is
      new Gtk.Handlers.Return_Callback (Gtk_Widget_Record, Boolean);
 
   function Delete_Event (Widget : access Gtk_Widget_Record'Class)
      return Boolean is
   begin
      return False;
   end Delete_Event;
 
   procedure Destroy (Widget : access Gtk_Widget_Record'Class) is
   begin
      Gtk.Main.Main_Quit;
   end Destroy;
 
   procedure Clicked (Widget : access Gtk_Widget_Record'Class) is
      X, Y : GInt;
   begin
      Get_Pointer (Window, X, Y);
      Set_Text (Label, "At" & GInt'Image (X) & GInt'Image (Y));
   end Clicked;
 
begin
   Gtk.Main.Init;
   Gtk.Window.Gtk_New (Window);
   Gtk_New (Grid, 1, 2, False);
   Add (Window, Grid);
   Gtk_New (Label);
   Attach (Grid, Label, 0, 1, 0, 1);
   Gtk_New (Button, "Click me");
   Attach (Grid, Button, 0, 1, 1, 2);
   Return_Handlers.Connect
   (  Window,
      "delete_event",
      Return_Handlers.To_Marshaller (Delete_Event'Access)
   );
   Handlers.Connect
   (  Window,
      "destroy",
      Handlers.To_Marshaller (Destroy'Access)
   );
   Handlers.Connect
   (  Button,
      "clicked",
      Handlers.To_Marshaller (Clicked'Access)
   );
   Show_All (Grid);
   Show (Window);
 
   Gtk.Main.Main;
end Tell_Mouse;
Task: Mouse position







Python: def setup():
    size(640, 480)

def draw():
    
    ellipse(mouseX, mouseY, 5, 5) 
    println("x:{} y:{}".format(mouseX, mouseY))





Ada: with GLib;        use GLib;
with Gtk.Button;  use Gtk.Button;
with Gtk.Label;   use Gtk.Label;
with Gtk.Window;  use Gtk.Window;
with Gtk.Widget;  use Gtk.Widget;
with Gtk.Table;   use Gtk.Table;
 
with Gtk.Handlers;
with Gtk.Main;
 
procedure Tell_Mouse is
   Window : Gtk_Window;
   Grid   : Gtk_Table;
   Button : Gtk_Button;
   Label  : Gtk_Label;
 
   package Handlers is new Gtk.Handlers.Callback (Gtk_Widget_Record);
   package Return_Handlers is
      new Gtk.Handlers.Return_Callback (Gtk_Widget_Record, Boolean);
 
   function Delete_Event (Widget : access Gtk_Widget_Record'Class)
      return Boolean is
   begin
      return False;
   end Delete_Event;
 
   procedure Destroy (Widget : access Gtk_Widget_Record'Class) is
   begin
      Gtk.Main.Main_Quit;
   end Destroy;
 
   procedure Clicked (Widget : access Gtk_Widget_Record'Class) is
      X, Y : GInt;
   begin
      Get_Pointer (Window, X, Y);
      Set_Text (Label, "At" & GInt'Image (X) & GInt'Image (Y));
   end Clicked;
 
begin
   Gtk.Main.Init;
   Gtk.Window.Gtk_New (Window);
   Gtk_New (Grid, 1, 2, False);
   Add (Window, Grid);
   Gtk_New (Label);
   Attach (Grid, Label, 0, 1, 0, 1);
   Gtk_New (Button, "Click me");
   Attach (Grid, Button, 0, 1, 1, 2);
   Return_Handlers.Connect
   (  Window,
      "delete_event",
      Return_Handlers.To_Marshaller (Delete_Event'Access)
   );
   Handlers.Connect
   (  Window,
      "destroy",
      Handlers.To_Marshaller (Destroy'Access)
   );
   Handlers.Connect
   (  Button,
      "clicked",
      Handlers.To_Marshaller (Clicked'Access)
   );
   Show_All (Grid);
   Show (Window);
 
   Gtk.Main.Main;
end Tell_Mouse;
Task: Mouse position








VB: Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    Me.Print "X:" & X
    Me.Print "Y:" & Y
End Sub




Ada: with GLib;        use GLib;
with Gtk.Button;  use Gtk.Button;
with Gtk.Label;   use Gtk.Label;
with Gtk.Window;  use Gtk.Window;
with Gtk.Widget;  use Gtk.Widget;
with Gtk.Table;   use Gtk.Table;
 
with Gtk.Handlers;
with Gtk.Main;
 
procedure Tell_Mouse is
   Window : Gtk_Window;
   Grid   : Gtk_Table;
   Button : Gtk_Button;
   Label  : Gtk_Label;
 
   package Handlers is new Gtk.Handlers.Callback (Gtk_Widget_Record);
   package Return_Handlers is
      new Gtk.Handlers.Return_Callback (Gtk_Widget_Record, Boolean);
 
   function Delete_Event (Widget : access Gtk_Widget_Record'Class)
      return Boolean is
   begin
      return False;
   end Delete_Event;
 
   procedure Destroy (Widget : access Gtk_Widget_Record'Class) is
   begin
      Gtk.Main.Main_Quit;
   end Destroy;
 
   procedure Clicked (Widget : access Gtk_Widget_Record'Class) is
      X, Y : GInt;
   begin
      Get_Pointer (Window, X, Y);
      Set_Text (Label, "At" & GInt'Image (X) & GInt'Image (Y));
   end Clicked;
 
begin
   Gtk.Main.Init;
   Gtk.Window.Gtk_New (Window);
   Gtk_New (Grid, 1, 2, False);
   Add (Window, Grid);
   Gtk_New (Label);
   Attach (Grid, Label, 0, 1, 0, 1);
   Gtk_New (Button, "Click me");
   Attach (Grid, Button, 0, 1, 1, 2);
   Return_Handlers.Connect
   (  Window,
      "delete_event",
      Return_Handlers.To_Marshaller (Delete_Event'Access)
   );
   Handlers.Connect
   (  Window,
      "destroy",
      Handlers.To_Marshaller (Destroy'Access)
   );
   Handlers.Connect
   (  Button,
      "clicked",
      Handlers.To_Marshaller (Clicked'Access)
   );
   Show_All (Grid);
   Show (Window);
 
   Gtk.Main.Main;
end Tell_Mouse;
Task: Mouse position

C: #include <stdio.h>
#include <X11/Xlib.h>

int main()
{
  Display *d;
  Window inwin;      
  Window inchildwin; 
  int rootx, rooty; 
  int childx, childy;  
  Atom atom_type_prop; 
  int actual_format;   
  unsigned int mask;   
  unsigned long n_items, bytes_after_ret;
  Window *props; 

  
  d = XOpenDisplay(NULL); 

  
  (void)XGetWindowProperty(d, DefaultRootWindow(d),
			   XInternAtom(d, "_NET_ACTIVE_WINDOW", True),
			   0, 1, False, AnyPropertyType,
			   &atom_type_prop, &actual_format,
			   &n_items, &bytes_after_ret, (unsigned char**)&props);
			  
  XQueryPointer(d, props[0], &inwin,  &inchildwin,
		&rootx, &rooty, &childx, &childy, &mask);
  printf("relative to active window: %d,%d\n", childx, childy);

  XFree(props);           
  (void)XCloseDisplay(d); 
  return 0;
}
Task: Mouse position



C#: using System;
using System.Windows.Forms;
static class Program
{
    [STAThread]
    static void Main()
    {
        Console.WriteLine(Control.MousePosition.X);
        Console.WriteLine(Control.MousePosition.Y);
    }
}
Task: Mouse position





Java: Point mouseLocation = MouseInfo.getPointerInfo().getLocation();
Task: Mouse position







Python: def setup():
    size(640, 480)

def draw():
    
    ellipse(mouseX, mouseY, 5, 5) 
    println("x:{} y:{}".format(mouseX, mouseY))
Task: Mouse position








VB: Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    
    Me.Print "X:" & X
    Me.Print "Y:" & Y
End Sub
Task: Mouse position




Go: package main

import (
    "fmt"
    "github.com/go-vgo/robotgo"
)

func isInside(x, y, w, h, mx, my int) bool {
    rx := x + w - 1
    ry := y + h - 1
    return mx >= x && mx <= rx && my >= y && my <= ry
}

func main() {
    name := "gedit" 
    fpid, err := robotgo.FindIds(name)
    if err == nil && len(fpid) > 0 {
        pid := fpid[0]
        robotgo.ActivePID(pid) 
        x, y, w, h := robotgo.GetBounds(pid)
        fmt.Printf("The active window's top left corner is at (%d, %d)\n", x, y)
        fmt.Printf("Its width is %d and its height is %d\n", w, h)
        mx, my := robotgo.GetMousePos()
        fmt.Printf("The screen location of the mouse cursor is (%d, %d)\n", mx, my)
        if !isInside(x, y, w, h, mx, my) {
            fmt.Println("The mouse cursor is outside the active window")
        } else {
            wx := mx - x
            wy := my - y
            fmt.Printf("The window location of the mouse cursor is (%d, %d)\n", wx, wy)
        }
    } else {
        fmt.Println("Problem when finding PID(s) of", name)
    }
}
Task: Terminal control_Hiding the cursor



C#: static void Main(string[] args)
{
    Console.Write("At the end of this line you will see the cursor, process will sleep for 5 seconds.");
    System.Threading.Thread.Sleep(5000);
    Console.CursorVisible = false;
    Console.WriteLine();
    Console.Write("At the end of this line you will not see the cursor, process will sleep for 5 seconds.");
    System.Threading.Thread.Sleep(5000);
}









Ada: with Ada.Text_Io;

with Ansi;

procedure Hiding is
   use Ada.Text_Io;
begin
   Put ("Hiding the cursor for 2.0 seconds...");
   delay 0.500;
   Put (Ansi.Hide);
   delay 2.000;
   Put ("And showing again.");
   delay 0.500;
   Put (Ansi.Show);
   delay 2.000;
   New_Line;
end Hiding;
Task: Terminal control_Hiding the cursor

C: 

#include<curses.h>
#include<stdio.h>

int
main ()
{
  printf
    ("At the end of this line you will see the cursor, process will sleep for 5 seconds.");
  napms (5000);
  curs_set (0);
  printf
    ("\nAt the end of this line you will NOT see the cursor, process will again sleep for 5 seconds.");
  napms (5000);
  printf ("\nGoodbye.");
  return 0;
}











Ada: with Ada.Text_Io;

with Ansi;

procedure Hiding is
   use Ada.Text_Io;
begin
   Put ("Hiding the cursor for 2.0 seconds...");
   delay 0.500;
   Put (Ansi.Hide);
   delay 2.000;
   Put ("And showing again.");
   delay 0.500;
   Put (Ansi.Show);
   delay 2.000;
   New_Line;
end Hiding;
Task: Terminal control_Hiding the cursor


C++: #include <Windows.h>
int main()
{
  bool showCursor = false;
  
  HANDLE std_out = GetStdHandle(STD_OUTPUT_HANDLE); 
  CONSOLE_CURSOR_INFO cursorInfo;                   
  GetConsoleCursorInfo(out, &cursorInfo);           
  cursorInfo.bVisible = showCursor;                 
  SetConsoleCursorInfo(out, &cursorInfo);           
}










Ada: with Ada.Text_Io;

with Ansi;

procedure Hiding is
   use Ada.Text_Io;
begin
   Put ("Hiding the cursor for 2.0 seconds...");
   delay 0.500;
   Put (Ansi.Hide);
   delay 2.000;
   Put ("And showing again.");
   delay 0.500;
   Put (Ansi.Show);
   delay 2.000;
   New_Line;
end Hiding;
Task: Terminal control_Hiding the cursor




Go: package main

import (
    "os"
    "os/exec"
    "time"
)

func main() {
    tput("civis") 
    time.Sleep(3 * time.Second)
    tput("cvvis") 
    time.Sleep(3 * time.Second)
}

func tput(arg string) error {
    cmd := exec.Command("tput", arg)
    cmd.Stdout = os.Stdout
    return cmd.Run()
}








Ada: with Ada.Text_Io;

with Ansi;

procedure Hiding is
   use Ada.Text_Io;
begin
   Put ("Hiding the cursor for 2.0 seconds...");
   delay 0.500;
   Put (Ansi.Hide);
   delay 2.000;
   Put ("And showing again.");
   delay 0.500;
   Put (Ansi.Show);
   delay 2.000;
   New_Line;
end Hiding;
Task: Terminal control_Hiding the cursor







Python: print("\x1b[?25l") 
print("\x1b[?25h") 





Ada: with Ada.Text_Io;

with Ansi;

procedure Hiding is
   use Ada.Text_Io;
begin
   Put ("Hiding the cursor for 2.0 seconds...");
   delay 0.500;
   Put (Ansi.Hide);
   delay 2.000;
   Put ("And showing again.");
   delay 0.500;
   Put (Ansi.Show);
   delay 2.000;
   New_Line;
end Hiding;
Task: Terminal control_Hiding the cursor

C: 

#include<curses.h>
#include<stdio.h>

int
main ()
{
  printf
    ("At the end of this line you will see the cursor, process will sleep for 5 seconds.");
  napms (5000);
  curs_set (0);
  printf
    ("\nAt the end of this line you will NOT see the cursor, process will again sleep for 5 seconds.");
  napms (5000);
  printf ("\nGoodbye.");
  return 0;
}
Task: Terminal control_Hiding the cursor



C#: static void Main(string[] args)
{
    Console.Write("At the end of this line you will see the cursor, process will sleep for 5 seconds.");
    System.Threading.Thread.Sleep(5000);
    Console.CursorVisible = false;
    Console.WriteLine();
    Console.Write("At the end of this line you will not see the cursor, process will sleep for 5 seconds.");
    System.Threading.Thread.Sleep(5000);
}
Task: Terminal control_Hiding the cursor


C++: #include <Windows.h>
int main()
{
  bool showCursor = false;
  
  HANDLE std_out = GetStdHandle(STD_OUTPUT_HANDLE); 
  CONSOLE_CURSOR_INFO cursorInfo;                   
  GetConsoleCursorInfo(out, &cursorInfo);           
  cursorInfo.bVisible = showCursor;                 
  SetConsoleCursorInfo(out, &cursorInfo);           
}
Task: Terminal control_Hiding the cursor







Python: print("\x1b[?25l") 
print("\x1b[?25h")
Task: Terminal control_Hiding the cursor








VB: Locate , , 0    

Sleep 500       

Locate , , 1    

Sleep
Task: Terminal control_Hiding the cursor




Go: package main

import (
    "os"
    "os/exec"
    "time"
)

func main() {
    tput("civis") 
    time.Sleep(3 * time.Second)
    tput("cvvis") 
    time.Sleep(3 * time.Second)
}

func tput(arg string) error {
    cmd := exec.Command("tput", arg)
    cmd.Stdout = os.Stdout
    return cmd.Run()
}
Task: Terminal control_Hiding the cursor






PHP: #!/usr/bin/php
<?php
echo "\e[?25l"; // Cursor hide escape sequence
sleep(5);
echo "\e[?25h"; // Cursor show escape sequence
sleep(5);






Ada: with Ada.Text_Io;

with Ansi;

procedure Hiding is
   use Ada.Text_Io;
begin
   Put ("Hiding the cursor for 2.0 seconds...");
   delay 0.500;
   Put (Ansi.Hide);
   delay 2.000;
   Put ("And showing again.");
   delay 0.500;
   Put (Ansi.Show);
   delay 2.000;
   New_Line;
end Hiding;
Task: Terminal control_Hiding the cursor






PHP: #!/usr/bin/php
<?php
echo "\e[?25l"; // Cursor hide escape sequence
sleep(5);
echo "\e[?25h"; // Cursor show escape sequence
sleep(5);
Task: Simple windowed application



C#: using System.Windows.Forms;

class RosettaForm : Form
{
    RosettaForm()
    {
        var clickCount = 0;

        var label = new Label();
        label.Text = "There have been no clicks yet.";
        label.Dock = DockStyle.Top;
        Controls.Add(label);

        var button = new Button();
        button.Text = "Click Me";
        button.Dock = DockStyle.Bottom;
        button.Click += delegate
                        {
                            clickCount++;
                            label.Text = "Number of clicks: " + clickCount + ".";
                        };
        Controls.Add(button);
    }

    static void Main()
    {
        Application.Run(new RosettaForm());
    }
}









Ada: with Gdk.Event;   use Gdk.Event;
with Gtk.Button;  use Gtk.Button;
with Gtk.Label;   use Gtk.Label;
with Gtk.Window;  use Gtk.Window;
with Gtk.Widget;  use Gtk.Widget;
with Gtk.Table;   use Gtk.Table;

with Gtk.Handlers;
with Gtk.Main;

procedure Simple_Windowed_Application is
   Window : Gtk_Window;
   Grid   : Gtk_Table;
   Button : Gtk_Button;
   Label  : Gtk_Label;
   Count  : Natural := 0;

   package Handlers is new Gtk.Handlers.Callback (Gtk_Widget_Record);
   package Return_Handlers is
      new Gtk.Handlers.Return_Callback (Gtk_Widget_Record, Boolean);

   function Delete_Event (Widget : access Gtk_Widget_Record'Class)
      return Boolean is
   begin
      return False;
   end Delete_Event;

   procedure Destroy (Widget : access Gtk_Widget_Record'Class) is
   begin
     Gtk.Main.Main_Quit;
   end Destroy;

   procedure Clicked (Widget : access Gtk_Widget_Record'Class) is
   begin
     Count := Count + 1;
     Set_Text (Label, "The button clicks:" & Natural'Image (Count));
   end Clicked;

begin
   Gtk.Main.Init;
   Gtk.Window.Gtk_New (Window);
   Gtk_New (Grid, 1, 2, False);
   Add (Window, Grid);
   Gtk_New (Label, "There have been no clicks yet");
   Attach (Grid, Label, 0, 1, 0, 1);
   Gtk_New (Button, "Click me");
   Attach (Grid, Button, 0, 1, 1, 2);
   Return_Handlers.Connect
   (  Window,
      "delete_event",
      Return_Handlers.To_Marshaller (Delete_Event'Access)
   );
   Handlers.Connect
   (  Window,
      "destroy",
      Handlers.To_Marshaller (Destroy'Access)
   );
   Handlers.Connect
   (  Button,
      "clicked",
      Handlers.To_Marshaller (Clicked'Access)
   );
   Show_All (Grid);
   Show (Window);

   Gtk.Main.Main;
end Simple_Windowed_Application;
Task: Simple windowed application

C: #include <stdio.h>
#include <gtk/gtk.h>

const gchar *clickme = "Click Me";
guint counter = 0;

#define MAXLEN 64
void clickedme(GtkButton *o, gpointer d)
{
    GtkLabel *l = GTK_LABEL(d);
    char nt[MAXLEN];
    
    counter++;
    snprintf(nt, MAXLEN, "You clicked me %d times", counter);
    gtk_label_set_text(l, nt);
}

int main(int argc, char **argv)
{
    GtkWindow *win;
    GtkButton *button;
    GtkLabel *label;
    GtkVBox *vbox;

    gtk_init(&argc, &argv);
    win = (GtkWindow*)gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(win, clickme);
    button = (GtkButton*)gtk_button_new_with_label(clickme);
    label = (GtkLabel*)gtk_label_new("There have been no clicks yet");
    gtk_label_set_single_line_mode(label, TRUE);
    vbox = (GtkVBox*)gtk_vbox_new(TRUE, 1);
    gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET(label));
    gtk_container_add(GTK_CONTAINER(vbox), GTK_WIDGET(button));
    gtk_container_add(GTK_CONTAINER(win), GTK_WIDGET(vbox));
    g_signal_connect(G_OBJECT(win), "delete-event", (GCallback)gtk_main_quit, NULL);
    g_signal_connect(G_OBJECT(button), "clicked", (GCallback)clickedme, label);
    gtk_widget_show_all(GTK_WIDGET(win));
    gtk_main();
    return 0;
}











Ada: with Gdk.Event;   use Gdk.Event;
with Gtk.Button;  use Gtk.Button;
with Gtk.Label;   use Gtk.Label;
with Gtk.Window;  use Gtk.Window;
with Gtk.Widget;  use Gtk.Widget;
with Gtk.Table;   use Gtk.Table;

with Gtk.Handlers;
with Gtk.Main;

procedure Simple_Windowed_Application is
   Window : Gtk_Window;
   Grid   : Gtk_Table;
   Button : Gtk_Button;
   Label  : Gtk_Label;
   Count  : Natural := 0;

   package Handlers is new Gtk.Handlers.Callback (Gtk_Widget_Record);
   package Return_Handlers is
      new Gtk.Handlers.Return_Callback (Gtk_Widget_Record, Boolean);

   function Delete_Event (Widget : access Gtk_Widget_Record'Class)
      return Boolean is
   begin
      return False;
   end Delete_Event;

   procedure Destroy (Widget : access Gtk_Widget_Record'Class) is
   begin
     Gtk.Main.Main_Quit;
   end Destroy;

   procedure Clicked (Widget : access Gtk_Widget_Record'Class) is
   begin
     Count := Count + 1;
     Set_Text (Label, "The button clicks:" & Natural'Image (Count));
   end Clicked;

begin
   Gtk.Main.Init;
   Gtk.Window.Gtk_New (Window);
   Gtk_New (Grid, 1, 2, False);
   Add (Window, Grid);
   Gtk_New (Label, "There have been no clicks yet");
   Attach (Grid, Label, 0, 1, 0, 1);
   Gtk_New (Button, "Click me");
   Attach (Grid, Button, 0, 1, 1, 2);
   Return_Handlers.Connect
   (  Window,
      "delete_event",
      Return_Handlers.To_Marshaller (Delete_Event'Access)
   );
   Handlers.Connect
   (  Window,
      "destroy",
      Handlers.To_Marshaller (Destroy'Access)
   );
   Handlers.Connect
   (  Button,
      "clicked",
      Handlers.To_Marshaller (Clicked'Access)
   );
   Show_All (Grid);
   Show (Window);

   Gtk.Main.Main;
end Simple_Windowed_Application;
Task: Simple windowed application


C++: #ifndef CLICKCOUNTER_H
#define CLICKCOUNTER_H

#include <QWidget>
class QLabel ;
class QPushButton ;
class QVBoxLayout ;

class Counter : public QWidget {
    Q_OBJECT
public :
   Counter( QWidget * parent = 0 ) ;
private :
   int number ;
   QLabel *countLabel ;
   QPushButton *clicker ;
   QVBoxLayout *myLayout ;
private slots :
   void countClicks( ) ;
} ;
#endif










Ada: with Gdk.Event;   use Gdk.Event;
with Gtk.Button;  use Gtk.Button;
with Gtk.Label;   use Gtk.Label;
with Gtk.Window;  use Gtk.Window;
with Gtk.Widget;  use Gtk.Widget;
with Gtk.Table;   use Gtk.Table;

with Gtk.Handlers;
with Gtk.Main;

procedure Simple_Windowed_Application is
   Window : Gtk_Window;
   Grid   : Gtk_Table;
   Button : Gtk_Button;
   Label  : Gtk_Label;
   Count  : Natural := 0;

   package Handlers is new Gtk.Handlers.Callback (Gtk_Widget_Record);
   package Return_Handlers is
      new Gtk.Handlers.Return_Callback (Gtk_Widget_Record, Boolean);

   function Delete_Event (Widget : access Gtk_Widget_Record'Class)
      return Boolean is
   begin
      return False;
   end Delete_Event;

   procedure Destroy (Widget : access Gtk_Widget_Record'Class) is
   begin
     Gtk.Main.Main_Quit;
   end Destroy;

   procedure Clicked (Widget : access Gtk_Widget_Record'Class) is
   begin
     Count := Count + 1;
     Set_Text (Label, "The button clicks:" & Natural'Image (Count));
   end Clicked;

begin
   Gtk.Main.Init;
   Gtk.Window.Gtk_New (Window);
   Gtk_New (Grid, 1, 2, False);
   Add (Window, Grid);
   Gtk_New (Label, "There have been no clicks yet");
   Attach (Grid, Label, 0, 1, 0, 1);
   Gtk_New (Button, "Click me");
   Attach (Grid, Button, 0, 1, 1, 2);
   Return_Handlers.Connect
   (  Window,
      "delete_event",
      Return_Handlers.To_Marshaller (Delete_Event'Access)
   );
   Handlers.Connect
   (  Window,
      "destroy",
      Handlers.To_Marshaller (Destroy'Access)
   );
   Handlers.Connect
   (  Button,
      "clicked",
      Handlers.To_Marshaller (Clicked'Access)
   );
   Show_All (Grid);
   Show (Window);

   Gtk.Main.Main;
end Simple_Windowed_Application;