Module: Swt

Defined in:
lib/swt/full.rb,
lib/swt/minimal.rb,
lib/swt/grid_data.rb,
lib/swt/event_loop.rb,
lib/swt/jar_loader.rb,
lib/swt/cucumber_runner.rb

Defined Under Namespace

Modules: Custom, DND, Events, Graphics, Layout, Widgets Classes: Browser, CucumberRunner, EventLoop, RRunnable

Constant Summary collapse

VERSION =

also change in swt.gemspec

"4.6.1"
X64_BIT_CPUS =
%w(amd64 x86_64)

Class Method Summary collapse

Class Method Details

.botObject



91
92
93
94
95
96
97
98
99
100
# File 'lib/swt/full.rb', line 91

def self.bot
  @bot ||= begin
    Dir[File.expand_path("../../../vendor/swtbot", __FILE__) + "/*.jar"].each do |fn|
      require fn
    end
    bot = org.eclipse.swtbot.swt.finder.SWTBot.new
    bot.extend SwtBotExtensions
    bot
  end
end

.displayObject



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/swt/minimal.rb', line 77

def self.display
  @display ||= begin
    if defined?(SWT_APP_NAME)
      Swt::Widgets::Display.app_name = SWT_APP_NAME
    end
    display ||= (Swt::Widgets::Display.getCurrent || Swt::Widgets::Display.new)

    # clipboard class must be imported after the display is created
    Swt::DND.send(:import, org.eclipse.swt.dnd.Clipboard)
    display
  end
end

.event_loop(&stop_condition) ⇒ Object



90
91
92
93
# File 'lib/swt/minimal.rb', line 90

def self.event_loop(&stop_condition)
  stop_conditions << stop_condition
  run_event_loop
end

.event_loop_running?Boolean

Returns:

  • (Boolean)


99
100
101
# File 'lib/swt/minimal.rb', line 99

def self.event_loop_running?
  @event_loop_running
end

.jar_pathObject



7
8
9
# File 'lib/swt/jar_loader.rb', line 7

def self.jar_path
  @jar_path ||= File.expand_path(relative_jar_path, __FILE__)
end

.relative_jar_pathObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/swt/jar_loader.rb', line 11

def self.relative_jar_path
  case RbConfig::CONFIG["host_os"]
  when /darwin/i
    if x64_bit_cpu?
      '../../../vendor/swt/swt-osx64'
    else
      raise 'No 32 bit Mac OSX SWT jar available :('
    end
  when /linux/i
    if x64_bit_cpu?
      '../../../vendor/swt/swt-linux64'
    else
      '../../../vendor/swt/swt-linux32'
    end
  when /windows|mswin/i
    if x64_bit_cpu?
      '../../../vendor/swt/swt-win64'
    else
      '../../../vendor/swt/swt-win32'
    end
  end
end

.run_event_loopObject



103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/swt/minimal.rb', line 103

def self.run_event_loop
  return if event_loop_running?
  @event_loop_running = true
  this_display = display

  until stop_conditions.any? {|c| c[] }
    unless this_display.read_and_dispatch
      this_display.sleep
    end
  end

  this_display.dispose
end

.stop_conditionsObject



95
96
97
# File 'lib/swt/minimal.rb', line 95

def self.stop_conditions
  @stop_conditions ||= []
end

.sync_exec(&block) ⇒ Object

Runs the given block in the SWT Event thread



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/swt/minimal.rb', line 50

def self.sync_exec(&block)
  error, throwable = nil, false
  result = nil
  runnable = Swt::RRunnable.new do
    begin
      result = block.call
    rescue Object => e
      error = e
    end
  end

  unless display.is_disposed
    display.syncExec(runnable)
    if error
      raise error
    end
  end
  result
end

.timer_exec(ms, &block) ⇒ Object

Runs the given block in the SWT Event thread after the given number of milliseconds



72
73
74
75
# File 'lib/swt/minimal.rb', line 72

def self.timer_exec(ms, &block)
  runnable = Swt::RRunnable.new(&block)
  display.timerExec(ms, runnable)
end

.x64_bit_cpu?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/swt/jar_loader.rb', line 34

def self.x64_bit_cpu?
  X64_BIT_CPUS.include? RbConfig::CONFIG["host_cpu"]
end