PowerShell, ShowUI and the Twitter API

June 26, 2011

in Microsoft,PowerShell,ShowUI,Video Tutorial,WPF,twitter

Checkout the video tutorial and the less than 30 lines of code.

The Result

I built this WPF application using PowerShell and ShowUI. I used a single Url to get the data back from the Twitter API, sliced and diced the XML in PowerShell, used WPF Databinding, Templates, a Grid and ListBox (and a little more) to get this visual.

image

The Video

 

The Code

Import-Module ShowUI            

function Search-Twitter ($q = "PowerShell") {
    $wc = New-Object Net.Webclient
    $url = "http://search.twitter.com/search.rss?q=$q"
    ([xml]$wc.downloadstring($url)).rss.channel.item | select *
}            

$ws = @{
    WindowStartupLocation = "CenterScreen"
    SizeToContent = "Width"
    Height = 550
    Title = "PowerShell, ShowUI and the Twitter API"
}            

New-Window @ws -Show {
    ListBox -Background Black -ItemTemplate {
        Grid -Columns 55, 300 {
            Image -Name Image -Margin 5 -Column 0
            TextBlock -Name Title -Margin 5 `
            -Column 1 -TextWrapping Wrap -Foreground White
        } |
            ConvertTo-DataTemplate -binding @{
                "Image.Source" = "image_link"
                "Title.Text" = "title"
            }
    } -DataContext {Search-Twitter PowerShell} `
      -DataBinding @{ItemsSource="."}
}

{ 4 trackbacks }

New-SimpleForm – Holy dynamic GUI Batman! « Tome's Land of IT
07.06.11 at 4:40 pm
Episode 152 – PrimalForms 2011 with Alex and David « PowerScripting Podcast
07.07.11 at 10:19 pm
PowerShell, ShowUI and the Twitter API–Part 2
07.09.11 at 10:43 am
PowerShell ‘Net User’ ShowUI GUI
07.18.11 at 9:01 am

{ 4 comments… read them below or add one }

Thiyagu 07.18.11 at 11:09 am

Hi,

How can we bind a PSObject using ShowUI?

thanks
Thiyagu

Doug Finke 07.18.11 at 12:07 pm

Thanks for the question Thiyagu.

New-Window -SizeToContent WidthAndHeight -DataContext {
    New-Object psobject -Property @{
        name ="Jon"
        age = 10
    }

} -Show {
    UniformGrid -Columns 1 {
        TextBox -IsReadOnly -Margin 5 -DataBinding @{Text= New-Binding -Path name}
        TextBox -IsReadOnly -Margin 5 -DataBinding @{Text= New-Binding -Path age}
    }
}
Thiyagu 07.18.11 at 1:15 pm

Thank you Doug for that quick example, it works very nicely.

Hemanth (@SqlChow) 01.02.12 at 2:28 pm

I did not know about ShowUI, until I read your post, and it looks amazing. Certainly looks much more cleaner than my output. I wrote script to get local trends so, maybe this time I will try to use ShowUI :)

This is an excellent example of how we can make it fun for folks, and get them more interested in Powershell.

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>

Contrat Creative Commons

© 2007-2012, Doug Finke