Ruby Shoes and the start of a PowerShell version

by Doug Finke on March 25, 2008

in PowerShell, Ruby, Shoes

Chris Sells wrote about the book Nobody Knows Shoes. Shoes is a tiny toolkit. For making windowy Ruby programs that run on Mac, Windows, Linux and so on. Download it HERE

Trivial Shoes App

Shoes.app {
  button("Press Me") { alert("You pressed me") }
}

PowerShell Version

. .\Shoes
Shoes app {
   button "Press Me" { alert "You pressed me" }
}
image 

PowerShell Shoes Toolkit

[void] [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms")

$frm
$tlp

function Shoes ($target, [scriptblock]$block) {
  switch ($target) {
    "app" {
      $frm = New-Object Windows.Forms.Form
      $tlp = New-Object System.Windows.Forms.TableLayoutPanel
      [void] $frm.Controls.Add($tlp)

      & $block

      $frm.Add_Shown( { $frm.Activate() } )
      $frm.ShowDialog()
    }
  }
}

function button($text,[scriptblock]$block) {
  $ctl = New-Object Windows.Forms.Button
  $ctl.Text = $Text
  [void] $tlp.Controls.Add($ctl)

  $ctl.add_click($block)
}

function alert($what) {
  [System.Windows.Forms.MessageBox]::Show($what)
}

{ 1 comment… read it below or add one }

1 Joel "Jaykul" Bennett 12.22.08 at 10:16 am

This looks good … I started playing with the same idea from WPF http://huddledmasses.org/powerboots-shoes-for-powershell/ but I’m pipelining it because it just seems more natural in PowerShell. I do like the way you piggybacked on the scriptblocks to nest the controls the way they do in Shoes though …

Leave a Comment

You can use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>