UnboundMethod exception when inheriting Shoes class
rajsahae opened this issue · 18 comments
Mac OSX 10.8.3
I was following this example from the Shoes book by _why and I found it didn't work.
class BookList < Shoes
url '/', :index
url '/twain', :twain
url '/kv', :vonnegut
def index
para "Books I've read: ",
link("by Mark Twain", :click => '/twain'),
link("by Kurt Vonnegut", :click => '/kv')
end
def twain
para "Just Huck Finn.\n",
link("Go Back", :click => '/')
end
def vonnegut
para "Cat's Cradle, Sirens of Titan. Breakfast of Champions.\n",
link("Go Back", :click => '/')
end
end
Shoes.app width: 400, height: 400
Which was giving me this exception:
I also tried running the "class-book.rb" example from the "samples" folder in the repo because I saw it used the same approach, and I get the same type of error.
What's going on here?
BTW on Ubuntu 10.10, both apps work no problem.
No idea. :/
Exactly the same problem here running Mac OSX 10.8.3.
Looks like this issue is back? #140
FWIW I checked and verified on OSX 10.8.3
that the issue is most succinctly described as in this comment #140 (comment)
Damn :-/ urls have been shaky in the old shoes, I could never us them because they used to segfault on my linux for even the simplest examples...
Yeah, URLs are an amazing feature, but they've never been fully-baked.
Is there a way to get around using URLs, perhaps by clearing the window and freshly repopulating it?
Yeah there is I've something that I could/should extract into a gem (took it from hackety and refinend it) but never did... basically you can take a slot and then hide it's contents. And then show another slot in the same place.
Is there a way to use variables with this slot showing/hiding technique?
I've found the source at
https://github.com/dmgarland/TrafficLight
works to separate the code into a class, but when I try to assign the pieces to a variable (like '@main = foobar.app ...) it doesn't work.
My code I'm trying to get to work with both a class and slot hiding/showing:
https://github.com/jessc/many-file-editor/blob/master/many_file_editor.rb
Hi,
the library like thingy that I wrote can be found here haven't tested it with many projects though really should get to work on making it a gem... :-/
class variables in Ruby are mostly not a good idea, you probably would rather use instance variables of the class object.
@JessC How about the following?
class ManyFileEditor
def main_window(foobar)
s = self
foobar.app do
@main_window =flow do
para "main_window"
button "Hide" do
para "second"
@main_window.hide()
@editing_window = s.editing_window(foobar)
@editing_window.show()
end
end
end
end
def editing_window(foobar)
f = nil
foobar.app do
f = flow do
para "editing_window"
end
end
f
end
def initialize(foobar)
main_window(foobar)
end
end
Shoes.app :title => "Many File Editor" do
@many_file_editor = ManyFileEditor.new(self)
end
Thanks, that's a clean solution!
Hmm, I'm just a newbie, but why does the first work and not the second?
flow :margin => 10, :width => '96%' do
flow :margin => 10, :width => '96%', :height => '100%' do
When switching to the @main_window flow that includes the height property it just shows an infinitely scrolling window.
Oh, strange! I confirmed the "infinitely scrolling window" on my Windows 7 with Shoes 3 (0.r1514). I think that you found a bug. :-P
Just so you know, as work as halted on the old shoes this most likely will not get fixed. URLs work in the new shoes4 but that's not quite ready yet.
Hey @ashbb...I liked your solution as a temporary fix, but I really appreciated the cleanness of the url(path, method) syntax, so I expanded on your idea and came up with this:
First -- a class to encapsulate some of that nifty URL behavior:
class ShoesAppWrapper
def self.url(path, method)
@@urls ||= []
@@urls << {:path => path, :method => method}
end
def initialize(shoes)
@shoes = shoes
@panels = create_panels
@panels['/'].show
@current_panel = @panels['/']
end
private
def create_panels
panels = {}
@@urls.each do |url|
panel = @shoes.stack(:width => @shoes.width, :height => @shoes.height) do
self.send(url[:method])
end
panel.top = 0
panel.left = 0
panels[url[:path]] = panel
panel.hide
end
return panels
end
def visit(panel_path)
@current_panel.hide
@current_panel = @panels[panel_path]
@current_panel.show
end
end
Then you do something like this:
require 'app_wrapper'
class SimpleApp < ShoesAppWrapper
url '/', :index
url '/something', :something_else
def index
@shoes.button("Press Me!") do
visit('/something')
end
end
def something_else
@shoes.button("Now Press Me!") do
visit('/')
end
end
end
Shoes.app(:width => 400, :height => 400){ @app = SimpleApp.new(self) }
Hopefully the above is pretty grokable on it's own, but I'll probably blog this up at some point too, and I'll link it here 😄
Hi @stlewis, Interesting!
We've been developing Shoes 4 now. Shoes 4 will be published at RubyGems.org as a gem. So, I think it's cool if you upload your shoes_app_wrapper as a gem for Shoes 4. ;-)
Bug fixed in Shoes 3.2.12 and tested with Linux, Windows, OSX (10.9)