librelist archives

« back to archive

From:
Sebastjan Hribar
Date:
2012-10-21 @ 19:47
Hi,

I need help yet again. I was challenged by a colleague of mine to make a
flashcard application for learning foreign vocabulary since I was all
enthusiastic about Ruby and Shoes:)....so I'm making one....

So far i have most of the code down and the basic GUI as well. I have 2
questions:

1. Why don't the elements in the code below flow in the flow? Also, how
can I have the edit line title and the input field in the same row:
Name: [          ]
2. When saving the object via YAML:Store I get all the data on the
edit_line properties written in the database:

---
? &82915810 !ruby/object:Shoes::EditLine
  initials: &82915870
    :left: 0
    :top: 0
    :width: 200
    :height: 28
    :angle: 0
    :curve: 0
  left: 5
  top: 263
  width: 200
  height: 28
  angle: 0
  curve: 0
  real: !ruby/object:Gtk::Entry {}
  app: &82914430 !ruby/object:Shoes::App
    width: 800
    height: 900
    margin: 10
.
.
.
It goes on and on and on...


When I run the code in gedit I get:

---
avto: !ruby/object:Flashcard
  name: avto
  source: avto
  target: car
  part_of_speech: noun
  definition: vehicle
  example: I drive a car.

---------------------------------------------------------
code:

require 'green_shoes'
require_relative "card.rb"
require "yaml/store"

Shoes.app width: 800, height: 900, margin: 10,
        title: "FLashcards learning v.01" do

  stack width: 800, height: 600 do
      stack width: 800, height: 200, margin: 10 do
        border black, strokewidth: 2
        para "This is a flashcard application for learning a foreign"
        para "language. The first section is intended for you to create"
        para "flashcards of your choice. In the second section you use"
        para "the created flashcards to learn the vocabulary."
      end

      stack width: 800, height: 200 do
        border black, strokewidth: 2
          flow width: 800, height: 200, margin: 5 do
            border red, strokewidth: 1
            para "Enter flashcard's details:"
            para "Name:"; @name = edit_line
            para "Source:"; @source = edit_line
            para "Target:"; @target = edit_line
            para "Part of speech:"; @part_of_speech = edit_line
            para "Definition:"; @definition = edit_line
            para "Example:"; @example = edit_line

            button "Save flashcard to database." do
                card = Flashcard.new(@name, @source, @target,
                                  @part_of_speech, @definition,
@example)
                db = YAML::Store.new("database.store")

                db.transaction do
                db[card.name] = card
                end
            end
          end
      end

      stack width: 800, height: 500, margin: 10 do
        border black, strokewidth: 2
      end
  end
end
-------------------------------------------------

Thank you and kind regards.
seba

Re: [shoes]

From:
Cecil Coupe
Date:
2012-10-21 @ 20:40
Hi,

   you don't want to store the edit_line, a graphical widget, you want 
to store the text inside the edit_line so

   card = Flashcard.new (@name.text, @source.text....)

--Cecil

On 10/21/2012 01:47 PM, Sebastjan Hribar wrote:
>                 card = Flashcard.new(@name, @source, @target,
>                                    @part_of_speech, @definition,
> @example)

Re:

From:
Sebastjan Hribar
Date:
2012-10-21 @ 20:34
I've just added the content of the third stack:

      stack width: 800, height: 500, margin: 10 do
        border black, strokewidth: 2

        @db.transaction(true) do
           @all_cards = @db.roots
        end

        para "Choose a flashcard:"
        list_box items = @all_cards
      end

But now I get the error about the transaction method:

flash_app.rb:44:in `block (3 levels) in <main>': undefined method
`transaction' for nil:NilClass (NoMethodError)

As if the transaction method can't handle the instance variables:(



Dne 21.10.2012 (ned) ob 21:47 +0200 je Sebastjan Hribar napisal(a):
> Hi,
> 
> I need help yet again. I was challenged by a colleague of mine to make a
> flashcard application for learning foreign vocabulary since I was all
> enthusiastic about Ruby and Shoes:)....so I'm making one....
> 
> So far i have most of the code down and the basic GUI as well. I have 2
> questions:
> 
> 1. Why don't the elements in the code below flow in the flow? Also, how
> can I have the edit line title and the input field in the same row:
> Name: [          ]
> 2. When saving the object via YAML:Store I get all the data on the
> edit_line properties written in the database:
> 
> ---
> ? &82915810 !ruby/object:Shoes::EditLine
>   initials: &82915870
>     :left: 0
>     :top: 0
>     :width: 200
>     :height: 28
>     :angle: 0
>     :curve: 0
>   left: 5
>   top: 263
>   width: 200
>   height: 28
>   angle: 0
>   curve: 0
>   real: !ruby/object:Gtk::Entry {}
>   app: &82914430 !ruby/object:Shoes::App
>     width: 800
>     height: 900
>     margin: 10
> .
> .
> .
> It goes on and on and on...
> 
> 
> When I run the code in gedit I get:
> 
> ---
> avto: !ruby/object:Flashcard
>   name: avto
>   source: avto
>   target: car
>   part_of_speech: noun
>   definition: vehicle
>   example: I drive a car.
> 
> ---------------------------------------------------------
> code:
> 
> require 'green_shoes'
> require_relative "card.rb"
> require "yaml/store"
> 
> Shoes.app width: 800, height: 900, margin: 10,
>         title: "FLashcards learning v.01" do
> 
>   stack width: 800, height: 600 do
>       stack width: 800, height: 200, margin: 10 do
>         border black, strokewidth: 2
>         para "This is a flashcard application for learning a foreign"
>         para "language. The first section is intended for you to create"
>         para "flashcards of your choice. In the second section you use"
>         para "the created flashcards to learn the vocabulary."
>       end
> 
>       stack width: 800, height: 200 do
>         border black, strokewidth: 2
>           flow width: 800, height: 200, margin: 5 do
>             border red, strokewidth: 1
>             para "Enter flashcard's details:"
>             para "Name:"; @name = edit_line
>             para "Source:"; @source = edit_line
>             para "Target:"; @target = edit_line
>             para "Part of speech:"; @part_of_speech = edit_line
>             para "Definition:"; @definition = edit_line
>             para "Example:"; @example = edit_line
> 
>             button "Save flashcard to database." do
>                 card = Flashcard.new(@name, @source, @target,
>                                   @part_of_speech, @definition,
> @example)
>                 db = YAML::Store.new("database.store")
> 
>                 db.transaction do
>                 db[card.name] = card
>                 end
>             end
>           end
>       end
> 
>       stack width: 800, height: 500, margin: 10 do
>         border black, strokewidth: 2
>       end
>   end
> end
> -------------------------------------------------
> 
> Thank you and kind regards.
> seba

Re:

From:
Sebastjan Hribar
Date:
2012-10-22 @ 05:15
I solved this by placing 

@db = YAML::Store.new("database.store")

in the last stack as well. Is there any better or more correct way to do
it?



Dne 21.10.2012 (ned) ob 22:34 +0200 je Sebastjan Hribar napisal(a):
> I've just added the content of the third stack:
> 
>       stack width: 800, height: 500, margin: 10 do
>         border black, strokewidth: 2
> 
>         @db.transaction(true) do
>            @all_cards = @db.roots
>         end
> 
>         para "Choose a flashcard:"
>         list_box items = @all_cards
>       end
> 
> But now I get the error about the transaction method:
> 
> flash_app.rb:44:in `block (3 levels) in <main>': undefined method
> `transaction' for nil:NilClass (NoMethodError)
> 
> As if the transaction method can't handle the instance variables:(
> 
> 
> 
> Dne 21.10.2012 (ned) ob 21:47 +0200 je Sebastjan Hribar napisal(a):
> > Hi,
> > 
> > I need help yet again. I was challenged by a colleague of mine to make a
> > flashcard application for learning foreign vocabulary since I was all
> > enthusiastic about Ruby and Shoes:)....so I'm making one....
> > 
> > So far i have most of the code down and the basic GUI as well. I have 2
> > questions:
> > 
> > 1. Why don't the elements in the code below flow in the flow? Also, how
> > can I have the edit line title and the input field in the same row:
> > Name: [          ]
> > 2. When saving the object via YAML:Store I get all the data on the
> > edit_line properties written in the database:
> > 
> > ---
> > ? &82915810 !ruby/object:Shoes::EditLine
> >   initials: &82915870
> >     :left: 0
> >     :top: 0
> >     :width: 200
> >     :height: 28
> >     :angle: 0
> >     :curve: 0
> >   left: 5
> >   top: 263
> >   width: 200
> >   height: 28
> >   angle: 0
> >   curve: 0
> >   real: !ruby/object:Gtk::Entry {}
> >   app: &82914430 !ruby/object:Shoes::App
> >     width: 800
> >     height: 900
> >     margin: 10
> > .
> > .
> > .
> > It goes on and on and on...
> > 
> > 
> > When I run the code in gedit I get:
> > 
> > ---
> > avto: !ruby/object:Flashcard
> >   name: avto
> >   source: avto
> >   target: car
> >   part_of_speech: noun
> >   definition: vehicle
> >   example: I drive a car.
> > 
> > ---------------------------------------------------------
> > code:
> > 
> > require 'green_shoes'
> > require_relative "card.rb"
> > require "yaml/store"
> > 
> > Shoes.app width: 800, height: 900, margin: 10,
> >         title: "FLashcards learning v.01" do
> > 
> >   stack width: 800, height: 600 do
> >       stack width: 800, height: 200, margin: 10 do
> >         border black, strokewidth: 2
> >         para "This is a flashcard application for learning a foreign"
> >         para "language. The first section is intended for you to create"
> >         para "flashcards of your choice. In the second section you use"
> >         para "the created flashcards to learn the vocabulary."
> >       end
> > 
> >       stack width: 800, height: 200 do
> >         border black, strokewidth: 2
> >           flow width: 800, height: 200, margin: 5 do
> >             border red, strokewidth: 1
> >             para "Enter flashcard's details:"
> >             para "Name:"; @name = edit_line
> >             para "Source:"; @source = edit_line
> >             para "Target:"; @target = edit_line
> >             para "Part of speech:"; @part_of_speech = edit_line
> >             para "Definition:"; @definition = edit_line
> >             para "Example:"; @example = edit_line
> > 
> >             button "Save flashcard to database." do
> >                 card = Flashcard.new(@name, @source, @target,
> >                                   @part_of_speech, @definition,
> > @example)
> >                 db = YAML::Store.new("database.store")
> > 
> >                 db.transaction do
> >                 db[card.name] = card
> >                 end
> >             end
> >           end
> >       end
> > 
> >       stack width: 800, height: 500, margin: 10 do
> >         border black, strokewidth: 2
> >       end
> >   end
> > end
> > -------------------------------------------------
> > 
> > Thank you and kind regards.
> > seba
> 

Re: [shoes] Re:

From:
ashbb
Date:
2012-10-22 @ 11:36
Hi Sebastjan,

> I was challenged by a colleague of mine to make a flashcard
> application for learning foreign vocabulary since I was all
> enthusiastic about Ruby and Shoes:)
Wow, fantastic!

> 1. Why don't the elements in the code below flow in the flow?
Ah,... this is one of Green Shoes restrictions.
Please add each width dimensions explicitly like this:

  para "Name:", width: 150; @name = edit_line
  para "Source:", width: 150; @source = edit_line
   :
   :

> 2. When saving the object via YAML:Store I get all the data
> on the edit_line properties written in the database
Yeah, as Cecil already mentioned, it's better to store the text
inside the edit_line.

> But now I get the error about the transaction method:
>
> flash_app.rb:44:in `block (3 levels) in <main>': undefined method
> `transaction' for nil:NilClass (NoMethodError)
Because the instance variable @db is a nil object until user clicks
the "Save flashcard to database." button.

Try out this code I revised a little bit: http://pastebin.com/Z4br6RLq

Cheers,
ashbb

Re: [shoes] Re:

From:
Sebastjan Hribar
Date:
2012-10-22 @ 12:47
Dne 22.10.2012 (pon) ob 20:36 +0900 je ashbb napisal(a):
> Hi Sebastjan,
> 
> > I was challenged by a colleague of mine to make a flashcard
> > application for learning foreign vocabulary since I was all
> > enthusiastic about Ruby and Shoes:)
> Wow, fantastic!
> 
> > 1. Why don't the elements in the code below flow in the flow?
> Ah,... this is one of Green Shoes restrictions.
> Please add each width dimensions explicitly like this:
> 
>   para "Name:", width: 150; @name = edit_line
>   para "Source:", width: 150; @source = edit_line
>    :
>    :
> 
> > 2. When saving the object via YAML:Store I get all the data
> > on the edit_line properties written in the database
> Yeah, as Cecil already mentioned, it's better to store the text
> inside the edit_line.
> 
> > But now I get the error about the transaction method:
> >
> > flash_app.rb:44:in `block (3 levels) in <main>': undefined method
> > `transaction' for nil:NilClass (NoMethodError)
> Because the instance variable @db is a nil object until user clicks
> the "Save flashcard to database." button.
> 
> Try out this code I revised a little bit: http://pastebin.com/Z4br6RLq
> 
> Cheers,
> ashbb
> 
Hi ashbb,

thanks a lot, works perfectly.
I can now move on to the last part, that is the actual flashcard
mechanics. I need to display certain the flashcard attributes based on
the selected flashcard and the rest upon a click on a button.

regards
seba

Re: [shoes] Re:

From:
ashbb
Date:
2012-10-22 @ 15:19
Hi Sebastjan,

> thanks a lot, works perfectly.
I'm glad to be of help. :)

> I can now move on to the last part
Cool!
If you have any other problems or questions, feel free post here again.
And after you finish developing, please share your fantastic Green Shoes
app!

Have fun with Shoes. :-D
ashbb

Re: [shoes] Re:

From:
Sebastjan Hribar
Date:
2012-10-22 @ 16:42
Dne 23.10.2012 (tor) ob 00:19 +0900 je ashbb napisal(a):
> Hi Sebastjan,
> 
> > thanks a lot, works perfectly.
> I'm glad to be of help. :)
> 
> > I can now move on to the last part
> Cool!
> If you have any other problems or questions, feel free post here
> again.
> And after you finish developing, please share your fantastic Green
> Shoes app!
 Will do:)

I do have one more question at this point though. Why the db object
doesn't have to be an instance variable? Is it because it is declared at
the top level?

regards,
seba

Re: [shoes] Re:

From:
ashbb
Date:
2012-10-23 @ 11:47
Hi Sebastjan,

> Why the db object doesn't have to be an instance variable?
The db variable is a local variable. It is used within the range of local
variable scope.

Refer to: Ruby Variable Scope
http://www.techotopia.com/index.php/Ruby_Variable_Scope

ashbb

Re: [shoes] Re:

From:
Sebastjan Hribar
Date:
2012-10-26 @ 12:23
Thank you.  I believe most of my misunderstandings comes still comes
from my lack of knowing the green shoes and its rules.

Unfortunately I have another problem. I don't have any prior experiences
with PStore od YAML::Store for that matter. I want to be able to
implement the following flashcard mechanism:

Upon clicking a button a sample card is retrieved from the database and
certain attributes are shown. With another click the rest of the
attributes are also shown.

The problem is that I can retrieve one name or all the names via
db.roots, however, for some reason I can't retrieve the attributes.

I am looking into the PStore docs and some rare info on the net.

I've tried:
            db.transaction(true) do
              @all = db.roots
              para @all
              para @all.sample
              @test = @all.sample
              para db[@test["name"]]
	    end

The app runs and produces no errors, but there is nothing displayed for
the line: para db[@test["name"]].

The first two paras are just for testing.

If you need the entire code please let me know, but I haven't changed
much since the last time.

regards
seba


Dne 23.10.2012 (tor) ob 20:47 +0900 je ashbb napisal(a):
> Hi Sebastjan,
> 
> > Why the db object doesn't have to be an instance variable?
> The db variable is a local variable. It is used within the range of
> local variable scope.
> 
> Refer to: Ruby Variable Scope
> http://www.techotopia.com/index.php/Ruby_Variable_Scope
> 
> ashbb

Re: [shoes] Re:

From:
Sebastjan Hribar
Date:
2012-10-26 @ 14:01
Furthermore,

when running 

            db.transaction do
              p db["avto"]
	    end

in command line, I get: 
#<Flashcard:0x89d28b4 @name="avto", @source="avto", @target="car",
@part_of_speech="ljlj", @definition="kjk", @example="kj">


and when running in the green shoes app I get:

#<Flashcard:0x89d28b4


So maybe even the code below 

para db[@test["name"]]

is correct and should display the attribute, but it doesn't.

regards
seba


Dne 26.10.2012 (pet) ob 14:23 +0200 je Sebastjan Hribar napisal(a):
> Thank you.  I believe most of my misunderstandings comes still comes
> from my lack of knowing the green shoes and its rules.
> 
> Unfortunately I have another problem. I don't have any prior experiences
> with PStore od YAML::Store for that matter. I want to be able to
> implement the following flashcard mechanism:
> 
> Upon clicking a button a sample card is retrieved from the database and
> certain attributes are shown. With another click the rest of the
> attributes are also shown.
> 
> The problem is that I can retrieve one name or all the names via
> db.roots, however, for some reason I can't retrieve the attributes.
> 
> I am looking into the PStore docs and some rare info on the net.
> 
> I've tried:
>             db.transaction(true) do
>               @all = db.roots
>               para @all
>               para @all.sample
>               @test = @all.sample
>               para db[@test["name"]]
> 	    end
> 
> The app runs and produces no errors, but there is nothing displayed for
> the line: para db[@test["name"]].
> 
> The first two paras are just for testing.
> 
> If you need the entire code please let me know, but I haven't changed
> much since the last time.
> 
> regards
> seba
> 
> 
> Dne 23.10.2012 (tor) ob 20:47 +0900 je ashbb napisal(a):
> > Hi Sebastjan,
> > 
> > > Why the db object doesn't have to be an instance variable?
> > The db variable is a local variable. It is used within the range of
> > local variable scope.
> > 
> > Refer to: Ruby Variable Scope
> > http://www.techotopia.com/index.php/Ruby_Variable_Scope
> > 
> > ashbb
> 

Re: [shoes] Re:

From:
ashbb
Date:
2012-10-26 @ 14:27
Hi Sebastjan,

Try out the following code I revised a little bit. ;-)

http://pastebin.com/CNMPfNdE

Cheers,
ashbb