Posts mit dem Label WPK werden angezeigt. Alle Posts anzeigen
Posts mit dem Label WPK werden angezeigt. Alle Posts anzeigen

Mittwoch, 27. April 2011

Search for Firefox Bookmarks with given combination of 1 to 3 keywords

When I found that Firefox stores its bookmarks in a sqlite database places.sqlite I wrote the following PowerShell script to search for bookmark by keyword combination.

Here is the code:

ipmo WPK            
            
if (! $sqlitedll)            
{            
    $sqlitedll = [System.Reflection.Assembly]::LoadFrom("C:\Program Files\System.Data.SQLite\bin\System.Data.SQLite.dll")             
}            
            
$ConnectionString = "Data Source=C:\Var\sqlite_ff4\places.sqlite"            
            
$conn = new-object System.Data.SQLite.SQLiteConnection             
$conn.ConnectionString = $ConnectionString             
$conn.Open()             
            
function Invoke-sqlite            
{            
    param( [string]$sql,            
           [System.Data.SQLite.SQLiteConnection]$connection            
           )            
    $cmd = new-object System.Data.SQLite.SQLiteCommand($sql,$connection)            
    $ds = New-Object system.Data.DataSet            
    $da = New-Object System.Data.SQLite.SQLiteDataAdapter($cmd)            
    $da.fill($ds) | Out-Null            
    return $ds.tables[0]            
}            
            
function Show-Bockmarks ($resource) {            
    New-Grid -Rows 2 -Columns 1 -width 1400 -hight 1000  {            
            
        New-StackPanel -Orientation horizontal -column 0 -row 0 -Children {            
             New-Label    '1. Keyword'            
             New-TextBox  -Name tag1 -width 200            
             New-Label    '2. Keyword'            
             New-TextBox  -Name tag2 -width 200            
             New-Label    '3. Keyword'            
             New-TextBox  -Name tag3 -width 200            
             New-Button -Name Search "search" -On_Click {            
            $text1 = $window | Get-ChildControl Tag1            
            $tag1 = $text1.Text            
            $text2 = $window | Get-ChildControl Tag2            
            $tag2 = $text2.Text            
            $text3 = $window | Get-ChildControl Tag3            
            $tag3 = $text3.Text            
            if ( $tag2 -ne '') {            
$clause2 = @"            
    join moz_bookmarks l2 on b.fk = l2.fk and b.id <> l2.id
    join moz_bookmarks t2 on l2.parent = t2.id and  t2.parent = 4 and upper(t2.title) = upper('$tag2')
"@                                    
            } else { $clause2 = '' }                    
            
            if ( $tag3 -ne '') {            
$clause3 = @"            
    join moz_bookmarks l3 on b.fk = l3.fk and b.id <> l3.id
    join moz_bookmarks t3 on l3.parent = t3.id and  t3.parent = 4 and upper(t3.title) = upper('$tag3')
"@                                    
            } else { $clause3 = '' }                    
            
$ff_sql = @"
SELECT b.title, datetime (b.dateAdded / 1000000, 'unixepoch', 'localtime') dateAdded , p.url
    from moz_bookmarks b
    join moz_bookmarks l1 on b.fk = l1.fk and b.id <> l1.id
    join moz_bookmarks t1 on l1.parent = t1.id and  t1.parent = 4 and upper(t1.title) = upper('$tag1')
    join moz_places p  on b.fk = p.id $clause2 $clause3
where b.title is not null and b.type = 1
"@            
            $conn = $resource.conn            
            $window.Title = "$($conn.database) Database Browser"            
            $TableView = $window | Get-ChildControl TableView            
            $TableView.ItemsSource = @(Invoke-sqlite -sql $ff_sql -connection $conn)            
             }             
             New-Button -Name Cancel "Close" -On_Click {$window.Close()}             
        }            
        New-ListView -Column 0 -Row 1 -Name TableView -View {            
           New-GridView -AllowsColumnReorder -Columns {            
               New-GridViewColumn "title"             
               New-GridViewColumn "dateAdded"             
               New-GridViewColumn "url"             
           }            
        }   -On_SelectionChanged {            
             start $this.selecteditem.url            
        }            
        #}            
            
    } -asjob -Resource $resource            
}            
            
Show-Bockmarks -resource @{conn = $conn}            

You have to install System.Data.SQLite
from http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki

I had problems when I checked the install in GAC option. Therefore I installed it without that option and supply the absolute path in my script.

Note: You can't open places.sqlite while Firefox is running. I copied it and coded the path of the copy into my script.

Now I can enter a keyword, press search and the grid fills. Double clicking starts the bookmark in the default browser.

Sonntag, 16. Mai 2010

Please help - I want to send back a keystroke to the ISE window

Hello WPF friends, I need a little help. I want to add a button which sends F7 keystroke to the ISE-window from which I run this little WPK script.


ipmo WPK                        
                        
$env:WPKResult = "auto"                          
New-StackPanel {                        
    New-RadioButton -Content "auto"     -GroupName Results -IsChecked $True -On_Click { $env:WPKResult = "auto" }                        
    New-RadioButton -Content "list"     -GroupName Results -On_Click { $env:WPKResult = "list" }                        
    New-RadioButton -Content "table"    -GroupName Results -On_Click { $env:WPKResult = "table" }            
    New-RadioButton -Content "grid"     -GroupName Results -On_Click { $env:WPKResult = "grid" }            
    New-RadioButton -Content "variable" -GroupName Results -On_Click { $env:WPKResult = "variable" }            
    New-RadioButton -Content "csv"      -GroupName Results -On_Click { $env:WPKResult = "csv" }            
    New-RadioButton -Content "file"     -GroupName Results -On_Click { $env:WPKResult = "file" }            
    New-Button -Content "execute Sql"  -On_click { New-Button "I want to send F7 key-stroke to calling ISE" -show }                        
} -asjob                        
                        

This script is intended to be run in ISE and to add some cool GUI to SQLPSX.

Thanks

Bernd

Mittwoch, 12. Mai 2010

A try in WPK (one way and only once)

The best I found in WPK seems to be the the following:

ipmo WPK            
            
$option = "To File" # this value might be prompted by the user            
             
             
New-StackPanel {            
    New-RadioButton -Content "To Text" -GroupName Results -IsChecked $True -On_Click {             
        $Resource.Result = "To Text"             
        $info = $window | Get-ChildControl info            
        $info.text = $Resource.Result            
        $env:WPKResult = $Resource.Result            
        }            
    New-RadioButton -Content "To Grid" -GroupName Results -On_Click {              
        $Resource.Result = "To Grid"             
        $info = $window | Get-ChildControl info            
        $info.text = $Resource.Result            
        $env:WPKResult = $Resource.Result            
        }            
    New-RadioButton -Content "To File" -GroupName Results -On_Click {              
        $Resource.Result = "To File"             
        $info = $window | Get-ChildControl info            
        $info.text = $Resource.Result            
        $env:WPKResult = $Resource.Result            
    }            
    New-RadioButton -Content "To CSV" -GroupName Results -On_Click {              
        $Resource.Result = "To CSV"             
        $info = $window | Get-ChildControl info            
        $info.text = $Resource.Result            
        $env:WPKResult = $Resource.Result            
    }            
    New-textBox -Name info             
    } -On_Loaded {            
            $info = $window | Get-ChildControl info            
            $info.text = $Resource.Result            
    }-asjob -resource @{Result = $option}            
            

I can modify the value within GUI and query it outside

$env:WPKResult
 
I misuse the processes environment, which is shared between the runspaces. Hmm better than pidgeon carrying USB sticks, but it is restricted to strings.

I guess I have to really dive into PowerBoots  (and that is the polite version ;-) of my opinion about WPK)

Have some fun trying to find further work arounds.

Bernd

 
 
 

A small Async PowerBootsWindow

Hello,
here I'll show a little async PowerBoots Gui, which is able to modify variables in the main thread.

ipmo PowerBoots            
            
$options = @{ "Results" = "To Text" }            
             
Boots {             
    StackPanel {            
        RadioButton -Content "To Text" -GroupName Results -IsChecked $True -On_Click { $options.Results = "To Text" }            
        RadioButton -Content "To Grid" -GroupName Results -On_Click {  $options.Results = "To Grid" }            
        RadioButton -Content "To File" -GroupName Results -On_Click {  $options.Results = "To File" }            
        RadioButton -Content "To CSV" -GroupName Results -On_Click {  $options.Results = "To CSV" }            
                }            
      } -async            
            
            

Is it possible to do the same thing with WPK?

Samstag, 24. April 2010

WPF Linkcollection for PowerShell

During the last time I played with some ways to present GUI from PowerShell. I spend some time collection links, which I want to share now.

First there are two toolkits between you can select.

WPK which is part of PowerShellPack and Powerboots.

WPK is created by James brundage
and it comes with some examples in the Modules\WPK\Examples folder.

Videos:
A Brief Introduction to using WPF-Containers
Multitouch Fingerpaint in 30 Lines of PowerShell Script

Some blog postings:
Hey, Scripting Guy! Using the Windows Presentation Foundation PowerShell Kit to Create a GUI
PowerShell Picture Viewer using WPF and WPK
Write-Progress & WPK

Test-Spelling

Projects using WPK:
SQLPSX
Try PowerShell (currently only in source not released)


PowerBoots is created by Joel Bennett (Jaykul) of HuddledMasses.org
and when installed, you find the examples in ...\Modules\PowerBoots\Samples\Samples.ps1

Some Blogs about it:
PowerBoots 0.2
PowerShell Picture Viewer using PowerBoots

Jaykuls tagged WPF

Posts Tagged ‘WPF’
PowerBoots: The tutorial walkthrough
PowerBoots: Loading XAML Windows in PowerShell 1.0 or 2.0

Creating GUI with Powershell and WPF was possible without the aid of toolkits, even in the dark adges of CTP 2 and CTP 3. Code from that early time needs to be adopted to run today, but for the curious, you find interessting stuff in it too.
Thanks to Max Trinidad for his post containing a link to the old trasures.

and here is th eearly serie from James Brundage:
Part 1
Part 2
Part 3
Part 4
Part 5
Part 6
Part 7

To make the examples run in PowerShell V2 you need help from the following posts
Windows PowerShell CTP2 to CTP3 Conversion Guide by James Brundage
PowerShell 2.0 CTP3 has arrived! by Oisin Grehan


Look for WPF tag in PowerShell Team Blog

finally you may want to look at some general WPF links
WPF Tutorial by Christian Mosers
WPF and XAML Tutorials by Josh Smith

Now have some fun, exploring WPF by yourself.

Bernd