I know the script had been broken on the fxruby site. (don''t know if
this is
the same one as in the book though)
It broke because the dilbert site changed.
I updated the script from the fxruby side a while ago since I run this
script daily.
Not sure if this will fix you the issue you are having, but it runs here
fine for me.
####################################################
#!/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 + 12, @imageview.contentHeight + 12) #
added the + part because clipping the copywrite info and the right side of
the frame
end
def image_data
doc = Hpricot(open("http://www.dilbert.com/"))
#url = doc.search("img").find { |e| e[''alt''] =~
/Today''s Comic/ } #note
need to update this since the comic page changed
url = doc.search("img").find { |e| e[''src''] =~
/\/dyn\/str_strip\/.*\.gif/ } #This is the updated search 2008-04-22
#puts url
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
####################################################
datatec
On Tue, Aug 12, 2008 at 5:49 AM, Wayne Vovil <wayne.vovil at gmail.com>
wrote:
> Hi
>
> I am able to run all the contents of the FXRuby Lean and Mean book; but
> when I download dilbert.rb from fxruby site and run (after installing
> hpricot as a gem) I get an error as below:
>
> dilbert.rb:46:in `image_data'': undefined method `[]'' for
nil:NilClass
> (NoMethodError)
> from dilbert.rb:37:in `initialize''
> from dilbert.rb:60:in `new''
> from dilbert.rb:60
>
> As a novice I cannot work out what is wrong. Any ideas please?
>
> Cheers
>
> Wayne
> Sydney Australia
>
> _______________________________________________
> fxruby-users mailing list
> fxruby-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/fxruby-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://rubyforge.org/pipermail/fxruby-users/attachments/20080812/af1ea6c4/attachment.html>