Sha256: af6d9b2c0764e7dc5bbad175c0aa464d9e94be021ddcd1ea50b8124146b667a4

Contents?: true

Size: 1.58 KB

Versions: 18

Compression:

Stored size: 1.58 KB

Contents

#!/usr/bin/env ruby

require 'fox16'
require 'open-uri'
begin
  require 'hpricot'
rescue LoadError
  require 'fox16/missingdep'
  MSG = <<EOM
  Sorry, this example depends on the Hpricot extension. Please
  see http://code.whytheluckystiff.net/hpricot/ for instructions
  on how to install Hpricot.
EOM
  missingDependency(MSG)
end

include Fox

class DailyDilbert < FXMainWindow

 include Responder

  def initialize(app)
    # Invoke base class initialize first
    super(app, "Daily Dilbert Viewer", :opts => DECOR_ALL, :width => 850, :height => 600, :padLeft => 0, :padRight => 0)

    # Sunken border for image widget
    imagebox = FXHorizontalFrame.new(self,
      FRAME_SUNKEN|FRAME_THICK|LAYOUT_FILL_X|LAYOUT_FILL_Y)
  
    # Make image widget
    @imageview = FXImageView.new(imagebox,
      :opts => LAYOUT_FILL_X|LAYOUT_FILL_Y|HSCROLLER_NEVER|VSCROLLER_NEVER)
      
    # Construct a GIF image and store it in the image viewer
    @imageview.image = FXGIFImage.new(getApp(), image_data)

    # Resize main window client area to fit image size
    resize(@imageview.contentWidth, @imageview.contentHeight)
  end
  
  def image_data
    doc = Hpricot(open("http://www.dilbert.com/"))
    url = doc.search("img").find { |e| e['src'] =~ /\/dyn\/str_strip\/.*\.gif/ }
    open("http://www.dilbert.com" + url['src'], "rb").read
  end
  
  def create
    super
    show(PLACEMENT_SCREEN)
  end
end

if __FILE__ == $0
  # Make application
  application = FXApp.new("DailyDilbert", "FoxTest")

  # Make window
  window = DailyDilbert.new(application)

  # Create it
  application.create

  # Run
  application.run
end

Version data entries

18 entries across 18 versions & 2 rubygems

Version Path
fxruby-1.6.22.pre2-x86-mingw32 examples/dilbert.rb
fxruby-1.6.22.pre2 examples/dilbert.rb
fxrubi-1.6.22.pre1-x86-mingw32 examples/dilbert.rb
fxrubi-1.6.22.pre1 examples/dilbert.rb
fxruby-1.6.20-x86-mingw32 examples/dilbert.rb
fxruby-1.6.20-x86-linux examples/dilbert.rb
fxruby-1.6.20 examples/dilbert.rb
fxruby-1.6.20-universal-darwin-10 examples/dilbert.rb
fxruby-1.6.19-x86-mingw32 examples/dilbert.rb
fxruby-1.6.17-universal-darwin-9 examples/dilbert.rb
fxruby-1.6.17-x86-mswin32-60 examples/dilbert.rb
fxruby-1.6.17 examples/dilbert.rb
fxruby-1.6.18-universal-darwin-9 examples/dilbert.rb
fxruby-1.6.18 examples/dilbert.rb
fxruby-1.6.18-x86-mswin32-60 examples/dilbert.rb
fxruby-1.6.19-universal-darwin-9 examples/dilbert.rb
fxruby-1.6.19-x86-mswin32-60 examples/dilbert.rb
fxruby-1.6.19 examples/dilbert.rb