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

#%, #&, #*, #**, #+, #-, #-@, #/, #<, #<<, #<=, #==, #>, #>=, #>>, #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

Returns a new instance of RubyThreadFix.



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/Qt4.rb', line 34

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



68
69
70
# File 'lib/Qt4.rb', line 68

def self.queue
  @@queue
end

Instance Method Details

#callback_timeoutObject



53
54
55
56
57
58
59
60
61
# File 'lib/Qt4.rb', line 53

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



63
64
65
66
# File 'lib/Qt4.rb', line 63

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

#ruby_thread_timeoutObject



49
50
51
# File 'lib/Qt4.rb', line 49

def ruby_thread_timeout
  sleep(@ruby_thread_sleep_period)
end

#stopObject



72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/Qt4.rb', line 72

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