pythoncom and IDispatch

2006-05-15 Thread fraca7
Hello. I got a little problem while using pythoncom to automate IE; for 
some reason, changing the 'selectedIndex' on an instance of 
IHTMLSelectElement doesn't fire the 'onchange' event (I guess this is a 
bug in mshtml).

So, I tried to get the 'onchange' event handler and call it myself. 
According to the docs, this is a simple IDispatch implementation and 
calling Invoke() should do the trick; I actually have a working example 
of this in Delphi.

But I can't manage to get it work in Python; the following code


 idisp = pythoncom.WrapObject(elt.onchange)
 idisp.Invoke(pythoncom.DISPID_VALUE,
  0x400, # LOCALE_USER_DEFAULT
  pythoncom.DISPATCH_METHOD,
  False)

fails with an AttributeError:

Traceback (most recent call last): 

   File "C:\Python22\Lib\site-packages\win32com\server\policy.py", line 
283, in _
Invoke_ 

 return self._invoke_(dispid, lcid, wFlags, args) 

   File "C:\Python22\Lib\site-packages\win32com\server\policy.py", line 
288, in _
invoke_ 

 return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, 
None)
   File "C:\Python22\Lib\site-packages\win32com\server\policy.py", line 
581, in _
invokeex_ 

 return func(*args) 

   File "ietest.py", line 44, in OnDocumentComplete 

 self.deleg.onDocumentComplete(Dispatch(disp), url) 

   File "ietest.py", line 122, in onDocumentComplete 

 self.current.onDocumentComplete(self, browser, url) 

   File "ietest.py", line 141, in onDocumentComplete 

 sink.nextStep() 

   File "ietest.py", line 96, in nextStep 

 self.current.onStart(self) 

   File "ietest.py", line 191, in onStart 

 False) 

pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, 'Python 
COM Serve
r Internal Error', 'Unexpected Python Error: exceptions.AttributeError: 
_Invoke_
', None, 0, -2147467259), None) 


Did I miss something ?

TIA
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Module written in C does not repond to Ctrl-C interruption.

2006-03-03 Thread fraca7
Bo Peng a écrit :
> Dear list,
> 
> I have not done a thorough test, but it occurs to me that
> 
> 1. python code can be interrupted by Ctrl-C.
> 2. A C module, if I add a main() function and run independently, can be 
> interrupted by Ctrl-C.
> 3. If I load the C module in python and run, the program will not 
> respond to Ctrl-C interruption. I have to kill python explicitly.
> 
> If this is a known behavior or just a special case of mine? Any fix to 
> it? I am using python 2.3.4 under Redhat EL4 with gcc 3.3.4.

You may want to call intrcheck() or PyErr_CheckSignals in your C code 
and react accordingly.

 From what I can see, PyErr_CheckSignals() returns 0 if no interrupt 
occurred and -1 (setting a KeyboardInterrupt exception) if one did.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mutable numbers

2006-02-21 Thread fraca7
fraca7 a écrit :
> Steve Holden a écrit :
> 
>> [Thinks: or maybe fraca7 just meant that integers will be garbage 
>> collected when there are no more references to them].
> 
> Actually I meant that the memory is reused, but the same integer won't 
> always have the same address.

And of course this means they're garbaged collected, but free() won't be 
called. I must read before answering :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mutable numbers

2006-02-21 Thread fraca7
Steve Holden a écrit :

> [Thinks: or maybe fraca7 just meant that integers will be garbage 
> collected when there are no more references to them].

Actually I meant that the memory is reused, but the same integer won't 
always have the same address.

I guess that in your example, the '121' is assigned the 'old' address of 
12100, and the result of the operation is assigned the next chunk; the 
following seems to confirm that:

  >>> id(12100)
  8628480
  >>> id(102)
  8628480
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mutable numbers

2006-02-21 Thread fraca7
Suresh Jeevanandam a écrit :
> # I am new to python.
> 
> In python all numbers are immutable. This means there is one object ( a 
> region in the memory ) created every time we do an numeric operation. I 
> hope there should have been some good reasons why it was designed this way.

The memory allocation for integers is optimized. 'Small' integers 
(between -5 and 100 IIRC) are allocated once and reused. The memory for 
larger integers is allocated once and reused whenever possible, so the 
malloc() overhead is negligible.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Mouse manipulation

2006-01-30 Thread fraca7
arkestra a écrit :
> I am writing a script that interacts with the computer screen.
> 
> Is there a module (either built in or add on) that would allow the
> script to manipulate the mouse pointer ? -- eg right click, move two
> pixels to the right, left click etc?


Under Windows, see the SendInput Win32 function (use win32all). Under 
Linux, you can write a C binding for the XTest extension.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: windows service problem

2005-10-03 Thread fraca7
JackPhil a écrit :

> the problem is i can run the service in debug mode, and it seems works
> fine(i can connect the server with browser), but when i start the
> service in the services control panel, i can't connect the server, the
> server seems not start, and i can't stop the service.

Make sure it doesn't output anything to stdout or stderr, I've run into 
problems with that. I always include this kind of code in NT services:

class Devnull:
 def write(self, bf):
 pass
 def close(self):
 pass
 def flush(self):
 pass

sys.stdout = sys.stderr = Devnull()
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: A rather unpythonic way of doing things

2005-09-29 Thread fraca7
Richie Hindle a écrit :
> [Peter]
> 
>>http://www.pick.ucam.org/~ptc24/yvfc.html
> 
> 
> [Jeff]
> 
>>Yuma Valley Agricultural Center?
>>Yaak Valley Forest Council?
> 
> 
> I went through the same process.  My guess is "Yes, Very F'ing Clever."
> Peter?
> 

print ''.join(map(lambda x: chrord(x) - ord('a')) + 13) % 26) + 
ord('a')), 'yvfc'))

:)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Migrate PYD Files

2005-09-08 Thread fraca7
David Duerrenmatt a écrit :

> Is there a way to use old pyd files (Python 1.5.2) with a newer version
> of Python without recompiling them?

No. In general, incrementing the middle version number means that the 
Python C API has changed in an incompatible manner. There are some 
exceptions (2.2 modules may work in 2.3) but there's no way you can use 
a 1.5 .pyd with Python >= 2.2. As far as I know.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Creating custom event in WxPython

2005-09-01 Thread fraca7
[EMAIL PROTECTED] a écrit :

> Now when my socket thread detects an incoming message, I need my main
> thread to interpret the message and react to it by updating the GUI.
> IMO the best way to achieve this is by having my socket thread send a
> custom event to my application's event loop for the main thread to
> process. However, I'm at a total loss as far as creating custom events
> is concerned. The WxWindows documentation isn't very helpful on this
> either.

I think this is what you're looking for:

# begin code

import wx

wxEVT_INVOKE = wx.NewEventType()

class InvokeEvent(wx.PyEvent):
 def __init__(self, func, args, kwargs):
 wx.PyEvent.__init__(self)
 self.SetEventType(wxEVT_INVOKE)
 self.__func = func
 self.__args = args
 self.__kwargs = kwargs

 def invoke(self):
 self.__func(*self.__args, **self.__kwargs)

class MyFrame(wx.Frame):
 def __init__(self, *args, **kwargs):
 wx.Frame.__init__(self, *args, **kwargs)
 self.Connect(-1, -1, wxEVT_INVOKE, self.onInvoke)

 def onInvoke(self, evt):
 evt.invoke()

 def invokeLater(self, func, *args, **kwargs):
 self.GetEventHandler().AddPendingEvent(InvokeEvent(func, args, 
kwargs))

# end code

This way, if frm is an instance of MyFrame, invoking 
frm.invokeLater(somecallable, arguments...) will invoke 'somecallable' 
with the specified arguments in the main GUI thread.

I found this idiom somewhere on the Web and can't remember where.

HTH
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Is my thread safe from premature garbage collection?

2005-09-01 Thread fraca7
[EMAIL PROTECTED] a écrit :

> Anyway, if anyone could make a definite statement on whether threads
> are safe from unwanted garbage collection, that'd be really great.
> Thanks in advance for any helpful replies!

As far as I know, the threading module keeps a reference around for each 
thread, until its target method returns. I frequently use a thread 
without keeping any reference to it and never encountered any problem.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Read from stdouton Popen on WinXP?

2005-08-17 Thread fraca7
mhenry1384 a écrit :
> I am trying to run a program and filter the output on Windows XP.
> Since I want to filter the output, I'd like to read it a line at a time
> and only print the lines I care about.

> [snip]

I had the exact same problem yesterday. This is an obvious use case for 
the "bufsize" parameter to os.popen4, except that the Windows 
implementation doesn't accept anything but -1...

The only way I can see out of this is to use win32api to launch the 
process through CreateProcess, then perform asynchronous I/O on its 
stdout using the OVERLAPPED structure in a call to ReadFile... Ugly...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gdb python C API

2005-07-21 Thread fraca7
[EMAIL PROTECTED] a écrit :

> Actually, take a look in the distribution at Misc/gdbinit.  In particular,
> check out the pystack command.

Wow, nice! This will be put to good use, thanks :)
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: gdb python C API

2005-07-21 Thread fraca7
derrick a écrit :

> are there any tools / methods that others have used to get what line of
> the python script is being executed while running in gdb? or if it would
> actually show me the source python script (instead of the the python c
> source) that would help.

I don't think so, but when having a memory problem I usually find 
valgrind very useful.

http://valgrind.org/

HTH
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: multi threading and win9x

2005-06-21 Thread fraca7
Tim Peters a écrit :

> All versions of Windows >= Win95 use threads heavily, have very solid
> thread support, and the Win32 API was thread-aware from the start 
> Thread _scheduling_ is pretty bizarre <= WinME, but process scheduling
> is too.  Don't try to use hundreds of threads <= WinME and you should
> be fine.

But note that Win95 has a system memory leak of about 5 Kb per thread,
if I recall correctly...
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Multithreaded Python FSM (Harel State Machines)

2005-06-16 Thread fraca7
Leonard J. Reder a écrit :

> [snip]

http://smc.sourceforge.net/

It's probably not what you're looking for, but it's the closest I can 
think of.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Case Sensitive, Multiline Comments

2005-05-30 Thread Fraca7
On Mon, 30 May 2005 20:56:22 +, Roel Schroeven wrote:

> You haven't looked very well though: there are actually quite a lot of 
> extra spaces. Still, it's nicely done indeed.

C-u M-q ?

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: write to the same file from multiple processes at the same time?

2005-05-27 Thread fraca7
gabor a écrit :

> [snip]

Try this:

http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65203
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Linuz Python Module using PythonC/ API

2005-05-25 Thread fraca7
David a écrit :

> [snip]

> CC=g++

So actually your 'initutm' is '_Z7initutmv' for the linker. Try building 
with gcc instead, or declaring

extern "C" PyMODINIT_FUNC initutm(void);

or something like that.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: Python 2.3.2 for PalmOS available

2005-04-21 Thread Fraca7
On Tue, 19 Apr 2005 08:03:15 -0700, Lucio Torre wrote:

> Do you have any experience on PODS? The whole thing is based on
> Codewarrior and Codewarrior for palm is dead.

Nope. Actually, I'm kind of reluctant to use IDEs and it seems PODS is
targeted towards Eclipse users; I'd rather use prc-tools since I'm used to
the GNU development tools.
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: ANN: Python 2.3.2 for PalmOS available

2005-04-18 Thread Fraca7
On Fri, 15 Apr 2005 16:40:05 -0700, [EMAIL PROTECTED] wrote:

> Hello,

> While talking with Facundo while in a PyAr meeting (python-argentina,
> http://www.python.org/ar ) he told me that there is some interest in
> this platform.

You bet there is. i almost bought a Pocket PC instead of my Clié TH55
because I thought Python would be available sooner on it...

> So, ive made an initial release that has no documentation on how to use
> it or compile it (it requires codewarrior). If there is any interest on
> this, please let me know so we can work on getting this as a real port.

I'm a beginner at PalmOS programming (actually, I've read a book about it,
and that's it) but I'd be glad to help...

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Windows, Python and low level networking

2005-03-23 Thread fraca7
[EMAIL PROTECTED] wrote:
Is it possible to have low level netwoking with python under Windows?
Like raw sockets?
Is it possible to send a single packet using python under windows?
Yes. But be aware of restrictions on raw sockets in XP SP2:
http://blogs.msdn.com/michael_howard/archive/2004/08/12/213611.aspx
and don't blame it on Python if it doesn't work :)
There's a way to overcome this, but it comes with its load of other 
problems.

Anyway, this doesn't belong there, so
fu2 comp.os.ms-windows.networking.tcp-ip
--
http://mail.python.org/mailman/listinfo/python-list


Re: Obfuscated Python: fun with shadowing builtins

2005-03-17 Thread fraca7
Michael Hoffman wrote:
Enjoy ;)
That's not the exact word that first came to my mind :)
--
http://mail.python.org/mailman/listinfo/python-list


Re: compiled open source Windows lisp (was Re: Python becoming less Lisp-like)

2005-03-15 Thread Fraca7
On Tue, 15 Mar 2005 12:25:02 -0800, Brandon J. Van Every wrote:

> Last I looked, 2 years ago?, there were no compiled, open source lisps that
> ran on Windows.  Has this changed?

I don't think so. I recently (about 2 months ago) started to want to learn
Lisp (didn't go far for now) and wanted to find a Windows impl, to
evaluate "cross-platformability". The only open source/free software Lisp
interpreter I found was Common Lisp under Cygwin. Not exactly win32
native. But good enough, I think.

-- 
One Page Principle:
A specification that will not fit on one page of 8.5x11 inch
paper cannot be understood.
-- Mark Ardis

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: c.l.p.announce question

2005-03-15 Thread Fraca7
On Tue, 15 Mar 2005 14:54:18 -0500, Bill Mill wrote:

> On Tue, 15 Mar 2005 22:24:52 +0100, Fraca7 <[EMAIL PROTECTED]> wrote:
>> Hello.

>> It's not quite clear from the chart; I'd like to know if it's kosher to
>> announce the creation of a Python-oriented blog on
>> comp.lang.python.announce ?

> Well, it's a little late to back out now, isn't it? So check out
> http://fraca7.free.fr/blog/ for "from fraca7 import *", y'all.

Err, so much for discretion. Though discretion isn't exactly the point
about blogging, as far as I know :)

> More to the point, add yourself at
> http://lowlife.jp/cgi-bin/moin.cgi/PythonProgrammersWeblog and
> http://www.planetpython.org/ (see email info on that site), and people
> will find your blog. I know for a fact that the daily python-url editors
> (when not away on vacation) read planet python, and they'll send
> thousands of visitors to you if they link you.

Thank you very much. that's exactly what I was looking for. According to
my recent observations though, the daily Python URL is in idle state until
editors return :)

-- 
"In order to make an apple pie from scratch, you must first create the
universe."
-- Carl Sagan, Cosmos

-- 
http://mail.python.org/mailman/listinfo/python-list


c.l.p.announce question

2005-03-15 Thread Fraca7
Hello.

It's not quite clear from the chart; I'd like to know if it's kosher to
announce the creation of a Python-oriented blog on
comp.lang.python.announce ?

TIA

-- 
There's no trick to being a humorist when you have the whole government
working for you.
-- Will Rodgers

-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Non-blocking input on windows, like select in Unix

2005-03-02 Thread fraca7
Jonathan Fine a écrit :
Paul Rubin wrote:

As I recall, some posts to this list say that Windows provides
non-blocking i/o for sockets but not for files.
No, Windows does provide non-blocking I/O for regular files, but it's a 
completely different mechanism than the one used by winsock. You'll have 
to use win32all and enter the Dark Side, that is Windows APIs.

You don't want to do that if you're not already familiar with 
CreateProcess, CreatePipe, overlapped structures, WaitForSingleObject & 
al...
--
http://mail.python.org/mailman/listinfo/python-list