librelist archives

« back to archive

Customizing Listbox text, and setting style attributes for a class

Customizing Listbox text, and setting style attributes for a class

From:
Rosalind O'Brien
Date:
2011-10-16 @ 18:44
Hi all!
I'm new to shoes and I have a couple of questions:

1. I'm writing a shoes app ("Policeman" release) that contains a listbox
with items that I want to display in a particular font, because they
contain characters that don't display in certain fonts. I also want to
adjust the font size because the default size is small and hard to read.
Does anyone know how to set the font and font size of listbox items in
shoes?

Here's basically what I'm trying to do:

Shoes.app do
 stack do
   list_box :items => ["dʌbəlkwoʊd"],
            :height => 100,
            :font => "Lucida Sans" #height and font seem to have no effect
 end
end

2. how do I go about applying a style to a class of elements?  The manual
says this should be possible, but I didn't see directions for it anywhere.
 For instance, I'd like to make it so all para's in my app have "Lucida
Sans" font of size "12".

Thanks!
Ros

Re: [shoes] Customizing Listbox text, and setting style attributes for a class

From:
J. Kaiden
Date:
2011-10-16 @ 23:08
hi Rosalind,

  welcome to Shoes!

  1.  -hmm, not sure about setting text font in a list_box, others on this
list should be able to help you out better than i with whether that's
possible - you  might have to create your own 'list_boxish' widget (not such
a big deal...)

  2.  Shoes methods like 'para,' 'inscription,' 'banner,' etc, come sized
already, and display in the default font.  if you wanted to make your own
method to define how text shows, you could do something like this:

#######
  Shoes.app do

def my_para(txt)
para txt, font: "Purisa", size: 38, stroke: lime
end

   my_para("hi there, world")

  end
#######

  or, if you want/need to use the #style method...

#######
  Shoes.app do

def my_para(txt)
mp = para txt
mp.style(font: "Purisa", size: 38, stroke: lime)
end

  my_para("hi there, world")

  end
#######

hth,
Shoes On!

  - j

>

Re: [shoes] Customizing Listbox text, and setting style attributes for a class

From:
ashbb
Date:
2011-10-17 @ 12:30
Hi Rosalind, J et al,

1st: Sorry, you can't change font type and size of ListBox object so far.
But Shoes can handle UTF-8 characters.
So, save the following code into the file as UTF-8 format.
Then run with your Shoes like this: shoes test.rb

  # -*- encoding: utf-8 -*-
  # test.rb
  Shoes.app do
    list_box items: ["dʌbəlkwoʊd"]
  end

If this doesn't work well, run the following and input items you want to
display in the list_box by hand.

  Shoes.app do
    items = ask 'input items'
    list_box items: items.split
  end

2nd: Try out the following.

  Shoes.app do
    style Para, font: "Lucida Sans", size: 36
    para "hello hello"
    para "Looks nice?"
  end

Hope this helps,
ashbb

Re: [shoes] Customizing Listbox text, and setting style attributes for a class

From:
Rosalind O'Brien
Date:
2011-10-18 @ 23:52
Hi J, asshb, et al,
Thanks for your replies. I think I have the question of applying a style to
a class down, now.  I might tackle the new widget thing or not, but it's
good to know that I can at least display the characters I need in the
listbox as is, even if they're a bit small for my liking.

May the shoes be with you,
Ros

On Mon, Oct 17, 2011 at 6:30 AM, ashbb <ashbbb@gmail.com> wrote:

> Hi Rosalind, J et al,
>
> 1st: Sorry, you can't change font type and size of ListBox object so far.
> But Shoes can handle UTF-8 characters.
> So, save the following code into the file as UTF-8 format.
> Then run with your Shoes like this: shoes test.rb
>
>   # -*- encoding: utf-8 -*-
>   # test.rb
>   Shoes.app do
>     list_box items: ["dʌbəlkwoʊd"]
>   end
>
> If this doesn't work well, run the following and input items you want to
> display in the list_box by hand.
>
>   Shoes.app do
>     items = ask 'input items'
>     list_box items: items.split
>   end
>
> 2nd: Try out the following.
>
>   Shoes.app do
>     style Para, font: "Lucida Sans", size: 36
>     para "hello hello"
>     para "Looks nice?"
>   end
>
> Hope this helps,
> ashbb
>
>

Best way to handle getting full path in shoes

From:
Wayne Brissette
Date:
2011-10-22 @ 10:18
I'm just now starting to play with Shoes (and Ruby for that matter … I've 
been an AppleScript person for a long time)… 

I do have a basic question though (maybe this is more Ruby related than 
Shoes), but here goes.

In this basic script I came up with to list the files, I want to list full
paths. How do I do that? 

Shoes.app :title =>'Add Navtitle Field', :width => 300 do
  stack do
    para "Choose the directory to list files"
    button("Choose") do
	folder = ask_open_folder
	clear()
	Dir.entries(folder).each {|indfile| para "files are: " + indfile + "\n"} 
	end
  end
end


I would think I should be able to use the Files.dirname but when I tried, 
it failed and I'm not so sure I can. Maybe it's all a matter of 
misunderstanding how File.dirname is used. 

Wayne

---

"Success usually comes to those who are too busy to be looking for it" 
- Henry David Thoreau

Re: [shoes] Best way to handle getting full path in shoes

From:
J. Kaiden
Date:
2011-10-22 @ 11:16
hi Wayne,

  welcome to Shoes!

  try this:

       Dir.entries(folder).each {|indfile| para "files are: " +
File.expand_path(indfile) + "\n"}

  hth,

  - j

Re: [shoes] Best way to handle getting full path in shoes

From:
Wayne Brissette
Date:
2011-10-22 @ 13:48
On Oct 22, 2011, at 6:16 AM, J. Kaiden wrote:

> hi Wayne,
>   
>   welcome to Shoes!
> 
>   try this:
> 
>        Dir.entries(folder).each {|indfile| para "files are: " + 
File.expand_path(indfile) + "\n"}
> 
>   hth,
> 
>   - j
> 

Thanks! That worked perfectly. : )

Wayne

Re: [shoes] Best way to handle getting full path in shoes

From:
Wayne Brissette
Date:
2011-10-24 @ 09:27
On Oct 22, 2011, at 6:16 AM, J. Kaiden wrote:

> hi Wayne,
>   
>   welcome to Shoes!
> 
>   try this:
> 
>        Dir.entries(folder).each {|indfile| para "files are: " + 
File.expand_path(indfile) + "\n"}

Hi all, it's  me again. ;) 

I'm wondering if this is a Shoes thing, or a Ruby thing, but 
File.expand_path isn't returning the right path. Initially I didn't notice
this since I tested this on a directory that was on the same volume as the
test Shoes script. However, when I tried this  on a directory that resided
on another volume, my path stayed the same as the previous one. In all 
cases it looks like it's using the path to where the script resides, not 
where the files are located.

What am I missing? shouldn't the File methods point to the files and not 
where the Shoes script resides? 

Thanks,
Wayne

Re: [shoes] Best way to handle getting full path in shoes

From:
Eric Watson
Date:
2011-10-24 @ 11:22
On Oct 24, 2011, at 4:27 AM, Wayne Brissette wrote:

> Hi all, it's  me again. ;) 
> 
> I'm wondering if this is a Shoes thing, or a Ruby thing, but 
File.expand_path isn't returning the right path. Initially I didn't notice
this since I tested this on a directory that was on the same volume as the
test Shoes script. However, when I tried this  on a directory that resided
on another volume, my path stayed the same as the previous one. In all 
cases it looks like it's using the path to where the script resides, not 
where the files are located.
> 
> What am I missing? shouldn't the File methods point to the files and not
where the Shoes script resides? 

Wayne, 

It's a ruby thing ;)

File.expand_path is kind of dumb. It doesn't look for a real path, it just
tells you what the full path to the filename you specify *would be*. With 
one argument, it give the full path assuming the file is in the current 
directory. If you want the full path to a different directory, just pass 
that directory as the second argument. Like this:


huckle:code eric$ irb
rbx-head :001 > f = "file.txt"
 => "file.txt" 
rbx-head :002 > File.expand_path f
 => "/Users/eric/code/file.txt" 
rbx-head :003 > File.expand_path f, "/Volumes/some/other/volume"
 => "/Volumes/some/other/volume/file.txt" 
rbx-head :004 > 


Hope that helps!

Eric

Re: [shoes] Best way to handle getting full path in shoes

From:
J. Kaiden
Date:
2011-10-24 @ 10:33
hi Wayne,

  as far as i understand it, File.expand_path always returns the path that
the script is located in - it can be used for locating other files or
directories relative to where the script is.

  if you want to recursively search another directory and extract the paths
of all the files and directories in it, check out the Find module...

  http://www.ruby-doc.org/stdlib-1.9.2/libdoc/find/rdoc/Find.html


<http://www.ruby-doc.org/stdlib-1.9.2/libdoc/find/rdoc/Find.html>  hth,

  - j

Re: [shoes] Best way to handle getting full path in shoes

From:
Wayne Brissette
Date:
2011-10-24 @ 19:14
<head><style>body{font-size:10pt;font-family:arial,sans-serif;background-color:#ffffff;color:black;}p{margin:0px;}</style></head><body><font
color="#000000"><font size="2"><font face="arial,sans-serif">I suspect 
it's just me being the idiot, and trying to think this script out the way 
I would have done it in AppleScript, but If I did something like this in 
AppleScript: </font></font></font><div><font class="Apple-style-span"
size="2"><br></font></div><div><div><font color="#000000"><font 
size="2"><font face="arial,sans-serif"><p style="margin: 0.0px 0.0px 0.0px
0.0px; font: 12.0px Verdana; color: #1e00c4"><span style="color: 
#000000"><b>set</b> </span><span style="color: 
#2b9700">SourceFolder</span><span style="color: #000000"> <b>to</b> 
</span><b>choose folder</b></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 
Verdana"><b>tell</b> <span style="color: 
#3200ff"><i>application</i></span> "Finder"</p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px Verdana"><span 
class="Apple-tab-span" style="white-space:pre">	</span><b>set</b> <span 
style="color: #2b9700">FileNames</span> <b>to</b> <span style="color: 
#9200e2">name</span> <b>of</b> <b>every</b> <span style="color: 
#3200ff"><i>file</i></span> <b>of</b> <span style="color: 
#2b9700">SourceFolder</span></p>
<p style="margin: 0.0px 0.0px 0.0px 0.0px; font: 12.0px 
Verdana"><b>end</b> <b>tell</b></p><div><b><br></b></div><div><b><span 
class="Apple-style-span" style="font-weight: normal; ">What I guess I'm 
trying to figure out is how to get shoes to do this same behavior. That is
all me to pick a directory, so that later I can go through that directory 
and parse various files. Looking at Eric's example, he provided the path, 
but what I'm missing I think is how to get that path from shoes pick a 
directory dialog. </span></b></div><div><b><span 
class="Apple-style-span" style="font-weight: normal; 
"><br></span></b></div><div><b><span class="Apple-style-span" 
style="font-weight: normal; ">Also, did the Mac OS X 10.7 version of Shoes
ever get 
released? </span></b></div><div><br></div></font></font></font><blockquote
style="PADDING-LEFT: 5px; MARGIN-LEFT: 0px; BORDER-LEFT: #0000ff 2px 
solid"><wasnotrice@gmail.com><zzzhtml><zzzbody style="word-wrap: 
break-word; -webkit-nbsp-mode: space; -webkit-line-break: 
after-white-space; "><div><div><br></div><div><div>huckle:code eric$ 
irb</div><div>rbx-head :001 > f = "file.txt"</div><div> => 
"file.txt" </div><div>rbx-head :002 > File.expand_path 
f</div><div> => 
"/Users/eric/code/file.txt" </div><div>rbx-head :003 > 
File.expand_path f, "/Volumes/some/other/volume"</div><div> => 
"/Volumes/some/other/volume/file.txt" </div><div>rbx-head :004 
> </div></div><div><br></div></div></zzzbody></zzzhtml></wasnotrice@gmail.com></blockquote></div></div></body>

Re: [shoes] Best way to handle getting full path in shoes

From:
Wayne Brissette
Date:
2011-10-24 @ 19:19
Let's try this again, making sure plain text is selected. Sorry folks! 

I suspect it's just me being the idiot, and trying to think this script 
out the way I would have done it in AppleScript, but If I did something 
like this in AppleScript: 

set SourceFolder to choose folder
tell application "Finder"
	set FileNames to name of every file of SourceFolder
end tell

What I guess I'm trying to figure out is how to get shoes to do this same 
behavior. That is all me to pick a directory, so that later I can go 
through that directory and parse various files. Looking at Eric's example,
he provided the path, but what I'm missing I think is how to get that path
from shoes pick a directory dialog. 


> huckle:code eric$ irb
> rbx-head :001 > f = "file.txt"
>  => "file.txt" 
> rbx-head :002 > File.expand_path f
>  => "/Users/eric/code/file.txt" 
> rbx-head :003 > File.expand_path f, "/Volumes/some/other/volume"
>  => "/Volumes/some/other/volume/file.txt" 
> rbx-head :004 > 


Also, did the Mac OS X 10.7 version of Shoes ever get released? 

Wayne

Re: [shoes] Best way to handle getting full path in shoes

From:
Cecil Coupe
Date:
2011-10-25 @ 07:51
Wayne, 
  
  Try this little Shoes/Ruby snippet that pops up a dialog box for the
folder name and displays the file names and folder names within.

Shoes.app do
  dirString = ask_open_folder
  title dirString+":\n"
  fileNames = []
  Dir.foreach(dirString) do |nm| 
    fileNames << nm
  end
  fileNames.each do |foo| 
    para dirString+"/"+foo+"\n"
  end
end

For an Applescripter there are many rubyism's in that snippet that may
confuse you as when mixed into Shoes. In Ruby, there are many ways to
get a file list and I know my example is not the best way, but it does
put up a dialog for a folder, it runs through folder contents and
creates an array of the filenames inside (beware -- sub-folders are
filenames too) and it prints out the full path to the file (or
subdirectory). Dot (.) and Dot-dot (..) are file names and directories.

--Cecil

On Mon, 2011-10-24 at 14:19 -0500, Wayne Brissette wrote:
> Let's try this again, making sure plain text is selected. Sorry folks! 
> 
> I suspect it's just me being the idiot, and trying to think this script 
out the way I would have done it in AppleScript, but If I did something 
like this in AppleScript: 
> 
> set SourceFolder to choose folder
> tell application "Finder"
> 	set FileNames to name of every file of SourceFolder
> end tell
> 
> What I guess I'm trying to figure out is how to get shoes to do this 
same behavior. That is all me to pick a directory, so that later I can go 
through that directory and parse various files. Looking at Eric's example,
he provided the path, but what I'm missing I think is how to get that path
from shoes pick a directory dialog. 
> 
> 
> > huckle:code eric$ irb
> > rbx-head :001 > f = "file.txt"
> >  => "file.txt" 
> > rbx-head :002 > File.expand_path f
> >  => "/Users/eric/code/file.txt" 
> > rbx-head :003 > File.expand_path f, "/Volumes/some/other/volume"
> >  => "/Volumes/some/other/volume/file.txt" 
> > rbx-head :004 > 
> 
> 
> Also, did the Mac OS X 10.7 version of Shoes ever get released? 
> 
> Wayne

Re: [shoes] Best way to handle getting full path in shoes

From:
Wayne Brissette
Date:
2011-10-25 @ 09:29
Thanks Cecil. This does do what I was wanting to do. 

Wayne