The App itself, in slot/box terminology, is a flow. See the Slots section for more, but this just means that any elements placed directly at the top-level will flow.
Starts up a Shoes app window. This is the starting place for making a Shoes program. Inside the block, you fill the window with various Shoes elements (buttons, artwork, etc.) and, outside the block, you use the styles
to describe how big the window is. Perhaps also the name of the app or if it's resizable.
Shoes.app(title: "White Circle",
width: 200, height: 200, resizable: false) {
background black
fill white
oval top: 20, left: 20, radius: 160
}
In the case above, a small window is built. 200 pixels by 200 pixels. It's not resizable. And, inside the window, two elements: a black background and a white circle.
Once an app is created, it is added to the Shoes.APPS list. If you want an app to spawn more windows, see the window method and the dialog method.
Builds a complete list of all the Shoes apps that are open right now. Once an app is closed, it is removed from the list. Yes, you can run many apps at once in Shoes. It's completely encouraged.
Returns a string containing all of the text that's on the system clipboard. This is the global clipboard that every program on the computer cuts and pastes into.
Stores a string
of text in the system clipboard.
Closes the app window. If multiple windows are open and you want to close the entire application, use the built-in method exit
.
Starts a download thread (much like XMLHttpRequest, if you're familiar with JavaScript.) This method returns immediately and runs the download in the background. Each download thread also fires start
, progress
and finish
events. You can send the download to a file or just get back a string (in the finish
event.)
If you attach a block to a download, it'll get called as the finish
event.
Shoes.app do
stack do
title "Searching Google", size: 16
@status = para "One moment..."
# Search Google for 'shoes' and print the HTTP headers
download "http://www.google.com/search?q=shoes" do |goog|
@status.text = "Headers: " + goog.response.headers.inspect
end
end
end
And, if we wanted to use the downloaded data, we'd get it using goog.response.body
. This example is truly the simplest form of download
: pulling some web data down into memory and handling it once it's done.
Another simple use of download
is to save some web data to a file, using the :save
style.
Shoes.app do
stack do
title "Downloading Google image", size: 16
@status = para "One moment..."
download "http://www.google.com/logos/nasa50th.gif",
save: "nasa50th.gif" do
@status.text = "Okay, is downloaded."
end
end
end
In this case, you can still get the headers for the downloaded file, but response.body
will be nil
, since the data wasn't saved to memory. You will need to open the file to get the downloaded goods.
If you need to send certain headers or actions to the web server, you can use the :method
, :headers
and :body
styles to customize the HTTP request. (And, if you need to go beyond these, you can always break out Ruby's OpenURI class.)
Shoes.app do
stack do
title "POSTing to Google", size: 16
@status = para "One moment..."
download "http://www.stevex.net/dump.php",
method: "POST", body: "v=1.0&q=shoes" do |dump|
require 'hpricot'
@status.text = Hpricot(dump.response.body).inner_text
end
end
end
As you can see from the above example, Shoes includes the Hpricot library for parsing HTML.
Gets a string containing the URL of the current app.
Identifies the mouse cursor's location, along with which button is being pressed.
Shoes.app do
@p = para
animate do
button, left, top = self.mouse
@p.replace "mouse: #{button}, #{left}, #{top}"
end
end
Gets the app which launched this app. In most cases, this will be nil
. But if this app was launched using the window method, the owner will be the app which called window
.
Has the window been fully constructed and displayed? This is useful for threaded code which may try to use the window before it is completely built. (Also see the start
event which fires once the window is open.)
Changes the location, in order to view a different Shoes URL.
Absolute URLs (such as http://google.com) are okay, but Shoes will be expecting a Shoes application to be at that address. (So, google.com won't work, as it's an HTML app.)
Next: The Styles Master List