librelist archives

« back to archive

#close, #clear error with widgets

#close, #clear error with widgets

From:
J. Kaiden
Date:
2011-08-01 @ 13:47
hey all,

  back with a couple of questions about widgets, windows, and the like...

  i'm working on a baseball scorecard - it's meant to work something like
this:  the Shoes.app main window is full of entry boxes where you enter the
names of the players on each team.  once you've pressed a save button, the
main app window is closed, and an "at bat widget" pops up where you define
what's happened in a particular player's at bat.  when you press the save
button on the widget, it's meant to close, and a new "at bat widget" pops up
for the next player.

  below is a simplified version of what i'm trying to do.  in the "real"
version, i close the Shoes.app main window and pop up the first widget
without any errors.  when i try to call #close on the widget and pop up a
new one however, the new widget pops up, but the first does not close - and
i get the following error:

=>  (<unknown>:3115): Gtk-CRITICAL **: gtk_widget_queue_draw: assertion
`GTK_IS_WIDGET (widget)' failed

  in the simplified version i get similar errors, even when closing the
Shoes.app main window.

  here's the example code:

#####################
require 'observer'

module Elements
include Observable
def show_main(string)
stack{
para string, stroke: gray
btn = button("send"){changed; notify_observers(string)}
}
end
end

class ExampleWidget < Shoes::Widget
include Observable
def initialize(string)
box = self
win = window width: 250, height: 300 do
extend Elements
show_main(string)
add_observer(box)
end
end
 def update(message)
changed; notify_observers(message)
end
end
 Shoes.app do
start = self
@count = 1
button("launch widget"){
stack {
@ew = example_widget(@count.to_s)
start.close
} #this doesn't work if it's not in a stack, why?
@ew.add_observer(self)
}
 def update(message)
p message
@ew.close
@count += 1
stack{@ew = example_widget(@count.to_s)}
@ew.add_observer(self)
end
 end
#########################

  another question i have involves calling #example_widget() from within the
button block in the Shoes.app.  i've noticed before that unless i put the
call to a widget within a slot, i get a no method error... in this case
<undefined method `example_widget' for (Shoes::App "Shoes")> .    it's not
really a problem, as putting the call within a slot works fine, but it seems
very odd to me...

  mainly i'm interested in why i can't close my widgets!  looking at @ew's
methods, i see #close and #clear (which i also tried,) but calling them
gives me errors, any ideas?

  thanks,

  - j

Re: [shoes] #close, #clear error with widgets

From:
ashbb
Date:
2011-08-01 @ 15:20
Hi J,

Thank you for sharing the interesting snippet. :)

> why i can't close my widgets!
Is this your question?
If so, try out the following:

- Use `@win` instead of `win`
  like this:   `@win = window width: 250, height: 300 do`

- And add win() method like this:  `attr_reader :win`

- Then you can close your widget's window like this : `@ew.win.close`

>  i've noticed before that unless i put the call to a widget within
> a slot, i get a no method error... in this case <undefined method
> `example_widget' for (Shoes::App "Shoes")> .
Oh, I've confirmed the issue.
But, umm... strange. Sorry, I don't know why...
Seems like a bug, though...

ashbb

Re: [shoes] #close, #clear error with widgets

From:
J. Kaiden
Date:
2011-08-01 @ 15:41
>
>
> > why i can't close my widgets!
> Is this your question?
>

  it is - sorry if my question got lost in all the babbling ;)


> If so, try out the following:
>
> - Use `@win` instead of `win`
>   like this:   `@win = window width: 250, height: 300 do`
>
> - And add win() method like this:  `attr_reader :win`
>
> - Then you can close your widget's window like this : `@ew.win.close`
>
>
  a great idea!  don't know why i didn't think of it - in fact i was looking
for a #win method in @ew.methods, and it never occurred to me to just use
the attr_reader to make one myself...  duh.

  it still throws the error, but works all the same - good enough for who
it's for ;)

  the error is interesting to me - i wasn't aware that red Shoes used gtk
for rendering, but the error suggests it does...

  anyway -
  thanks once again!

 - j

Re: [shoes] #close, #clear error with widgets

From:
Steve Klabnik
Date:
2011-08-01 @ 17:12
It uses GTK on Linux, and native widgets on Mac and Windows.

Re: [shoes] #close, #clear error with widgets

From:
J. Kaiden
Date:
2011-08-01 @ 21:10
On Mon, Aug 1, 2011 at 7:12 PM, Steve Klabnik <steve@steveklabnik.com>wrote:

> It uses GTK on Linux, and native widgets on Mac and Windows.
>

  ...so is this strictly a linux issue?

=>  (<unknown>:3115): Gtk-CRITICAL **: gtk_widget_queue_draw: assertion
`GTK_IS_WIDGET (widget)' failed

  this error doesn't crash the app, but is persistent..  does it crash under
other systems?  i wonder, should i be doing something differently, or should
i just live with it?

  -j

Re: [shoes] #close, #clear error with widgets

From:
Steve Klabnik
Date:
2011-08-01 @ 21:22
>   ...so is this strictly a linux issue?

yes.

> other systems?  i wonder, should i be doing something differently, or should
> i just live with it?

Try running 'firefox' from your terminal sometimes. ;)

That said, one of the first things I want to work on with Red Shoes is
getting it to compile with no warnings and run with none, either. :)

Re: [shoes] #close, #clear error with widgets

From:
J. Kaiden
Date:
2011-08-01 @ 21:44
On Mon, Aug 1, 2011 at 11:22 PM, Steve Klabnik <steve@steveklabnik.com>wrote:

> Try running 'firefox' from your terminal sometimes. ;)
>

  haha - hadn't tried that before - point taken...  i'll quit worrying and
get back to wasting time writing this thing so i can waste more time scoring
ballgames ;)

 - j