Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env ruby
require 'fox16'
require 'fox16/kwargs'
require 'open-uri'
begin
require 'rubyful_soup'
rescue LoadError
require 'fox16/missingdep'
MSG = <<EOM
Sorry, this example depends on the RubyfulSoup extension. Please
check the Ruby Application Archives for an appropriate
download site.
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
src = open("http://www.dilbert.com/").read
soup = BeautifulSoup.new(src)
url = soup.find('img', { :attrs => { 'alt' => /Today's Comic/ } })
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