From 08de292b856e0e182db831ee7a6348695a19c103 Mon Sep 17 00:00:00 2001 From: Marius Hanne Date: Sat, 23 Feb 2013 20:32:50 +0100 Subject: examples for Ecore pipe. Thanks to jeremyz for the original -native version! --- test/test_ecore_pipe-native.rb | 52 +++++++++++++++++++++++++++++++++++++++ test/test_ecore_pipe.rb | 56 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 108 insertions(+) create mode 100644 test/test_ecore_pipe-native.rb create mode 100644 test/test_ecore_pipe.rb diff --git a/test/test_ecore_pipe-native.rb b/test/test_ecore_pipe-native.rb new file mode 100644 index 0000000..7dc095a --- /dev/null +++ b/test/test_ecore_pipe-native.rb @@ -0,0 +1,52 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +require 'efl/native/ecore' +require 'efl/native/elm/elm_win' +require 'efl/native/elm/elm_bg' +require 'efl/native/elm/elm_label' +require 'efl/native/elm/elm_object' +# +include Efl::Native +# +elm_init 0, FFI::MemoryPointer::NULL +# +win_del = Proc.new { |data,evas_object,event_info| elm_exit() } +# +win = elm_win_add nil, "App name", :elm_win_basic +elm_win_title_set win, "Window title" +evas_object_smart_callback_add win, "delete,request", win_del, nil +# +bg = elm_bg_add win +evas_object_size_hint_weight_set bg, 1.0, 1.0 +elm_win_resize_object_add win, bg +evas_object_show bg +# +lb = elm_label_add win +elm_object_part_text_set lb, nil, "Hello World" +evas_object_size_hint_weight_set lb, 1.0, 1.0 +elm_win_resize_object_add win, lb +evas_object_show lb +# +evas_object_move win, 300, 300 +evas_object_resize win, 200, 100 +# +evas_object_show win +# +pipe_cb = Proc.new { |date,buffer,n| + elm_object_part_text_set lb, nil, buffer.read_string[0..n-1] +} +# +pipe = ecore_pipe_add pipe_cb, nil +# +pid = fork { + ecore_pipe_read_close(pipe); + [ "hello", "dying", "old", "planet", "earth"].each do |w| + sleep 1 + ecore_pipe_write pipe, w, w.length + end +} +# +elm_run +ecore_pipe_del pipe +elm_shutdown diff --git a/test/test_ecore_pipe.rb b/test/test_ecore_pipe.rb new file mode 100644 index 0000000..e2786b3 --- /dev/null +++ b/test/test_ecore_pipe.rb @@ -0,0 +1,56 @@ +#! /usr/bin/env ruby +# -*- coding: UTF-8 -*- +# +require 'efl/ecore' +require 'efl/elm/elm_win' +require 'efl/elm/elm_bg' +require 'efl/elm/elm_label' +# +include Efl +# +class MyWin < Elm::ElmWin + # + attr_reader :pipe + def initialize + super(nil, "Pipe test") do + title_set "Hello, World!" + resize 200, 100 + show + end + @bg = Elm::ElmBg.new(self) do + size_hint_weight_expand + show + end + resize_object_add @bg + # + @label = Elm::ElmLabel.new(self) do + text_set "Hello World" + size_hint_weight_expand + show + end + resize_object_add @label + # + @pipe = Ecore.ecore_pipe_add(method(:pipe_cb), nil) + end + # + def pipe_cb date, buffer, n + @label.text_set buffer.read_string[0..n-1] + end +end +# +Elm.init +# +@win = MyWin.new +# +pid = fork do + Ecore.ecore_pipe_read_close(@win.pipe) + [ "hello", "dying", "old", "planet", "earth"].each do |w| + sleep 1 + Ecore.ecore_pipe_write @win.pipe, w, w.length + end +end +Elm.run +Ecore.ecore_pipe_del @win.pipe +Elm.shutdown +# +# EOF -- cgit v1.1-2-g2b99