All Projects → clevr-dev → Anybox

clevr-dev / Anybox

Licence: mit
Designed to facilitate script input/output with an easily customizable WPF window.

Programming Languages

powershell
5483 projects

Labels

Projects that are alternatives of or similar to Anybox

Lambda Converters
Strongly-typed lambda expressions as value converters, data template selectors, and validation rules
Stars: ✭ 99 (-23.26%)
Mutual labels:  wpf
Aura.ui
A Library with a lot of Controls for AvaloniaUI
Stars: ✭ 114 (-11.63%)
Mutual labels:  wpf
Osu Player
A multifunctional media player for osu and osuer. Modern interface with WPF.
Stars: ✭ 123 (-4.65%)
Mutual labels:  wpf
Wpfcontrib
A collection of WPF controls and utility classes I've accumulated over the years.
Stars: ✭ 106 (-17.83%)
Mutual labels:  wpf
Xaml Code Experiences
A collection of the experiences I have collected during days of Xamarin and Wpf, while following the MVVM design pattern.
Stars: ✭ 114 (-11.63%)
Mutual labels:  wpf
Tinylittlemvvm
A small MVVM library for WPF built on top of MahApps.Metro, supporting .NET Framework 4.7.2 and .NET Core 3
Stars: ✭ 120 (-6.98%)
Mutual labels:  wpf
Reactivemvvm
Cross-platform ReactiveUI sample app built for a talk at MSK .NET conf.
Stars: ✭ 94 (-27.13%)
Mutual labels:  wpf
Patchfluent
💧 🦄 Customize Windows 10 Updates
Stars: ✭ 128 (-0.78%)
Mutual labels:  wpf
Cardidleremastered
Card Idle is a WPF remake of Idle Master
Stars: ✭ 114 (-11.63%)
Mutual labels:  wpf
Xmouse Controls
Windows utility to enable or disable active window tracking, raising and also the delay in milliseconds. This is known as x-mouse behavior or focus follows mouse.
Stars: ✭ 122 (-5.43%)
Mutual labels:  wpf
Biaui
WPF dark theme and controls for .NET Core and .NET Framework
Stars: ✭ 109 (-15.5%)
Mutual labels:  wpf
Huehue
A simple yet powerful open source LED controller for Windows and Arduino
Stars: ✭ 113 (-12.4%)
Mutual labels:  wpf
Toggldesktop
Toggl Desktop app for Windows, Mac and Linux
Stars: ✭ 1,663 (+1189.15%)
Mutual labels:  wpf
Tiefsee
Stars: ✭ 100 (-22.48%)
Mutual labels:  wpf
Materialdesigninxamltoolkit
Google's Material Design in XAML & WPF, for C# & VB.Net.
Stars: ✭ 11,603 (+8894.57%)
Mutual labels:  wpf
Accelerider.windows
A shell that runs Accelerider applications on the Windows platform.
Stars: ✭ 1,350 (+946.51%)
Mutual labels:  wpf
Gong Wpf Dragdrop
The GongSolutions.WPF.DragDrop library is a drag'n'drop framework for WPF
Stars: ✭ 1,669 (+1193.8%)
Mutual labels:  wpf
Stikynotes
一个便捷的Windows桌面便利贴/A convenitent Windows Notes
Stars: ✭ 128 (-0.78%)
Mutual labels:  wpf
Arcgis Toolkit Dotnet
Toolkit for ArcGIS Runtime SDK for .NET
Stars: ✭ 125 (-3.1%)
Mutual labels:  wpf
Gw2pao
Guild Wars 2 Personal Assistant Overlay
Stars: ✭ 122 (-5.43%)
Mutual labels:  wpf

Message Box, Input Box, AnyBox

Read the release notes on GitHub or my site.

Overview

Creating forms in Powershell can be tedious, from aligning the content just right to wiring up events. Thankfully, when it comes to GUIs for Powershell scripts, a simple message box or input box usually does the trick. The problem is that the not-so-built-in offerings for Powershell are extremely limited in (1) features and (2) customization.

Typical Message box:

Add-Type -AssemblyName PresentationFramework

[System.Windows.MessageBox]::Show('hello world', 'MessageBoxDemo')

Typical Input box:

[Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic')

[Microsoft.VisualBasic.Interaction]::InputBox('interesting input', 'InputBoxDemo')

Neither of these approaches are customizable beyond the essentials; they are focused purely on their limited functional. They're also not very Powershell-esque. If you want anything more, you'll have to create it yourself. A few options exist to make the creation of a custom form simpler (form designers), but the learning curve can be steep for a non-developer Powershell users (e.g., engineers, admins), and it is a tedious task even for the Powershell experts.

AnyBox was developed to satisfy both the need for simplicity and advanced customization when creating appealing WPF forms in Windows Powershell.

How to get it

Install AnyBox from the Powershell Gallery with:

Install-Module -Name 'AnyBox'

Then, load it with:

Import-Module AnyBox

Message Box

Simple message box with AnyBox:

Show-AnyBox -Title 'MessageBoxDemo' -Message 'hello world' -Buttons 'OK'

Center the content and increase font size:

Show-AnyBox -Title 'MessageBoxDemo' -Message 'hello world' -FontSize 14 -ContentAlignment 'Center' -Buttons 'OK'

Add more buttons:

Show-AnyBox -Title 'MessageBoxDemo' -Message 'hello world' -FontSize 14 -ContentAlignment 'Center' -Buttons 'Yes','No','Maybe?'

Change the modal frame and set the window topmost:

Show-AnyBox -Title 'MessageBoxDemo' -Message 'hello world' -FontSize 14 -ContentAlignment 'Center' -Buttons 'Yes','No','Maybe?' -WindowStyle 'ToolWindow' -Topmost

Make it gnarly:

Show-AnyBox -Title 'MessageBoxDemo' -Message 'hello world' -FontSize 14 -ContentAlignment 'Center' -Buttons 'Yes','No','Maybe?' -Topmost `
    -Icon 'Warning' -BackgroundColor 'Black' -FontColor 'Orange' -FontFamily 'Comic Sans MS'

Input Box

Simple input box with AnyBox:

Show-AnyBox -Title 'InputBoxDemo' -Prompt "what's your name?" -Buttons 'Cancel','Submit'

Add more prompts and a comment:

Show-AnyBox -Title 'InputBoxDemo' -Prompts "what's your name?","what's your number?" -Buttons 'Cancel','Submit' -Comment '* responses are confidential'

The next couple of examples jump ahead a bit, but to give you an idea of what's possible...

Multi-line input:

Show-AnyBox -Title 'InputBoxDemo' -Buttons 'Cancel','Submit' -Prompts @(
    New-AnyBoxPrompt -Message 'Query:' -LineHeight 5
)

Grouped prompts and collapsible prompts:

Show-AnyBox -Title 'InputBoxDemo' -Buttons 'Cancel','Submit' -MinWidth 100 -Prompts @(
    New-AnyBoxPrompt -Group 'Connection Info' -Message 'SQL Instance:'
    New-AnyBoxPrompt -Group 'Connection Info' -Message 'User Name:'
    New-AnyBoxPrompt -Group 'Connection Info' -Message 'Password:' -InputType Password
    New-AnyBoxPrompt -Group 'Query' -LineHeight 5 -Collapsible
)

AnyBox

AnyBox makes a fine replacement for your typical message box and input box, and it can do a lot more. So much so that, given a long list of parameters, it may be more intuitive to "build" the AnyBox top-down rather than calling the function with a long list of parameters. For example, the two functions below produce the same AnyBox:

Show-AnyBox -Icon 'Question' -Title 'AnyBoxDemo' -Prompts "what's your name?","what's your number?" -FontSize 14 -ContentAlignment 'Center' -Buttons 'Yes','No','Maybe?' -DefaultButton 'Yes' -CancelButton 'No' -ButtonRows 2 -Topmost

or, since v0.3.4

Import-Module AnyBox

$anybox = New-Object AnyBox.AnyBox

$anybox.Icon = 'Question'
$anybox.Title = 'AnyBoxDemo'
$anybox.Prompts = 'what''s your name?','what''s your number?'
$anybox.FontSize = 14
$anybox.ContentAlignment = 'Center'
$anybox.Buttons = 'Yes','No','Maybe?'
$anybox.DefaultButton = 'Yes'
$anybox.CancelButton = 'No'
$anybox.ButtonRows = 2
$anybox.Topmost = $true

$anybox | Show-AnyBox

Prompts

AnyBox offers many different prompt types. The typical prompt Text, shown in the examples above, is used when the value for "-Prompts" is a string. As you'll see, Text can be represented as a text box, combo box, or set of radio buttons. To use other prompt types and make customizations to individual prompts, use New-AnyBoxPrompt.

Import-Module AnyBox

$anybox = New-Object AnyBox.AnyBox

$anybox.Prompts = @(
  # typical text prompt, but with default value.
  New-AnyBoxPrompt -InputType Text -Message "what's your name?" -DefaultValue 'donald'
  # typical text prompt, but with validation (must be all numeric).
  New-AnyBoxPrompt -InputType Text -Message "what's your number?" -ValidateScript { $_ -match '^[0-9]+$' }
  # sets are shown as drop-down lists.
  New-AnyBoxPrompt -InputType Text -Message "what's your favorite color?" -ValidateSet 'red','blue','green' -DefaultValue 'blue'
  # or sets of radio buttons.
  New-AnyBoxPrompt -InputType Text -Message "what's your favorite fruit?" -ValidateSet 'apple','banana','tomato?' -DefaultValue 'banana' -ShowSetAs Radio
  # date input.
  New-AnyBoxPrompt -InputType Date -Message "what's your birthday?" -DefaultValue '1970-01-01'
  # secure string input.
  New-AnyBoxPrompt -InputType Password -Message "what's your SSN?"
  # file input
  New-AnyBoxPrompt -InputType FileOpen -Message "Upload supporting documents:"
  # link input
  New-AnyBoxPrompt -InputType Link -Message "Terms & Conditions" -DefaultValue 'www.donaldmellenbruch.com'
  # checkbox (boolean) input.
  New-AnyBoxPrompt -InputType Checkbox -Message "I have read the terms & conditions" -DefaultValue $false
)

$anybox.ContentAlignment = 'Center'
$anybox.Buttons = 'Cancel','Submit'
$anybox.Icon = 'Question'

$anybox | Show-AnyBox

Buttons

To create a customized button, use New-AnyBoxButton. There are a few pre-made action buttons that can be created from a template, such as 'CopyMessage', which will copy the displayed message to the clipboard.

Import-Module AnyBox

$anybox = New-Object AnyBox.AnyBox

$anybox.Icon = 'Error'
$anybox.Message = 'Process.exe exited with code -1.'

$anybox.Buttons = @(
  New-AnyBoxButton -Text 'Close' -IsCancel
  New-AnyBoxButton -Template 'CopyMessage'
  New-AnyBoxButton -Text 'Retry' -IsDefault
)

$anybox | Show-AnyBox

Data Grid

In addition to messages, prompts, and buttons, AnyBox can present a data grid, complete with a search bar.

Import-Module AnyBox

$anybox = New-Object AnyBox.AnyBox

$anybox.Title = 'Windows Services'
$anybox.ContentAlignment = 'Center'
$anybox.MaxHeight = 600

$anybox.GridData = Get-Service | Select-Object Status, Name, DisplayName

$anybox.Buttons = @(
  New-AnyBoxButton -Text 'Close'
  New-AnyBoxButton -Template 'ExploreGrid'
  New-AnyBoxButton -Template 'SaveGrid'
)

$anybox | Show-AnyBox

Suppress the grid search bar by setting $anybox.NoGridSearch=$true

Handling Input

Getting a message to users is only half the battle. Handling their responses is the other half, and AnyBox makes that easier too.

After an AnyBox window closes, it returns a hashtable of user inputs (if any). The hashtable will contain a key for each prompt and each button. By default, prompt keys are named "Input_#", where # is index of the prompt in the order they were defined (starting from 0). Buttons, by default, are named by their text. To override the corresponding key name, specify a -Name for the prompt/button when defining it with New-AnyBoxPrompt/New-AnyBoxButton. Names cannot contain spaces.

Import-Module AnyBox

$anybox = New-Object AnyBox.AnyBox

$anybox.Prompts = 1..3 | ForEach-Object { New-AnyBoxPrompt -Message "Prompt $_" -Name "Prompt_$_" }
$anybox.Buttons = 1..3 | ForEach-Object { New-AnyBoxButton -Text "Button $_" -Name "Button_$_" }

$response = $anybox | Show-AnyBox

$response

## 
## Name                           Value                                                                                   
## ----                           -----                                                                                   
## Prompt_3                       also, text                                                                              
## Button_1                       False                                                                                   
## Prompt_2                       moar text                                                                               
## Prompt_1                       some text                                                                               
## Button_3                       True                                                                                    
## Button_2                       False

To examine the output for a specific prompt/button (here, Prompt_1):

$response['Prompt_1']

To see which button was clicked, iterate over the hashtable.

$response.Keys | Where-Object { $_ -like 'Button_*' -and $response[$_] -eq $true }

A similar method of iterating over the responses, which will return an array of key-value pairs that match a condition.

$response.GetEnumerator() | Where-Object { $_.Name -like 'Prompt_*' -and $_.Value -like '*' }

So, a simple AnyBox workflow could look something like:

Import-Module AnyBox

# build the AnyBox
$anybox = New-Object AnyBox.AnyBox

$anybox.Prompts = New-AnyBoxPrompt -Name 'name' -Message "what's your name?" -ValidateNotEmpty

$anybox.Buttons = @(
    New-AnyBoxButton -Name 'cancel' -Text 'Cancel' -IsCancel
    New-AnyBoxButton -Name 'submit' -Text 'Submit' -IsDefault
)

# show the AnyBox; collect responses.
$response = $anybox | Show-AnyBox

# act on responses.
if ($response['submit'] -eq $true) {
    $name = $response['name']
    Show-AnyBox -Message "Hello $name!" -Buttons 'OK'
}
else {
    Show-AnyBox -Message "Ouch!" -Buttons 'OK'
}

----->

New in v0.4.0

Three new parameters were introduced in v0.4.0:

  • -ProgressBar: show an indeterminate progress bar.
  • -While: only show the window while the provided scriptblock evaluates to $true.
  • -WindowStartupLocation: specify the startup location for the AnyBox.

The demo below incorporates each of the new features.

$job = Start-ThreadJob -ScriptBlock { Start-Sleep -Seconds 5 }

###

$anybox = New-Object AnyBox.AnyBox

$anybox.Message = 'A background job is running'
$anybox.Comment = 'This window will close when complete'

$anybox.WindowStyle = 'None'
$anybox.ContentAlignment = 'Center'
$anybox.Topmost = $true
$anybox.WindowStartupLocation = 'BottomRight'

$anybox.ProgressBar = $true
$anybox.While = { $job.State -eq 'Running' }

$anybox | Show-AnyBox

###

$null = $job | Receive-Job -Wait -AutoRemoveJob

More resources

This guide was reworked as of AnyBox v0.3.4. More extensive docs exist at:

https://www.donaldmellenbruch.com/doc/anybox/

Cheers!

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].