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 > |