librelist archives

« back to archive

list box in shoes??

list box in shoes??

From:
serialhex
Date:
2011-06-16 @ 16:59
  hi all, i was looking through the shoes docs (green shoes to be exact, as
that's what i'm using mostly) and couldn't find a way to make a list box.  i
could find a drop-down list (like this:
http://en.wikipedia.org/wiki/Drop-down_list ) but not a list box (like
this: http://en.wikipedia.org/wiki/List_box ) oddly enough the 'list box' in
(green) shoes is the same as the drop-down list thing.  maybe there's a way
to make it always dropped down or something? idk, anyway, any help is
*GREATLY* appreciated (it's either that or i'll have to come up with some
funky new way to do ui stuff)

hex

-- 

> > Other than the fact Linux has a cool name, could someone explain why I
> > should use Linux over BSD?
>
> No.  That's it.  The cool name, that is.  We worked very hard on
> creating a name that would appeal to the majority of people, and it
> certainly paid off: thousands of people are using linux just to be able
> to say "OS/2? Hah.  I've got Linux.  What a cool name".  386BSD made the
> mistake of putting a lot of numbers and weird abbreviations into the
> name, and is scaring away a lot of people just because it sounds too
> technical.
	-- Linus Torvalds' follow-up to a question about Linux

Re: [shoes] list box in shoes??

From:
J. Kaiden
Date:
2011-06-16 @ 21:05
hi hex,

  check out the question i asked about creating a playlist -
http://librelist.com/browser//shoes/2011/6/8/creating-a-playlist/ -
i was looking for something similar, and Steve and ashbb helped me come up
with some "funky new ways to do ui stuff" ;)  ...  one uses the observer
pattern to notify the main app of a selection made in the list box, and the
other pops up a menu when an item is selected.  take a look if either of
these is something like what you're thinking of...

with observer:
###
require 'observer'

class ListCell < Shoes::Widget
  def initialize(entry)
    fill black
    r = rect()
    r.width= 600
    r.height= 27
    para entry, :stroke => white
    r.hover{r.style(:fill => blue)}
    r.leave{r.style(:fill => black)}
    r.click{yield entry}
  end
end

class ListManager < Shoes::Widget
include Observable
  def initialize(array)
    array.each{|item|
      list_cell(item) do |entry|
changed
notify_observers(entry)
      end
    }
  end
end
Shoes.app :title => "main" do
 @app = self
@list = %W[aparagus cucumbers leafygreens]
 def update(message)
para "observed: #{message} ", :stroke => red
end
 def manager(parent, list)
app = self
window{
@manager = list_manager(list)
@manager.add_observer(parent)
}
end
 button ("playlist"){self.manager(@app, @list)}
end
####

with a pop-up menu - in this example only the "play" option of the menu is
actually implemented, but you'll get the idea...:

#####
class ListCell < Shoes::Widget
  def initialize(entry)
    fill black
    r = rect()
    r.width= 595
    r.height= 27
    para entry, :stroke => white
    r.hover{r.style(:fill => blue)}
    r.leave{r.style(:fill => black)}
    r.click{yield(entry)}
  end
end

class PlayList < Shoes::Widget
  def initialize(array)
    window :title => "playlist" do
array.each{|item|
list_cell(item){|entry|
win = window :title => "playlist", :width => 340, :height => 30 do
button("play"){cmd = "play:#{entry}"; yield(cmd); win.close}
button("insert"){cmd = "insert:#{entry}"; yield(cmd); win.close}
button("delete"){cmd = "delete:#{entry}"; yield(cmd); win.close}
button("clear list"){cmd = "clear"; yield(cmd); win.close}
end
}
}
    end
  end
end

Shoes.app do

@lineup = %W[asparagus cucumbers leafygreens]
 def playlist
stack{
plist = play_list(@lineup){|cmd|
command = cmd.split(":")[0]
selected = cmd.split(":")[-1]
case command
when "play"
self.pl_play(selected)
end
}
}
end
 def pl_play(selected)
para "pl says play #{selected}", :stroke => yellow
end
 button("playlist"){self.playlist}
end
######

  cheers,

  - j