问题描述
我使用gtk pixbuf加载图像,在ruby中创建图像幻灯片。我对ruby& GTK,这可能是一个愚蠢的问题。
I am creating an image slideshow in ruby, using gtk pixbuf to load images. I am very new to ruby & GTK, this may be an stupid question.
目前图像变化与GUI button_press_event相关联,我希望它们根据设置的时间自动更改/刷新,如幻灯片或动画。我看到使用gif方法的gtk动画,但我想使用单独的jpeg文件内联序列,以便我可以设置显示幻灯片的时间。循环遍历完所有图像后,GUI应显示重放或退出按钮。 (我还没有使用过@time,它只是有可能性)感谢您的任何建议;
Currently image changes are linked to the GUI button_press_event, I would like them to change /refresh automatically based on a set time, like a slideshow or animation. I saw the gtk animation using a gif method, but I would like to use individual jpeg files inline sequence, so that I can set the time to show a slide. Once the loop has gone through all the images, the GUI should display buttons for replay or quit. ( I haven't used @time yet, it is just there for possibilities ) Thanks for any suggestions;
require 'gtk2'
class Pics
attr_accessor :pile, :picindex, :imgLoaded, :image, :box, :window, :time
def initialize
@window = Gtk::Window.new()
@window.signal_connect("destroy"){Gtk.main_quit}
pic1 = "1.jpg"
pic2 = "2.jpg"
pic3 = "3.jpg"
pic4 = "4.jpg"
@pile = [pic1, pic2, pic3, pic4]
@picindex = 0
self.getImage
@box = Gtk::EventBox.new.add(@image)
@time = true
end
def nuImage
@box.remove(@image)
@picindex = @picindex + 1
@picindex = 0 if @picindex == @pile.length
self.getImage
@box.add(@image)
@box.show
end
def getImage
@imgLoaded = @pile[@picindex]
img = Gdk::Pixbuf.new(@imgLoaded, 556, 900)
@image = Gtk::Image.new(img)
@image.show
end
end # class Pics
pics = Pics.new
pics.box.signal_connect("button_press_event"){pics.nuImage}
pics.window.set_default_size(556, 900)
pics.window.add(pics.box)
pics.window.show_all
Gtk.main
推荐答案
使用GLib.timeout_add()或GLib.timeout_add_seconds()。如果您不想再使用它,请返回False。阅读GLib文档,部分:主要事件循环
use GLib.timeout_add () or GLib.timeout_add_seconds (). Return False if you don't want to use it anymore.read GLib documentation, Section: Main Event Loop
这篇关于Ruby GTK Pixbuf定时图像更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!