(win32) speedfan api control
hello, If you run the Mainboard monitor, speedfan, here is an ActivePython script to force automatic fan control. http://www.almico.com/speedfan.php It's a great example of how clean the WinApi interface is in ActivePython. The script sets focus to the checkbox of interest and toggles the checkbox. AFAIK, speedfan will only start without fan control, requiring the user to manually check the checkbox to turn it on. hope someone finds it useful, tlviewer #!/usr/bin/python # author: [EMAIL PROTECTED] # date: April 1, 2005 # description: turn on SpeedFan automatic fan speed # keywords: speedfan readings #import win32api as ap import win32gui as wi import win32ui as ui import win32con as wc # dialog class name cl = "TJvXPCheckbox" try: hWndÂ=Âwi.FindWindowEx(Â0,Â0,Â"TForm1",Â"SpeedFanÂ4.20") printÂhWnd hWndÂ=Âwi.FindWindowEx(ÂhWnd,Â0,Â"TPageControl",Â"") printÂhWnd hWndÂ=Âwi.FindWindowEx(ÂhWnd,Â0,Â"TTabSheet",Â"Readings") printÂhWnd hWndÂ=Âwi.FindWindowEx(ÂhWnd,Â0,Âcl,Â"AutomaticÂfanÂspeed") printÂhWnd resÂ=Âwi.SetForegroundWindow(hWnd) res=wi.SendMessageTimeout(hWnd,wc.WM_LBUTTONDOWN,wc.MK_LBUTTON,0,2,75) resÂ=Âwi.SendMessageTimeout(ÂhWnd,wc.WM_LBUTTONUP,Â0,Â0,Â2,Â75Â) printÂres except: pass #end code -- http://mail.python.org/mailman/listinfo/python-list
win32: structured storage
hello,
In honor of the chm exploit that I got hit by last week, I trying
to code some ActivePython to list the directory inside a CHM.
CHM is supposed to be structured storage (ITSF). If a given CHM
file is infected it most likely has an embedded EXE file -- mine
had one called [Open.exe].
The following code works for Excell sheets, XLS, but fails for
CHM files.
# begin python
from win32com import storagecon as sc
import os, win32api
import pythoncom as pyc
from pywintypes import IID
its_clsid = IID('{5d02926a-212e-11d0-9df9-00a0c922e6ec}')
its_iid= IID('{88cc31de-27ab-11d0-9df9-00a0c922e6ec}')
#
pyc.CoInitialize()
# commented out after failing on my Win2k box
#pyc.CoCreateInstance( its_clsid,None,pyc.CLSCTX_INPROC_SERVER, its_iid)
m = sc.STGM_READ | sc.STGM_SHARE_EXCLUSIVE
# quarantined CHM virus
fname = "e:/batch/junkx.chm"
#fname = "C:/Documents and Settings/Administrator/My Documents/02_taxes.xls"
pss = pyc.StgOpenStorageEx( fname, m, sc.STGFMT_STORAGE,0, pyc.IID_IStorage)
ele = pss.EnumElements( 0, None,0)
obj = ele.next()
print obj[0]
obj = ele.next()
print obj[0]
# end python
with the XLS file, I get the names of the two sheets.
Is there another way to parse the central directory out of
a CHM file?
tia,
tlviewer
--
http://mail.python.org/mailman/listinfo/python-list
Re: win32: structured storage
"Robert Kern" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED]
> tlviewer wrote:
>
> > Is there another way to parse the central directory out of
> > a CHM file?
>
> google("chmlib python")
Anyone know the calling syntax for the functions?
PythonWin 2.3.2 (#49, Nov 13 2003, 10:34:54) [MSC v.1200 32 bit (Intel)] on
win32.
Portions Copyright 1994-2001 Mark Hammond
([EMAIL PROTECTED]) - see 'Help/About PythonWin' for further copyright
information.
>>> import os, sys
>>> import pychm._chmlib as chm
>>> obj=chm.chm_open('e:/batch/AdvCrypto')
>>> obj
>>> chm.chm_open('e:/batch/AdvCrypto')
>>> chm
>>> enm=chm.chm_enumerate()
Traceback (most recent call last):
File "", line 1, in ?
TypeError: chm_enumerate() takes exactly 4 arguments (0 given)
>>> chm.chm_enumerate(obj)
I doubt if the build is good ...
regards,
tlviewer
--
http://mail.python.org/mailman/listinfo/python-list
pygame on win32, image.fromstring()
hello,
The script below is a prototype for loading playing card images
from the bitmap resource in cards.dll (WinXP)
I like the idea of not keeping copies of the images
as files.
I'm able to extract the card images as files, then load
them in pygame as a surface, but I keep getting errors
when directly loading the image as string.
The call below never works, what I'm I doing wrong?
gm.image.fromstring()
I tried to use PIL too, but I can't tell yet if
pygame will accept the image string from PIL.
# begin python
import win32api as wi
import string as st
import pygame as gm
import Image as im
hnd = wi.LoadLibrary("c:/winnt/system32/cards.dll")
# this header works for 71x96x1BPP image
# must be one line
header = [ chr(0x42), chr(0x4D), chr(0xDE), chr(0x0D), chr(0x00), chr(0x00),
chr(0x00), chr(0x00), chr(0x00), chr(0x00), chr(0x4A), chr(0x00), chr(0x00),
chr(0x00)]
#sheader = ''.join([ chr(header[x]) for x in range(len(header))])
str = wi.LoadResource( hnd, 2, 11, 1033)
fp = open( "e:/batch/python/aceclub.bmp", "wt")
str = st.join(header,'') + str
fp.write( str)
fp.close ()
wi.FreeLibrary(hnd)
print len(str)
# gives: ValueError: String length does not equal format and resolution size
img = gm.image.fromstring(str,(71,96),"P")
#print img.mode
#fp = open("e:/batch/msdn/Bitmap_11.bmp", "rb")
obj = gm.image.load("e:/batch/python/aceclub.bmp")
print obj.get_rect()
--
http://mail.python.org/mailman/listinfo/python-list
Re: pygame on win32, image.fromstring()
"Greg Krohn" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] > tlviewer wrote: > > hello, > > hi > > > fp = open( "e:/batch/python/aceclub.bmp", "wt") > > wt? Should this be wb? > > > # gives: ValueError: String length does not equal format and resolution size > > img = gm.image.fromstring(str,(71,96),"P") > > The pygame docs say "P" is for 8bit pallete indices. When I look at the > properties of aceclub.bmp, Windows says it's Bit Depth is 4. I'm not sure if > they're talking about the same thing, though. If so, you could probably use PIL > to convert the depth. Yes, that was the trouble. Based on your suggestion, I now massage the image string with PIL, then fromstring() works! obj =Image.open(StringIO.StringIO(str)) #obj.convert( mode='P') # conversion is implicit, mode is 'P' already img = gm.image.fromstring(obj.tostring(),(71,96),"P") Next I'm going to load all 53 card resources into a list (array) of strings, then write it out, pickled. That should smooth out loading the game when I use 4-6 decks (Blackjack-21). thanks for getting to my post so quickly, tlviewer -- -- http://mail.python.org/mailman/listinfo/python-list
Re: pygame on win32, image.fromstring()
tlviewer wrote:
> Next I'm going to load all 53 card resources into a list (array) of
> strings, then write it out, pickled. That should smooth out loading the
>game when I use 4-6 decks (Blackjack-21).
# -*- coding: cp1252 -*-
"""
keywords: resource bitmap pickle
description: pickle resources from cards.dll
requires:
Pygame from www.pygame.org,
PIL from www.pythonware.com/products/pil/
WinXP out:
63 ioerror
64 ioerror
66 resource skipped
saving pickled list
closing
debugging
"""
# imports
import win32api as wi
import string as st
import pygame as gm
import Image as im
import StringIO
import win32con as wc
import os, sys
import pickle as pkl
# OS independent path -- win32 only
sysroot = os.environ.get('SYSTEMROOT')
# get module handle for cards DLL
hnd = wi.LoadLibrary(sysroot + '/system32/cards.dll')
"""
Loadresource returns the card image without a header! I dumped these
header strings from ResourceHacker. There are only 2 kinds: one for the
pictures, and one for Ace+numbers.
"""
# this header works for 71x96x1BPP image
pic_header = [ chr(0x42), chr(0x4D), chr(0xDE), chr(0x0D), chr(0x00), \
chr(0x00), chr(0x00), chr(0x00), chr(0x00), chr(0x00), chr(0x4A), \
chr(0x00), chr(0x00), chr(0x00)]
num_header = [ chr(0x42), chr(0x4D), chr(0xA0), chr(0x04), chr(0x00), \
chr(0x00), chr(0x00), chr(0x00), chr(0x00), chr(0x00), chr(0x20), \
chr(0x00), chr(0x00), chr(0x00)]
fname = 'pkl_deck.dat'
fname = os.curdir + '/' + fname
debugr=1
#init main array to hold the cards as strings
arr_cards=[]
def cards(fname):
#sheader = ''.join([ chr(header[x]) for x in range(len(header))])
if debugr!=0:
str = wi.LoadResource( hnd, 2, 1, 1033)
str = st.join(num_header,'') + str
fp = open( os.curdir + '/aceclub.bmp', "wb")
fp.write( str)
fp.close ()
for i in range(1,68):
#default header (num)
#print "fetch ", i
header = num_header
if i % 13 > 10:
header = pic_header
try:
str = wi.LoadResource( hnd, wc.RT_BITMAP, i, 1033)
except:
print "%d" % i, " resource skipped"
continue
str = st.join(header,'') + str
try:
obj = im.open(StringIO.StringIO(str))
arr_cards.insert(i,obj.tostring())
except IOError:
print "%d" % i, " ioerror"
pass
wi.FreeLibrary(hnd)
#
# pickle out the list
print "saving pickled list"
fp = open(os.curdir + '/pkl_deck.dat', "wb")
try:
pkl.dump( arr_cards, fp, 1) #binary size Win2k:312kB WinXP:445kB
except:
print "errored, but still closing file"
fp.close()
else:
print "closing"
fp.close()
#fp = open("e:/batch/msdn/Bitmap_11.bmp", "rb")
## main ##
# retrieve the deck from our pickled list, or repickle the list to file
if not os.path.exists(fname):
cards(fname)
else:
fp = open(os.curdir + '/pkl_deck.dat','rb')
val=fp.read()
print "pickled list len=",len(val)
fp.close
arr_cards=pkl.loads(val)
if debugr!=0:
img = gm.image.fromstring(arr_cards[11],(71,96),"P")
print "debugging",img, img.get_rect()
--
http://mail.python.org/mailman/listinfo/python-list
