Module: Gtk

Defined in:
lib/Gtk.rb

Overview

this file is part of manqod manqod is distributed under the CDDL licence the author of manqod is Dobai-Pataky Balint([email protected])

Defined Under Namespace

Classes: PrintSettings, TreeIter

Constant Summary collapse

PENDING_CALLS_MUTEX =

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

Mutex.new
PENDING_CALLS =
[]

Class Method Summary collapse

Class Method Details

.init_thread_protectObject



44
45
46
47
48
# 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?Boolean

Returns:

  • (Boolean)


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

def self.is_linux?
   RUBY_PLATFORM.downcase.include?("linux")
end

.is_windows?Boolean

Returns:

  • (Boolean)


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

def self.is_windows?
   RUBY_PLATFORM.downcase.include?("mswin") || RUBY_PLATFORM.downcase.include?("mingw")
end

.new_thread(&proc) ⇒ Object



12
13
14
15
16
17
18
19
20
# 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_changesObject



103
104
105
106
107
108
109
# 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_flushObject



30
31
32
33
34
35
36
37
38
39
40
41
42
# 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) ⇒ Object



22
23
24
25
26
27
28
# 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