From: Michael B. <be...@ju...> - 2014-05-20 20:06:54
|
Hi, I am trying to display an image from the web in a GTK window. Fetching the image works, and displaying local images works too, but how can I get my web image into an GTK::image object? Here's my code. https://gist.github.com/anonymous/aa4f27aa135bc59bc792 -- Ruby complains about an implicit conversion from nil to integer I am trying to convert the image to a "well-behaved" blob using Imagemagick/RMagick, because I have read in the documentation that Gdk::Pixbuf accepts data input. Is there a better way? Cheers Michael |
From: Masafumi Y. <my...@gm...> - 2014-05-23 12:56:25
|
Hi, We can display web images in a GTK window by the following way: ... require "tempfile" ... image_path = Tempfile.open("display-web-image-in-gtk") do |tempfile| urlimage = open("http://rmagick.rubyforge.org/framed_clown.jpg") tempfile.write(urlimage.read) tempfile.path end posh = Gdk::Pixbuf.new(image_path) ... This way is saving web images to local temp directory. When the script is finished, temp files will be deleted. And, doesn't need RMagick. How about this? Thanks, -- myokoym 2014-05-21 5:06 GMT+09:00 Michael Below <be...@ju...>: > Hi, > > I am trying to display an image from the web in a GTK window. Fetching > the image works, and displaying local images works too, but how can I > get my web image into an GTK::image object? Here's my code. > https://gist.github.com/anonymous/aa4f27aa135bc59bc792 -- Ruby complains > about an implicit conversion from nil to integer > > I am trying to convert the image to a "well-behaved" blob using > Imagemagick/RMagick, because I have read in the documentation that > Gdk::Pixbuf accepts data input. Is there a better way? > > Cheers > > Michael > > > ------------------------------------------------------------------------------ > "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE > Instantly run your Selenium tests across 300+ browser/OS combos. > Get unparalleled scalability from the best Selenium testing platform available > Simple to use. Nothing to install. Get started now for free." > http://p.sf.net/sfu/SauceLabs > _______________________________________________ > ruby-gnome2-devel-en mailing list > rub...@li... > https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en |
From: Michael B. <be...@ju...> - 2014-05-25 18:54:42
|
Hi, thanks for your help, this got me a big step further. Now I want to display a slideshow: I am retrieving images from flickr into an array, and now I want to iterate through those images with #each My code shows only the last image. Seems like the window is not updated while the initial code is run. I would like to force an update at the end of each #each iteration. How may I do that? Is there a better way? My current code is here: https://gist.github.com/anonymous/3ac047a590a1f02769e5 Cheers Michael |
From: Detlef R. <det...@gm...> - 2014-05-26 02:47:12
|
hi, Am 25.05.2014 20:54, schrieb Michael Below: > My code shows only the last image. Seems like the window is not updated > while the initial code is run. I would like to force an update at the > end of each #each iteration. How may I do that? Is there a better way? I don't tested it, but I think the problem is, that you while fetching your images never go back to your Gtk main loop. This is necessary to get the updates done. So after creating every Gtk::Image you should add this line. I think, that it will help. Gtk.main_iteration while Gtk.events_pending? Cheers, detlef |
From: Masafumi Y. <my...@gm...> - 2014-05-26 03:30:37
|
Hi, 2014-05-26 3:54 GMT+09:00 Michael Below <be...@ju...>: > thanks for your help, this got me a big step further. Now I want to > display a slideshow: I am retrieving images from flickr into an array, > and now I want to iterate through those images with #each > > My code shows only the last image. Seems like the window is not updated > while the initial code is run. I would like to force an update at the > end of each #each iteration. How may I do that? Is there a better way? A GTK window is just shown when `Gtk.main` is called. `show_all` sets flag to be displayed to all widgets, but doesn't actually display until `Gtk.main` is called. It seems that need to design such as the following: * Do paging when an event occurred. ... FlickRaw.api_key= FlickRaw.shared_secret= @pixbufs = [] results = flickr.photos.search(:tags => "tag", :per_page => 1) results.each {|currentresult| ... if myheight > 700 ... end @pixbufs << currentpixbuf } update_image(@pixbufs.first) # event handler signal_connect("key-press-event") do |_widget, event| case event.keyval when Gdk::Keyval::GDK_KEY_Right @pixbufs.push(@pixbufs.shift) update_image(@pixbufs.first) when Gdk::Keyval::GDK_KEY_Left @pixbufs.unshift(@pixbufs.pop) update_image(@pixbufs.first) end end # auto mode GLib::Timeout.add(1000) do @pixbufs.push(@pixbufs.shift) update_image(@pixbufs.first) true # continue end end def update_image(currentpixbuf) if (defined?(@gtkimage)).nil? @gtkimage = Gtk::Image.new :pixbuf => currentpixbuf add @gtkimage else @gtkimage.set_pixbuf(currentpixbuf) end show_all end ... Thanks, -- myokoym |
From: Michael B. <be...@ju...> - 2014-05-26 06:47:12
|
Hi, Am Montag, den 26.05.2014, 12:30 +0900 schrieb Masafumi Yokoyama: > A GTK window is just shown when `Gtk.main` is called. > `show_all` sets flag to be displayed to all widgets, but doesn't > actually display until `Gtk.main` is called. Ah, I understand... I even tried to move Gtk.main into my #each loop, but this way it makes sense. > It seems that need to design such as the following: Thanks, works fine. Cheers Michael |
From: Michael B. <be...@ju...> - 2014-08-16 22:14:01
|
Hi, I am working on the web display issue again. Now I would like to refresh the images. I.e.: - get a set of 50 images - display the first set, meanwhile get another set of 50 images - as soon as the second set is downloaded, and the first set has been shown at least once, switch from displaying first set to displaying second set - repeat infinitely Thanks to your help, I have got the code to display the first set of pictures in a loop like this: def auto_show(pixbufs) # auto mode GLib::Timeout.add(600) do @pixbufs.push(pixbufs.shift) update_image(pixbufs.first) true # continue end end I guess I could add a second Timeout that switches the picture sets every 5 minutes or so. But is there a way to change the picture sets after successfully loading the next one? I successfully moved the download process into a separate thread, but I can't get the download to run again and again while displaying images and updating the buffer. Cheers Michael Am Montag, den 26.05.2014, 08:46 +0200 schrieb Michael Below: > Hi, > > Am Montag, den 26.05.2014, 12:30 +0900 schrieb Masafumi Yokoyama: > > > A GTK window is just shown when `Gtk.main` is called. > > `show_all` sets flag to be displayed to all widgets, but doesn't > > actually display until `Gtk.main` is called. > > Ah, I understand... I even tried to move Gtk.main into my #each loop, > but this way it makes sense. > > > It seems that need to design such as the following: > > Thanks, works fine. > > Cheers > > Michael |
From: Michael B. <be...@ju...> - 2014-08-17 19:57:42
|
Hi, I would like to download a series of images, and then the next one, not individual images. That way I get a broader selection of images (including older ones with the first download, newer ones later). I am including my current code below. I tried loading a second set of images after starting the auto_show, but the whole download is done before the first image is shown. Best Michael -snip- require 'gtk3' require 'open-uri' require 'tempfile' require 'flickraw' class RubyApp < Gtk::Window def initialize super signal_connect "destroy" do Gtk.main_quit end set_default_size 300, 200 maximize set_window_position Gtk::Window::Position::CENTER @pixbufs = [] @flickpixbufs = [] iswindow = true FlickRaw.api_key= FlickRaw.shared_secret= flickthread = Thread.new { flickresults = flickr.photos.search(:tags => "Tag", :per_page => 50) getimages(flickresults,"FlickRaw.url_b(currentresult)",@flickpixbufs) } # event handler signal_connect("key-press-event") do |_widget, event| case event.keyval when Gdk::Keyval::GDK_KEY_Right @pixbufs.push(@pixbufs.shift) update_image(@pixbufs.first) when Gdk::Keyval::GDK_KEY_Left @pixbufs.unshift(@pixbufs.pop) update_image(@pixbufs.first) when Gdk::Keyval::GDK_KEY_F11 if iswindow fullscreen iswindow = false else unfullscreen iswindow = true end end end flickthread.join @pixbufs = @flickpixbufs update_image(@pixbufs.first) auto_show(@pixbufs) end def getimages(resultarray, method, pixbufsarray) resultarray.each{|currentresult| image_path = Tempfile.open("display-web-image-in-gtk") do | tempfile| begin urlimage = open(eval(method)) rescue OpenURI::HTTPError => e puts e puts "cannot load image" break end tempfile.write(urlimage.read) tempfile.path end unless image_path.nil? fillpixbufs(image_path,pixbufsarray) end } end def fillpixbufs(image,dlpixbufs) begin currentpixbuf = Gdk::Pixbuf.new(image) rescue IOError => e puts e puts "cannot load images" exit end maxheight = 700 myheight = currentpixbuf.height if myheight > maxheight mywidth = currentpixbuf.width newwidth=(mywidth*(maxheight.to_f/myheight)).round currentpixbuf=currentpixbuf.scale(newwidth,maxheight,Gdk::Pixbuf::INTERP_BILINEAR) end puts image dlpixbufs << currentpixbuf end def auto_show(pixbufs) # auto mode GLib::Timeout.add(600) do @pixbufs.push(pixbufs.shift) update_image(pixbufs.first) true # continue end end def update_image(currentpixbuf) if (defined?(@gtkimage)).nil? @gtkimage = Gtk::Image.new :pixbuf => currentpixbuf add @gtkimage else @gtkimage.set_pixbuf(currentpixbuf) end show_all end end Gtk.init window = RubyApp.new Gtk.main -snip- Am Sonntag, den 17.08.2014, 14:21 +0200 schrieb Detlef Reichl: > Hi, > > I don't know, whats your code look like, but I would do it in this way: > > > Create a thread, that loads down the images. Every time, an image is > completely loaded a flag is set by the loader. Then it waits, that the > flag is unset. > > The display system has a Fifo, where it cycles over with a timeout. In > this timeout the loader flag is tested. If it is set, the image is > pushed into the Fifo and the flag is unset after this. > > Cheers, detlef > > > > Am 17.08.2014 00:13, schrieb Michael Below: > > Hi, > > > > I am working on the web display issue again. > > Now I would like to refresh the images. I.e.: > > > > - get a set of 50 images > > - display the first set, meanwhile get another set of 50 images > > - as soon as the second set is downloaded, and the first set has been > > shown at least once, switch from displaying first set to displaying > > second set > > - repeat infinitely > > > > Thanks to your help, I have got the code to display the first set of > > pictures in a loop like this: > > > > def auto_show(pixbufs) # auto mode > > GLib::Timeout.add(600) do > > @pixbufs.push(pixbufs.shift) > > update_image(pixbufs.first) > > true # continue > > end > > end > > > > I guess I could add a second Timeout that switches the picture sets > > every 5 minutes or so. But is there a way to change the picture sets > > after successfully loading the next one? > > > > I successfully moved the download process into a separate thread, but I > > can't get the download to run again and again while displaying images > > and updating the buffer. > > > > Cheers > > Michael > > > > > > Am Montag, den 26.05.2014, 08:46 +0200 schrieb Michael Below: > >> Hi, > >> > >> Am Montag, den 26.05.2014, 12:30 +0900 schrieb Masafumi Yokoyama: > >> > >>> A GTK window is just shown when `Gtk.main` is called. > >>> `show_all` sets flag to be displayed to all widgets, but doesn't > >>> actually display until `Gtk.main` is called. > >> > >> Ah, I understand... I even tried to move Gtk.main into my #each loop, > >> but this way it makes sense. > >> > >>> It seems that need to design such as the following: > >> > >> Thanks, works fine. > >> > >> Cheers > >> > >> Michael > > > > > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > > ruby-gnome2-devel-en mailing list > > rub...@li... > > https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en > > > > > ------------------------------------------------------------------------------ > _______________________________________________ > ruby-gnome2-devel-en mailing list > rub...@li... > https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en |
From: Detlef R. <det...@gm...> - 2014-08-18 16:39:08
|
Hi, I think, that it is a bug in current (ruby) gtk. Not even the example in the ruby-gnome source in ruby-gnome2/gtk3/sample/misc/hreads.rb runs as expected. Cheers, detlef Am 17.08.2014 21:56, schrieb Michael Below: > > Hi, > > I would like to download a series of images, and then the next one, not > individual images. That way I get a broader selection of images > (including older ones with the first download, newer ones later). > > I am including my current code below. I tried loading a second set of > images after starting the auto_show, but the whole download is done > before the first image is shown. > > Best > Michael > > > -snip- > > require 'gtk3' > require 'open-uri' > require 'tempfile' > require 'flickraw' > > class RubyApp < Gtk::Window > > def initialize > super > > signal_connect "destroy" do > Gtk.main_quit end > > set_default_size 300, 200 > maximize > set_window_position Gtk::Window::Position::CENTER > > @pixbufs = [] > @flickpixbufs = [] > iswindow = true > > > FlickRaw.api_key= > FlickRaw.shared_secret= > > flickthread = Thread.new { > flickresults = flickr.photos.search(:tags => "Tag", :per_page => > 50) > > getimages(flickresults,"FlickRaw.url_b(currentresult)",@flickpixbufs) > } > > # event handler > signal_connect("key-press-event") do |_widget, event| > case event.keyval > when Gdk::Keyval::GDK_KEY_Right > @pixbufs.push(@pixbufs.shift) > update_image(@pixbufs.first) > when Gdk::Keyval::GDK_KEY_Left > @pixbufs.unshift(@pixbufs.pop) > update_image(@pixbufs.first) > when Gdk::Keyval::GDK_KEY_F11 > if iswindow > fullscreen > iswindow = false > else > unfullscreen > iswindow = true > end > end > end > > flickthread.join > @pixbufs = @flickpixbufs > update_image(@pixbufs.first) > > auto_show(@pixbufs) > > end > > def getimages(resultarray, method, pixbufsarray) > resultarray.each{|currentresult| > image_path = Tempfile.open("display-web-image-in-gtk") do | > tempfile| > begin > urlimage = open(eval(method)) > rescue OpenURI::HTTPError => e > puts e > puts "cannot load image" > break > end > tempfile.write(urlimage.read) > tempfile.path > end > unless image_path.nil? > fillpixbufs(image_path,pixbufsarray) > end > } > end > > def fillpixbufs(image,dlpixbufs) > begin > currentpixbuf = Gdk::Pixbuf.new(image) > rescue IOError => e > puts e > puts "cannot load images" > exit > end > maxheight = 700 > myheight = currentpixbuf.height > if myheight > maxheight > mywidth = currentpixbuf.width > newwidth=(mywidth*(maxheight.to_f/myheight)).round > > currentpixbuf=currentpixbuf.scale(newwidth,maxheight,Gdk::Pixbuf::INTERP_BILINEAR) > end > puts image > dlpixbufs << currentpixbuf > end > > def auto_show(pixbufs) # auto mode > GLib::Timeout.add(600) do > @pixbufs.push(pixbufs.shift) > update_image(pixbufs.first) > true # continue > end > end > > def update_image(currentpixbuf) > if (defined?(@gtkimage)).nil? > @gtkimage = Gtk::Image.new :pixbuf => currentpixbuf > add @gtkimage > else > @gtkimage.set_pixbuf(currentpixbuf) > end > show_all > end > end > > > Gtk.init > window = RubyApp.new > Gtk.main > > -snip- > > > Am Sonntag, den 17.08.2014, 14:21 +0200 schrieb Detlef Reichl: >> Hi, >> >> I don't know, whats your code look like, but I would do it in this way: >> >> >> Create a thread, that loads down the images. Every time, an image is >> completely loaded a flag is set by the loader. Then it waits, that the >> flag is unset. >> >> The display system has a Fifo, where it cycles over with a timeout. In >> this timeout the loader flag is tested. If it is set, the image is >> pushed into the Fifo and the flag is unset after this. >> >> Cheers, detlef >> >> >> >> Am 17.08.2014 00:13, schrieb Michael Below: >>> Hi, >>> >>> I am working on the web display issue again. >>> Now I would like to refresh the images. I.e.: >>> >>> - get a set of 50 images >>> - display the first set, meanwhile get another set of 50 images >>> - as soon as the second set is downloaded, and the first set has been >>> shown at least once, switch from displaying first set to displaying >>> second set >>> - repeat infinitely >>> >>> Thanks to your help, I have got the code to display the first set of >>> pictures in a loop like this: >>> >>> def auto_show(pixbufs) # auto mode >>> GLib::Timeout.add(600) do >>> @pixbufs.push(pixbufs.shift) >>> update_image(pixbufs.first) >>> true # continue >>> end >>> end >>> >>> I guess I could add a second Timeout that switches the picture sets >>> every 5 minutes or so. But is there a way to change the picture sets >>> after successfully loading the next one? >>> >>> I successfully moved the download process into a separate thread, but I >>> can't get the download to run again and again while displaying images >>> and updating the buffer. >>> >>> Cheers >>> Michael >>> >>> >>> Am Montag, den 26.05.2014, 08:46 +0200 schrieb Michael Below: >>>> Hi, >>>> >>>> Am Montag, den 26.05.2014, 12:30 +0900 schrieb Masafumi Yokoyama: >>>> >>>>> A GTK window is just shown when `Gtk.main` is called. >>>>> `show_all` sets flag to be displayed to all widgets, but doesn't >>>>> actually display until `Gtk.main` is called. >>>> >>>> Ah, I understand... I even tried to move Gtk.main into my #each loop, >>>> but this way it makes sense. >>>> >>>>> It seems that need to design such as the following: >>>> >>>> Thanks, works fine. >>>> >>>> Cheers >>>> >>>> Michael >>> >>> >>> >>> ------------------------------------------------------------------------------ >>> _______________________________________________ >>> ruby-gnome2-devel-en mailing list >>> rub...@li... >>> https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en >>> >> >> >> ------------------------------------------------------------------------------ >> _______________________________________________ >> ruby-gnome2-devel-en mailing list >> rub...@li... >> https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en > > > > > ------------------------------------------------------------------------------ > _______________________________________________ > ruby-gnome2-devel-en mailing list > rub...@li... > https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en > |
From: Michael B. <be...@ju...> - 2014-08-19 07:37:27
|
Hi, do you think this can be fixed? Doing downloads in the background is pretty important for my project, I don't want long gaps between the sets. Cheers Michael On 18. August 2014 18:38:59 MESZ, Detlef Reichl <det...@gm...> wrote: >Hi, > >I think, that it is a bug in current (ruby) gtk. Not even the example >in >the ruby-gnome source in > >ruby-gnome2/gtk3/sample/misc/hreads.rb > >runs as expected. > >Cheers, detlef > > >Am 17.08.2014 21:56, schrieb Michael Below: >> >> Hi, >> >> I would like to download a series of images, and then the next one, >not >> individual images. That way I get a broader selection of images >> (including older ones with the first download, newer ones later). >> >> I am including my current code below. I tried loading a second set of >> images after starting the auto_show, but the whole download is done >> before the first image is shown. >> >> Best >> Michael >> >> >> -snip- >> >> require 'gtk3' >> require 'open-uri' >> require 'tempfile' >> require 'flickraw' >> >> class RubyApp < Gtk::Window >> >> def initialize >> super >> >> signal_connect "destroy" do >> Gtk.main_quit end >> >> set_default_size 300, 200 >> maximize >> set_window_position Gtk::Window::Position::CENTER >> >> @pixbufs = [] >> @flickpixbufs = [] >> iswindow = true >> >> >> FlickRaw.api_key= >> FlickRaw.shared_secret= >> >> flickthread = Thread.new { >> flickresults = flickr.photos.search(:tags => "Tag", :per_page >=> >> 50) >> >> getimages(flickresults,"FlickRaw.url_b(currentresult)",@flickpixbufs) >> } >> >> # event handler >> signal_connect("key-press-event") do |_widget, event| >> case event.keyval >> when Gdk::Keyval::GDK_KEY_Right >> @pixbufs.push(@pixbufs.shift) >> update_image(@pixbufs.first) >> when Gdk::Keyval::GDK_KEY_Left >> @pixbufs.unshift(@pixbufs.pop) >> update_image(@pixbufs.first) >> when Gdk::Keyval::GDK_KEY_F11 >> if iswindow >> fullscreen >> iswindow = false >> else >> unfullscreen >> iswindow = true >> end >> end >> end >> >> flickthread.join >> @pixbufs = @flickpixbufs >> update_image(@pixbufs.first) >> >> auto_show(@pixbufs) >> >> end >> >> def getimages(resultarray, method, pixbufsarray) >> resultarray.each{|currentresult| >> image_path = Tempfile.open("display-web-image-in-gtk") do | >> tempfile| >> begin >> urlimage = open(eval(method)) >> rescue OpenURI::HTTPError => e >> puts e >> puts "cannot load image" >> break >> end >> tempfile.write(urlimage.read) >> tempfile.path >> end >> unless image_path.nil? >> fillpixbufs(image_path,pixbufsarray) >> end >> } >> end >> >> def fillpixbufs(image,dlpixbufs) >> begin >> currentpixbuf = Gdk::Pixbuf.new(image) >> rescue IOError => e >> puts e >> puts "cannot load images" >> exit >> end >> maxheight = 700 >> myheight = currentpixbuf.height >> if myheight > maxheight >> mywidth = currentpixbuf.width >> newwidth=(mywidth*(maxheight.to_f/myheight)).round >> >> >currentpixbuf=currentpixbuf.scale(newwidth,maxheight,Gdk::Pixbuf::INTERP_BILINEAR) >> end >> puts image >> dlpixbufs << currentpixbuf >> end >> >> def auto_show(pixbufs) # auto mode >> GLib::Timeout.add(600) do >> @pixbufs.push(pixbufs.shift) >> update_image(pixbufs.first) >> true # continue >> end >> end >> >> def update_image(currentpixbuf) >> if (defined?(@gtkimage)).nil? >> @gtkimage = Gtk::Image.new :pixbuf => currentpixbuf >> add @gtkimage >> else >> @gtkimage.set_pixbuf(currentpixbuf) >> end >> show_all >> end >> end >> >> >> Gtk.init >> window = RubyApp.new >> Gtk.main >> >> -snip- >> >> >> Am Sonntag, den 17.08.2014, 14:21 +0200 schrieb Detlef Reichl: >>> Hi, >>> >>> I don't know, whats your code look like, but I would do it in this >way: >>> >>> >>> Create a thread, that loads down the images. Every time, an image is >>> completely loaded a flag is set by the loader. Then it waits, that >the >>> flag is unset. >>> >>> The display system has a Fifo, where it cycles over with a timeout. >In >>> this timeout the loader flag is tested. If it is set, the image is >>> pushed into the Fifo and the flag is unset after this. >>> >>> Cheers, detlef >>> >>> >>> >>> Am 17.08.2014 00:13, schrieb Michael Below: >>>> Hi, >>>> >>>> I am working on the web display issue again. >>>> Now I would like to refresh the images. I.e.: >>>> >>>> - get a set of 50 images >>>> - display the first set, meanwhile get another set of 50 images >>>> - as soon as the second set is downloaded, and the first set has >been >>>> shown at least once, switch from displaying first set to displaying >>>> second set >>>> - repeat infinitely >>>> >>>> Thanks to your help, I have got the code to display the first set >of >>>> pictures in a loop like this: >>>> >>>> def auto_show(pixbufs) # auto mode >>>> GLib::Timeout.add(600) do >>>> @pixbufs.push(pixbufs.shift) >>>> update_image(pixbufs.first) >>>> true # continue >>>> end >>>> end >>>> >>>> I guess I could add a second Timeout that switches the picture sets >>>> every 5 minutes or so. But is there a way to change the picture >sets >>>> after successfully loading the next one? >>>> >>>> I successfully moved the download process into a separate thread, >but I >>>> can't get the download to run again and again while displaying >images >>>> and updating the buffer. >>>> >>>> Cheers >>>> Michael >>>> >>>> >>>> Am Montag, den 26.05.2014, 08:46 +0200 schrieb Michael Below: >>>>> Hi, >>>>> >>>>> Am Montag, den 26.05.2014, 12:30 +0900 schrieb Masafumi Yokoyama: >>>>> >>>>>> A GTK window is just shown when `Gtk.main` is called. >>>>>> `show_all` sets flag to be displayed to all widgets, but doesn't >>>>>> actually display until `Gtk.main` is called. >>>>> >>>>> Ah, I understand... I even tried to move Gtk.main into my #each >loop, >>>>> but this way it makes sense. >>>>> >>>>>> It seems that need to design such as the following: >>>>> >>>>> Thanks, works fine. >>>>> >>>>> Cheers >>>>> >>>>> Michael >>>> >>>> >>>> >>>> >------------------------------------------------------------------------------ >>>> _______________________________________________ >>>> ruby-gnome2-devel-en mailing list >>>> rub...@li... >>>> https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en >>>> >>> >>> >>> >------------------------------------------------------------------------------ >>> _______________________________________________ >>> ruby-gnome2-devel-en mailing list >>> rub...@li... >>> https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en >> >> >> >> >> >------------------------------------------------------------------------------ >> _______________________________________________ >> ruby-gnome2-devel-en mailing list >> rub...@li... >> https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en >> > > >------------------------------------------------------------------------------ >_______________________________________________ >ruby-gnome2-devel-en mailing list >rub...@li... >https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en |
From: Kouhei S. <ko...@co...> - 2014-08-19 12:32:36
|
Hi, Could you show a workable code without flicker account? I don't have flicker account. So I couldn't try your code... :< Thanks, -- kou In <6d5...@em...> "Re: [ruby-gnome2-devel-en] Displaying web images" on Tue, 19 Aug 2014 09:36:55 +0200, Michael Below <be...@ju...> wrote: > Hi, > do you think this can be fixed? > Doing downloads in the background is pretty important for my project, I don't want long gaps between the sets. > Cheers > Michael > > On 18. August 2014 18:38:59 MESZ, Detlef Reichl <det...@gm...> wrote: >>Hi, >> >>I think, that it is a bug in current (ruby) gtk. Not even the example >>in >>the ruby-gnome source in >> >>ruby-gnome2/gtk3/sample/misc/hreads.rb >> >>runs as expected. >> >>Cheers, detlef >> >> >>Am 17.08.2014 21:56, schrieb Michael Below: >>> >>> Hi, >>> >>> I would like to download a series of images, and then the next one, >>not >>> individual images. That way I get a broader selection of images >>> (including older ones with the first download, newer ones later). >>> >>> I am including my current code below. I tried loading a second set of >>> images after starting the auto_show, but the whole download is done >>> before the first image is shown. >>> >>> Best >>> Michael >>> >>> >>> -snip- >>> >>> require 'gtk3' >>> require 'open-uri' >>> require 'tempfile' >>> require 'flickraw' >>> >>> class RubyApp < Gtk::Window >>> >>> def initialize >>> super >>> >>> signal_connect "destroy" do >>> Gtk.main_quit end >>> >>> set_default_size 300, 200 >>> maximize >>> set_window_position Gtk::Window::Position::CENTER >>> >>> @pixbufs = [] >>> @flickpixbufs = [] >>> iswindow = true >>> >>> >>> FlickRaw.api_key= >>> FlickRaw.shared_secret= >>> >>> flickthread = Thread.new { >>> flickresults = flickr.photos.search(:tags => "Tag", :per_page >>=> >>> 50) >>> >>> getimages(flickresults,"FlickRaw.url_b(currentresult)",@flickpixbufs) >>> } >>> >>> # event handler >>> signal_connect("key-press-event") do |_widget, event| >>> case event.keyval >>> when Gdk::Keyval::GDK_KEY_Right >>> @pixbufs.push(@pixbufs.shift) >>> update_image(@pixbufs.first) >>> when Gdk::Keyval::GDK_KEY_Left >>> @pixbufs.unshift(@pixbufs.pop) >>> update_image(@pixbufs.first) >>> when Gdk::Keyval::GDK_KEY_F11 >>> if iswindow >>> fullscreen >>> iswindow = false >>> else >>> unfullscreen >>> iswindow = true >>> end >>> end >>> end >>> >>> flickthread.join >>> @pixbufs = @flickpixbufs >>> update_image(@pixbufs.first) >>> >>> auto_show(@pixbufs) >>> >>> end >>> >>> def getimages(resultarray, method, pixbufsarray) >>> resultarray.each{|currentresult| >>> image_path = Tempfile.open("display-web-image-in-gtk") do | >>> tempfile| >>> begin >>> urlimage = open(eval(method)) >>> rescue OpenURI::HTTPError => e >>> puts e >>> puts "cannot load image" >>> break >>> end >>> tempfile.write(urlimage.read) >>> tempfile.path >>> end >>> unless image_path.nil? >>> fillpixbufs(image_path,pixbufsarray) >>> end >>> } >>> end >>> >>> def fillpixbufs(image,dlpixbufs) >>> begin >>> currentpixbuf = Gdk::Pixbuf.new(image) >>> rescue IOError => e >>> puts e >>> puts "cannot load images" >>> exit >>> end >>> maxheight = 700 >>> myheight = currentpixbuf.height >>> if myheight > maxheight >>> mywidth = currentpixbuf.width >>> newwidth=(mywidth*(maxheight.to_f/myheight)).round >>> >>> >>currentpixbuf=currentpixbuf.scale(newwidth,maxheight,Gdk::Pixbuf::INTERP_BILINEAR) >>> end >>> puts image >>> dlpixbufs << currentpixbuf >>> end >>> >>> def auto_show(pixbufs) # auto mode >>> GLib::Timeout.add(600) do >>> @pixbufs.push(pixbufs.shift) >>> update_image(pixbufs.first) >>> true # continue >>> end >>> end >>> >>> def update_image(currentpixbuf) >>> if (defined?(@gtkimage)).nil? >>> @gtkimage = Gtk::Image.new :pixbuf => currentpixbuf >>> add @gtkimage >>> else >>> @gtkimage.set_pixbuf(currentpixbuf) >>> end >>> show_all >>> end >>> end >>> >>> >>> Gtk.init >>> window = RubyApp.new >>> Gtk.main >>> >>> -snip- >>> >>> >>> Am Sonntag, den 17.08.2014, 14:21 +0200 schrieb Detlef Reichl: >>>> Hi, >>>> >>>> I don't know, whats your code look like, but I would do it in this >>way: >>>> >>>> >>>> Create a thread, that loads down the images. Every time, an image is >>>> completely loaded a flag is set by the loader. Then it waits, that >>the >>>> flag is unset. >>>> >>>> The display system has a Fifo, where it cycles over with a timeout. >>In >>>> this timeout the loader flag is tested. If it is set, the image is >>>> pushed into the Fifo and the flag is unset after this. >>>> >>>> Cheers, detlef >>>> >>>> >>>> >>>> Am 17.08.2014 00:13, schrieb Michael Below: >>>>> Hi, >>>>> >>>>> I am working on the web display issue again. >>>>> Now I would like to refresh the images. I.e.: >>>>> >>>>> - get a set of 50 images >>>>> - display the first set, meanwhile get another set of 50 images >>>>> - as soon as the second set is downloaded, and the first set has >>been >>>>> shown at least once, switch from displaying first set to displaying >>>>> second set >>>>> - repeat infinitely >>>>> >>>>> Thanks to your help, I have got the code to display the first set >>of >>>>> pictures in a loop like this: >>>>> >>>>> def auto_show(pixbufs) # auto mode >>>>> GLib::Timeout.add(600) do >>>>> @pixbufs.push(pixbufs.shift) >>>>> update_image(pixbufs.first) >>>>> true # continue >>>>> end >>>>> end >>>>> >>>>> I guess I could add a second Timeout that switches the picture sets >>>>> every 5 minutes or so. But is there a way to change the picture >>sets >>>>> after successfully loading the next one? >>>>> >>>>> I successfully moved the download process into a separate thread, >>but I >>>>> can't get the download to run again and again while displaying >>images >>>>> and updating the buffer. >>>>> >>>>> Cheers >>>>> Michael >>>>> >>>>> >>>>> Am Montag, den 26.05.2014, 08:46 +0200 schrieb Michael Below: >>>>>> Hi, >>>>>> >>>>>> Am Montag, den 26.05.2014, 12:30 +0900 schrieb Masafumi Yokoyama: >>>>>> >>>>>>> A GTK window is just shown when `Gtk.main` is called. >>>>>>> `show_all` sets flag to be displayed to all widgets, but doesn't >>>>>>> actually display until `Gtk.main` is called. >>>>>> >>>>>> Ah, I understand... I even tried to move Gtk.main into my #each >>loop, >>>>>> but this way it makes sense. >>>>>> >>>>>>> It seems that need to design such as the following: >>>>>> >>>>>> Thanks, works fine. >>>>>> >>>>>> Cheers >>>>>> >>>>>> Michael >>>>> >>>>> >>>>> >>>>> >>------------------------------------------------------------------------------ >>>>> _______________________________________________ >>>>> ruby-gnome2-devel-en mailing list >>>>> rub...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en >>>>> >>>> >>>> >>>> >>------------------------------------------------------------------------------ >>>> _______________________________________________ >>>> ruby-gnome2-devel-en mailing list >>>> rub...@li... >>>> https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en >>> >>> >>> >>> >>> >>------------------------------------------------------------------------------ >>> _______________________________________________ >>> ruby-gnome2-devel-en mailing list >>> rub...@li... >>> https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en >>> >> >> >>------------------------------------------------------------------------------ >>_______________________________________________ >>ruby-gnome2-devel-en mailing list >>rub...@li... >>https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en |
From: Detlef R. <det...@gm...> - 2014-08-19 14:26:29
|
Hi, because I also do not have a flickr account, I wrote this little test: #!/usr/bin/env ruby require 'gtk3' class Win < Gtk::Window def initialize super button = Gtk::Button.new :label => 'click' add button button.signal_connect(:clicked) {p 'clicked'} end end th = Thread.new do 0.upto(5) do |i| p i sleep 0.5 end end th.join win = Win.new win.show_all Gtk.main If I start it, first the count down of the thread completely runs down and then the window appears. If I remove the th.join call the window will be shown directly, but the countdown often hangs at start, stops if the pointer leaves the window. Also the program terminates, when the thread ends. Afaik the window remain in this case, right? Cheers, detlef Am 19.08.2014 14:32, schrieb Kouhei Sutou: > Hi, > > Could you show a workable code without flicker account? > I don't have flicker account. So I couldn't try your > code... :< > > Thanks, > -- > kou > > In <6d5...@em...> > "Re: [ruby-gnome2-devel-en] Displaying web images" on Tue, 19 Aug 2014 09:36:55 +0200, > Michael Below <be...@ju...> wrote: > >> Hi, >> do you think this can be fixed? >> Doing downloads in the background is pretty important for my project, I don't want long gaps between the sets. >> Cheers >> Michael >> >> On 18. August 2014 18:38:59 MESZ, Detlef Reichl <det...@gm...> wrote: >>> Hi, >>> >>> I think, that it is a bug in current (ruby) gtk. Not even the example >>> in >>> the ruby-gnome source in >>> >>> ruby-gnome2/gtk3/sample/misc/hreads.rb >>> >>> runs as expected. >>> >>> Cheers, detlef >>> >>> >>> Am 17.08.2014 21:56, schrieb Michael Below: >>>> >>>> Hi, >>>> >>>> I would like to download a series of images, and then the next one, >>> not >>>> individual images. That way I get a broader selection of images >>>> (including older ones with the first download, newer ones later). >>>> >>>> I am including my current code below. I tried loading a second set of >>>> images after starting the auto_show, but the whole download is done >>>> before the first image is shown. >>>> >>>> Best >>>> Michael >>>> >>>> >>>> -snip- >>>> >>>> require 'gtk3' >>>> require 'open-uri' >>>> require 'tempfile' >>>> require 'flickraw' >>>> >>>> class RubyApp < Gtk::Window >>>> >>>> def initialize >>>> super >>>> >>>> signal_connect "destroy" do >>>> Gtk.main_quit end >>>> >>>> set_default_size 300, 200 >>>> maximize >>>> set_window_position Gtk::Window::Position::CENTER >>>> >>>> @pixbufs = [] >>>> @flickpixbufs = [] >>>> iswindow = true >>>> >>>> >>>> FlickRaw.api_key= >>>> FlickRaw.shared_secret= >>>> >>>> flickthread = Thread.new { >>>> flickresults = flickr.photos.search(:tags => "Tag", :per_page >>> => >>>> 50) >>>> >>>> getimages(flickresults,"FlickRaw.url_b(currentresult)",@flickpixbufs) >>>> } >>>> >>>> # event handler >>>> signal_connect("key-press-event") do |_widget, event| >>>> case event.keyval >>>> when Gdk::Keyval::GDK_KEY_Right >>>> @pixbufs.push(@pixbufs.shift) >>>> update_image(@pixbufs.first) >>>> when Gdk::Keyval::GDK_KEY_Left >>>> @pixbufs.unshift(@pixbufs.pop) >>>> update_image(@pixbufs.first) >>>> when Gdk::Keyval::GDK_KEY_F11 >>>> if iswindow >>>> fullscreen >>>> iswindow = false >>>> else >>>> unfullscreen >>>> iswindow = true >>>> end >>>> end >>>> end >>>> >>>> flickthread.join >>>> @pixbufs = @flickpixbufs >>>> update_image(@pixbufs.first) >>>> >>>> auto_show(@pixbufs) >>>> >>>> end >>>> >>>> def getimages(resultarray, method, pixbufsarray) >>>> resultarray.each{|currentresult| >>>> image_path = Tempfile.open("display-web-image-in-gtk") do | >>>> tempfile| >>>> begin >>>> urlimage = open(eval(method)) >>>> rescue OpenURI::HTTPError => e >>>> puts e >>>> puts "cannot load image" >>>> break >>>> end >>>> tempfile.write(urlimage.read) >>>> tempfile.path >>>> end >>>> unless image_path.nil? >>>> fillpixbufs(image_path,pixbufsarray) >>>> end >>>> } >>>> end >>>> >>>> def fillpixbufs(image,dlpixbufs) >>>> begin >>>> currentpixbuf = Gdk::Pixbuf.new(image) >>>> rescue IOError => e >>>> puts e >>>> puts "cannot load images" >>>> exit >>>> end >>>> maxheight = 700 >>>> myheight = currentpixbuf.height >>>> if myheight > maxheight >>>> mywidth = currentpixbuf.width >>>> newwidth=(mywidth*(maxheight.to_f/myheight)).round >>>> >>>> >>> currentpixbuf=currentpixbuf.scale(newwidth,maxheight,Gdk::Pixbuf::INTERP_BILINEAR) >>>> end >>>> puts image >>>> dlpixbufs << currentpixbuf >>>> end >>>> >>>> def auto_show(pixbufs) # auto mode >>>> GLib::Timeout.add(600) do >>>> @pixbufs.push(pixbufs.shift) >>>> update_image(pixbufs.first) >>>> true # continue >>>> end >>>> end >>>> >>>> def update_image(currentpixbuf) >>>> if (defined?(@gtkimage)).nil? >>>> @gtkimage = Gtk::Image.new :pixbuf => currentpixbuf >>>> add @gtkimage >>>> else >>>> @gtkimage.set_pixbuf(currentpixbuf) >>>> end >>>> show_all >>>> end >>>> end >>>> >>>> >>>> Gtk.init >>>> window = RubyApp.new >>>> Gtk.main >>>> >>>> -snip- >>>> >>>> >>>> Am Sonntag, den 17.08.2014, 14:21 +0200 schrieb Detlef Reichl: >>>>> Hi, >>>>> >>>>> I don't know, whats your code look like, but I would do it in this >>> way: >>>>> >>>>> >>>>> Create a thread, that loads down the images. Every time, an image is >>>>> completely loaded a flag is set by the loader. Then it waits, that >>> the >>>>> flag is unset. >>>>> >>>>> The display system has a Fifo, where it cycles over with a timeout. >>> In >>>>> this timeout the loader flag is tested. If it is set, the image is >>>>> pushed into the Fifo and the flag is unset after this. >>>>> >>>>> Cheers, detlef >>>>> >>>>> >>>>> >>>>> Am 17.08.2014 00:13, schrieb Michael Below: >>>>>> Hi, >>>>>> >>>>>> I am working on the web display issue again. >>>>>> Now I would like to refresh the images. I.e.: >>>>>> >>>>>> - get a set of 50 images >>>>>> - display the first set, meanwhile get another set of 50 images >>>>>> - as soon as the second set is downloaded, and the first set has >>> been >>>>>> shown at least once, switch from displaying first set to displaying >>>>>> second set >>>>>> - repeat infinitely >>>>>> >>>>>> Thanks to your help, I have got the code to display the first set >>> of >>>>>> pictures in a loop like this: >>>>>> >>>>>> def auto_show(pixbufs) # auto mode >>>>>> GLib::Timeout.add(600) do >>>>>> @pixbufs.push(pixbufs.shift) >>>>>> update_image(pixbufs.first) >>>>>> true # continue >>>>>> end >>>>>> end >>>>>> >>>>>> I guess I could add a second Timeout that switches the picture sets >>>>>> every 5 minutes or so. But is there a way to change the picture >>> sets >>>>>> after successfully loading the next one? >>>>>> >>>>>> I successfully moved the download process into a separate thread, >>> but I >>>>>> can't get the download to run again and again while displaying >>> images >>>>>> and updating the buffer. >>>>>> >>>>>> Cheers >>>>>> Michael >>>>>> >>>>>> >>>>>> Am Montag, den 26.05.2014, 08:46 +0200 schrieb Michael Below: >>>>>>> Hi, >>>>>>> >>>>>>> Am Montag, den 26.05.2014, 12:30 +0900 schrieb Masafumi Yokoyama: >>>>>>> >>>>>>>> A GTK window is just shown when `Gtk.main` is called. >>>>>>>> `show_all` sets flag to be displayed to all widgets, but doesn't >>>>>>>> actually display until `Gtk.main` is called. >>>>>>> >>>>>>> Ah, I understand... I even tried to move Gtk.main into my #each >>> loop, >>>>>>> but this way it makes sense. >>>>>>> >>>>>>>> It seems that need to design such as the following: >>>>>>> >>>>>>> Thanks, works fine. >>>>>>> >>>>>>> Cheers >>>>>>> >>>>>>> Michael >>>>>> >>>>>> >>>>>> >>>>>> >>> ------------------------------------------------------------------------------ >>>>>> _______________________________________________ >>>>>> ruby-gnome2-devel-en mailing list >>>>>> rub...@li... >>>>>> https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en >>>>>> >>>>> >>>>> >>>>> >>> ------------------------------------------------------------------------------ >>>>> _______________________________________________ >>>>> ruby-gnome2-devel-en mailing list >>>>> rub...@li... >>>>> https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en >>>> >>>> >>>> >>>> >>>> >>> ------------------------------------------------------------------------------ >>>> _______________________________________________ >>>> ruby-gnome2-devel-en mailing list >>>> rub...@li... >>>> https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en >>>> >>> >>> >>> ------------------------------------------------------------------------------ >>> _______________________________________________ >>> ruby-gnome2-devel-en mailing list >>> rub...@li... >>> https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en > > ------------------------------------------------------------------------------ > _______________________________________________ > ruby-gnome2-devel-en mailing list > rub...@li... > https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en > |
From: Mike C. <mik...@gm...> - 2014-08-19 21:40:02
|
I know this doesn't help your problem directly at all, but I thought I would mention it anyway. Many years ago I had problems with threads and GTK. Eventually I gave up and used the on_idle call to run code when the UI wasn't being used. If you partition your problem and process little bits at a time, it will work smoothly in the background. It seems like a pain in the neck and you might ask yourself why should you write your own scheduler. But in reality, I have used this technique quite often professionally and find that I can control the reactiveness of the UI much, much better. Even when I have real threads, I often find this works better. Also no need for mutex. Anyway, given the event loop in GTK, this is essentially the reactor pattern. The timing is a bit bad because I'm just off on holiday soon, but I can try to provide some code examples in a little over a week if anyone is interested. On 19 August 2014 15:26, Detlef Reichl <det...@gm...> wrote: > Hi, > > because I also do not have a flickr account, I wrote this little test: > > > #!/usr/bin/env ruby > > require 'gtk3' > > class Win < Gtk::Window > def initialize > super > button = Gtk::Button.new :label => 'click' > add button > button.signal_connect(:clicked) {p 'clicked'} > end > end > > th = Thread.new do > 0.upto(5) do |i| > p i > sleep 0.5 > end > end > th.join > > win = Win.new > win.show_all > Gtk.main > > > If I start it, first the count down of the thread completely runs down > and then the window appears. If I remove the th.join call the window > will be shown directly, but the countdown often hangs at start, stops if > the pointer leaves the window. Also the program terminates, when the > thread ends. Afaik the window remain in this case, right? > > Cheers, detlef > > > > Am 19.08.2014 14:32, schrieb Kouhei Sutou: > > Hi, > > > > Could you show a workable code without flicker account? > > I don't have flicker account. So I couldn't try your > > code... :< > > > > Thanks, > > -- > > kou > > > > In <6d5...@em...> > > "Re: [ruby-gnome2-devel-en] Displaying web images" on Tue, 19 Aug 2014 > 09:36:55 +0200, > > Michael Below <be...@ju...> wrote: > > > >> Hi, > >> do you think this can be fixed? > >> Doing downloads in the background is pretty important for my project, I > don't want long gaps between the sets. > >> Cheers > >> Michael > >> > >> On 18. August 2014 18:38:59 MESZ, Detlef Reichl <det...@gm...> > wrote: > >>> Hi, > >>> > >>> I think, that it is a bug in current (ruby) gtk. Not even the example > >>> in > >>> the ruby-gnome source in > >>> > >>> ruby-gnome2/gtk3/sample/misc/hreads.rb > >>> > >>> runs as expected. > >>> > >>> Cheers, detlef > >>> > >>> > >>> Am 17.08.2014 21:56, schrieb Michael Below: > >>>> > >>>> Hi, > >>>> > >>>> I would like to download a series of images, and then the next one, > >>> not > >>>> individual images. That way I get a broader selection of images > >>>> (including older ones with the first download, newer ones later). > >>>> > >>>> I am including my current code below. I tried loading a second set of > >>>> images after starting the auto_show, but the whole download is done > >>>> before the first image is shown. > >>>> > >>>> Best > >>>> Michael > >>>> > >>>> > >>>> -snip- > >>>> > >>>> require 'gtk3' > >>>> require 'open-uri' > >>>> require 'tempfile' > >>>> require 'flickraw' > >>>> > >>>> class RubyApp < Gtk::Window > >>>> > >>>> def initialize > >>>> super > >>>> > >>>> signal_connect "destroy" do > >>>> Gtk.main_quit end > >>>> > >>>> set_default_size 300, 200 > >>>> maximize > >>>> set_window_position Gtk::Window::Position::CENTER > >>>> > >>>> @pixbufs = [] > >>>> @flickpixbufs = [] > >>>> iswindow = true > >>>> > >>>> > >>>> FlickRaw.api_key= > >>>> FlickRaw.shared_secret= > >>>> > >>>> flickthread = Thread.new { > >>>> flickresults = flickr.photos.search(:tags => "Tag", :per_page > >>> => > >>>> 50) > >>>> > >>>> getimages(flickresults,"FlickRaw.url_b(currentresult)",@flickpixbufs) > >>>> } > >>>> > >>>> # event handler > >>>> signal_connect("key-press-event") do |_widget, event| > >>>> case event.keyval > >>>> when Gdk::Keyval::GDK_KEY_Right > >>>> @pixbufs.push(@pixbufs.shift) > >>>> update_image(@pixbufs.first) > >>>> when Gdk::Keyval::GDK_KEY_Left > >>>> @pixbufs.unshift(@pixbufs.pop) > >>>> update_image(@pixbufs.first) > >>>> when Gdk::Keyval::GDK_KEY_F11 > >>>> if iswindow > >>>> fullscreen > >>>> iswindow = false > >>>> else > >>>> unfullscreen > >>>> iswindow = true > >>>> end > >>>> end > >>>> end > >>>> > >>>> flickthread.join > >>>> @pixbufs = @flickpixbufs > >>>> update_image(@pixbufs.first) > >>>> > >>>> auto_show(@pixbufs) > >>>> > >>>> end > >>>> > >>>> def getimages(resultarray, method, pixbufsarray) > >>>> resultarray.each{|currentresult| > >>>> image_path = Tempfile.open("display-web-image-in-gtk") do | > >>>> tempfile| > >>>> begin > >>>> urlimage = open(eval(method)) > >>>> rescue OpenURI::HTTPError => e > >>>> puts e > >>>> puts "cannot load image" > >>>> break > >>>> end > >>>> tempfile.write(urlimage.read) > >>>> tempfile.path > >>>> end > >>>> unless image_path.nil? > >>>> fillpixbufs(image_path,pixbufsarray) > >>>> end > >>>> } > >>>> end > >>>> > >>>> def fillpixbufs(image,dlpixbufs) > >>>> begin > >>>> currentpixbuf = Gdk::Pixbuf.new(image) > >>>> rescue IOError => e > >>>> puts e > >>>> puts "cannot load images" > >>>> exit > >>>> end > >>>> maxheight = 700 > >>>> myheight = currentpixbuf.height > >>>> if myheight > maxheight > >>>> mywidth = currentpixbuf.width > >>>> newwidth=(mywidth*(maxheight.to_f/myheight)).round > >>>> > >>>> > >>> > currentpixbuf=currentpixbuf.scale(newwidth,maxheight,Gdk::Pixbuf::INTERP_BILINEAR) > >>>> end > >>>> puts image > >>>> dlpixbufs << currentpixbuf > >>>> end > >>>> > >>>> def auto_show(pixbufs) # auto mode > >>>> GLib::Timeout.add(600) do > >>>> @pixbufs.push(pixbufs.shift) > >>>> update_image(pixbufs.first) > >>>> true # continue > >>>> end > >>>> end > >>>> > >>>> def update_image(currentpixbuf) > >>>> if (defined?(@gtkimage)).nil? > >>>> @gtkimage = Gtk::Image.new :pixbuf => currentpixbuf > >>>> add @gtkimage > >>>> else > >>>> @gtkimage.set_pixbuf(currentpixbuf) > >>>> end > >>>> show_all > >>>> end > >>>> end > >>>> > >>>> > >>>> Gtk.init > >>>> window = RubyApp.new > >>>> Gtk.main > >>>> > >>>> -snip- > >>>> > >>>> > >>>> Am Sonntag, den 17.08.2014, 14:21 +0200 schrieb Detlef Reichl: > >>>>> Hi, > >>>>> > >>>>> I don't know, whats your code look like, but I would do it in this > >>> way: > >>>>> > >>>>> > >>>>> Create a thread, that loads down the images. Every time, an image is > >>>>> completely loaded a flag is set by the loader. Then it waits, that > >>> the > >>>>> flag is unset. > >>>>> > >>>>> The display system has a Fifo, where it cycles over with a timeout. > >>> In > >>>>> this timeout the loader flag is tested. If it is set, the image is > >>>>> pushed into the Fifo and the flag is unset after this. > >>>>> > >>>>> Cheers, detlef > >>>>> > >>>>> > >>>>> > >>>>> Am 17.08.2014 00:13, schrieb Michael Below: > >>>>>> Hi, > >>>>>> > >>>>>> I am working on the web display issue again. > >>>>>> Now I would like to refresh the images. I.e.: > >>>>>> > >>>>>> - get a set of 50 images > >>>>>> - display the first set, meanwhile get another set of 50 images > >>>>>> - as soon as the second set is downloaded, and the first set has > >>> been > >>>>>> shown at least once, switch from displaying first set to displaying > >>>>>> second set > >>>>>> - repeat infinitely > >>>>>> > >>>>>> Thanks to your help, I have got the code to display the first set > >>> of > >>>>>> pictures in a loop like this: > >>>>>> > >>>>>> def auto_show(pixbufs) # auto mode > >>>>>> GLib::Timeout.add(600) do > >>>>>> @pixbufs.push(pixbufs.shift) > >>>>>> update_image(pixbufs.first) > >>>>>> true # continue > >>>>>> end > >>>>>> end > >>>>>> > >>>>>> I guess I could add a second Timeout that switches the picture sets > >>>>>> every 5 minutes or so. But is there a way to change the picture > >>> sets > >>>>>> after successfully loading the next one? > >>>>>> > >>>>>> I successfully moved the download process into a separate thread, > >>> but I > >>>>>> can't get the download to run again and again while displaying > >>> images > >>>>>> and updating the buffer. > >>>>>> > >>>>>> Cheers > >>>>>> Michael > >>>>>> > >>>>>> > >>>>>> Am Montag, den 26.05.2014, 08:46 +0200 schrieb Michael Below: > >>>>>>> Hi, > >>>>>>> > >>>>>>> Am Montag, den 26.05.2014, 12:30 +0900 schrieb Masafumi Yokoyama: > >>>>>>> > >>>>>>>> A GTK window is just shown when `Gtk.main` is called. > >>>>>>>> `show_all` sets flag to be displayed to all widgets, but doesn't > >>>>>>>> actually display until `Gtk.main` is called. > >>>>>>> > >>>>>>> Ah, I understand... I even tried to move Gtk.main into my #each > >>> loop, > >>>>>>> but this way it makes sense. > >>>>>>> > >>>>>>>> It seems that need to design such as the following: > >>>>>>> > >>>>>>> Thanks, works fine. > >>>>>>> > >>>>>>> Cheers > >>>>>>> > >>>>>>> Michael > >>>>>> > >>>>>> > >>>>>> > >>>>>> > >>> > ------------------------------------------------------------------------------ > >>>>>> _______________________________________________ > >>>>>> ruby-gnome2-devel-en mailing list > >>>>>> rub...@li... > >>>>>> https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en > >>>>>> > >>>>> > >>>>> > >>>>> > >>> > ------------------------------------------------------------------------------ > >>>>> _______________________________________________ > >>>>> ruby-gnome2-devel-en mailing list > >>>>> rub...@li... > >>>>> https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en > >>>> > >>>> > >>>> > >>>> > >>>> > >>> > ------------------------------------------------------------------------------ > >>>> _______________________________________________ > >>>> ruby-gnome2-devel-en mailing list > >>>> rub...@li... > >>>> https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en > >>>> > >>> > >>> > >>> > ------------------------------------------------------------------------------ > >>> _______________________________________________ > >>> ruby-gnome2-devel-en mailing list > >>> rub...@li... > >>> https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en > > > > > ------------------------------------------------------------------------------ > > _______________________________________________ > > ruby-gnome2-devel-en mailing list > > rub...@li... > > https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en > > > > > > ------------------------------------------------------------------------------ > _______________________________________________ > ruby-gnome2-devel-en mailing list > rub...@li... > https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en > |
From: Michael B. <be...@ju...> - 2014-08-20 06:46:17
|
Hi, many thanks for your example. If I move the "th.join" into the last line, after Gtk.main, it works as expected: Prints a zero, displays the window, displays the next numbers. I will look into this. Cheers Michael Am Dienstag, den 19.08.2014, 16:26 +0200 schrieb Detlef Reichl: > #!/usr/bin/env ruby > > require 'gtk3' > > class Win < Gtk::Window > def initialize > super > button = Gtk::Button.new :label => 'click' > add button > button.signal_connect(:clicked) {p 'clicked'} > end > end > > th = Thread.new do > 0.upto(5) do |i| > p i > sleep 0.5 > end > end > th.join > > win = Win.new > win.show_all > Gtk.main |
From: Detlef R. <det...@gm...> - 2014-08-17 12:34:16
|
Hi, I don't know, whats your code look like, but I would do it in this way: Create a thread, that loads down the images. Every time, an image is completely loaded a flag is set by the loader. Then it waits, that the flag is unset. The display system has a Fifo, where it cycles over with a timeout. In this timeout the loader flag is tested. If it is set, the image is pushed into the Fifo and the flag is unset after this. Cheers, detlef Am 17.08.2014 00:13, schrieb Michael Below: > Hi, > > I am working on the web display issue again. > Now I would like to refresh the images. I.e.: > > - get a set of 50 images > - display the first set, meanwhile get another set of 50 images > - as soon as the second set is downloaded, and the first set has been > shown at least once, switch from displaying first set to displaying > second set > - repeat infinitely > > Thanks to your help, I have got the code to display the first set of > pictures in a loop like this: > > def auto_show(pixbufs) # auto mode > GLib::Timeout.add(600) do > @pixbufs.push(pixbufs.shift) > update_image(pixbufs.first) > true # continue > end > end > > I guess I could add a second Timeout that switches the picture sets > every 5 minutes or so. But is there a way to change the picture sets > after successfully loading the next one? > > I successfully moved the download process into a separate thread, but I > can't get the download to run again and again while displaying images > and updating the buffer. > > Cheers > Michael > > > Am Montag, den 26.05.2014, 08:46 +0200 schrieb Michael Below: >> Hi, >> >> Am Montag, den 26.05.2014, 12:30 +0900 schrieb Masafumi Yokoyama: >> >>> A GTK window is just shown when `Gtk.main` is called. >>> `show_all` sets flag to be displayed to all widgets, but doesn't >>> actually display until `Gtk.main` is called. >> >> Ah, I understand... I even tried to move Gtk.main into my #each loop, >> but this way it makes sense. >> >>> It seems that need to design such as the following: >> >> Thanks, works fine. >> >> Cheers >> >> Michael > > > > ------------------------------------------------------------------------------ > _______________________________________________ > ruby-gnome2-devel-en mailing list > rub...@li... > https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en > |