Giter VIP home page Giter VIP logo

swiftgtk's Introduction

SwiftGtk

SwiftGtk is a experimental Gtk+ binding for Swift that tries to make usage of Gtk+ pleasant and "Swifty" as much as possible. Currently it implements only a small subset of Gtk+ and it works on Mac OS X and Linux.

Dependencies

You need to have Swift 3.1 or higher installed on your computer (tested with 3.1.1 bundled with Xcode 8.3.3) and depending on your platform you need to install Gtk+3. On Mac OS X you can also build the project with Xcode.

Mac OS X

You need to have Gtk+3 installed on your machine. Recommended way for installing Gtk+3 is through homebrew.

brew install gtk+3

Linux

You need to have Gtk+3 and Clang installed on your machine. You can easily install them with apt-get.

sudo apt-get install libgtk-3-dev clang

Usage

SwiftGtk supports Swift Package Manager so you only need to add SwiftGtk to your Package.swift.

import PackageDescription

let package = Package(
    name: "SwiftGtkApplication",
    dependencies: [
        .Package(url: "https://github.com/TomasLinhart/SwiftGtk", Version(0, 3, 1))
    ]
)

After that run swift build in the folder where Package.swift is located. Once it builds you can execute the application .build/debug/SwiftGtkApplication.

Demo

Following code will create a window with a button that when it is pressed presents another window.

import SwiftGtk

let app = Application(applicationId: "com.example.application")
app.run { window in
    window.title = "Hello World"
    window.defaultSize = Size(width: 400, height: 400)
    window.resizable = true

    let button = Button(label: "Press Me")
    button.clicked = { _ in
        let newWindow = Window(windowType: .topLevel)
        newWindow.title = "Just a window"
        newWindow.defaultSize = Size(width: 200, height: 200)
        let labelPressed = Label(text: "Oh, you pressed the button.")
        newWindow.add(labelPressed)

        newWindow.showAll()
    }

    window.add(button)
}

License

All code is licensed under MIT license.

swiftgtk's People

Contributors

tomaslinhart avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

swiftgtk's Issues

Segmentation fault

I am trying to use your library on Ubuntu 15.10 and I get the following output when I attempt to build my project:

Cloning https://github.com/TomasLinhart/SwiftGtk
git clone --recursive --depth 10 https://github.com/TomasLinhart/SwiftGtk /media/sf_projects/prototype/hello-swift/Hello/Packages/SwiftGtk

Segmentation fault (core dumped)

[Archlinux] Still not building

Thank you for latest changes. However, it is still failing at CGtk (running in Archlinux):

Fetching https://github.com/TomasLinhart/SwiftGtk
Fetching https://github.com/TomasLinhart/CGtk-Linux
Cloning https://github.com/TomasLinhart/CGtk-Linux
Resolving https://github.com/TomasLinhart/CGtk-Linux at 1.2.0
Cloning https://github.com/TomasLinhart/SwiftGtk
Resolving https://github.com/TomasLinhart/SwiftGtk at 0.3.0
Compile Swift Module 'SwiftGtk' (24 sources)
<module-includes>:2:10: note: in file included from <module-includes>:2:
#include "/usr/include/gtk-3.0/gtk/gtk.h"
         ^
/usr/include/gtk-3.0/gtk/gtk.h:30:10: note: in file included from /usr/include/gtk-3.0/gtk/gtk.h:30:
#include <gdk/gdk.h>etching https://github.com/TomasLinhart/SwiftGtk
Fetching https://github.com/TomasLinhart/CGtk-Linux
Cloning https://github.com/TomasLinhart/CGtk-Linux
Resolving https://github.com/TomasLinhart/CGtk-Linux at 1.2.0
Cloning https://github.com/TomasLinhart/SwiftGtk
Resolving https://github.com/TomasLinhart/SwiftGtk at 0.3.0
Compile Swift Module 'SwiftGtk' (24 sources)
<module-includes>:2:10: note: in file included from <module-includes>:2:
#include "/usr/include/gtk-3.0/gtk/gtk.h"
         ^
/usr/include/gtk-3.0/gtk/gtk.h:30:10: note: in file i
         ^
/usr/include/gtk-3.0/gdk/gdk.h:30:10: note: in file included from /usr/include/gtk-3.0/gdk/gdk.h:30:
#include <gdk/gdkconfig.h>
         ^
/usr/include/gtk-3.0/gdk/gdkconfig.h:13:10: note: in file included from /usr/include/gtk-3.0/gdk/gdkconfig.h:13:
#include <glib.h>
         ^
/usr/include/glib-2.0/glib.h:37:10: note: in file included from /usr/include/glib-2.0/glib.h:37:
#include <glib/gbookmarkfile.h>
         ^
/usr/include/glib-2.0/glib/gbookmarkfile.h:171:11: error: declaration of 'time_t' must be imported from module 'SwiftGlibc.POSIX.sys.types' before it is required
                                                    time_t          stamp,
                                                    ^
/usr/include/bits/types/time_t.h:8:18: note: previous declaration is here
typedef __time_t time_t;
                 ^
/home/luis/Dropbox/Documentos/Coding/Swift/CurseMusic/.build/checkouts/SwiftGtk--6996955162340312306/Sources/PositionType.swift:5:8: error: could not build Objective-C module 'CGtk'
import CGtk
       ^
<module-includes>:2:10: note: in file included from <module-includes>:2:
#include "/usr/include/gtk-3.0/gtk/gtk.h"
         ^
/usr/include/gtk-3.0/gtk/gtk.h:30:10: note: in file included from /usr/include/gtk-3.0/gtk/gtk.h:30:
#include <gdk/gdk.h>
         ^
/usr/include/gtk-3.0/gdk/gdk.h:30:10: note: in file included from /usr/include/gtk-3.0/gdk/gdk.h:30:
#include <gdk/gdkconfig.h>
         ^
/usr/include/gtk-3.0/gdk/gdkconfig.h:13:10: note: in file included from /usr/include/gtk-3.0/gdk/gdkconfig.h:13:
#include <glib.h>
         ^
/usr/include/glib-2.0/glib.h:37:10: note: in file included from /usr/include/glib-2.0/glib.h:37:
#include <glib/gbookmarkfile.h>
         ^
/usr/include/glib-2.0/glib/gbookmarkfile.h:171:11: error: declaration of 'time_t' must be imported from module 'SwiftGlibc.POSIX.sys.types' before it is required
                                                    time_t          stamp,
                                                    ^
/usr/include/bits/types/time_t.h:8:18: note: previous declaration is here
typedef __time_t time_t;
                 ^
/home/luis/Dropbox/Documentos/Coding/Swift/CurseMusic/.build/checkouts/SwiftGtk--6996955162340312306/Sources/PositionType.swift:5:8: error: could not build Objective-C module 'CGtk'
import CGtk
       ^
<module-includes>:2:10: note: in file included from <module-includes>:2:
#include "/usr/include/gtk-3.0/gtk/gtk.h"
         ^
/usr/include/gtk-3.0/gtk/gtk.h:30:10: note: in file included from /usr/include/gtk-3.0/gtk/gtk.h:30:
#include <gdk/gdk.h>
         ^
/usr/include/gtk-3.0/gdk/gdk.h:30:10: note: in file included from /usr/include/gtk-3.0/gdk/gdk.h:30:
#include <gdk/gdkconfig.h>
         ^
/usr/include/gtk-3.0/gdk/gdkconfig.h:13:10: note: in file included from /usr/include/gtk-3.0/gdk/gdkconfig.h:13:
#include <glib.h>
         ^
/usr/include/glib-2.0/glib.h:37:10: note: in file included from /usr/include/glib-2.0/glib.h:37:
#include <glib/gbookmarkfile.h>
         ^
/usr/include/glib-2.0/glib/gbookmarkfile.h:171:11: error: declaration of 'time_t' must be imported from module 'SwiftGlibc.POSIX.sys.types' before it is required
                                                    time_t          stamp,
                                                    ^
/usr/include/bits/types/time_t.h:8:18: note: previous declaration is here
typedef __time_t time_t;
                 ^
/home/luis/Dropbox/Documentos/Coding/Swift/CurseMusic/.build/checkouts/SwiftGtk--6996955162340312306/Sources/PositionType.swift:5:8: error: could not build Objective-C module 'CGtk'
import CGtk
       ^
<module-includes>:2:10: note: in file included from <module-includes>:2:
#include "/usr/include/gtk-3.0/gtk/gtk.h"
         ^
/usr/include/gtk-3.0/gtk/gtk.h:30:10: note: in file included from /usr/include/gtk-3.0/gtk/gtk.h:30:
#include <gdk/gdk.h>
         ^
/usr/include/gtk-3.0/gdk/gdk.h:30:10: note: in file included from /usr/include/gtk-3.0/gdk/gdk.h:30:
#include <gdk/gdkconfig.h>
         ^
/usr/include/gtk-3.0/gdk/gdkconfig.h:13:10: note: in file included from /usr/include/gtk-3.0/gdk/gdkconfig.h:13:
#include <glib.h>
         ^
/usr/include/glib-2.0/glib.h:37:10: note: in file included from /usr/include/glib-2.0/glib.h:37:
#include <glib/gbookmarkfile.h>
         ^
/usr/include/glib-2.0/glib/gbookmarkfile.h:171:11: error: declaration of 'time_t' must be imported from module 'SwiftGlibc.POSIX.sys.types' before it is required
                                                    time_t          stamp,
                                                    ^
/usr/include/bits/types/time_t.h:8:18: note: previous declaration is here
typedef __time_t time_t;
                 ^
/home/luis/Dropbox/Documentos/Coding/Swift/CurseMusic/.build/checkouts/SwiftGtk--6996955162340312306/Sources/PositionType.swift:5:8: error: could not build Objective-C module 'CGtk'
import CGtk
       ^
<module-includes>:2:10: note: in file included from <module-includes>:2:
#include "/usr/include/gtk-3.0/gtk/gtk.h"
         ^
/usr/include/gtk-3.0/gtk/gtk.h:30:10: note: in file included from /usr/include/gtk-3.0/gtk/gtk.h:30:
#include <gdk/gdk.h>
         ^
/usr/include/gtk-3.0/gdk/gdk.h:30:10: note: in file included from /usr/include/gtk-3.0/gdk/gdk.h:30:
#include <gdk/gdkconfig.h>
         ^
/usr/include/gtk-3.0/gdk/gdkconfig.h:13:10: note: in file included from /usr/include/gtk-3.0/gdk/gdkconfig.h:13:
#include <glib.h>
         ^
/usr/include/glib-2.0/glib.h:37:10: note: in file included from /usr/include/glib-2.0/glib.h:37:
#include <glib/gbookmarkfile.h>
         ^
/usr/include/glib-2.0/glib/gbookmarkfile.h:171:11: error: declaration of 'time_t' must be imported from module 'SwiftGlibc.POSIX.sys.types' before it is required
                                                    time_t          stamp,
                                                    ^
/usr/include/bits/types/time_t.h:8:18: note: previous declaration is here
typedef __time_t time_t;
                 ^
/home/luis/Dropbox/Documentos/Coding/Swift/CurseMusic/.build/checkouts/SwiftGtk--6996955162340312306/Sources/PositionType.swift:5:8: error: could not build Objective-C module 'CGtk'
import CGtk
       ^
<module-includes>:2:10: note: in file included from <module-includes>:2:
#include "/usr/include/gtk-3.0/gtk/gtk.h"
         ^
/usr/include/gtk-3.0/gtk/gtk.h:30:10: note: in file included from /usr/include/gtk-3.0/gtk/gtk.h:30:
#include <gdk/gdk.h>
         ^
/usr/include/gtk-3.0/gdk/gdk.h:30:10: note: in file included from /usr/include/gtk-3.0/gdk/gdk.h:30:
#include <gdk/gdkconfig.h>
         ^
/usr/include/gtk-3.0/gdk/gdkconfig.h:13:10: note: in file included from /usr/include/gtk-3.0/gdk/gdkconfig.h:13:
#include <glib.h>
         ^
/usr/include/glib-2.0/glib.h:37:10: note: in file included from /usr/include/glib-2.0/glib.h:37:
#include <glib/gbookmarkfile.h>
         ^
/usr/include/glib-2.0/glib/gbookmarkfile.h:171:11: error: declaration of 'time_t' must be imported from module 'SwiftGlibc.POSIX.sys.types' before it is required
                                                    time_t          stamp,
                                                    ^
/usr/include/bits/types/time_t.h:8:18: note: previous declaration is here
typedef __time_t time_t;
                 ^
/home/luis/Dropbox/Documentos/Coding/Swift/CurseMusic/.build/checkouts/SwiftGtk--6996955162340312306/Sources/PositionType.swift:5:8: error: could not build Objective-C module 'CGtk'
import CGtk
       ^
<module-includes>:2:10: note: in file included from <module-includes>:2:
#include "/usr/include/gtk-3.0/gtk/gtk.h"
         ^
/usr/include/gtk-3.0/gtk/gtk.h:30:10: note: in file included from /usr/include/gtk-3.0/gtk/gtk.h:30:
#include <gdk/gdk.h>
         ^
/usr/include/gtk-3.0/gdk/gdk.h:30:10: note: in file included from /usr/include/gtk-3.0/gdk/gdk.h:30:
#include <gdk/gdkconfig.h>
         ^
/usr/include/gtk-3.0/gdk/gdkconfig.h:13:10: note: in file included from /usr/include/gtk-3.0/gdk/gdkconfig.h:13:
#include <glib.h>
         ^
/usr/include/glib-2.0/glib.h:37:10: note: in file included from /usr/include/glib-2.0/glib.h:37:
#include <glib/gbookmarkfile.h>
         ^
/usr/include/glib-2.0/glib/gbookmarkfile.h:171:11: error: declaration of 'time_t' must be imported from module 'SwiftGlibc.POSIX.sys.types' before it is required
                                                    time_t          stamp,
                                                    ^
/usr/include/bits/types/time_t.h:8:18: note: previous declaration is here
typedef __time_t time_t;
                 ^
/home/luis/Dropbox/Documentos/Coding/Swift/CurseMusic/.build/checkouts/SwiftGtk--6996955162340312306/Sources/PositionType.swift:5:8: error: could not build Objective-C module 'CGtk'
import CGtk
       ^
<module-includes>:2:10: note: in file included from <module-includes>:2:
#include "/usr/include/gtk-3.0/gtk/gtk.h"
         ^
/usr/include/gtk-3.0/gtk/gtk.h:30:10: note: in file included from /usr/include/gtk-3.0/gtk/gtk.h:30:
#include <gdk/gdk.h>
         ^
/usr/include/gtk-3.0/gdk/gdk.h:30:10: note: in file included from /usr/include/gtk-3.0/gdk/gdk.h:30:
#include <gdk/gdkconfig.h>
         ^
/usr/include/gtk-3.0/gdk/gdkconfig.h:13:10: note: in file included from /usr/include/gtk-3.0/gdk/gdkconfig.h:13:
#include <glib.h>
         ^
/usr/include/glib-2.0/glib.h:37:10: note: in file included from /usr/include/glib-2.0/glib.h:37:
#include <glib/gbookmarkfile.h>
         ^
/usr/include/glib-2.0/glib/gbookmarkfile.h:171:11: error: declaration of 'time_t' must be imported from module 'SwiftGlibc.POSIX.sys.types' before it is required
                                                    time_t          stamp,
                                                    ^
/usr/include/bits/types/time_t.h:8:18: note: previous declaration is here
typedef __time_t time_t;
                 ^
/home/luis/Dropbox/Documentos/Coding/Swift/CurseMusic/.build/checkouts/SwiftGtk--6996955162340312306/Sources/PositionType.swift:5:8: error: could not build Objective-C module 'CGtk'
import CGtk
       ^
<unknown>:0: error: build had 1 command failures
swift-build: error: exit(1): /usr/bin/swift-build-tool -f /home/luis/Dropbox/Documentos/Coding/Swift/CurseMusic/.build/debug.yaml
[Finished in 30.1s with exit code 1]
[cmd: ['swift', 'build']]

Point users to an up-to-date fork in the readme

Hi Tomas,

I have created a fork of SwiftGtk that:

  1. is compatible with the latest Swift version
  2. has a neater repository structure
  3. is safer (no use of unowned)
  4. is actively maintained

Given that the last change to SwiftGtk was 5 years ago and you probably aren't interested in maintaining it anymore, would you be happy to prefix the readme with a link pointing to my fork as the newer version?

By the way, thanks for making this package, it's significantly nicer and easier to build compared to the other Swift Gtk packages I have found, great job!

Compile error!

Hi, i include your project in to my project and trying to build, after i got compile error

:0: error: build had 1 command failures
error: exit(1): /swift-3.0/usr/bin/swift-build-tool -f /home/user/swiftProjects/linSwift/.build/debug.yaml

[Enquiry] What is supported?

Thank you for your time and for this project.

You mention that only a subset of Gtk is supported. I couldn't find what is not supported...

Could you explain or point me to documentation?

Best

Project Status

What’s the current state of this project? It appears to be abandoned/unmaintained. If so, are there any maintained/active alternatives?

Building error

Following instructions from the README file leads to error in archlinux:

Compile Swift Module 'SwiftGtkApplication' (1 sources)
/tmp/swift/.build/checkouts/SwiftGtk--1935834152443114942/module.modulemap:3:8: error: redefinition of module 'CGtk'
module CGtk {
       ^
/tmp/swift/.build/checkouts/CGtk-Linux-2346253804840976437/module.modulemap:1:8: note: previously defined here
module CGtk [system] {
       ^
/tmp/swift/.build/checkouts/SwiftGtk--1935834152443114942/module.modulemap:3:8: error: redefinition of module 'CGtk'
module CGtk {
       ^
/tmp/swift/.build/checkouts/CGtk-Linux-2346253804840976437/module.modulemap:1:8: note: previously defined here
module CGtk [system] {
       ^
<unknown>:0: error: could not build Objective-C module 'SwiftShims'
<unknown>:0: error: build had 1 command failures
swift-build: error: exit(1): /usr/bin/swift-build-tool -f /tmp/swift/.build/debug.yaml
[Finished in 0.5s with exit code 1]

What am I doing wrong?

[Help] How to use headerbar? How Gtk classes are translated into swift?

Dear Tomas,

Thank you for this bindings! This is super useful.

I have a little experience in Vala, but on trying to use some elements from gtk I get errors. Specifically I am trying to use headerbars. How do this class translates into Swift? What am I doing wrong in the code below?

import SwiftGtk

let app = Application(applicationId: "com.example.application")

app.run { window in
    window.defaultSize = Size(width: 400, height: 400)
    window.resizable = true
    let headerbar = Headerbar()
    headerbar.set_title("My test")


    let button = Button(label: "Press Me")
    button.clicked = { _ in
        let newWindow = Window(windowType: .topLevel)
        newWindow.title = "Just a window"
        newWindow.defaultSize = Size(width: 200, height: 200)
        let labelPressed = Label(text: "Oh, you pressed the button.")
        newWindow.add(labelPressed)

        newWindow.showAll()
    }
    window.set_titlebar(headerbar)
    window.add(button)
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.