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
SHA1:c12edca429f097c1c6c8ea605d6a19ef171d3e64
Date: 2018-04-22 22:49:55
User: mario
Comment:Undo $results._proceed=1 default, as window closing would leave it default.
Tags And Properties
  • branch=trunk inherited from [7e2f1fd24a]
  • sym-trunk inherited from [7e2f1fd24a]
Context
2018-04-22
22:49
[c12edca429] Leaf: Undo $results._proceed=1 default, as window closing would leave it default. (user: mario, tags: trunk)
19:45
[d4ba9808be] Remove logging from Out-Gui (user: mario, tags: trunk)
Changes

Changes to modules/guimenu.psm1.

763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
...
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
...
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
            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 }
            }}
................................................................................
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"}
................................................................................
          }),
          (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 }
            }







|







 







|







 







|









|







763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
...
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
...
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
            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 }
            }}
................................................................................
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"}
................................................................................
          }),
          (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 }
            }