All Projects → haskell-gi → Haskell Gi

haskell-gi / Haskell Gi

Licence: other
Generate Haskell bindings for GObject-Introspection capable libraries

Programming Languages

haskell
3896 projects

Labels

Projects that are alternatives of or similar to Haskell Gi

Keera Hails
Keera Hails: Haskell on Rails - Reactive Programming Framework for Interactive Haskell applications
Stars: ✭ 153 (-19.47%)
Mutual labels:  gtk
Forms Gtk Progress
Xamarin.Forms GTK Backend Progress
Stars: ✭ 166 (-12.63%)
Mutual labels:  gtk
Gala
Gala Window Manager
Stars: ✭ 173 (-8.95%)
Mutual labels:  gtk
Higgledy
Higher-kinded data via generics
Stars: ✭ 153 (-19.47%)
Mutual labels:  ghc
Gaupol
Editor for text-based subtitle files
Stars: ✭ 159 (-16.32%)
Mutual labels:  gtk
Rkflashkit
rkflashkit is an open source toolkit for flashing Linux kernel images to rockchip rk3066/rk3188/rk3288 etc. based devices. It's programmed with python and gtk2.
Stars: ✭ 169 (-11.05%)
Mutual labels:  gtk
Go Gtk
Go binding for GTK
Stars: ✭ 1,832 (+864.21%)
Mutual labels:  gtk
Node Webkitgtk
webkitgtk bindings for 🚀 Node.js
Stars: ✭ 185 (-2.63%)
Mutual labels:  gtk
Granite
Library that extends GTK with common widgets and utilities
Stars: ✭ 164 (-13.68%)
Mutual labels:  gtk
Gvsbuild
GTK+ 3 stack for Windows
Stars: ✭ 173 (-8.95%)
Mutual labels:  gtk
Ofxgpio
Library C++ for raspberrypi and orangepi, GPIO interfaces compatible with openframeworks.
Stars: ✭ 155 (-18.42%)
Mutual labels:  gtk
Tryton
Mirror of Tryton Client
Stars: ✭ 156 (-17.89%)
Mutual labels:  gtk
Automathemely
Simple, set-and-forget python application for changing between desktop themes according to light and dark hours
Stars: ✭ 169 (-11.05%)
Mutual labels:  gtk
Ulauncher
Linux Application Launcher
Stars: ✭ 2,362 (+1143.16%)
Mutual labels:  gtk
Awesome Gtk
List of awesome GTK+ (gtk3) applications
Stars: ✭ 174 (-8.42%)
Mutual labels:  gtk
Clamtk
An easy to use, light-weight, on-demand virus scanner for Linux systems
Stars: ✭ 151 (-20.53%)
Mutual labels:  gtk
Gtkhash
A cross-platform desktop utility for computing message digests or checksums
Stars: ✭ 167 (-12.11%)
Mutual labels:  gtk
Files
File browser designed for elementary OS
Stars: ✭ 187 (-1.58%)
Mutual labels:  gtk
Swiftgtk
A Swift wrapper around gtk-3.x and gtk-4.x that is largely auto-generated from gobject-introspection
Stars: ✭ 180 (-5.26%)
Mutual labels:  gtk
Gtk Fortran
A GTK / Fortran binding
Stars: ✭ 171 (-10%)
Mutual labels:  gtk

haskell-gi

Generate Haskell bindings for GObject Introspection capable libraries.

Installation

To compile the bindings generated by haskell-gi, make sure that you have installed the necessary development packages for the libraries you are interested in. The following are examples for some common distributions. (If your distribution is not listed please send a pull request!)

Fedora

sudo dnf install gobject-introspection-devel webkitgtk4-devel gtksourceview3-devel

Debian / Ubuntu

sudo apt-get install libgirepository1.0-dev libwebkit2gtk-4.0-dev libgtksourceview-3.0-dev

Arch Linux

sudo pacman -S gobject-introspection gobject-introspection-runtime gtksourceview3 webkit2gtk

Mac OSX

Install Homebrew and install GTK+ and GObject Introspection:

brew install gobject-introspection gtk+ gtk+3

Ensure the path to libffi (probably /usr/local/opt/libffi/lib/pkgconfig) is in the PKG_CONFIG_PATH environment variable.

Windows

Please see here for detailed installation instructions in Windows.

⚠️ GHC 8.2.x ⚠️

Unfortunately there is a bug in 8.2.x versions of GHC that makes it panic when compiling bindings generated by haskell-gi. Versions 8.0.x and earlier of GHC are not affected by the bug, and version 8.4.1 has the bug fixed. The simplest workaround is to avoid using GHC 8.2.x when using bindings generated by haskell-gi. Alternatively, disabling overloading will avoid the bug.

Using the generated bindings

The most recent versions of the generated bindings are available from hackage. To install, start by making sure that you have a recent (2.0 or later) version of cabal-install, for instance:

$ cabal install cabal-install
$ cabal --version
cabal-install version 2.4.1.0
compiled using version 2.4.1.0 of the Cabal library

Here is an example "Hello World" program:

{-# LANGUAGE OverloadedStrings, OverloadedLabels #-}
{- cabal:
build-depends: base, haskell-gi-base, gi-gtk == 3.0.*
-}

import qualified GI.Gtk as Gtk
import Data.GI.Base

main :: IO ()
main = do
  Gtk.init Nothing

  win <- new Gtk.Window [ #title := "Hi there" ]

  on win #destroy Gtk.mainQuit

  button <- new Gtk.Button [ #label := "Click me" ]

  on button #clicked (set button [ #sensitive := False,
                                   #label := "Thanks for clicking me" ])

  #add win button

  #showAll win

  Gtk.main

This program uses the new OverloadedLabels extension in GHC 8.0, so make sure you have a recent enough version of GHC installed. To run this program, copy it to a file (hello.hs, say), and then

$ cabal v2-run hello.hs

For a more involved example, see for instance this WebKit example. Further documentation can be found in the Wiki.

Translating from the C API to the haskell-gi generated API

The translation from the original C API to haskell-gi is fairly straightforward: for method names simply remove the library prefix (gtk, gdk, etc.), and convert to camelCase. I.e. gtk_widget_show becomes widgetShow in the module GI.Gtk (provided by the gi-gtk package).

For properties, add the type of the object as a prefix: so the sensitive property of GtkWidget becomes widgetSensitive in gi-gtk. These can be set using the new syntax, as follows:

b <- new Button [widgetSensitive := True]

or using set after having created the button

b `set` [widgetSensitive := False]

Alternatively you can use setWidgetSensitive and friends to set properties individually if you don't like the list syntax.

Finally, for signals you want to use the onTypeSignalName functions, for example onButtonClicked:

onButtonClicked b $ do ...

This is the basic dictionary. Note that all the resulting symbols can be conveniently searched in hoogle.

There is also support for the OverloadedLabels extension in GHC 8.0 or higher. So the examples above can be shortened (by omitting the type that introduces the signal/property/method) to

b <- new Button [#sensitive := True]
on b #clicked $ do ...
#show b

Hopefully this helps to get started! For any further questions there is a gitter channel that may be helpful at https://gitter.im/haskell-gi/haskell-gi.

Binding to new libraries

It should be rather easy to generate bindings to any library with gobject-introspection support, see the examples in the bindings folder. Pull requests appreciated!

Higher-Level Bindings

The bindings in haskell-gi aim for complete coverage of the bound APIs, but as a result they are imperative in flavour. For nicer, higher-level approaches based on these bindings, see:

Other Resources


Join the chat at https://gitter.im/haskell-gi/haskell-gi Linux CI

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].