Question [Outil gratuit]PrimalForms from Sapien

Plus d'informations
il y a 17 ans 4 mois #3192 par Laurent Dardenne
Un outil gratuit de conception de Winform générant du code PowerShell:
PowerShell Winforms - PrimalForms from Sapien

Un exemple :
[code:1]
#Generated Form Function
function GenerateForm {
########################################################################
# Code Generated By: SAPIEN Technologies PrimalForms 2009 v1.0.0.0
# Generated On: 06/11/2008 21:50
# Generated By: Dardenne
########################################################################

#region Import the Assembles
[reflection.assembly]::loadwithpartialname(\"System.Windows.Forms\"«») | Out-Null
[reflection.assembly]::loadwithpartialname(\"System.Drawing\"«») | Out-Null
#endregion

#region Generated Form Objects
$form1 = New-Object System.Windows.Forms.Form
$éçdùoied = New-Object System.Windows.Forms.PropertyGrid
$comboBox1 = New-Object System.Windows.Forms.ComboBox
$notifyIcon1 = New-Object System.Windows.Forms.NotifyIcon
#endregion Generated Form Objects

#
#Generated Event Script Blocks
#
#Provide Custom Code for events specified in PrimalForms.
$handler_notifyIcon1_BalloonTipClicked=
{
#TODO: Place custom script here

}

$handler_form1_Click=
{
#TODO: Place custom script here

}

$handler_comboBox1_SelectedIndexChanged=
{
#TODO: Place custom script here

}

$handler_form1_FormClosing=
{
#TODO: Place custom script here

}

$handler_comboBox1_Click=
{
#TODO: Place custom script here

}

#
#region Generated Form Code
$form1.Text = 'Primal Form'
$form1.Name = 'form1'
$form1.DataBindings.DefaultDataSourceUpdateMode = 0
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 292
$System_Drawing_Size.Height = 266
$form1.ClientSize = $System_Drawing_Size
$form1.add_Click($handler_form1_Click)
$form1.add_FormClosing($handler_form1_FormClosing)

$éçdùoied.CommandsActiveLinkColor = [System.Drawing.Color]::FromArgb(255,169,169,169)
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 130
$System_Drawing_Size.Height = 130
$éçdùoied.Size = $System_Drawing_Size
$éçdùoied.Name = 'éçdùoied'
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 46
$System_Drawing_Point.Y = 122
$éçdùoied.Location = $System_Drawing_Point
$éçdùoied.DataBindings.DefaultDataSourceUpdateMode = 0
$éçdùoied.CommandsLinkColor = [System.Drawing.Color]::FromArgb(255,255,255,0)
$éçdùoied.TabIndex = 1

$form1.Controls.Add($éçdùoied)

$comboBox1.FormattingEnabled = $True
$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 121
$System_Drawing_Size.Height = 21
$comboBox1.Size = $System_Drawing_Size
$comboBox1.DataBindings.DefaultDataSourceUpdateMode = 0
$comboBox1.Name = 'comboBox1'
$System_Drawing_Point = New-Object System.Drawing.Point
$System_Drawing_Point.X = 46
$System_Drawing_Point.Y = 22
$comboBox1.Location = $System_Drawing_Point
$comboBox1.TabIndex = 0
$comboBox1.add_SelectedIndexChanged($handler_comboBox1_SelectedIndexChanged)
$comboBox1.add_Click($handler_comboBox1_Click)

$form1.Controls.Add($comboBox1)

$notifyIcon1.Visible = $True
$notifyIcon1.Text = 'notifyIcon1'
$notifyIcon1.add_BalloonTipClicked($handler_notifyIcon1_BalloonTipClicked)

#endregion Generated Form Code

#Show the Form
$form1.ShowDialog()| Out-Null

} #End Function

#Call the Function
GenerateForm
[/code:1]
Les fichiers projet des Winforms sont au format Xml :
[code:1]

<Object type=\"PrimalForm.Form, PrimalForms, Version=5.0.3229.17428, Culture=neutral, PublicKeyToken=null\" name=\"form1\" children=\"Controls\">
<Object type=\"System.Windows.Forms.PropertyGrid, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\" name=\"éçdùoied\" children=\"Controls\">
<Property name=\"CommandsActiveLinkColor\">DarkGray</Property>
<Property name=\"Size\">130, 130</Property>
<Property name=\"Name\">éçdùoied</Property>
<Property name=\"Location\">46, 122</Property>
<Property name=\"DataBindings\">
<Property name=\"DefaultDataSourceUpdateMode\">OnValidation</Property>
</Property>
<Property name=\"CommandsLinkColor\">Yellow</Property>
<Property name=\"TabIndex\">1</Property>
</Object>
<Object type=\"System.Windows.Forms.ComboBox, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\" name=\"comboBox1\" children=\"Controls\">
<Property name=\"FormattingEnabled\">True</Property>
<Property name=\"Size\">121, 21</Property>
<Property name=\"DataBindings\">
<Property name=\"DefaultDataSourceUpdateMode\">OnValidation</Property>
</Property>
<Property name=\"Name\">comboBox1</Property>
<Property name=\"Location\">46, 22</Property>
<Property name=\"TabIndex\">0</Property>
<Event name=\"SelectedIndexChanged\">handler_comboBox1_SelectedIndexChanged</Event>
<Event name=\"Click\">handler_comboBox1_Click</Event>
</Object>
<Property name=\"Text\">Primal Form</Property>
<Property name=\"Name\">form1</Property>
<Property name=\"DataBindings\">
<Property name=\"DefaultDataSourceUpdateMode\">OnValidation</Property>
</Property>
<Property name=\"ClientSize\">292, 266</Property>
<Event name=\"Click\">handler_form1_Click</Event>
<Event name=\"FormClosing\">handler_form1_FormClosing</Event>
</Object>
<Object type=\"System.Windows.Forms.NotifyIcon, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089\" name=\"notifyIcon1\">
<Property name=\"Visible\">True</Property>
<Property name=\"Text\">notifyIcon1</Property>
<Event name=\"BalloonTipClicked\">handler_notifyIcon1_BalloonTipClicked</Event>
</Object>
[/code:1]
Ce qui, je pense, permettra une génération automatique de template ;).

Seul les composants standards de VS sont gérés, les composants tiers ne le sont pas.
De plus les composants ne supportant le mode de thread de PS v1 ne sont pas listés.
Mais la génération, à partir d'un projet, du code PS ne semble pas possible en ligne de commande.

Cela reste un outil trés intéressant.

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 17 ans 4 mois #3216 par Robin Lemesle
Effectivement, l'arrivé d'un editeur de formulaire graphique en PS (gratuit qui plus est) est un événement. Je vais en faire une news et un tuto.

Robin MVP PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 17 ans 4 mois #3223 par Laurent Dardenne
Robin écrit:

Effectivement, l'arrivé d'un editeur de formulaire graphique en PS (gratuit qui plus est) est un événement. Je vais en faire une news et un tuto.

Si tu as le temps regarde si cet outil gére les ressources.
Après reflexion je suppose que c'est une partie, limité en fonctionnalités, de la prochaine version de leur éditeur (PrimalScript).
Si j'ai le temps je regarde comment automatiser les appel à l'interface et manipuler le fichier de config XML sous PS.

Il reste un autre point, la V2 propose le paramètre -STA qui devrait permettre l'usage de certains composants qui sous la V1 ne peuvent être gérés, le BackGroundWorker par exemple.
Enfin là j'en demande peut être un peu trop ;-)

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 17 ans 4 mois #3229 par Laurent Dardenne
Pour les ressources il gére un fichier par ressource :
[code:1]
<Property name=\"Image\">G:\PS\Fichier-exemples\PSicon.jpg</Property>
[/code:1]
ce qui donne
[code:1]
$pictureBox1.Image = [System.Drawing.Image]::FromFile('G:\PS\Fichier-exemples\PSicon.jpg')
[/code:1]
La méthode FormFile ne supporte pas les chemins relatifs \".\ressources\PSicon.jpg\" et verrouille le fichier tant que la méthode Dispose n'est pas appelé :
[code:1]
$pictureBox1.Image.Dispose()
[/code:1]
Mais le soft ne gére pas cet appel.
On peut retrouver les lignes appellant cette méthode :
[code:1]
$Lines=select-string -path Test1.ps1 \"]::FromFile\"
foreach ($Mi in $Lines) {$Mi.Line}
[/code:1]
Reste ensuite à automatiser la génération des lignes d'appel à Dispose...

Les menus ne sont pas proposés dans les listes des composants et un seul composant de type panel est proposé (System.Windows.Forms.Panel).

Je pense que le script Convert-Form reste dans la course :-)

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 17 ans 4 mois #3231 par Laurent Dardenne
Pour modifier les noms de chemin dans le fichier XML :
[code:1]
cd \"$env:UserProfile\Mes Documents\Sapien\Forms\"

[xml] $Frm=Get-Content Test.pff
$Frm
$NewPath=\"C:\temp\Res\"

$SbChangepath={ param ([String] $OldFullName,[String] $NewDirectory)
\"{0}\{1}\" -F $NewDirectory,$([System.IO.Path]::GetFilename($OldFullName))
}

$frm.object.object|`
#Recherche les lignes référençant des classes utilisant un fichier ressource
?{$_.GetAttribute(\"type\"«») -match \"(.PictureBox|.Button)\"}|`
# Recherche dans les noeuds celui nommé image
% {$_.property|? {$_.name -eq \"Image\"}|`
# et possédant un noeud \"#text\" renseigné
? {$_.\"#text\" -ne $null}|`
#On modifie le nom du répertoire
% {$_.\"#text\"=( &$SbChangepath $($_.\"#text\"«») $NewPath) } }

$Frm.Save(\"$pwd\Test01.pff\"«»)
[/code:1]

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Plus d'informations
il y a 17 ans 4 mois #3232 par Laurent Dardenne
Et enfin l'automatisation du chargement et de la génération:
[code:1]
#Nécessite les cmdlets 'WASP' : www.codeplex.com/WASP

&\"C:\Program Files\Sapien Technologies, Inc\PrimalForms\PrimalForms.exe\"
Start-Sleep 2
$PFHandle=( Get-Process \"PrimalForms\" ).MainWindowHandle

$XMLFileName=\"Test2.pff\"
$Directory=\"$env:UserProfile\Mes Documents\Sapien\Forms\"
$Pff=$Directory+\"\\"+$XMLFileName

#Touches :http://msdn.microsoft.com/fr-fr/library/system.windows.forms.sendkeys(VS.80).aspx
#Open: Control-O
#Insére le nom complet du fichier projet
#Valide par enter
Send-keys -Window $PFHandle -keys \"^o$Pff{Enter}\"
#Enregistre sous: Control-E
#Génére le script
#Quitte Alt-F4
Send-keys -Window $PFHandle -keys \"^e{Enter} %({F4})\"
#
[/code:1]

Tutoriels PowerShell

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.106 secondes
Propulsé par Kunena