Powershell GUI fronted (WPF) to run categorized console scripts

⌈⌋ ⎇ branch:  ClickyColoury


Check-in [c12edca429]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Undo $results._proceed=1 default, as window closing would leave it default.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: c12edca429f097c1c6c8ea605d6a19ef171d3e64
User & Date: mario 2018-04-22 22:49:55
Context
2018-05-16
18:00
Move input form expander into scrollviewer check-in: d90fd410d2 user: mario tags: trunk
2018-04-22
22:49
Undo $results._proceed=1 default, as window closing would leave it default. check-in: c12edca429 user: mario tags: trunk
19:45
Remove logging from Out-Gui check-in: d4ba9808be user: mario tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to modules/guimenu.psm1.

763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
            elseif (Test-Path ($SELECT_FN -f $NAME)) { $ls = Get-Content ($SELECT_FN -f $NAME) } # read combobox.name.txt else
            else { $ls = @("Null") }
            if (!$VALUE) { $VALUE = $ls[0] }  # default value = first entry in select list
            return W ComboBox @{Height=22; Width=260; IsEditable=$true; Text=$VALUE; ItemsSource=$ls }
        }
        "btn|button|action" {
            return W Button @{Content="â–¶ "+$PARAM.description; Width=125; Height=26; HorizontalAlignment="Left"; Background="#cc77ff77"; Add_Click=[scriptblock]::create(
               '$results["{0}"] = 1; $w.Close()' -f $NAME   # scriptblock workaround, because $w lives in parent function scope, but $NAME only here
            )}
        }
        "file|choose" {
            return W Button @{Content="File → "+$PARAM.description; Background="#eeffee77"; Add_Click={
                $f = WF OpenFileDialog @{CheckFileExists=$false; Filter="Text (*.txt)|*.txt|CSV (*.csv)|*.csv|JSON (*.json)|*.json|XML (*.xml)|*.xml|Powershell (*.ps1)|*.ps1|All Files (*.*)|*.*"; SupportMultiDottedExtensions=$true; Title="Script '$NAME' file"}
                if ($f.ShowDialog() -and $f.FileName) { $this.Content = $f.FileName }
            }}







|







763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
            elseif (Test-Path ($SELECT_FN -f $NAME)) { $ls = Get-Content ($SELECT_FN -f $NAME) } # read combobox.name.txt else
            else { $ls = @("Null") }
            if (!$VALUE) { $VALUE = $ls[0] }  # default value = first entry in select list
            return W ComboBox @{Height=22; Width=260; IsEditable=$true; Text=$VALUE; ItemsSource=$ls }
        }
        "btn|button|action" {
            return W Button @{Content="â–¶ "+$PARAM.description; Width=125; Height=26; HorizontalAlignment="Left"; Background="#cc77ff77"; Add_Click=[scriptblock]::create(
               '$results._proceed = $results["{0}"] = 1; $w.Close()' -f $NAME   # scriptblock workaround, because $w lives in parent function scope, but $NAME only here
            )}
        }
        "file|choose" {
            return W Button @{Content="File → "+$PARAM.description; Background="#eeffee77"; Add_Click={
                $f = WF OpenFileDialog @{CheckFileExists=$false; Filter="Text (*.txt)|*.txt|CSV (*.csv)|*.csv|JSON (*.json)|*.json|XML (*.xml)|*.xml|Powershell (*.ps1)|*.ps1|All Files (*.*)|*.*"; SupportMultiDottedExtensions=$true; Title="Script '$NAME' file"}
                if ($f.ShowDialog() -and $f.FileName) { $this.Content = $f.FileName }
            }}
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
function Read-GuiExtraParams {
    Param(
       $meta = @{
          title="INPUT"; description="EXAMPLE"; doc="META"; version="0.0";
          vars=@( @{name="mail"; type="string"; description="email addr"; value="user@local"} )
       },
       $height = 450, $CURRENT_STORE = $GUI.vars_previous,
       $vars = @{}, $widget_blocks = @(), $results = @{_proceed=1}
    )
    if (!$meta.vars) { return }

    #-- create input widgets, wrap in label and description
    $widget_blocks = $meta.vars | % {
        $vars[$_.name] = New-GuiVarInput $_ $CURRENT_STORE
        W Label @{Content=$_.name; FontWeight="Bold"}







|







791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
function Read-GuiExtraParams {
    Param(
       $meta = @{
          title="INPUT"; description="EXAMPLE"; doc="META"; version="0.0";
          vars=@( @{name="mail"; type="string"; description="email addr"; value="user@local"} )
       },
       $height = 450, $CURRENT_STORE = $GUI.vars_previous,
       $vars = @{}, $widget_blocks = @(), $results = @{_proceed=0}
    )
    if (!$meta.vars) { return }

    #-- create input widgets, wrap in label and description
    $widget_blocks = $meta.vars | % {
        $vars[$_.name] = New-GuiVarInput $_ $CURRENT_STORE
        W Label @{Content=$_.name; FontWeight="Bold"}
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
          }),
          (W DockPanel @{
            Add=@(
              (W Button @{Content="Cancel"; Width=70; Height=30; Dock="Right"; BackGround="Red";
                Add_Click={ $results._proceed = 0; $w.close() }
              }),
              (W Button @{Content="â–¶ Run"; Width=150; Height=30; BackGround="Green";
                Add_Click={ $w.close() }
              })
            )
          })
        )}#=stackpanel
      )
    })#=window
    [void]$w.ShowDialog()

    #-- fetch vars
    if ($results._proceed -or $proceed) {
        ForEach ($NAME in $vars.Keys) {
            $results[$NAME] = switch -regex ($meta.vars | ? { $_.name -eq $NAME } | % { $_.type}) {
                "bool"     { [int32]($vars[$NAME].IsChecked); break }
                "but|btn"  { $results[$NAME]; break } # already set in button scriptblock
                "file|cho" { $vars[$NAME].Content; break }
                "str|.*"   { $vars[$NAME].Text; break }
            }







|









|







830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
          }),
          (W DockPanel @{
            Add=@(
              (W Button @{Content="Cancel"; Width=70; Height=30; Dock="Right"; BackGround="Red";
                Add_Click={ $results._proceed = 0; $w.close() }
              }),
              (W Button @{Content="â–¶ Run"; Width=150; Height=30; BackGround="Green";
                Add_Click={ $results._proceed = 1; $w.close() }
              })
            )
          })
        )}#=stackpanel
      )
    })#=window
    [void]$w.ShowDialog()

    #-- fetch vars
    if ($results._proceed) {
        ForEach ($NAME in $vars.Keys) {
            $results[$NAME] = switch -regex ($meta.vars | ? { $_.name -eq $NAME } | % { $_.type}) {
                "bool"     { [int32]($vars[$NAME].IsChecked); break }
                "but|btn"  { $results[$NAME]; break } # already set in button scriptblock
                "file|cho" { $vars[$NAME].Content; break }
                "str|.*"   { $vars[$NAME].Text; break }
            }