Skip to content

Commit

Permalink
Add keylistener to app
Browse files Browse the repository at this point in the history
  • Loading branch information
fism88 committed Jul 28, 2013
1 parent ea5a4fc commit 1ab0e2a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
47 changes: 47 additions & 0 deletions lib/shoes/log_window.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
module Shoes::LogWindow
def self.setup(app)
app.stack do
app.flow do
app.background app.black
app.stack do
app.tagline "Shoes Console", :stroke => app.white
end
app.button "Clear", :margin => 6, :width => 80, :height => 40 do
Shoes.log.clear
end
end
@log, @hash = app.stack, nil
#update
app.every(0.2) do
#update
end
end
end

def self.update
if @hash != Shoes.log.hash
@hash = Shoes.log.hash
@log.clear do
i = 0
Shoes.log.each do |typ, msg, at, mid, rbf, rbl|
stack do
background "#f1f5e1" if i % 2 == 0
inscription strong(typ.to_s.capitalize, :stroke => "#05C"), " in ",
flow do
stack :margin => 4, :width => -20 do
s = msg.to_s
s << "\n#{msg.backtrace.join("\n")}" if msg.kind_of?(Exception)
para s, :margin => 4, :margin_top => 0
end
end
end
i += 1
end
end
end
end
end

Shoes.app do
Shoes::LogWindow.setup(app)
end
6 changes: 6 additions & 0 deletions lib/shoes/swt/app.rb
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,12 @@ def attach_event_listeners
def attach_shell_event_listeners
@shell.addControlListener ShellControlListener.new(self)
@shell.addListener(::Swt::SWT::Close, main_window_on_close) if main_app?
blk = proc { |key|
if key == :"control_/"
%x(bin/shoes lib/shoes/log_window.rb)
end
}
@shell.add_key_listener(::Shoes::Swt::KeyListener.new(blk))
end

def attach_real_event_listeners
Expand Down

0 comments on commit 1ab0e2a

Please sign in to comment.