Skip to content

Commit

Permalink
for #383
Browse files Browse the repository at this point in the history
* manual update - points to wiki
* Tests/events/capture.rb - example
  Time handling is wrong.
  • Loading branch information
Cecil committed Dec 14, 2017
1 parent 434b8dc commit 3cb8390
Show file tree
Hide file tree
Showing 5 changed files with 80 additions and 8 deletions.
50 changes: 50 additions & 0 deletions Tests/events/capture.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
require 'yaml'
Shoes.app do
stack do
tagline "Capture Clicks for another app"
para "Load this"
flow do
@el = edit_line width: 450
@el.text = "#{DIR}/samples/simple/chipmunk.rb"
button "select app" do
path = ask_file_open
@el.text = path if path
end
end
para "Save events to"
flow do
@sv = edit_line width: 450
@sv.text = "#{DIR}/events.yaml"
button "Change" do
path = ask_file_save
@sv.text = path if path
end
end
flow do
button "Start app and capture" do
$capture = []
eval IO.read(@el.text).force_encoding("UTF-8"), TOPLEVEL_BINDING, @el.text
w2 = Shoes.APPS[-1]
x = w2.left
y = w2.top
w2.move x+80, y-40
$base_t = Time.now
w2.event = proc do |evt|
case evt.type
when :click
#$stderr.puts "click handler2 with #{evt.type}"
$capture << { time: (Time.now - $baset), x: evt.x, y: evt.y}
evt.accept = true
else
evt.accept = true
end
end
end
end
flow do
button "stop and save" do
File.open(@sv.text, 'w') {|f| YAML.dump($capture, f)}
end
end
end
end
30 changes: 24 additions & 6 deletions Tests/events/event2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,37 @@
stack do
tagline "Manage clicks for second Window"
para "Demonstrates communication with second app"
flow do
@el = edit_line width: 450
@el.text = "#{DIR}/samples/simple/chipmunk.rb"
button "select app" do
path = ask_file_open
@el.text = path if path
end
end
flow do
$ck = check checked: true; para "Pass clicks?"
end
flow do
button "Set handler for 2nd window" do
@w2 = Shoes.APPS[-1]
@w2.event = proc do |evt|
$stderr.puts "event handler2 with #{evt.type}"
evt.accept = $ck.checked?
button "Start app with handler for it" do
eval IO.read(@el.text).force_encoding("UTF-8"), TOPLEVEL_BINDING, @el.text
w2 = Shoes.APPS[-1]
x = w2.left
y = w2.top
w2.move x+80, y-40
w2.event = proc do |evt|
case evt.type
when :click
$stderr.puts "click handler2 with #{evt.type}"
evt.accept = $ck.checked?
else
evt.accept = true
end
end
end
end
end

=begin
# 2nd App
eval IO.read("#{DIR}/samples/simple/chipmunk.rb").force_encoding("UTF-8"), TOPLEVEL_BINDING
start do
Expand All @@ -25,4 +42,5 @@
y = app.top
w.move x+80, y-40
end
=end
end
2 changes: 1 addition & 1 deletion shoes/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -545,7 +545,7 @@ VALUE shoes_app_set_event_handler(VALUE self, VALUE block) {
fprintf(stderr, "set app event handler\n");
ATTRSET(canvas->attr, event, block);
canvas->app->use_event_handler = 1;
shoes_hash_debug(canvas->attr);
//shoes_hash_debug(canvas->attr);
return Qtrue;
} else {
canvas->app->use_event_handler = 0;
Expand Down
2 changes: 1 addition & 1 deletion shoes/types/native.c
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ void shoes_control_send(VALUE self, ID event) {
y = self_t->place.y;
h = self_t->place.h;
w = self_t->place.w;
VALUE evt = shoes_event_new_widget(cShoesEvent, event, self, 1, x, y, w, h, Qnil);
VALUE evt = shoes_event_new_widget(cShoesEvent, event, self, 1, x, y, w, h, Qnil, Qnil);
shoes_safe_block(app->canvas, evtproc, rb_ary_new3(1, evt));
shoes_event *tevent;
Data_Get_Struct(evt, shoes_event, tevent);
Expand Down
4 changes: 4 additions & 0 deletions static/manual-en.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5500,7 +5500,11 @@ If you have 7 entries (0..6), append at 7 (array.size) or face the nil's that pl
It will be serious mistake to set [nil, newvalue] or ["newlabel", nil] and expect that Shoes will fix your nil.
It will segfault, if you are lucky.

== Event Streams ==

This a very arcane and specialized capabilty. It's documented at the
[[https://github.com/shoes/shoes3/wiki/event-streams ShoesS Wiki]] You will want to study
and play with the Test/events/* scripts

== Terminal ==

Expand Down

0 comments on commit 3cb8390

Please sign in to comment.