Module: Gtk

Defined in:
lib/rugui/framework_adapters/GTK.rb

Constant Summary collapse

GTK_PENDING_BLOCKS =
[]
GTK_PENDING_BLOCKS_LOCK =
Monitor.new

Class Method Summary collapse

Class Method Details

.get_style_file_contents(path, filename) ⇒ Object



66
67
68
# File 'lib/rugui/framework_adapters/GTK.rb', line 66

def Gtk.get_style_file_contents(path, filename)
  IO.read(File.join(path, filename)).sub('{ROOT_PATH}', RuGUI.configuration.root_path)
end

.is_style_file?(path, filename) ⇒ Boolean

Returns:

  • (Boolean)


62
63
64
# File 'lib/rugui/framework_adapters/GTK.rb', line 62

def Gtk.is_style_file?(path, filename)
  File.extname(filename) == '.rc' or /gtkrc/.match(filename) if File.file?(File.join(path, filename))
end

.load_style_pathsObject



53
54
55
56
57
58
59
60
# File 'lib/rugui/framework_adapters/GTK.rb', line 53

def Gtk.load_style_paths
  styles_paths = RuGUI.configuration.styles_paths.select { |path| File.directory?(path) }
  styles_paths.each do |path|
    Dir.new(path).each do |entry|
      Gtk::RC.parse_string(get_style_file_contents(path, entry)) if is_style_file?(path, entry)
    end
  end
end

.queue(&block) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/rugui/framework_adapters/GTK.rb', line 30

def Gtk.queue(&block)
  if Thread.current == Thread.main
    block.call
  else
    GTK_PENDING_BLOCKS_LOCK.synchronize do
      GTK_PENDING_BLOCKS << block
    end
  end
end

.queue_timeout(timeout) ⇒ Object

Adds a timeout to execute pending blocks in a queue.



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rugui/framework_adapters/GTK.rb', line 41

def Gtk.queue_timeout(timeout)
  Gtk.timeout_add timeout do
    GTK_PENDING_BLOCKS_LOCK.synchronize do
      GTK_PENDING_BLOCKS.each do |block|
        block.call
      end
      GTK_PENDING_BLOCKS.clear
    end
    true
  end
end