Class: Qt::RubyThreadFix

Inherits:
Object show all
Defined in:
lib/Qt4.rb

Constant Summary collapse

@@queue =
Queue.new

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#%, #&, #*, #**, #+, #-, #[email protected], #/, #<, #<<, #<=, #==, #>, #>=, #>>, #QCOMPARE, #QEXPECT_FAIL, #QFAIL, #QSKIP, #QTEST, #QVERIFY, #QVERIFY2, #QWARN, #^, ancestors, #is_a?, #methods, private_slots, #protected_methods, #public_methods, q_classinfo, q_signal, q_slot, signals, #singleton_methods, slots, #|, #~

Constructor Details

#initializeRubyThreadFix


26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/Qt4.rb', line 26

def initialize
  super()
  # Enable threading
  @ruby_thread_sleep_period = 0.01
  @ruby_thread_timer = Qt::Timer.new(self)
  connect(@ruby_thread_timer, SIGNAL('timeout()'), SLOT('ruby_thread_timeout()'))
  @ruby_thread_timer.start(0)
  @callback_timer = Qt::Timer.new(self)
  connect(@callback_timer, SIGNAL('timeout()'), SLOT('callback_timeout()'))
  @callback_timer.start(1)
  @callback_timer2 = Qt::Timer.new(self)
  connect(@callback_timer2, SIGNAL('timeout()'), SLOT('callback_timeout2()'))
  @running = true
end

Class Method Details

.queueObject


60
61
62
# File 'lib/Qt4.rb', line 60

def self.queue
  @@queue
end

Instance Method Details

#callback_timeoutObject


45
46
47
48
49
50
51
52
53
# File 'lib/Qt4.rb', line 45

def callback_timeout
  if !@@queue.empty?
    # Start a backup timer in case this one goes modal.
    @callback_timer2.start(100)
    @@queue.pop.call until @@queue.empty?
    # Cancel the backup timer
    @callback_timer2.stop if @callback_timer2
  end
end

#callback_timeout2Object


55
56
57
58
# File 'lib/Qt4.rb', line 55

def callback_timeout2
  @callback_timer2.interval = 10
  @@queue.pop.call until @@queue.empty?
end

#ruby_thread_timeoutObject


41
42
43
# File 'lib/Qt4.rb', line 41

def ruby_thread_timeout
  sleep(@ruby_thread_sleep_period)
end

#stopObject


64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/Qt4.rb', line 64

def stop
  if @running
    @running = false
    @ruby_thread_timer.stop
    @callback_timer.stop
    @callback_timer2.stop
    @ruby_thread_timer.dispose
    @callback_timer.dispose
    @callback_timer2.dispose
    @ruby_thread_timer = nil
    @callback_timer = nil
    @callback_timer2 = nil
  end
end