The Shoes Manual

The App Object

An App is a single window running code at a URL. When you switch URLs, a new App object is created and filled up with stacks, flows and other Shoes elements.

The App is the window itself. Which may be closed or cleared and filled with new elements.

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. "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.

Shoes.APPS() » An array of Shoes::App objects

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.

clipboard() » a string

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. do
   stack do
     title "Searching Google", size: 16
     @status = para "One moment..."
     # Search Google for 'shoes' and print the HTTP headers
     download "" do |goog|
       @status.text = "Headers: " + goog.response.headers.inspect

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. do
   stack do
     title "Downloading Google image", size: 16
     @status = para "One moment..."
     download "",
       save: "nasa50th.gif" do
         @status.text = "Okay, is downloaded."

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.) do
   stack do
     title "POSTing to Google", size: 16
     @status = para "One moment..."
     download "",
              method: "POST", body: "v=1.0&q=shoes" do |dump|
       require 'hpricot'
       @status.text = Hpricot(dump.response.body).inner_text

As you can see from the above example, Shoes includes the Hpricot library for parsing HTML.

location() » a string

Gets a string containing the URL of the current app.

mouse() » an array of numbers: button, left, top

Identifies the mouse cursor's location, along with which button is being pressed. do
   @p = para
   animate do
     button, left, top = self.mouse
     @p.replace "mouse: #{button}, #{left}, #{top}"
owner() » Shoes::App

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.

started?() » true or false

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 are okay, but Shoes will be expecting a Shoes application to be at that address. (So, won't work, as it's an HTML app.)

Next: The Styles Master List