<html>
<head>
<title>Python Process Lister</title>
<HTA:APPLICATION
ID="processlister"
APPLICATIONNAME="Python Process Lister"
SCROLL="auto"
SCROLLFLAT = "yes"
SINGLEINSTANCE="yes"
>
<style type="text/css">
body {
background-color: #ababcd;
font-family: Verdana
font-size: 0.9 em;
color: #fff;
}
a:link {text-decoration: none; color:#343456}
a:visited {text-decoration: none;color:#343456}
a:active {text-decoration: none; color:#343456}
a:hover {text-decoration: underline; color:452200;}
</style>
</head>
<body onLoad="Initialisation()">
<center><h2>Liste des Process</h2></center>
<span id = "ProcessList"></span>
<!-- Script Python -->
<SCRIPT LANGUAGE="Python">
from win32com.client import GetObject
import win32gui
doc = document.All
ChaineConnexion = r"WinMgMts:\\%s\%s"
listProcess = []
process = None
def displayProc(args):
proc = None
numproc = int(args)
rep = window.confirm("Voulez-vous terminer le processus %s ?"%args )
if rep:
for p in process:
proc = p
if int(p.Handle) == numproc:
alert(u"Le processus %d va être supprimé"%numproc)
break
proc.Terminate
def getAllObjects(serveur = ".", espaceDenom = "root\cimv2", classe = "Win32_Process"):
c = GetObject(ChaineConnexion%(serveur,espaceDenom))
objects = c.ExecQuery(r"select * from %s"%classe)
return objects
def Initialisation():
win32gui.MessageBox(0, " Hello From Python", "Message d'Invite", 0)
RefreshList()
iTimerID = window.setInterval("RefreshList()", 10000)
def RefreshList():
global process
process = getAllObjects()
result = "<table>"
for processus in process:
result += """<tr><td align="right">%4d</td>
<td style="padding-left:15px;"><a class="maya" href="#" onClick="displayProc(%d)">%s</a></div></td>
<td>%s</td>
</tr>"""%(int(processus.Handle),int(processus.Handle),processus.Name,processus.CommandLine)
result += "</table>"
doc.ProcessList.InnerHTML = result
</SCRIPT>
</body>
</html>
Thursday, July 19, 2007
HTA - Python : Gestionnaire de Tâches
Sunday, July 15, 2007
HTA : Arguments en ligne de commande
<HTML>
<HEAD>
<TITLE>HTA Demo</TITLE>
<HTA:APPLICATION ID="oHTA"
APPLICATIONNAME="myApp"
BORDER="thin"
BORDERSTYLE="normal"
CAPTION="yes"
ICON=""
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
SHOWINTASKBAR="no"
SINGLEINSTANCE="no"
SYSMENU="yes"
VERSION="1.0"
WINDOWSTATE="maximize"/>
<SCRIPT language="Python">
d = document.all
lienMSN = "http://msdn2.microsoft.com/en-us/library/ms536495.aspx"
def window_onload():
sTempStr = "applicationName = " + d.oHTA.applicationName + "<br />"
sTempStr += "commandLineName = " + d.oHTA.commandLine + "<br />"
d.oPre.innerHTML = '<a href="%s">%s</a>'%(lienMSN,lienMSN) + "<br />" + sTempStr
</SCRIPT>
</HEAD>
<BODY SCROLL="no">
<p>Les arguments doivent suivre le nom du script et être entourés de guillemets</p>
<PRE ID=oPre></PRE>
</BODY>
</HTML>
Python et WMI
WMI (Windows Managment Instrumentation) est un ensemble de classes permettant d'auditer des serveurs Windows.
L'accés à ces classe est très aisée en Python comme le montre cet exemple:
L'accés à ces classe est très aisée en Python comme le montre cet exemple:
from win32com.client import GetObject
ChaineConnexion = r"WinMgMts:\\%s\%s"
def getAllObjects(serveur = ".", espaceDenom = "root\cimv2", classe = "Win32_Process"):
c = GetObject(ChaineConnexion%(serveur,espaceDenom))
objects = c.ExecQuery(r"select * from %s"%classe)
return objects
def test():
allObj = getAllObjects()
for proc in allObj:
print proc.Name
if __name__ == "__main__":
test()
Thursday, July 12, 2007
Python et HTA
Python peut parfaitement être utlisé dans les scripts HTA.
Ce qui est un avantage indéniable par rapport à l'utilisation de vbscript.
Ce qui est un avantage indéniable par rapport à l'utilisation de vbscript.
<html>
<head>
<TITLE>HTML Application Example</TITLE>
<HTA:APPLICATION ID="HTAEx" APPLICATIONNAME="HTAEx" ICON="e.ico" WINDOWSTATE="normal">
</head>
<body onLoad="Initialisation()">
<center><h1>Python in HTML Application</h1></center>
<FORM>
<INPUT TYPE="text" name="gauche">
<INPUT TYPE="button" name="gbutton" value = "MAJ Gauche">
</FORM>
<FORM>
<INPUT TYPE="text" name="centre">
<INPUT TYPE="button" name="cbutton" value = "MAJ Centre">
</FORM>
<FORM>
<INPUT TYPE="text" name="droite">
<INPUT TYPE="button" name="dbutton" value = "MAJ Droite">
</FORM>
<table width="100%" border=0>
<tr>
<td width="33%" valign="top" border= "black"><div id="tabgauche"> </div></td>
<td width="33%" valign="top"><div id="tabcentre"> </div></td>
<td width="33%" valign="top"><div id="tabdroite"> </div></td>
</tr>
</table>
<div id="espace"></div>
Sélectionnez une option :<br />
<select size="3" name="liste" onChange="SelectOption()">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
</select>
<!-- Script -->
<script language=Python>
import win32gui
import os
def GetValue(id):
#return document.getElementById(id).value
return document.getElementById(id).getAttribute("value")
def Initialisation():
win32gui.MessageBox(0, " Hello From Python", "Message d'Invite", 0)
d = document.getElementById('espace')
sp = " "*5
d.innerHTML = sp
def SelectOption(*args):
option = GetValue('liste')
win32gui.MessageBox(0, "Option : %s"%option, "Valeur de la Selection", 0)
def gbutton_Onclick():
valeur = GetValue('gauche')
div = document.getElementById('tabgauche')
div.innerHTML = valeur
def cbutton_Onclick():
valeur = GetValue('centre')
div = document.getElementById('tabcentre')
div.innerHTML = valeur
def dbutton_Onclick():
valeur = GetValue('droite')
div = document.getElementById('tabdroite')
div.innerHTML = valeur
</script>
</body>
</html>
Les Scripts HTA
Les applications 'hta' sont de simples fichiers html ayant pout extension 'hta'.
Leur intérêt, entre autre, est qu'il sont interprétes par Windows comme de véritables
applications. Ils permettent ainsi l'utilisation de tous les composants 'html' dans les
scripts écrits en vbscript ou tout autre langage supporté par wsh.
<html>
<head>
<title>Running a Script from Text</title>
<HTA:APPLICATION
ID="objScriptFromText"
APPLICATIONNAME="Running a Script from Text"
SCROLL="auto"
SINGLEINSTANCE="yes"
>
</head>
<SCRIPT Language="VBScript">
Sub RunScript
Msgbox "The script has run."
End Sub
Sub Pointer
document.body.style.cursor = "hand"
End Sub
Sub DefaultCursor
document.body.style.cursor = "default"
End Sub
</SCRIPT>
<body bgcolor="buttonface">
<span id="ClickableSpan" onClick="RunScript" onmouseover="Pointer"
onmouseout="DefaultCursor">
Click here to run the script</span>
</body>
</html>
Tuesday, June 5, 2007
XNA - Boo
Voci un exemple pour Boo, adapté de C# par Cédric Vidier.
Voci un exemple pour Boo, adapté de C# par Cédric Vidier.
namespace SimpleExample
import System
import System.Collections.Generic
import Microsoft.Xna.Framework
import Microsoft.Xna.Framework.Audio
import Microsoft.Xna.Framework.Content
import Microsoft.Xna.Framework.Graphics
import Microsoft.Xna.Framework.Input
import Microsoft.Xna.Framework.Storage
///
/// When run, you'll see an empty blue screen. This code can
/// be run in both Mono.Xna and Microsoft XNA without changing
/// any code.
///
class SimpleExampleGame(Microsoft.Xna.Framework.Game):
graphics as GraphicsDeviceManager
content as ContentManager
def constructor():
graphics = GraphicsDeviceManager(self)
content = ContentManager(Services)
/// Allows the game to perform any initialization it needs to before starting to run.
/// This is where it can query for any required services and load any non-graphic
/// related content. Calling base.Initialize will enumerate through any components
/// and initialize them as well.
protected override def Initialize():
// TODO: Add your initialization logic here
super()
/// Load your graphics content. If loadAllContent is true, you should
/// load content from both ResourceManagementMode pools. Otherwise, just
/// load ResourceManagementMode.Manual content.
///Which type of content to load.
protected override def LoadGraphicsContent(loadAllContent as bool):
if loadAllContent:
// TODO: Load any ResourceManagementMode.Automatic content
pass
// TODO: Load any ResourceManagementMode.Manual content
/// Unload your graphics content. If unloadAllContent is true, you should
/// unload content from both ResourceManagementMode pools. Otherwise, just
/// unload ResourceManagementMode.Manual content. Manual content will get
/// Disposed by the GraphicsDevice during a Reset.
///Which type of content to unload.
protected override def UnloadGraphicsContent(unloadAllContent as bool):
if unloadAllContent:
content.Unload()
/// Allows the game to run logic such as updating the world,
/// checking for collisions, gathering input and playing audio.
///Provides a snapshot of timing values.
protected override def Update(gameTime as GameTime):
// Allows the default game to exit on Xbox 360 and Windows
if GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed:
Exit()
// TODO: Add your update logic here
super(gameTime)
/// This is called when the game should draw itself.
///Provides a snapshot of timing values.
protected override def Draw(gameTime as GameTime):
graphics.GraphicsDevice.Clear(Color.CornflowerBlue)
// TODO: Add your drawing code here
super(gameTime)
Sunday, June 3, 2007
XNA - IronPython
IronPython et la version du célèbre langage (mon favori en fait) porté sur la plateforme .NET.
Xna et le framework de développement de jeux pour XBOX et Windows .Net. Voici un petit exemple écrit par Leaf:
Xna et le framework de développement de jeux pour XBOX et Windows .Net. Voici un petit exemple écrit par Leaf:
import clr
clr.AddReference('Microsoft.Xna.Framework')
clr.AddReference('Microsoft.Xna.Framework.Game')
from Microsoft.Xna.Framework import *
from Microsoft.Xna.Framework.Graphics import *
from Microsoft.Xna.Framework.Content import *
class MyGame(Game):
def __init__(self):
self.spriteX = self.spriteY = 0
self.spriteSpeedX = self.spriteSpeedY = 1
self.InitializeComponent()
def InitializeComponent(self):
self.graphics = GraphicsDeviceManager(self)
self.content = ContentManager(self.Services)
def LoadGraphicsContent(self, loadAllContent):
if loadAllContent:
self.texture = Texture2D.FromFile(self.graphics.GraphicsDevice, "sprite.jpg")
self.spriteBatch = SpriteBatch(self.graphics.GraphicsDevice)
def UnloadGraphicsContent(self, unloadAllContent):
if unloadAllContent:
self.texture.Dispose()
self.spritebatch.Dispose()
def Update(self, gameTime):
self.UpdateSprite()
Game.Update(self, gameTime)
def UpdateSprite(self):
self.spriteX += self.spriteSpeedX
self.spriteY += self.spriteSpeedY
maxX = self.graphics.GraphicsDevice.Viewport.Width - self.texture.Width
if self.spriteX > maxX:
self.spriteSpeedX *= -1
self.spriteX = maxX
elif self.spriteX < 0:
self.spriteSpeedX *= -1
self.spriteX = 0
maxY = self.graphics.GraphicsDevice.Viewport.Height - self.texture.Height
if self.spriteY > maxY:
self.spriteSpeedY *= -1
self.spriteX = maxY
elif self.spriteY < 0:
self.spriteSpeedY *= -1
self.spriteY = 0
def Draw(self, gameTime):
self.graphics.GraphicsDevice.Clear(Color.CornflowerBlue)
self.DrawSprite()
Game.Draw(self, gameTime)
def DrawSprite(self):
self.spriteBatch.Begin()
self.spriteBatch.Draw(self.texture, Rectangle(self.spriteX,
self.spriteY, self.texture.Width, self.texture.Height), Color.White)
self.spriteBatch.End()
game = MyGame()
game.Run()
Subscribe to:
Posts (Atom)