module Gtk

this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint(dpblnt@gmail.com)

Constants

PENDING_CALLS
PENDING_CALLS_MUTEX

Thread-safety stuff. Loosely based on booh, by Guillaume Cottenceau.

Public Class Methods

init_thread_protect() click to toggle source
# File lib/Gtk.rb, line 44
def self.init_thread_protect
        $gtk_pending_calls = []
        $gtk_pending_calls.extend(MonitorMixin)
        Gtk.timeout_add(100) {Gtk.thread_flush;true}
end
is_linux?() click to toggle source
# File lib/Gtk.rb, line 99
def self.is_linux?
   RUBY_PLATFORM.downcase.include?("linux")
end
is_windows?() click to toggle source
# File lib/Gtk.rb, line 95
def self.is_windows?
   RUBY_PLATFORM.downcase.include?("mswin") || RUBY_PLATFORM.downcase.include?("mingw")
end
new_thread(&proc) click to toggle source
# File lib/Gtk.rb, line 12
def self.new_thread(&proc)
        Thread.new{
                begin
                        Gtk.thread_protect(&proc)
                rescue =>err
                        print "#{err}\n#{err.join("\n")}"
                end
        }
end
show_thread_changes() click to toggle source
# File lib/Gtk.rb, line 103
def self.show_thread_changes
      Gtk.thread_protect{
                      while Gtk.events_pending? do 
                              Gtk.main_iteration_do(false)
                      end
              } unless Gtk.is_windows?
end
thread_flush() click to toggle source
# File lib/Gtk.rb, line 30
def self.thread_flush
        closure = nil
        continue = true
        begin
                $gtk_pending_calls.synchronize {
                        closure = $gtk_pending_calls.shift
                        continue = $gtk_pending_calls.size > 0
                }
                if closure
                        closure.call
                end
        end while continue
end
thread_protect(&proc) click to toggle source
# File lib/Gtk.rb, line 22
def self.thread_protect(&proc)
        if Thread.current == Thread.main
                proc.call
        else
                $gtk_pending_calls.synchronize {$gtk_pending_calls << proc}
        end
end