Module: Shoes::Swt::Common::ImageHandling

Included in:
ImagePattern
Defined in:
shoes-swt/lib/shoes/swt/common/image_handling.rb

Instance Method Summary collapse

Instance Method Details

#cleanup_temporary_filesObject



21
22
23
24
25
26
27
28
29
30
31
32
# File 'shoes-swt/lib/shoes/swt/common/image_handling.rb', line 21

def cleanup_temporary_files
  return unless cleanup_files.any?

  cleanup_files.each do |file|
    begin
      FileUtils.rm(file)
    rescue => e
      Shoes.logger.debug("Error during image temp file cleanup.\n#{e.class}: #{e.message}")
    end
  end
  cleanup_files.clear
end

#load_file_image_data(name) ⇒ Object

Why copy the file to a temporary location just to pass a different name to load? Because SWT doesn’t like us when we’re packaged!

Apparently the warbler-style path names we end up with for relative image paths don’t cross nicely to SWT, so we need to resolve the paths in Ruby-land before handing it over.



13
14
15
16
17
18
19
# File 'shoes-swt/lib/shoes/swt/common/image_handling.rb', line 13

def load_file_image_data(name)
  tmpname = File.join(Dir.tmpdir, "__shoes4_#{Time.now.to_i}_#{File.basename(name)}")
  FileUtils.cp(name, tmpname)

  cleanup_files << tmpname
  tmpname
end