librelist archives

« back to archive

Something Simple

Something Simple

From:
Richard Powell
Date:
2011-11-30 @ 00:37
So I'm fairly new to all this, and have been trying to figure things out on
my own.
But this has failed me. I'm not asking any one to do things for me, I want
to learn,
so any help or tips would be greatly appreciated.

Ok, so, I'll get right to it. I've been trying forever to try and find out
how to do this, but maybe there is no easy way...
[And I've been on Google for like 3 days...]

<code>

##Test for the Shoes

Shoes.app :width => 450, :height => 300 do

con={'a'=>'y', 'b'=>'p', 'c'=>'l', 'd'=>'t', 'e'=>'a',
'f'=>'v', 'g'=>'k', 'h'=>'r', 'i'=>'e', 'j'=>'z', 'k'=>'g',
'l'=>'m', 'm'=>'s', 'n'=>'h', 'o'=>'u', 'p'=>'b', 'q'=>'x',
'r'=>'n', 's'=>'c', 't'=>'d', 'u'=>'i', 'v'=>'j', 'w'=>'f',
'x'=>'q', 'y'=>'o', 'z'=>'w', ' '=>' ',

'A'=>'Y', 'B'=>'P', 'C'=>'L', 'D'=>'T', 'E'=>'A', 'F'=>'V',
'G'=>'K', 'H'=>'R', 'I'=>'E', 'J'=>'Z', 'K'=>'G', 'L'=>'M',
'M'=>'S', 'N'=>'H', 'O'=>'U', 'P'=>'B', 'Q'=>'X', 'R'=>'N',
'S'=>'C', 'T'=>'D', 'U'=>'I', 'V'=>'J', 'W'=>'F', 'X'=>'Q',
'Y'=>'O', 'Z'=>'W',

'1'=>'1', '2'=>'2', '3'=>'3', '4'=>'4', '5'=>'5', '6'=>'6',
'7'=>'7', '8'=>'8', '9'=>'9', '0'=>'0',

'!'=>'!', '@'=>'@', '#'=>'#', '$'=>'$', '%'=>'%', '^'=>'^',
'&'=>'&', '*'=>'*', '('=>'(', ')'=>')', '-'=>'-', '_'=>'_',
'='=>'=', '+'=>'+', '['=>'[', "]"=>"]", '{'=>'{', '}'=>'}', ';'=>';',
':'=>':',

"'"=>"'", '"'=>'"', ','=>',', '<'=>'<', '.'=>'.', '>'=>'>', '/'=>'/',
'?'=>'?',

'|'=>'|', '`'=>'`', '~'=>'~', "\n"=>"\n"}


tagline "English to Albhed!"
 edit_box :width => 400 do |e|
  @alb.text = e.text
 end

stack {
   @alb = para(" ")
   para @alb, " "
}
end

</code>

Now, what that code does is just replicate text beneath the edit_box.
What I want it to do is pass the characters put into the edit_box through
the 'con' hash, as the key,
retrieve the value, and spit it out underneath the edit_box. Any Help?

Re: [shoes] Something Simple

From:
Cecil Coupe
Date:
2011-11-30 @ 03:21
Richard,

try using this snippet inside your program

tagline "English to Albhed!"
edit_box :width => 400 do |e|
  @alb.text +=  con[e.text[-1]]
end

The |e| is a string of everything in the edit_box and you want to lookup
the last character in that string [-1] and run that through the hash and
append it to the para.

Best wishes as you explore Shoes
--Cecil


On Tue, 2011-11-29 at 16:37 -0800, Richard Powell wrote:

Re: [shoes] Something Simple

From:
Richard Powell
Date:
2011-11-30 @ 04:12
Ah, See, that what I wanted to do, just didn't know how to do it.
I'm really new to programming, so I'm still trying to figure things out...

Now I know I have to call the -1
Thank you for the tip!

I Like Ruby, and Shoes, I think I'll stick around and learn some things!

On Tue, Nov 29, 2011 at 7:21 PM, Cecil Coupe <ccoupe@cableone.net> wrote:

> Richard,
>
> try using this snippet inside your program
>
> tagline "English to Albhed!"
> edit_box :width => 400 do |e|
>   @alb.text +=  con[e.text[-1]]
> end
>
> The |e| is a string of everything in the edit_box and you want to lookup
> the last character in that string [-1] and run that through the hash and
> append it to the para.
>
> Best wishes as you explore Shoes
> --Cecil
>
>
> On Tue, 2011-11-29 at 16:37 -0800, Richard Powell wrote:
>
>
>

Re: [shoes] Something Simple

From:
ashbb
Date:
2011-11-30 @ 12:36
Hi Cecil, Richard and folks,

Although this discussion is already way ahead of me.

You can edit any character in the edit_box.
So, it's not enough to lookup the last character. ;-)

If you want to translate an input key by each keypress, I think it's better
to use `keypress` method instead of `edit_box`.

 # sample snippet

 Shoes.app  do
   @line = para
   @line.cursor = -1
   con={'a'=>'y', ..........} # skipped

   keypress do |k|
     case k
       when String, "\n"
         @line.text += con[k]
       when :backspace
         @line.text = @line.text[0..-2]
       else
     end
   end
 end

ashbb

Re: [shoes] Something Simple

From:
Richard Powell
Date:
2011-11-30 @ 13:41
I like this method, however you cannot select text, or paste text from your
clipboard.
That is why I was using the edit_box, but this is what I was going for, as
far as updating text as you type.

Shoes.app  do
tagline "English <=> Albhed!\n", :align => "center"
 para("English:\n")
   @line = para
stack {
 para("Albhed:")
  @line2 = para
}
   @line.cursor = -1
  @line2.cursor = -1
alb={'a'=>'y', ...} #The hash

   keypress do |k|
     case k
       when String, "\n"
         @line.text += k
 @line2.text += alb[k]
       when :backspace
         @line.text = @line.text[0..-2]
 @line2.text = @line2.text[0..-2]
       else
     end
   end
 end

It works very well, for every key I press, the normal text is displayed,
and on another line the 'translated' text.
I did this, and this is so far closest to a command line example I made:

##English <=> Albhed Translator!
##Made with Ruby Shoes!

Dir.mkdir("logs") unless File.exists?("logs")

Shoes.app :width => 410, :height => 350 do

eng={'y'=>'a', ..."} # Alb2Eng

alb={'a'=>'y', ...} # Eng2Alb

tagline "English <=> Albhed!\n", :align => "center"

para("English:\n")
 @eng = edit_box :width => 400
 stack {
para("Albhed:")
  @alb = edit_box :width => 400
 }
 button "Convert" do
  if @eng.text.size > 0 && @alb.text.size > 0
   alert("Remember to Clear!")
  else
    @alb.text.each_line do |line|
    line.each_char do |a|
     @eng.text += eng[a]
    end
    end
    @alb.text = ""
     @eng.text.each_line do |line|
     line.each_char do |e|
      @alb.text += alb[e]
    end
   end
  end
end
 button "Clear" do
  @eng.text = @alb.text = ""
 end

 button "Save" do
  if @eng.text.size == 0
   alert("No Text in English Form! Cannot Save to Log!")
  else
   if @alb.text.size == 0
    alert("No Text in Albhed Form! Cannot Save to Log!")
   else
    if @alb.text.size == @eng.text.size
     time=Time.new

     f = File.new("logs/Eng2Alb_Trans.html", "a")
     f.syswrite("\n\n<center><h2>############### #{time.strftime("%m-%d-%Y
%H: %M:%S")} ###############</h2></center>\n")
     f.syswrite("<b>English:</b>\n")
     f.syswrite("<font color='Red'>")
     f.syswrite @eng.text
     f.syswrite("</font>\n")
     f.syswrite("<hr>\n")
     f.syswrite("<b>Albhed:</b>\n")
     f.syswrite("<font color='Blue'>")
     f.syswrite @alb.text
     f.syswrite("</font>")
     f.close
     alert("Text Saved to Translation Log!")
    else
     alert("Somethings not right...")
    end
   end
  end
 end
 button "Log" do
  system("start Eng2Alb.html")
 end
end

Problem is, it doesn't do line breaks,
So if I go

"This .....[enter]
... and then this!"
It will only do the first line, and that's it.
I tried to 'each_line do |line|' wrapped outside of 'line.each_char do |e|'
it doesn't spit out any errors at me, and will still 'translate' the first
line, but not the others...





On Wed, Nov 30, 2011 at 4:36 AM, ashbb <ashbbb@gmail.com> wrote:

> Hi Cecil, Richard and folks,
>
> Although this discussion is already way ahead of me.
>
> You can edit any character in the edit_box.
> So, it's not enough to lookup the last character. ;-)
>
> If you want to translate an input key by each keypress, I think it's
> better to use `keypress` method instead of `edit_box`.
>
>  # sample snippet
>
>  Shoes.app  do
>    @line = para
>    @line.cursor = -1
>    con={'a'=>'y', ..........} # skipped
>
>    keypress do |k|
>      case k
>        when String, "\n"
>          @line.text += con[k]
>        when :backspace
>          @line.text = @line.text[0..-2]
>        else
>      end
>    end
>  end
>
> ashbb
>
>

Re: [shoes] Something Simple

From:
ashbb
Date:
2011-12-01 @ 12:00
Hi Richard,

> it doesn't spit out any errors at me
Ah,... try to open the Shoes console window.
I guess you will get some error messages.

> I tried to 'each_line do |line|' wrapped outside of
> 'line.each_char do |e|', ...... ,
> and will still 'translate' the first line,
> but not the others...
Good idea! But seems to need a little bit more. ;-)
Try out the following:

   @eng.text.each_line do |line|
     line.each_char do |e|
       @alb.text += (alb[e] or e)
     end
   end

You'll translate all lines. ;-)

ashbb

Re: [shoes] Something Simple

From:
Richard Powell
Date:
2011-12-04 @ 18:25
I like this, because if it can't pass through the hash, it goes straight on
through.

I'm trying to work on one that handles multibyte characters, I can get A
= Ψ [a greek letter] but I can't get Ψ = A because it reads byte by byte
and not the single character. How would I begin to handle that?


On Thu, Dec 1, 2011 at 4:00 AM, ashbb <ashbbb@gmail.com> wrote:

> Hi Richard,
>
> > it doesn't spit out any errors at me
> Ah,... try to open the Shoes console window.
> I guess you will get some error messages.
>
> > I tried to 'each_line do |line|' wrapped outside of
> > 'line.each_char do |e|', ...... ,
> > and will still 'translate' the first line,
> > but not the others...
> Good idea! But seems to need a little bit more. ;-)
> Try out the following:
>
>    @eng.text.each_line do |line|
>      line.each_char do |e|
>        @alb.text += (alb[e] or e)
>      end
>    end
>
> You'll translate all lines. ;-)
>
> ashbb
>
>

Re: [shoes] Something Simple

From:
ashbb
Date:
2011-12-05 @ 12:14
Hi Richard,

> because it reads byte by tyte and not the single character.
Umm,...
In Ruby 1.9, each_char() method can handle a single character.
Shoes 3 includes Ruby 1.9.1. So, Shoes 3 should handle multibyte characters.

Try out the following snippet. But you may have to choose a right font for
your environment.

  Shoes.app do
   ed = edit_box
   button 'print' do
     ed.text.force_encoding('UTF-8').each_line do |line|
       line.each_char do |c|
         @slot.append{para c, font: 'MS UI Gothic'}
       end
     end
   end
   @slot = flow
  end

ashbb

Re: [shoes] Something Simple

From:
Richard Powell
Date:
2011-12-05 @ 19:37
Ah, needed to force encode, that is a much simpler fix!
Now I have a two way multibyte character 'translator'
More like a substitution cipher, but yeah.

# coding: UTF-8
##English <=> Leet Translator!
##Made with Ruby Shoes!

Dir.mkdir("logs") unless File.exists?("logs")

Shoes.app :title => "English <=> Aleet Translator", :width => 400, :height
=> 350, :resizable => false do

tagline "English <=> Aleet\n", :align => "center"

para("English:
  ")
 button "Clear" do
  @eng.text = ""
 end
 @eng = edit_box :width => 400


para("Aleet:
     ")
 button "Clear" do
  @let.text = ""
 end
 @let = edit_box :width => 400



let = {'a'=>'ψ', 'b'=>'π', 'c'=>'λ', 'd'=>'τ', 'e'=>'ά', 'f'=>'κ',
'g'=>'ρ', 'h'=>'ε', 'i'=>'ζ', 'j'=>'γ', 'k'=>'μ', 'l'=>'σ', 'm'=>'η',
'n'=>'υ', 'o'=>'β', 'p'=>'ξ', 'q'=>'ν', 'r'=>'χ', 's'=>'δ', 't'=>'ἰ',
'u'=>'µ', 'v'=>'φ', 'w'=>'θ', 'x'=>'q', 'y'=>'o', 'z'=>'ω', 'A'=>'Ψ',
'B'=>'Π', 'C'=>'Λ', 'D'=>'Τ', 'E'=>'A', 'F'=>'ς', 'G'=>'K', 'H'=>'P',
'I'=>'E', 'J'=>'Z', 'K'=>'Γ', 'L'=>'M', 'M'=>'Σ', 'N'=>'H', 'O'=>'Y',
'P'=>'B', 'Q'=>'Ξ', 'R'=>'N', 'S'=>'X', 'T'=>'Δ', 'U'=>'Ἱ', 'V'=>'Φ',
'W'=>'Θ', 'X'=>'Ж', 'Y'=>'O', 'Z'=>'Ω'}

eng = let.invert


 button "Convert" do
  if @eng.text.size > 0 && @let.text.size > 0
   alert("Remember to Clear!")
    else
     let_text, eng_text = @let.text.force_encoding('UTF-8'),
@eng.text.force_encoding('UTF-8')
     @eng.text = let_text.each_char.map{|c| eng[c] or c}.join if
eng_text.empty?
     @let.text = eng_text.each_char.map{|c| let[c] or c}.join if
let_text.empty?
    end
  end



 button "Save" do
  if @eng.text.size == 0
   alert("No Text in English Form! Cannot Save to Log!")
  else
   if @let.text.size == 0
    alert("No Text in Aleet Form! Cannot Save to Log!")
   else
     time=Time.new
     f = File.new("logs/Eng2Let_Trans.html", "a")
     f.syswrite("\n\n<center><h2>############### #{time.strftime("%m-%d-%Y
%H:%M:%S")} ###############</h2></center>\n")
     f.syswrite("<b>English:</b>\n")
     f.syswrite("<font color='Red'>")
     f.syswrite @eng.text
     f.syswrite("</font>\n")
     f.syswrite("<hr>\n")
     f.syswrite("<b>Aleet:</b>\n")
     f.syswrite("<font color='Blue'>")
     f.syswrite @let.text
     f.syswrite("</font>")
     f.close
     alert("Text Saved to Translation Log!")
   end
  end
 end
 button "Log" do
   system("start Eng2Let.html")
 end
 button "Purge Log" do
   File.delete("logs/Eng2Let_Trans.html")
   alert("Log Purged!")
 end
 button "Help" do
   alert("You can translate from English to Aleet, or vice-versa. Just type
the language in the appropriate box, and be sure the other box is empty, or
it will return an error. Hit Convert and Voila! The Clear buttons will
erase all contents from the appropriate box, the Save button will store
your English <=> Aleet translation in an HTML file, which can be viewed by
pressing the Log Button. The Purge Log button will delete all of your logs
entirely, start out fresh!")
  end
end

Rake Tutorial?

From:
Wayne Brissette
Date:
2011-12-01 @ 12:01
I would like to make a standalone application using shoes. Currently I 
have my script which works, a modified version that works with the shoes 
application, but I want to make it so that folks using Windows (I'm on Mac
OS X) can use it as a standalone application. From an earlier thread folks
here mentioned I needed to use rake to do that since the packager has some
issues. Is there a tutorial on how to use rake to build standalone shoes 
apps? 

Wayne

Re: [shoes] Rake Tutorial?

From:
Steve Klabnik
Date:
2011-12-01 @ 16:50
There isn't. This is on my to-do list. I don't even know all the
details of how it works.

What I _do_ know is that you need a app.yml file in your main
directory, and that you can type 'rake APP=path/to/the/app && rake
installer APP=path/to/the/app' to make it build. This is what I do for
Hackety. You can see the app.yaml here:
https://github.com/hacketyhack/hacketyhack/blob/master/app.yaml

sort_by! fails in Windows

From:
Wayne Brissette
Date:
2011-12-01 @ 13:12
I have the following statement in my ruby script: 

ball_map.sort_by!

When I run the script with the shoes GUI wrapped around it, I get an error
in Windows (somebody about method not defined or something like that). 
When I run the same script in Mac OS X, it works. If I run the script 
minus shoes in Windows it also works as expected. Anybody heard of this? 
Why would it work in Mac OS X, but not Windows (both XP and 7)? Very odd. 

Wayne

Re: [shoes] sort_by! fails in Windows

From:
ashbb
Date:
2011-12-01 @ 13:30
Hi Wayne,

Umm,... strange.
Could you show us the code?
I'd like to run that on my Windows 7.

ashbb

Re: [shoes] sort_by! fails in Windows

From:
ashbb
Date:
2011-12-01 @ 13:55
Oops, I forgot that sort_by! method is supported since ruby 1.9.2.
But Shoes 3 (0.r1514) for Windows includes ruby 1.9.1.

ashbb

Re: [shoes] sort_by! fails in Windows

From:
Wayne Brisette
Date:
2011-12-01 @ 14:11
Well, then that might be the issue! ;) 

is sort_by available in 1.9.1 ? 

Wayne



________________________________
From: ashbb <ashbbb@gmail.com>
To: shoes@librelist.com
Sent: Thu, December 1, 2011 7:55:37 AM
Subject: Re: [shoes] sort_by! fails in Windows

Oops, I forgot that sort_by! method is supported since ruby 1.9.2.
But Shoes 3 (0.r1514) for Windows includes ruby 1.9.1.

ashbb

Re: [shoes] sort_by! fails in Windows

From:
ashbb
Date:
2011-12-01 @ 14:18
> is sort_by available in 1.9.1 ?
Yes!
So, try out the following (replace line 148 in parse_cvs.rb).

ball_map = ball_map.sort_by { |a| [a.pin_alpha.size, a.pin_alpha,
a.pin_number.to_i] }

ashbb

Re: [shoes] sort_by! fails in Windows

From:
Date:
2011-12-02 @ 09:17
Had a similar issue, was the encoding of the contents of the array, try 
enforcing encoding UTF16

Daddie888
-----Oorspronkelijk bericht-----
Van: shoes@librelist.com [mailto:shoes@librelist.com] Namens Wayne Brissette
Verzonden: donderdag 1 december 2011 14:12
Aan: shoes@librelist.com
Onderwerp: [shoes] sort_by! fails in Windows

I have the following statement in my ruby script: 

ball_map.sort_by!

When I run the script with the shoes GUI wrapped around it, I get an error
in Windows (somebody about method not defined or something like that). 
When I run the same script in Mac OS X, it works. If I run the script 
minus shoes in Windows it also works as expected. Anybody heard of this? 
Why would it work in Mac OS X, but not Windows (both XP and 7)? Very odd. 

Wayne

Re: [shoes] Something Simple

From:
Cecil Coupe
Date:
2011-11-30 @ 04:21
The fun thing about Shoes and Ruby are the multiple ways to do things.

My first rewrite doesn't handle the delete key and handling that is a
bit of a pain so I might rewrite it this way.

tagline "English to Albhed!"
 @eng = edit_box :width => 400
 button "Convert" do
  @alb.text = ""
  @eng.text.each_char do |c|
    @alb.text += con[c]
  end
 end
 button "Clear" do
  @eng.text = @alb.text = ""
 end
 @alb = edit_box :width => 400
end

This is kind of fun.


On Tue, 2011-11-29 at 16:37 -0800, Richard Powell wrote:

Re: [shoes] Something Simple

From:
Steve Klabnik
Date:
2011-11-30 @ 04:46
In general, Shoes is its own kind of thing. Rewards lots of
interesting kinds of coding. :)

Re: [shoes] Something Simple

From:
Richard Powell
Date:
2011-11-30 @ 07:33
Yeah, I was wondering how to deal with that, since it seemed to just go
back over the already submitted keys...
But I like that! I got it to Translate both ways.:

<code>
##Test for the Shoes

Shoes.app :width => 450, :height => 350 do

eng={'y'=>'a', 'p'=>'b', 'l'=>'c', 't'=>'d', 'a'=>'e',
'v'=>'f', 'k'=>'g', 'r'=>'h', 'e'=>'i', 'z'=>'j', 'g'=>'k',
'm'=>'l', 's'=>'m', 'h'=>'n', 'u'=>'o', 'b'=>'p', 'x'=>'q',
'n'=>'r', 'c'=>'s', 'd'=>'t', 'i'=>'u', 'j'=>'v', 'f'=>'w',
'q'=>'x', 'o'=>'y', 'w'=>'z', ' '=>' ',

'Y'=>'A', 'P'=>'B', 'L'=>'C', 'T'=>'D', 'A'=>'E', 'V'=>'F',
'K'=>'G', 'R'=>'H', 'E'=>'I', 'Z'=>'J', 'G'=>'K', 'M'=>'L',
'S'=>'M', 'H'=>'N', 'U'=>'O', 'B'=>'P', 'X'=>'Q', 'N'=>'R',
'C'=>'S', 'D'=>'T', 'I'=>'U', 'J'=>'V', 'F'=>'W', 'Q'=>'X',
'O'=>'Y', 'W'=>'Z',

'1'=>'1', '2'=>'2', '3'=>'3', '4'=>'4', '5'=>'5', '6'=>'6',
'7'=>'7', '8'=>'8', '9'=>'9', '0'=>'0',

'!'=>'!', '@'=>'@', '#'=>'#', '$'=>'$', '%'=>'%', '^'=>'^',
'&'=>'&', '*'=>'*', '('=>'(', ')'=>')', '-'=>'-', '_'=>'_',
'='=>'=', '+'=>'+', '['=>'[', "]"=>"]", '{'=>'{', '}'=>'}',
';'=>';', ':'=>':', "'"=>"'", '"'=>'"', ','=>',', '<'=>'<',
'.'=>'.', '>'=>'>', '/'=>'/', '?'=>'?', '|'=>'|', '`'=>'`',
'~'=>'~', "\n"=>"\n", "\b"=>"\b"}

alb={'a'=>'y', 'b'=>'p', 'c'=>'l', 'd'=>'t', 'e'=>'a',
'f'=>'v', 'g'=>'k', 'h'=>'r', 'i'=>'e', 'j'=>'z', 'k'=>'g',
'l'=>'m', 'm'=>'s', 'n'=>'h', 'o'=>'u', 'p'=>'b', 'q'=>'x',
'r'=>'n', 's'=>'c', 't'=>'d', 'u'=>'i', 'v'=>'j', 'w'=>'f',
'x'=>'q', 'y'=>'o', 'z'=>'w', ' '=>' ',

'A'=>'Y', 'B'=>'P', 'C'=>'L', 'D'=>'T', 'E'=>'A', 'F'=>'V',
'G'=>'K', 'H'=>'R', 'I'=>'E', 'J'=>'Z', 'K'=>'G', 'L'=>'M',
'M'=>'S', 'N'=>'H', 'O'=>'U', 'P'=>'B', 'Q'=>'X', 'R'=>'N',
'S'=>'C', 'T'=>'D', 'U'=>'I', 'V'=>'J', 'W'=>'F', 'X'=>'Q',
'Y'=>'O', 'Z'=>'W',

'1'=>'1', '2'=>'2', '3'=>'3', '4'=>'4', '5'=>'5', '6'=>'6',
'7'=>'7', '8'=>'8', '9'=>'9', '0'=>'0',

'!'=>'!', '@'=>'@', '#'=>'#', '$'=>'$', '%'=>'%', '^'=>'^',
'&'=>'&', '*'=>'*', '('=>'(', ')'=>')', '-'=>'-', '_'=>'_',
'='=>'=', '+'=>'+', '['=>'[', "]"=>"]", '{'=>'{', '}'=>'}',
';'=>';', ':'=>':', "'"=>"'", '"'=>'"', ','=>',', '<'=>'<',
'.'=>'.', '>'=>'>', '/'=>'/', '?'=>'?', '|'=>'|', '`'=>'`',
'~'=>'~', "\n"=>"\n", "\b"=>"\b"}

tagline "English to Albhed!"
 @eng = edit_box :width => 400
 button "Convert" do
 @alb.text.each_char do |e|
   @eng.text += eng[e]
 end
 @alb.text = ""
 @eng.text.each_char do |c|
   @alb.text += alb[c]
 end
 end
 button "Clear" do
 @eng.text = @alb.text = ""
 end
 @alb = edit_box :width => 400
end
</code>

Now it will Convert back and forth each time you press convert.
Now I want to make something like:
if @eng & @alb are not NULL, do not Convert anything.

On Tue, Nov 29, 2011 at 8:21 PM, Cecil Coupe <ccoupe@cableone.net> wrote:

> The fun thing about Shoes and Ruby are the multiple ways to do things.
>
> My first rewrite doesn't handle the delete key and handling that is a
> bit of a pain so I might rewrite it this way.
>
> tagline "English to Albhed!"
>  @eng = edit_box :width => 400
>  button "Convert" do
>  @alb.text = ""
>  @eng.text.each_char do |c|
>    @alb.text += con[c]
>  end
>  end
>  button "Clear" do
>  @eng.text = @alb.text = ""
>  end
>  @alb = edit_box :width => 400
> end
>
> This is kind of fun.
>
>
> On Tue, 2011-11-29 at 16:37 -0800, Richard Powell wrote:
>
>
>

Re: [shoes] Something Simple

From:
ashbb
Date:
2011-11-30 @ 13:19
Hi Richard,

> Now it will Convert back and forth each time you press convert.
Cool! Thank you for sharing the code.

> Now I want to make something like:
> if @eng & @alb are not NULL, do not Convert anything.
Aha, interesting! Let me refactoring the code.

How about this one. ;-)

  Shoes.app :width => 450, :height => 350 do
    eng = {'y'=>'a', .........} # skipped
    alb = eng.invert
    tagline "English to Albhed!"
    @eng = edit_box :width => 400
    button "Convert" do
      alb_text, eng_text = @alb.text, @eng.text
      @eng.text = alb_text.each_char.map{|c| eng[c] or c}.join if
eng_text.empty?
      @alb.text = eng_text.each_char.map{|c| alb[c] or c}.join  if
alb_text.empty?
    end
    button "Clear" do
      @eng.text = @alb.text = ""
    end
    @alb = edit_box :width => 400
  end

Cheers,
ashbb

Re: [shoes] Something Simple

From:
Cecil Coupe
Date:
2011-11-30 @ 08:26
On Tue, 2011-11-29 at 23:33 -0800, Richard Powell wrote:
> Now it will Convert back and forth each time you press convert.
> Now I want to make something like: if @eng & @alb are not NULL, do not
> Convert anything. 
> 

For newbies to Ruby, I recommend "Programming Ruby, The Pragmatic
Programmer's Guide" by Dave Thomas (et all)  It's in print (and open on
my desk often) and it's also free online.  For me, it's easier to use
than Google when I don't know that much but I think I know where to find
it. I wish Python had such an accessible intro in print.