librelist archives

« back to archive

Writing text files

Writing text files

From:
Luka Povreslo
Date:
2014-09-21 @ 19:04
I'm not sure is it ruby or shoes issue or am I doing something wrong,
here's my code:

Shoes.app do

@e = edit_box

button "Save" do

     File.open('somefile.txt', 'w') do |f|
       f.write @e.text
      end
end

button "Open" do
 @s.clear do
   @file = File.read('somefile.txt')
   para @file
 end

@e,text @file
end

@s =  stack :width => 1.0, :height => 0.7


end

Every time after I save the same or append some new text to a file, it just
gets wider, I mean if there was some text and then one line empty and then
some text again, there will be added more empty lines between those two
parts of the text when I save it so it becomes unreadable after few saves.
Anyone knows what am I doing wrong, maybe type of a file?

Re: [shoes] Writing text files

From:
Tobias Pfeiffer
Date:
2014-09-22 @ 10:17
Hi there,

you seem to create a new paragraph with the file content every time you 
open the file.

Might that be what you mean? Otherwise I'd need an scrrenshot or something
to determine what's wrong :-)

Tobi
On 09/21/2014 09:04 PM, Luka Povreslo wrote:
> I'm not sure is it ruby or shoes issue or am I doing something wrong,
> here's my code:
>
> Shoes.app do
>
> @e = edit_box
>
> button "Save" do
>
>      File.open('somefile.txt', 'w') do |f|
>        f.write @e.text
>       end
> end
>
> button "Open" do
>  @s.clear do
>    @file = File.read('somefile.txt')
>    para @file
>  end
>
> @e,text @file
> end
>
> @s =  stack :width => 1.0, :height => 0.7
>
>
> end
>
> Every time after I save the same or append some new text to a file, it
> just gets wider, I mean if there wa s some t ext and then one line empty
> and then some text again, there will be added more empty lines between
> those two parts of the text when I save it so it becomes unreadable
> after few saves. Anyone knows what am I doing wrong, maybe type of a file?

-- 
www.pragtob.info

Re: [shoes] Writing text files

From:
Luka Povreslo
Date:
2014-09-22 @ 17:00
2014-09-22 12:17 GMT+02:00 Tobias Pfeiffer <
tobias.pfeiffer@student.hpi.uni-potsdam.de>:

> Hi there,
>
> you seem to create a new paragraph with the file content every time you
> open the file.
>
> Might that be what you mean? Otherwise I'd need an scrrenshot or something
> to determine what's wrong :-)
>
> Tobi
> On 09/21/2014 09:04 PM, Luka Povreslo wrote:
> > I'm not sure is it ruby or shoes issue or am I doing something wrong,
> > here's my code:
> >
> > Shoes.app do
> >
> > @e = edit_box
> >
> > button "Save" do
> >
> >      File.open('somefile.txt', 'w') do |f|
> >        f.write @e.text
> >       end
> > end
> >
> > button "Open" do
> >  @s.clear do
> >    @file = File.read('somefile.txt')
> >    para @file
> >  end
> >
> > @e,text @file
> > end
> >
> > @s =  stack :width => 1.0, :height => 0.7
> >
> >
> > end
> >
> > Every time after I save the same or append some new text to a file, it
> > just gets wider, I mean if there wa s some t ext and then one line empty
> > and then some text again, there will be added more empty lines between
> > those two parts of the text when I save it so it becomes unreadable
> > after few saves. Anyone knows what am I doing wrong, maybe type of a
> file?
>
> --
> www.pragtob.info
>
>
Tobias, please check it on my blog where I've uploaded screenshots of an
app http://powerii.blog.hr/ . I don't think that could be a problem because
it's not just in my app that text gets wider, when I open a text file in my
editor it shows me the same thing. Problem is when I save the file, I can
click the button to open it countless times and the text will be ok, but
when I save it, problem starts.

Re: [shoes] Writing text files

From:
Carlos R. Tirado
Date:
2014-09-22 @ 17:47
Hi, from the screenshots (on your blog) it looks like you're in Windows,
and it occurs to me your issue could be related to writing CRLF as
line-endings to the file. I ran your sample code locally, on a Mac, and do
not have an issue (after fixing a small bug), no extra lines. On
non-Windows normally the line ending is only LF ("\n" vs. "\r\n").

Have you tried opening your file for writing using 'wb' instead of just
'w'? and see if it helps?

BTW, the small fix was changing
- @e,text @file
+ @e.text = @file

in the button "Open" block


On Mon, Sep 22, 2014 at 10:00 AM, Luka Povreslo <josomafijoso@gmail.com>
wrote:

>
>
> 2014-09-22 12:17 GMT+02:00 Tobias Pfeiffer <
> tobias.pfeiffer@student.hpi.uni-potsdam.de>:
>
>> Hi there,
>>
>> you seem to create a new paragraph with the file content every time you
>> open the file.
>>
>> Might that be what you mean? Otherwise I'd need an scrrenshot or
>> something to determine what's wrong :-)
>>
>> Tobi
>> On 09/21/2014 09:04 PM, Luka Povreslo wrote:
>> > I'm not sure is it ruby or shoes issue or am I doing something wrong,
>> > here's my code:
>> >
>> > Shoes.app do
>> >
>> > @e = edit_box
>> >
>> > button "Save" do
>> >
>> >      File.open('somefile.txt', 'w') do |f|
>> >        f.write @e.text
>> >       end
>> > end
>> >
>> > button "Open" do
>> >  @s.clear do
>> >    @file = File.read('somefile.txt')
>> >    para @file
>> >  end
>> >
>> > @e,text @file
>> > end
>> >
>> > @s =  stack :width => 1.0, :height => 0.7
>> >
>> >
>> > end
>> >
>> > Every time after I save the same or append some new text to a file, it
>> > just gets wider, I mean if there wa s some t ext and then one line empty
>> > and then some text again, there will be added more empty lines between
>> > those two parts of the text when I save it so it becomes unreadable
>> > after few saves. Anyone knows what am I doing wrong, maybe type of a
>> file?
>>
>> --
>> www.pragtob.info
>>
>>
> Tobias, please check it on my blog where I've uploaded screenshots of an
> app http://powerii.blog.hr/ . I don't think that could be a problem
> because it's not just in my app that text gets wider, when I open a text
> file in my editor it shows me the same thing. Problem is when I save the
> file, I can click the button to open it countless times and the text will
> be ok, but when I save it, problem starts.
>

Re: [shoes] Writing text files

From:
Luka Povreslo
Date:
2014-09-22 @ 18:20
Carlos, thank you(yes, I'm using win 8.1), you really saved me, looks like
this issue was related with opening file with argument 'w' which I was
using, 'wb' does the thing! :)

2014-09-22 19:47 GMT+02:00 Carlos R. Tirado <tremendo@gmail.com>:

> Hi, from the screenshots (on your blog) it looks like you're in Windows,
> and it occurs to me your issue could be related to writing CRLF as
> line-endings to the file. I ran your sample code locally, on a Mac, and do
> not have an issue (after fixing a small bug), no extra lines. On
> non-Windows normally the line ending is only LF ("\n" vs. "\r\n").
>
> Have you tried opening your file for writing using 'wb' instead of just
> 'w'? and see if it helps?
>
> BTW, the small fix was changing
> - @e,text @file
> + @e.text = @file
>
> in the button "Open" block
>
>
> On Mon, Sep 22, 2014 at 10:00 AM, Luka Povreslo <josomafijoso@gmail.com>
> wrote:
>
>
>
> 2014-09-22 12:17 GMT+02:00 Tobias Pfeiffer <
> tobias.pfeiffer@student.hpi.uni-potsdam.de>:
>
>> Hi there,
>>
>> you seem to create a new paragraph with the file content every time you
>> open the file.
>>
>> Might that be what you mean? Otherwise I'd need an scrrenshot or
>> something to determine what's wrong :-)
>>
>> Tobi
>> On 09/21/2014 09:04 PM, Luka Povreslo wrote:
>> > I'm not sure is it ruby or shoes issue or am I doing something wrong,
>> > here's my code:
>> >
>> > Shoes.app do
>> >
>> > @e = edit_box
>> >
>> > button "Save" do
>> >
>> >      File.open('somefile.txt', 'w') do |f|
>> >        f.write @e.text
>> >       end
>> > end
>> >
>> > button "Open" do
>> >  @s.clear do
>> >    @file = File.read('somefile.txt')
>> >    para @file
>> >  end
>> >
>> > @e,text @file
>> > end
>> >
>> > @s =  stack :width => 1.0, :height => 0.7
>> >
>> >
>> > end
>> >
>> > Every time after I save the same or append some new text to a file, it
>> > just gets wider, I mean if there wa s some t ext and then one line empty
>> > and then some text again, there will be added more empty lines between
>> > those two parts of the text when I save it so it becomes unreadable
>> > after few saves. Anyone knows what am I doing wrong, maybe type of a
>> file?
>>
>> --
>> www.pragtob.info
>>
>>
> Tobias, please check it on my blog where I've uploaded screenshots of an
> app http://powerii.blog.hr/ . I don't think that could be a problem
> because it's not just in my app that text gets wider, when I open a text
> file in my editor it shows me the same thing. Problem is when I save the
> file, I can click the button to open it countless times and the text will
> be ok, but when I save it, problem starts.
>
>
>

Re: [shoes] Writing text files

From:
Sebastjan Hribar
Date:
2014-09-22 @ 18:21
Hi,

I've tested it on LMDE with green shoes and with the same change as 
Carlos, plus I've changed the mode to 'a+'. And I've had to add the 
do/end to the @s stack.

With that, everything works as it should. No extra lines. Everything 
gets appended to the file sequentially and read back the same.

regards,
seba


On 22. 09. 2014 19:47, Carlos R. Tirado wrote:
> Hi, from the screenshots (on your blog) it looks like you're in 
> Windows, and it occurs to me your issue could be related to writing 
> CRLF as line-endings to the file. I ran your sample code locally, on a 
> Mac, and do not have an issue (after fixing a small bug), no extra 
> lines. On non-Windows normally the line ending is only LF ("\n" vs. 
> "\r\n").
>
> Have you tried opening your file for writing using 'wb' instead of 
> just 'w'? and see if it helps?
>
> BTW, the small fix was changing
> - @e,text @file
> + @e.text = @file
>
> in the button "Open" block
>
>
> On Mon, Sep 22, 2014 at 10:00 AM, Luka Povreslo 
> <josomafijoso@gmail.com <mailto:josomafijoso@gmail.com>> wrote:
>
>
>
>     2014-09-22 12:17 GMT+02:00 Tobias Pfeiffer
>     <tobias.pfeiffer@student.hpi.uni-potsdam.de
>     <mailto:tobias.pfeiffer@student.hpi.uni-potsdam.de>>:
>
>         Hi there,
>
>         you seem to create a new paragraph with the file content every
>         time you open the file.
>
>         Might that be what you mean? Otherwise I'd need an scrrenshot
>         or something to determine what's wrong :-)
>
>         Tobi
>         On 09/21/2014 09:04 PM, Luka Povreslo wrote:
>         > I'm not sure is it ruby or shoes issue or am I doing
>         something wrong,
>         > here's my code:
>         >
>         > Shoes.app do
>         >
>         > @e = edit_box
>         >
>         > button "Save" do
>         >
>         >      File.open('somefile.txt', 'w') do |f|
>         >        f.write @e.text
>         >       end
>         > end
>         >
>         > button "Open" do
>         >  @s.clear do
>         >    @file = File.read('somefile.txt')
>         >    para @file
>         >  end
>         >
>         > @e,text @file
>         > end
>         >
>         > @s =  stack :width => 1.0, :height => 0.7
>         >
>         >
>         > end
>         >
>         > Every time after I save the same or append some new text to
>         a file, it
>         > just gets wider, I mean if there wa s some t ext and then
>         one line empty
>         > and then some text again, there will be added more empty
>         lines between
>         > those two parts of the text when I save it so it becomes
>         unreadable
>         > after few saves. Anyone knows what am I doing wrong, maybe
>         type of a file?
>
>         --
>         www.pragtob.info <http://www.pragtob.info>
>
>
>     Tobias, please check it on my blog where I've uploaded screenshots
>     of an app http://powerii.blog.hr/ . I don't think that could be a
>     problem because it's not just in my app that text gets wider, when
>     I open a text file in my editor it shows me the same thing.
>     Problem is when I save the file, I can click the button to open it
>     countless times and the text will be ok, but when I save it,
>     problem starts.
>
>