From e2e4590fb190685938d5db5eeee9892c4bf5d126 Mon Sep 17 00:00:00 2001
From: Lars Kanis <kanis@comcard.de>
Date: Fri, 14 Mar 2014 13:14:56 +0100
Subject: [PATCH] Fix several examples.

Load icons independant from pwd.
---
 examples/WhatAQuietStiff.rb |  4 ++--
 examples/babelfish.rb       |  2 +-
 examples/browser.rb         |  2 +-
 examples/button.rb          | 12 +++---------
 examples/canvasdemo.rb      |  2 +-
 examples/dctest.rb          | 14 ++++----------
 examples/gembrowser.rb      |  8 ++++----
 examples/hello2.rb          |  2 +-
 examples/iconlist.rb        | 12 +++---------
 examples/imageviewer.rb     | 12 +++---------
 examples/mditest.rb         |  2 +-
 examples/shutter.rb         | 12 +++---------
 examples/splitter.rb        | 12 +++---------
 examples/table.rb           |  2 +-
 14 files changed, 31 insertions(+), 67 deletions(-)

diff --git a/examples/WhatAQuietStiff.rb b/examples/WhatAQuietStiff.rb
index 8d70f77..d87da66 100755
--- a/examples/WhatAQuietStiff.rb
+++ b/examples/WhatAQuietStiff.rb
@@ -38,11 +38,11 @@ class WhatAQuietWindow < FXMainWindow
     super(app, "What a Quiet Stiff", :opts => DECOR_ALL, :width => 850, :height => 600, :padLeft => 0, :padRight => 0)
 
     # Icons for list items
-    File.open("icons/bluebullet14x14.gif", "rb") do |f|
+    File.open(File.expand_path("../icons/bluebullet14x14.gif", __FILE__), "rb") do |f|
       bytes = f.read
       @itemIcon = FXGIFIcon.new(getApp(), bytes)
     end
-    File.open("icons/transpbullet14x14.gif", "rb") do |f|
+    File.open(File.expand_path("../icons/transpbullet14x14.gif", __FILE__), "rb") do |f|
       bytes = f.read
       @transpIcon = FXGIFIcon.new(getApp(), bytes)
     end
diff --git a/examples/babelfish.rb b/examples/babelfish.rb
index e9d41a5..85d14f9 100755
--- a/examples/babelfish.rb
+++ b/examples/babelfish.rb
@@ -33,7 +33,7 @@ class Babelfish < FXMainWindow
     FXLabel.new(controlsFrame, " to:")
     @toCombo = FXComboBox.new(controlsFrame, 15, :opts => COMBOBOX_STATIC|FRAME_SUNKEN|FRAME_THICK)
     @toCombo.numVisible = 6
-    Tranexp::Codes.constants.each do |lang|
+    Tranexp::Codes.constants.map(&:to_s).each do |lang|
       @fromCombo.appendItem(lang)
       @toCombo.appendItem(lang)
     end
diff --git a/examples/browser.rb b/examples/browser.rb
index b3da40a..6d62be5 100755
--- a/examples/browser.rb
+++ b/examples/browser.rb
@@ -41,7 +41,7 @@ class ClassTree
 
     # Get an hash containing class names for Fox
     classes = {}
-    @mFox.constants.each do |name|
+    @mFox.constants.map(&:to_s).each do |name|
       c = @mFox.const_get(name)
       if c.kind_of? Class
 	parentclass = c.superclass.name.sub("Fox::", "")
diff --git a/examples/button.rb b/examples/button.rb
index 0da7e88..a1de731 100755
--- a/examples/button.rb
+++ b/examples/button.rb
@@ -134,15 +134,9 @@ class ButtonWindow < FXMainWindow
 
   # Load the named icon from a file
   def loadIcon(filename)
-    begin
-      filename = File.join("icons", filename)
-      icon = nil
-      File.open(filename, "rb") do |f|
-        icon = FXPNGIcon.new(getApp(), f.read)
-      end
-      icon
-    rescue
-      raise RuntimeError, "Couldn't load icon: #{filename}"
+    filename = File.expand_path("../icons/#{filename}", __FILE__)
+    File.open(filename, "rb") do |f|
+      FXPNGIcon.new(getApp(), f.read)
     end
   end
 
diff --git a/examples/canvasdemo.rb b/examples/canvasdemo.rb
index 06b05e8..b13f10a 100755
--- a/examples/canvasdemo.rb
+++ b/examples/canvasdemo.rb
@@ -1,5 +1,5 @@
 require 'fox16'
-require '../lib/fox16/canvas'
+require 'fox16/canvas'
 
 include Fox
 include Canvas
diff --git a/examples/dctest.rb b/examples/dctest.rb
index 9237699..dd0fc76 100755
--- a/examples/dctest.rb
+++ b/examples/dctest.rb
@@ -532,7 +532,7 @@ class DCTestWindow < FXMainWindow
     FXMenuCommand.new(@filemenu, "&Quit\tCtl-Q", nil, getApp(), FXApp::ID_QUIT)
     FXMenuTitle.new(menubar, "&File", nil, @filemenu)
 
-    @birdImage = FXPNGImage.new(getApp(), File.open("icons/dippy.png", "rb").read)
+    @birdImage = FXPNGImage.new(getApp(), File.open(File.expand_path("../icons/dippy.png", __FILE__), "rb").read)
     @bitmap = FXBitmap.new(getApp(), $bitmap_bits, 0, 64, 64)
 
     @function = BLT_SRC
@@ -674,15 +674,9 @@ class DCTestWindow < FXMainWindow
 
   # Load the named icon from a file
   def loadIcon(filename, clr = FXRGB(192, 192, 192), opts = 0)
-    begin
-      filename = File.join("icons", filename)
-      icon = nil
-      File.open(filename, "rb") { |f|
-        icon = FXPNGIcon.new(getApp(), f.read, clr, opts)
-      }
-      icon
-    rescue
-      raise RuntimeError, "Couldn't load icon: #{filename}"
+    filename = File.expand_path("../icons/#{filename}", __FILE__)
+    File.open(filename, "rb") do |f|
+      FXPNGIcon.new(getApp(), f.read)
     end
   end
 end
diff --git a/examples/gembrowser.rb b/examples/gembrowser.rb
index 77df8b3..b62eb3f 100755
--- a/examples/gembrowser.rb
+++ b/examples/gembrowser.rb
@@ -37,7 +37,7 @@ class GemBrowser
   # Return an array of the installed specifications.
   def cache
 #   Gem.cache
-    Gem::Cache.from_installed_gems
+    Gem::SourceIndex.from_installed_gems
   end
 end
 
@@ -53,7 +53,7 @@ class GemInfoPanel < FXVerticalFrame
 
     self.backColor = FXRGB(255, 255, 255)
 
-    File.open(File.join("icons", "gem_big.png"), "rb") do |f|
+    File.open(File.expand_path("../icons/gem_big.png", __FILE__), "rb") do |f|
       @bigIcon = FXPNGIcon.new(getApp(), f.read)
     end
 
@@ -107,10 +107,10 @@ class GemsPanel < FXVerticalFrame
     # Save a reference to the browser
     @browser = br
 
-    File.open(File.join("icons", "gem_big.png"), "rb") do |f|
+    File.open(File.expand_path("../icons/gem_big.png", __FILE__), "rb") do |f|
       @bigIcon = FXPNGIcon.new(getApp(), f.read)
     end
-    File.open(File.join("icons", "gem_small.png"), "rb") do |f|
+    File.open(File.expand_path("../icons/gem_small.png", __FILE__), "rb") do |f|
       @smallIcon = FXPNGIcon.new(getApp(), f.read)
     end
 
diff --git a/examples/hello2.rb b/examples/hello2.rb
index 9dc0e8e..60b7306 100755
--- a/examples/hello2.rb
+++ b/examples/hello2.rb
@@ -30,7 +30,7 @@ main = FXMainWindow.new(application, "Hello", nil, nil, DECOR_ALL)
 # on disk.
 
 icon = nil
-File.open(File.join("icons", "hello2.png"), "rb") { |f|
+File.open(File.expand_path("../icons/hello2.png", __FILE__), "rb") { |f|
   icon = FXPNGIcon.new(application, f.read)
 }
 
diff --git a/examples/iconlist.rb b/examples/iconlist.rb
index ab262d9..8643d03 100755
--- a/examples/iconlist.rb
+++ b/examples/iconlist.rb
@@ -6,15 +6,9 @@ class IconListWindow < FXMainWindow
 
   # Load the named PNG icon from a file
   def loadIcon(filename)
-    begin
-      filename = File.join("icons", filename)
-      icon = nil
-      File.open(filename, "rb") do |f|
-        icon = FXPNGIcon.new(getApp(), f.read)
-      end
-      icon
-    rescue
-      raise RuntimeError, "Couldn't load icon: #{filename}"
+    filename = File.expand_path("../icons/#{filename}", __FILE__)
+    File.open(filename, "rb") do |f|
+      FXPNGIcon.new(getApp(), f.read)
     end
   end
 
diff --git a/examples/imageviewer.rb b/examples/imageviewer.rb
index 2d3f508..85ece9b 100755
--- a/examples/imageviewer.rb
+++ b/examples/imageviewer.rb
@@ -240,15 +240,9 @@ class ImageWindow < FXMainWindow
 
   # Convenience function to construct a PNG icon
   def getIcon(filename)
-    begin
-      filename = File.join("icons", filename)
-      icon = nil
-      File.open(filename, "rb") do |f|
-        icon = FXPNGIcon.new(getApp(), f.read)
-      end
-      icon
-    rescue
-      raise RuntimeError, "Couldn't load icon: #{filename}"
+    filename = File.expand_path("../icons/#{filename}", __FILE__)
+    File.open(filename, "rb") do |f|
+      FXPNGIcon.new(getApp(), f.read)
     end
   end
 
diff --git a/examples/mditest.rb b/examples/mditest.rb
index e744176..7180466 100755
--- a/examples/mditest.rb
+++ b/examples/mditest.rb
@@ -64,7 +64,7 @@ class MDITestWindow  < FXMainWindow
 
     # Icon for MDI Child
     @mdiicon = nil
-    File.open(File.join("icons", "penguin.png"), "rb") do |f|
+    File.open(File.expand_path("../icons/penguin.png", __FILE__), "rb") do |f|
       @mdiicon = FXPNGIcon.new(getApp(), f.read)
     end
 
diff --git a/examples/shutter.rb b/examples/shutter.rb
index 8386c7f..136f93e 100755
--- a/examples/shutter.rb
+++ b/examples/shutter.rb
@@ -28,15 +28,9 @@ class ShutterWindow < FXMainWindow
   # and constructs and returns a ICO icon object.
 
   def loadIcon(filename)
-    begin
-      filename = File.join("icons", filename)
-      icon = nil
-      File.open(filename, "rb") do |f|
-        icon = FXICOIcon.new(getApp(), f.read)
-      end
-      icon
-    rescue
-      raise RuntimeError, "Couldn't load icon: #{filename}"
+    filename = File.expand_path("../icons/#{filename}", __FILE__)
+    File.open(filename, "rb") do |f|
+      FXPNGIcon.new(getApp(), f.read)
     end
   end
 
diff --git a/examples/splitter.rb b/examples/splitter.rb
index 9ec6cc5..a8de10f 100755
--- a/examples/splitter.rb
+++ b/examples/splitter.rb
@@ -8,15 +8,9 @@ class SplitterWindow < FXMainWindow
 
   # Convenience function to load & construct an icon
   def makeIcon(filename)
-    begin
-      filename = File.join("icons", filename)
-      icon = nil
-      File.open(filename, "rb") do |f|
-        icon = FXPNGIcon.new(getApp(), f.read)
-      end
-      icon
-    rescue
-      raise RuntimeError, "Couldn't load icon: #{filename}"
+    filename = File.expand_path("../icons/#{filename}", __FILE__)
+    File.open(filename, "rb") do |f|
+      FXPNGIcon.new(getApp(), f.read)
     end
   end
 
diff --git a/examples/table.rb b/examples/table.rb
index 2d4f044..0335643 100755
--- a/examples/table.rb
+++ b/examples/table.rb
@@ -38,7 +38,7 @@ class TableWindow < FXMainWindow
 
     # Icon used in some cells
     penguinicon = nil
-    File.open(File.join('icons', 'penguin.png'), 'rb') do |f|
+    File.open(File.expand_path('../icons/penguin.png', __FILE__), 'rb') do |f|
       penguinicon = FXPNGIcon.new(getApp(), f.read, 0, IMAGE_ALPHAGUESS)
     end
 
-- 
GitLab