Rand Stats

Gnome::Gtk3

cpan:MARTIMM

gtk logo

Gnome Gtk3 - Widget toolkit for graphical interfaces

artistic-2.0

Documentation at this site has the GNU Free Documentation License.

Description

The purpose of this project is to create an interface to the GTK+ version 3 library.

History

There is already a bit of history for this package. It started off building the GTK::Glade package which soon became too big. So a part was separated into GTK::V3. After some working with the library I felt that the class names were a bit too long and that the words gtk and gdk were repeated too many times in the class path. E.g. there was GTK::V3::Gtk::GtkButton and GTK::V3::Gdk::GdkScreen to name a few. So, finally it was split into several other packages named, Gnome::N for the native linkup on behalf of any other Gnome modules, Gnome::Glib, Gnome::GObject, Gnome::Gdk3 and Gnome::Gtk3 according to what is shown on the developers page here. The classes in these packages are now renamed into e.g. Gnome::Gtk3::Button, Gnome::Gdk3::Screen, Gnome::GObject::Object and Gnome::Glib::List.

Note that all modules are now in :api<1> (as of 2024/4/5). This is done to prevent clashes with future distributions having the same class names only differing in this api string. So, add this string to your import statements and dependency modules of these classes in META6.json. Furthermore add this api string also when installing with zef.

Example

This example does the same as the example from GTK::Simple to show you the differences between the implementations. What immediately is clear is that this example is somewhat longer. To sum up;

Pros

Cons

A screenshot of the exampleA screenshot of Gtk Simple

The code can be found down on the Getting Started page.

use v6.d;

use Gnome::Gtk3::Main:api<1>;
use Gnome::Gtk3::Window:api<1>;
use Gnome::Gtk3::Grid:api<1>;
use Gnome::Gtk3::Button:api<1>;

# Instantiate main module for UI control
my Gnome::Gtk3::Main $m .= new;


# Class to handle signals
class AppSignalHandlers {

  # Handle 'Hello World' button click
  method first-button-click ( :_widget($b1), :other-button($b2) ) {
    $b1.set-sensitive(False);
    $b2.set-sensitive(True);
  }

  # Handle 'Goodbye' button click
  method second-button-click ( ) {
    $m.gtk-main-quit;
 }

  # Handle window managers 'close app' button
  method exit-program ( ) {
    $m.gtk-main-quit;
  }
}

# Instantiate the event handler class and register signals
my AppSignalHandlers $ash .= new;


# Create buttons and disable the second one
with my Gnome::Gtk3::Button $second .= new(:label('Goodbye')) {
  .set-sensitive(False);
  .register-signal( $ash, 'second-button-click', 'clicked');
}

with my Gnome::Gtk3::Button $button .= new(:label('Hello World')) {
  .register-signal(
    $ash, 'first-button-click', 'clicked',  :other-button($second)
  );
}

# Create grid and add buttons to the grid
with my Gnome::Gtk3::Grid $grid .= new {
  .attach( $button, 0, 0, 1, 1);
  .attach( $second, 0, 1, 1, 1);
}

# Create a top level window and set a title among other things
with my Gnome::Gtk3::Window $top-window .= new {
  .set-title('Hello GTK!');
  .set-border-width(20);

  # Create a grid and add it to the window
  .add($grid);

  .register-signal( $ash, 'exit-program', 'destroy');

  # Show everything and activate all
  .show-all;
}

# Start the event loop
$m.gtk-main;

Documentation

TODO

Versions of involved software

Installation

The version of Raku must be at least 2020.10, otherwise a few tests will not run!

There are several dependencies from one package to the other because it was one package in the past. To get all packages, just install the Gnome::Gtk3 package and the rest will be installed with it.

zef install 'Gnome::Gtk3:api<1>'

Issues

There are always some problems! If you find one, please help by filing an issue at my github project.

Attribution

Licenses

Author

Name: Marcel Timmerman Github account name: MARTIMM

Copyright

Β© 2019 - ∞ πŸ˜‰. Marcel Timmerman