librelist archives

« back to archive

window behavior

window behavior

From:
J. Kaiden
Date:
2011-07-25 @ 13:26
hey folks,

  i've got a question about how windows work in shoes.  i understand that
calling a window changes self, making things a bit tricky at times.  in the
following example, i want the drawing done by #show_main to be done in the
new window that has been popped up, not in the Shoes.app main window (as it
currently is...)

class BigCell < Shoes::Widget
 def initialize
cell = self
@win = window title: "At Bat", width: 250, height: 300 do
cell.show_main
end
end
 def show_main
@top = flow attach: @win do #ATTACH?  IF NOT, WHAT?
fill gray
rotate 45
first = rect 187, 125, 50, 50, 5
second = rect 100, 40, 50, 50, 5
third = rect 10, 125, 50, 50, 5
end
end
end

Shoes.app do
cell = big_cell
end
#########

  i thought that "attach: @win" would do the trick, but it clearly does not.
 any ideas about what might?

  when i move the #show_main method definition to be inside the @win window
block, it draws where i want it to - but BigCell has to later report back
via the observer pattern to the main app.  i can't include 'Observable' from
within the @win window to pass a message to BigCell and then later to the
main app - and if i include 'Observable' in BigCell, the observer methods
aren't recognized from within the @win window.

  another question - in the BigCell#initialize method, if i change the local
variable "cell" to an instance variable "@cell" it is not recognized from
within the @win window block - this makes sense as the window changes self,
and the @win window has no variable called @cell...  what i don't understand
is why on earth a local variable ("cell") IS recognized from within the @win
block. how / why does the local variable work but not the instance variable?

  thanks,

  - j

Re: [shoes] window behavior

From:
ashbb
Date:
2011-07-25 @ 14:58
Hi Jake,

> any ideas about what might?
How about using module? For example:

module ShowMain
  def show_main
    flow do
      fill gray
      rotate 45
      first = rect 187, 125, 50, 50, 5
      second = rect 100, 40, 50, 50, 5
      third = rect 10, 125, 50, 50, 5
    end
  end
end

class BigCell < Shoes::Widget
  def initialize
    window title: "At Bat", width: 250, height: 300 do
      extend ShowMain
      show_main
    end
  end
end

Shoes.app do
  cell = big_cell
end

> how / why does the local variable work but not the instance variable?
Because the local variable scope is not changed.
Look at the following snippet. The instance_eval method changes self, so
first @cell and second @cell are not the same. But the instance_eval doesn't

change the local variable scope, so you can access the local variable from
inside the block.

p self  #=> main
cell = 'hi'
@cell = 'hello'
obj = :someobject

obj.instance_eval do
  p self  #=> :someobject
  p cell  #=> "hi"
  p @cell #=> nil
end

Hope this helps,
ashbb

Re: [shoes] window behavior

From:
J. Kaiden
Date:
2011-07-25 @ 15:33
On Mon, Jul 25, 2011 at 4:58 PM, ashbb <ashbbb@gmail.com> wrote:

>
> How about using module?


  great idea!  works like a charm, thanks...


>
> > how / why does the local variable work but not the instance variable?
> Because the local variable scope is not changed.
>
 <snip>

> Hope this helps,
> ashbb
>

  sure does, thanks for the explanation!

  this list is the best...  you guys rule -

  - j