GithubHelp home page GithubHelp logo

ffi-tk's Introduction

FFI::Tk

This library provides you with a wrapper for the Tk windowing toolkit.

Installation

gem install ffi-tk

No compilation is required, but I'm not yet confident that this will run on every architecture without changes, FFI::Tk is being developed on Archlinux and Debian on Intel i686 and AMD x86_64, testers for other platforms are invited to give it a try and report any problems that occur.

You will need to have tk installed in order to actually use the library.

Ruby-FFI

Ruby-FFI is a ruby extension for programmatically loading dynamic libraries, binding functions within them, and calling those functions from Ruby code.

It lives at: http://wiki.github.com/ffi/ffi

Ruby-FFI ships with JRuby and Rubinius, and is available as a gem for MRI.

Hello, World!

require 'ffi-tk'

Tk.init

Tk::Button.new('.', text: 'Press me'){
  Tk.message_box(message: 'Hello, World!')
}.pack

Tk.mainloop

Aims and Means

First of all, FFI::Tk doesn't try to be a drop-in replacement for the tk library of Ruby's stdlib.

We will try to keep things as simple as possible, and there will not be 10 different ways to achieve the same thing through numerous aliases.

We will not rely on any compiled extensions and the only dependency is FFI to keep things portable between different Ruby implementations (as far as they do implement the 1.9.1 standard syntax and core functinoality.)

I (manveru) will not provide a version of FFI::Tk for 1.8.x, there may be other persons that undertake this step, but due to lack of true encoding support it will be significant overhead to cater to both versions as you can see if you read a bit through the stdlib tk library. We will provide only wrapping for the standard distribution of tcl/tk as of version 8.5.7. Earlier versions have not been tested, and later versions may be used by taking advantage of the Tcl stub mechanism.

Custom extensions of tcl/tk may be wrapped by other people, and we will add a link to any such project, but we try to keep things simple here.

A comprehensive suite of specs describes the behaviour of FFI::Tk as well as possible.

The namespaces used are:

  • Tk
  • FFI::Tk
  • FFI::Tcl

The Tk namespace conflicts with the name of the Ruby's stdlib tk, but the use of them within one application is mutually exclusive anyway.

License

FFI::Tk is distributed under MIT license. Parts of the documentation were obtained from the tcl/tk manpages and modified to clarify and apply to the specifics of the FFI::Tk wrapper. These parts of the documentation are under Tcl license.

The licenses can be found in doc/TCL_LICENSE and doc/MIT_LICENSE respectively.

ffi-tk's People

Contributors

lian avatar manveru avatar reactormonk avatar

Stargazers

 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

ffi-tk's Issues

"a string bvalue".to_s? no method error

I just saw the update and thought I'd take a look. The hello_world example in the README worked in irb so next thing I did was go to the examples directory within the gem install directory and execute the first example ruby choose_color.rb Wham! got the error after having picked a color....

undefined method `to_s?' for "#1abc96":String
Did you mean?  to_s
               to_sym
               to_str
               to_r
               to_f
               to_i
               to_c
/Users/dewayne/.rvm/gems/ruby-2.5.0/gems/ffi-tk-2018.02.20/lib/ffi-tk/command/choose_color.rb:28:in `choose_color'
choose_color.rb:10:in `block in <main>'
/Users/dewayne/.rvm/gems/ruby-2.5.0/gems/ffi-tk-2018.02.20/lib/ffi-tk/event/handler.rb:15:in `invoke'
/Users/dewayne/.rvm/gems/ruby-2.5.0/gems/ffi-tk-2018.02.20/lib/ffi-tk/event/data.rb:58:in `call'
/Users/dewayne/.rvm/gems/ruby-2.5.0/gems/ffi-tk-2018.02.20/lib/ffi-tk/tk.rb:132:in `block (2 levels) in tcl_event'
/Users/dewayne/.rvm/gems/ruby-2.5.0/gems/ffi-tk-2018.02.20/lib/ffi-tk/tk.rb:131:in `catch'
/Users/dewayne/.rvm/gems/ruby-2.5.0/gems/ffi-tk-2018.02.20/lib/ffi-tk/tk.rb:131:in `block in tcl_event'
/Users/dewayne/.rvm/gems/ruby-2.5.0/gems/ffi-tk-2018.02.20/lib/ffi-tk/tk.rb:130:in `catch'
/Users/dewayne/.rvm/gems/ruby-2.5.0/gems/ffi-tk-2018.02.20/lib/ffi-tk/tk.rb:130:in `tcl_event'
/Users/dewayne/.rvm/gems/ruby-2.5.0/gems/ffi-tk-2018.02.20/lib/ffi-tk/ffi/tcl.rb:92:in `call'
/Users/dewayne/.rvm/gems/ruby-2.5.0/gems/ffi-tk-2018.02.20/lib/ffi-tk/ffi/tcl.rb:92:in `Tcl_DoOneEvent'
/Users/dewayne/.rvm/gems/ruby-2.5.0/gems/ffi-tk-2018.02.20/lib/ffi-tk/ffi/tcl.rb:92:in `do_one_event'
/Users/dewayne/.rvm/gems/ruby-2.5.0/gems/ffi-tk-2018.02.20/lib/ffi-tk/ffi/tcl/interp.rb:63:in `do_one_event'
/Users/dewayne/.rvm/gems/ruby-2.5.0/gems/ffi-tk-2018.02.20/lib/ffi-tk/tk.rb:56:in `mainloop'
choose_color.rb:23:in `<main>'
    while executing
"::RubyFFI::event 0 "<Key>" 11 ?? ?? ?? ?? ?? 0x7fd403ab1c90 32 ?? ?? ?? 0 -885731115 ?? -5 -74 \  ?? ?? 0 space 32 ?? 0xa 0x0 2 . 0 0 "
    (command bound to event)

Proc object without a block

Any attempt to run a simple demo script with this command on Ruby 3.0 returns this error:

C:/Ruby30-x64/lib/ruby/gems/3.0.0/gems/ffi-tk-2018.02.20/lib/ffi-tk/thread_sender.rb:23:in new': tried to create Proc object without a block (ArgumentError)`

I was hoping to test this gem with Tk 8.7 as the ruby-tk gem does not support 8.7.

Runtime errors on OSX & Ruby 1.8/1.9

(M=ad12c4) igrigorik /git/yonde> irb -r 'lib/yonde'
Bond has detected EditLine and may not work with it. See the README's Limitations section.
ruby-1.9.2-p0 > y = Yonde.new
RuntimeError: bad event type or keysym "KP_Begin" during eval of: "bind .text0 \"\" { ::RubyFFI::event 6 \"\" %# %b %c %d %f %h %i %k %m %o %p %s %t %w %x %y %A %B %D %E %K %N %P %R %S %T %W %X %Y }"
    from /Users/igrigorik/.rvm/gems/ruby-1.9.2-p0/gems/ffi-tk-2010.08.23/lib/ffi-tk/ffi/tcl/interp.rb:96:in `eval'
    from /Users/igrigorik/.rvm/gems/ruby-1.9.2-p0/gems/ffi-tk-2010.08.23/lib/ffi-tk/event/handler.rb:35:in `register'
    from /Users/igrigorik/.rvm/gems/ruby-1.9.2-p0/gems/ffi-tk-2010.08.23/lib/ffi-tk/command/bind.rb:8:in `bind'
    from /Users/igrigorik/.rvm/gems/ruby-1.9.2-p0/gems/ffi-tk-2010.08.23/lib/ffi-tk/command/bind.rb:21:in `bind'
    from /Users/igrigorik/Development/github/yonde/lib/yonde/controller.rb:86:in `key'
    from /Users/igrigorik/Development/github/yonde/lib/yonde/controller.rb:56:in `initialize'
    from /Users/igrigorik/Development/github/yonde/lib/yonde.rb:23:in `new'
    from /Users/igrigorik/Development/github/yonde/lib/yonde.rb:23:in `initialize'
    from (irb):1:in `new'
    from (irb):1
    from /Users/igrigorik/.rvm/rubies/ruby-1.9.2-p0/bin/irb:17:in `'
(M=ad12c4) igrigorik /git/yonde> irb -r 'lib/yonde'
/opt/local/lib/ruby/gems/1.8/gems/ffi-tk-2010.08.23/lib/ffi-tk/ffi/tcl/obj.rb:12:in `gsub':TypeError: can't convert Hash into String

Any ideas / suggestions?

compilation error: StructLayout.c:363:9: error: lvalue required as left operand of assignment

I was trying to install ver on my Ubuntu 12.04, but installation failed on ffi-tk package. I got the same error message with gem versions 1.9.1 and 2.0.0.

Is there some way to get around this error?

sudo gem install ffi-tk
[sudo] password for sjs:
Building native extensions. This could take a while...
ERROR: Error installing ffi-tk:
ERROR: Failed to build gem native extension.

/usr/local/bin/ruby extconf.rb

extconf.rb:6:in <main>': Use RbConfig instead of obsolete and deprecated Config. extconf.rb:6:in

': Use RbConfig instead of obsolete and deprecated Config.
checking for ffi_call() in -lffi... yes
checking for ffi_prep_closure()... yes
checking for ffi_raw_call()... yes
checking for ffi_prep_raw_closure()... yes
checking for rb_thread_blocking_region()... yes
creating extconf.h
extconf.rb:24:in `': Use RbConfig instead of obsolete and deprecated Config.
creating Makefile

make
compiling Type.c
compiling Platform.c
compiling Types.c
compiling AutoPointer.c
compiling Buffer.c
compiling Call.c
Call.c: In function ‘rbffi_CallFunction’:
Call.c:301:9: warning: ‘rb_thread_blocking_region’ is deprecated (declared at /usr/local/include/ruby-2.0.0/ruby/intern.h:830) [-Wdeprecated-declarations]
compiling StructLayout.c
StructLayout.c: In function ‘struct_field_initialize’:
StructLayout.c:85:9: warning: variable ‘nargs’ set but not used [-Wunused-but-set-variable]
StructLayout.c: In function ‘struct_layout_initialize’:
StructLayout.c:363:9: error: lvalue required as left operand of assignment
make: *** [StructLayout.o] Error 1

Gem files will remain installed in /usr/local/lib/ruby/gems/2.0.0/gems/ffi-0.6.3 for inspection.
Results logged to /usr/local/lib/ruby/gems/2.0.0/gems/ffi-0.6.3/ext/ffi_c/gem_make.out

sudo gem1.9.1 install ffi-tk
Building native extensions. This could take a while...
ERROR: Error installing ffi-tk:
ERROR: Failed to build gem native extension.

    /usr/bin/ruby1.9.1 extconf.rb

extconf.rb:6: Use RbConfig instead of obsolete and deprecated Config.
checking for ffi_call() in -lffi... yes
checking for ffi_prep_closure()... yes
checking for ffi_raw_call()... yes
checking for ffi_prep_raw_closure()... yes
checking for rb_thread_blocking_region()... yes
creating extconf.h
creating Makefile

make
compiling Type.c
compiling Platform.c
compiling Types.c
compiling AutoPointer.c
compiling Buffer.c
compiling Call.c
compiling StructLayout.c
StructLayout.c: In function ‘struct_layout_initialize’:
StructLayout.c:363:9: error: lvalue required as left operand of assignment
make: *** [StructLayout.o] Error 1

Gem files will remain installed in /var/lib/gems/1.9.1/gems/ffi-0.6.3 for inspection.
Results logged to /var/lib/gems/1.9.1/gems/ffi-0.6.3/ext/ffi_c/gem_make.out

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.