Professional Web Applications Themes

TkPhotoImage :data=>buf - Ruby

does anyone know if this is simply a limitation of the gif formatted images? irb(main):001:0> TkPhotoImage.new :file=>'images/Back.gif' => #<TkPhotoImage:0xb73290ec type="photo", path="i00006"> irb(main):002:0> (data=IO.read 'images/Back.gif').size => 985 irb(main):003:0> TkPhotoImage.new :data=>data RuntimeError: couldn't recognize image data from /dmsp/reference/lib/ruby/1.8/tk.rb:1623:in `__invoke' from /dmsp/reference/lib/ruby/1.8/tk.rb:1623:in `_invoke' from /dmsp/reference/lib/ruby/1.8/tk.rb:1027:in `tk_call' from /dmsp/reference/lib/ruby/1.8/tkcanvas.rb:883:in `initialize' from /dmsp/reference/lib/ruby/1.8/tkcanvas.rb:926:in `initialize' from (irb):11:in `new' from (irb):11 from :0 am i limited to bitmaps for this or should other types of images be able to be loaded this way? what i'm trying to do is something like .... back_img = TkPhotoImage.new :data=>back_gif BEGIN { back_gif = '2158asdfanajk350w9ae8asdf....' } .... in otherwords i want ...

  1. #1

    Default TkPhotoImage :data=>buf



    does anyone know if this is simply a limitation of the gif formatted images?

    irb(main):001:0> TkPhotoImage.new :file=>'images/Back.gif'
    => #<TkPhotoImage:0xb73290ec type="photo", path="i00006">

    irb(main):002:0> (data=IO.read 'images/Back.gif').size
    => 985

    irb(main):003:0> TkPhotoImage.new :data=>data
    RuntimeError: couldn't recognize image data
    from /dmsp/reference/lib/ruby/1.8/tk.rb:1623:in `__invoke'
    from /dmsp/reference/lib/ruby/1.8/tk.rb:1623:in `_invoke'
    from /dmsp/reference/lib/ruby/1.8/tk.rb:1027:in `tk_call'
    from /dmsp/reference/lib/ruby/1.8/tkcanvas.rb:883:in `initialize'
    from /dmsp/reference/lib/ruby/1.8/tkcanvas.rb:926:in `initialize'
    from (irb):11:in `new'
    from (irb):11
    from :0

    am i limited to bitmaps for this or should other types of images be able to be
    loaded this way?

    what i'm trying to do is something like

    ....

    back_img = TkPhotoImage.new :data=>back_gif

    BEGIN {
    back_gif = '2158asdfanajk350w9ae8asdf....'
    }

    ....

    in otherwords i want to inline all my icon images in the script. i can do this
    by inlining them, writing out a tempfile, and using that tempfile - but would
    like to avoid the extra step...

    any suggestions welcome - i'm terrible with tk and have two days to whip out
    this gui...

    -a
    --
    ================================================== =============================
    | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
    | PHONE :: 303.497.6469
    | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
    | URL :: http://www.ngdc.noaa.gov/stp/
    | TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done
    ================================================== =============================

    Ara.T.Howard Guest

  2. #2

    Default Re: TkPhotoImage :data=>buf

    Hi,

    From: "Ara.T.Howard" <gov>
    Subject: TkPhotoImage :data=>buf
    Date: Sun, 22 Feb 2004 02:44:51 +0900
    Message-ID: <ngdc.noaa.gov> 

    It's a bug. I understand the reason og the trouble.
    But it may be a little difficalt to fix.

    The bug depends on string interchange between Ruby and
    Tk interpreter. To avoid the trouble of the difference
    of encoding between the interpreters, current Ruby/Tk
    converts encoding of strings automatically. Usually it
    will be convenient for Ruby/Tk users. Therefore, when
    treats a binary string (especially, includes null bytes),
    the data is garbled.

    To fix the bug, I'll have to edit tcltklib.c and TkVariable
    class, and add a new class "Tk::BinaryString" which is a
    subclass of Tk::EncodedString class. A Tk::EncodedString
    instance is a string with encoding information. By creating
    a Tk::BinaryString instance (has a special encoding 'binary')
    for a binary string, Ruby/Tk recognizes that the string
    never be converted and never be terminated by a null byte.

    Although this strategy may trouble Ruby/Tk users, it will
    be an actual and reasonable solution. I think so. Probably
    I'll have to change the implementation of TkVariable class.
    My only worry is en-bugging by side effects.

    Please wait for a good news about this.
    It will not be far-off.
    --
    Hidetoshi NAGAI (kyutech.ac.jp)


    Hidetoshi Guest

  3. #3

    Default Re: TkPhotoImage :data=>buf

    On Tue, 24 Feb 2004, Hidetoshi NAGAI wrote:
     
    >
    > It's a bug. I understand the reason og the trouble. But it may be a little
    > difficalt to fix.
    >
    > The bug depends on string interchange between Ruby and Tk interpreter. To
    > avoid the trouble of the difference of encoding between the interpreters,
    > current Ruby/Tk converts encoding of strings automatically. Usually it will
    > be convenient for Ruby/Tk users. Therefore, when treats a binary string
    > (especially, includes null bytes), the data is garbled.
    >
    > To fix the bug, I'll have to edit tcltklib.c and TkVariable class, and add a
    > new class "Tk::BinaryString" which is a subclass of Tk::EncodedString class.
    > A Tk::EncodedString instance is a string with encoding information. By
    > creating a Tk::BinaryString instance (has a special encoding 'binary') for a
    > binary string, Ruby/Tk recognizes that the string never be converted and
    > never be terminated by a null byte.
    >
    > Although this strategy may trouble Ruby/Tk users, it will be an actual and
    > reasonable solution. I think so. Probably I'll have to change the
    > implementation of TkVariable class. My only worry is en-bugging by side
    > effects.
    >
    > Please wait for a good news about this. It will not be far-off.[/ref]

    thanks for the detailed reply!

    if you you introduced the Tk::BinaryString class, and only used it when
    ':buf=>data' was used - that shouldn't cause any bugs should it?

    thanks again.

    -a
    --
    ================================================== =============================
    | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
    | PHONE :: 303.497.6469
    | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328
    | URL :: http://www.ngdc.noaa.gov/stp/
    | TRY :: for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done
    ================================================== =============================

    Ara.T.Howard Guest

Similar Threads

  1. Linking data, searching data, and format the data file
    By CobraC081375 in forum Macromedia Flash Data Integration
    Replies: 5
    Last Post: January 5th, 09:54 PM
  2. submitting forms and collecting data via server data base or email
    By Tom_Michaels@adobeforums.com in forum Adobe Acrobat Windows
    Replies: 6
    Last Post: June 10th, 02:45 PM
  3. Replies: 8
    Last Post: January 13th, 10:18 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139