[python-win32] python-win32 Digest, Vol 73, Issue 32
Khalid Moulfi
farplagek at gmail.com
Thu Apr 30 21:12:08 CEST 2009
Thks Tim Roberts for your explanation, I'll try it with version 2.2.1
Regards
KM
On Thu, Apr 30, 2009 at 8:46 PM, <python-win32-request at python.org> wrote:
> Send python-win32 mailing list submissions to
> python-win32 at python.org
>
> To subscribe or unsubscribe via the World Wide Web, visit
> http://mail.python.org/mailman/listinfo/python-win32
> or, via email, send a message with subject or body 'help' to
> python-win32-request at python.org
>
> You can reach the person managing the list at
> python-win32-owner at python.org
>
> When replying, please edit your Subject line so it is more specific
> than "Re: Contents of python-win32 digest..."
>
>
> Today's Topics:
>
> 1. Re: Extract icon from exe files (Nicolas EISEN)
> 2. Re: PythonWin IDE: how to assign a function/code to key F1
> etc. ? (Robert)
> 3. gpedit reload method in python (le dahut)
> 4. Re: Retrieve informations from NIST file. (Tim Roberts)
>
>
> ----------------------------------------------------------------------
>
> Message: 1
> Date: Thu, 30 Apr 2009 17:11:39 +0200
> From: Nicolas EISEN <neisen at linbox.com>
> Subject: Re: [python-win32] Extract icon from exe files
> To: Python-Win32 List <python-win32 at python.org>
> Message-ID: <49F9BFAB.7020508 at linbox.com>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
>
> Tim Roberts a ?crit :
> > EISEN Nicolas wrote:
> >
> >>>
> >>>
> >> I'm lucky, I found ...
> >>
> >> My Source :
> >>
> >> /from win32gui import *
> >> import win32con
> >> from pywintypes import HANDLE
> >> import win32ui
> >> listHicon = ExtractIconEx("c:\OpenOffice.exe",0)
> >> tupleIcon = GetIconInfo (HANDLE ( listHicon[0][0] ) )
> >>
> >> bitmapColor = tupel [4]
> >>
> >> picture = win32ui.CreateBitmap()
> >> buffer = picture.GetBitmapBits ( bitmapColor )
> >> /
> >>
> >> Python return :
> >> /win32ui.error: GetObject failed on bitmap/
> >> for the last line
> >>
> >> win32ui have CreateBitmap with 0 argument and GetBitmapBits with 1
> >> arguments
> >> but win32gui have CreateBitmap with 5 arguments and GetBitmapBits have
> >> 2 arguments
> >>
> >
> > Yes. Can't you see why? win32gui is just a thin wrapper around the
> > actual Win32 APIs. win32ui is an attempt to turn those APIs into
> > something more like Python objects. Objects have access to additional
> > state, so you don't have to specify as many parameters. When you call
> > picture.GetBitmapBits( bitmapColor )
> >
> > That's getting the pixels from the bitmap you just created. The
> > parameter it takes is the number of bytes is should copy (so you're
> > passing garbage). Your bitmap doesn't contain anything yet -- you
> > haven't even set the size -- so naturally the GetBitmapBits call fails.
> >
> > You need to do EXACTLY what the demo does. Create a bitmap, set its
> > size, then draw the icon on the bitmap, THEN pull the bits from the
> > bitmap. The icon doesn't actually contain bitmaps. It contains arrays
> > of pixels, but you need them to be a bitmap.
> >
> >
> >
> >> On the demo, hicon is use ton create the variable nid and re use it to
> >> display on the screen, but i want get only the bitmap bits.
> >>
> >
> > I'm not sure why you think these two things are different. The way you
> > get the bitmap bits is to draw the icon on a bitmap.
> >
> >
>
> With demo_menu, I script it :
>
> /from win32gui import */
> /import win32con/
> /from win32api import GetSystemMetrics/
>
>
> /ico_x = GetSystemMetrics(win32con.SM_CXSMICON)/
> /ico_y = GetSystemMetrics(win32con.SM_CYSMICON)/
>
> /large, small = ExtractIconEx("c:\dxdiag.exe",0)/
> /hicon = small[0]/
> /print type(hicon)/
> /DestroyIcon(large[0])/
>
> /#creating a source memory DC and selecting a icon in it/
> /srcDC = CreateCompatibleDC(0)/
> /SelectObject(srcDC,hicon);/
>
> /#creating a destination memory DC and selecting a memory bitmap to it/
> /hdcBitmap = CreateCompatibleDC(0)/
> /hdcScreen = GetDC(0)/
> /hbm = CreateCompatibleBitmap(hdcScreen, ico_x, ico_y)/
> /SelectObject(hdcBitmap, hbm)/
>
> /# copies source DC to memory DC resulting in a copy of hicon in hbm/
> /BitBlt(hdcBitmap,0,0,ico_x,ico_y,srcDC,0,0,win32con.SRCCOPY);/
>
> /bitmap = CreateBitmapFromHandle(hbm)/
> /hbm.SaveBitmapFile()/
>
> /DeleteDC(srcDC);/
> /DeleteDC(hdcBitmap);
> /
>
>
> I suppose, I have my icon picture on the Bitmap /hbm/ but how I get
> file's bits or how I save it ?
>
> There are SaveBitmapFile or GetBitmapBits methods on win32ui (PyCBitmap)
> but I test many disposition, I have always type problem between win32gui
> and win32ui objects.
> I try to use win32gui DC with icon and win32ui DC with bitmap, but
> always the type doesn't work : PyHandle (win32gui) is different from
> PyBitmap (win32ui).
>
> Please Help ! I 'm tired ...
>
>
> ------------------------------
>
> Message: 2
> Date: Thu, 30 Apr 2009 17:37:48 +0200
> From: Robert <kxroberto at googlemail.com>
> Subject: Re: [python-win32] PythonWin IDE: how to assign a
> function/code to key F1 etc. ?
> To: python-win32 at python.org
> Message-ID: <gtcgk2$86a$1 at ger.gmane.org>
> Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"
>
> Mark Hammond wrote:
> > Robert wrote:
> >> want to put new functions (short python code) on keys like F1, F12,
> >> Ctrl-F1 and other keys.
> >> Is there a mechanism/recipe ?
> >
> >
> > Look for the *.cfg files in the pythonwin directory.
> >
>
> Thanks.
>
> maybe some of the following stuff is useful for somebody, or for
> future PythonWin default:
>
> In attachment a patch for pywin/default.cfg, which does context
> (word) sensitive help from editor into Python Help and PythonWin Help
>
> F1 = HelpPy
> Ctrl+F1 = HelpPyWin
> ..
>
> and allows for faster edit-run cycle: running/interacting with
> (auto-unindented) selected code lines from editor
>
> Ctrl+K = Interact_SelectedLines
> Ctrl+E = ExecGlobal_SelectedLines
>
> ( the little patch of scintilla/config.py enables correct line
> numbers for traceback and debugging of code in default.cfg )
>
> -
>
> Also CtrlEnter.patch (-> framework/interact.py), which enables
> ad-hoc debugging from interactive pane (Ctrl-Enter) into an
> interactive statement (without long-winded F5 running into
> breakpoints etc). I did not put the code into default.cfg, because
> a lot of pre-processing code is shared with normal interactive
> statement execution.
>
>
> Robert
> -------------- next part --------------
> An embedded and charset-unspecified text was scrubbed...
> Name: cfg.patch
> URL: <
> http://mail.python.org/pipermail/python-win32/attachments/20090430/c26cfe43/attachment-0002.txt
> >
> -------------- next part --------------
> An embedded and charset-unspecified text was scrubbed...
> Name: CtrlEnter.patch
> URL: <
> http://mail.python.org/pipermail/python-win32/attachments/20090430/c26cfe43/attachment-0003.txt
> >
>
> ------------------------------
>
> Message: 3
> Date: Thu, 30 Apr 2009 17:30:48 +0200
> From: le dahut <le.dahut at laposte.net>
> Subject: [python-win32] gpedit reload method in python
> To: python-win32 at python.org
> Message-ID: <49F9C428.3080509 at laposte.net>
> Content-Type: text/plain; charset=ISO-8859-15; format=flowed
>
> Hello,
>
> "gpedit.msc" can change several parameters in system for example items
> in start menu or hidden drives in explorer. The changes made in "gpedit"
> are immediately applied, if you have "My computer" opened you can see
> selected letters disappear.
> I know that "gpedit" modifies
> HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\Explorer\NoDrives.
> But I don't know how "gpedit" updates the system, what sort of system
> call is done.
>
> I've already tried :
> win32gui.SendMessage(win32con.HWND_BROADCAST,
> win32con.WM_SETTINGCHANGE, 0, 'Environment')
> and the commande :
> RunDll32.exe USER32.DLL,UpdatePerUserSystemParameters ,1 ,True
> without success.
>
> Does someone know more about this ?
> Are there other API calls that update the system ?
>
>
> K.
>
>
>
> ------------------------------
>
> Message: 4
> Date: Thu, 30 Apr 2009 09:46:19 -0700
> From: Tim Roberts <timr at probo.com>
> Subject: Re: [python-win32] Retrieve informations from NIST file.
> To: Python-Win32 List <python-win32 at python.org>
> Message-ID: <49F9D5DB.6040305 at probo.com>
> Content-Type: text/plain; charset=ISO-8859-1
>
> Khalid Moulfi wrote:
> >
> > thanks for your quick answer.
> > Here is a sample of the first line of the NIST file :
> >
> > 1.001:0000000245 1.002:3000 1.003:1 19 2 0 4 1 4 2 4 3 4 4 4 5 4 6 4 7 4
> 8 4 9 4 10 4 11 4 12 4 13 4 14 15 15 15 16 15 17 15 18 1.004:NPS
> 1.005:20081029 1.006:4 1.007:51/Live
> > Scan 1.008:51/Live Scan 1.009:0844251404U 1.011:19.6850 1.012:19.6850
> 2.001:0000000188 2.002:0 2.003:3000 2.010:1005000190 2.019:20081029 2.029:0
> 2.054:Civilian 2.083:01 NA 02 NA 03 NA 04 NA 05 NA 06 NA 07 NA 08 NA 09 NA
> 10 NA 2.233:???? 2.235:1011973400606
> >
> > but as the end of the line is not displayed, I send you a copy of the
> > file with all the line.
>
> That's because your file contains null bytes ('\x00'). The string you
> display above shows everything up to the first null.
>
>
> > The thing is even if I take the number of character from let's say
> > 2.001 to the end of the line I do not get the real number of charatcer.
>
> What do you mean by that? Where did the numbers come from? The file
> contains one line of 471 bytes, including the newline. Does that agree
> with either of your sources?
>
>
> > My goal is to modify this first line by adding new tag (with special
> > character), suppress some of them, get the real number of length and
> > after all this update to modify it in the original nst file.
> >
> > I'll try as you said to open it with rb parameters and see.
>
> You will have to show me your code, along with what numbers you expect.
> The file you sent is 471 bytes long, and that's exactly what I read, in
> both text and binary modes:
>
> C:\tmp>python
> Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> x = open('sample_1005000190.nst')
> >>> y = open('sample_1005000190.nst', 'rb')
> >>> x1 = x.read()
> >>> y1 = y.read()
> >>> len(x1)
> 471
> >>> len(y1)
> 471
> >>> x1.find('2.001')
> 245
> >>> x1[-2:]
> '\x00\n'
> >>> y1[-2:]
> '\x00\n'
> >>> x.seek(0,0)
> >>> x2 = x.readlines()
> >>> len(x2)
> 1
> >>> len(x2[0])
> 471
> >>>
>
> The "2.001" is located at byte 245, so there should are 126 bytes from
> there to the end of the line. However, there are zero bytes (meaning
> '\x00') in this file, which might be confusing you.
>
> You have to know something about this data format to know how to modify
> it. It looks like the file consists of two major sections, separated by
> 0x1C characters. The major sections are then divided into records
> separated by 0x1D characters. Some of the records have fields in them,
> separated by 0x1E. There are 38 bytes of what look like garbage after
> the last field. So, you could parse it into records like this:
>
> Python 2.4.1 (#65, Mar 30 2005, 09:13:57) [MSC v.1310 32 bit
> (Intel)] on win32
> Type "help", "copyright", "credits" or "license" for more information.
> >>> x = open('sample_1005000190.nst','rb').read()
> >>> sections = x.split('\x1c')
> >>> len(sections)
> 3
> >>> [len(k) for k in sections]
> [244, 187, 38]
> >>> rec1 = sections[0].split('\x1d')
> >>> rec2 = sections[1].split('\x1d')
> >>> len(rec1)
> 11
> >>> len(rec2)
> 10
> >>> rec1
> ['1.001:0000000245', '1.002:3000',
> '1.003:1\x1f19\x1e2\x1f0\x1e4\x1f1\x1e4\x1f2\
>
> x1e4\x1f3\x1e4\x1f4\x1e4\x1f5\x1e4\x1f6\x1e4\x1f7\x1e4\x1f8\x1e4\x1f9\x1e4\x1f10
>
> \x1e4\x1f11\x1e4\x1f12\x1e4\x1f13\x1e4\x1f14\x1e15\x1f15\x1e15\x1f16\x1e15\x1f17
> \x1e15\x1f18', '1.004:NPS', '1.005:20081029', '1.006:4',
> '1.007:51/Live Scan', '
> 1.008:51/Live Scan', '1.009:0844251404U', '1.011:19.6850',
> '1.012:19.6850']
> >>> rec2
> ['2.001:0000000188', '2.002:0', '2.003:3000', '2.010:1005000190',
> '2.019:2008102
> 9', '2.029:0', '2.054:Civilian',
> '2.083:01\x1fNA\x1e02\x1fNA\x1e03\x1fNA\x1e04\x
>
> 1fNA\x1e05\x1fNA\x1e06\x1fNA\x1e07\x1fNA\x1e08\x1fNA\x1e09\x1fNA\x1e10\x1fNA',
> '
> 2.233:\xc8\xcf\xe6\xe4', '2.235:1011973400606']
> >>>
>
>
> Here, "sections" contains the three major sections. "rec1" contains the
> records from the first section. If you wanted to add a "1.013" record
> to the first section, you could say:
> rec1.append( "1.013:Cool Beans" )
> and then rebuild the file by saying:
> newsections = ['\x1d'.join(rec1), '\x1d'.join(rec2), sections[2]]
> open('newfile.nst','wb').write ('\x1c'.join(newsections) )
>
> But that assumes there's nothing in that garbage 3rd section that needs
> to be changed.
>
> It's just a matter of dividing the problem up into smaller problems
> until the solution pops out.
>
> --
> Tim Roberts, timr at probo.com
> Providenza & Boekelheide, Inc.
>
>
>
> ------------------------------
>
> _______________________________________________
> python-win32 mailing list
> python-win32 at python.org
> http://mail.python.org/mailman/listinfo/python-win32
>
>
> End of python-win32 Digest, Vol 73, Issue 32
> ********************************************
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-win32/attachments/20090430/ca037706/attachment-0001.htm>
More information about the python-win32
mailing list