Python COM automation - Controlling Microsoft Agent

2008-02-29 Thread Kamilche
Here's a snippet of code for pythoners to enjoy. Make the Microsoft genie speak text and dance about! ''' Requires: -- comtypes from: http://starship.python.net/crew/theller/comtypes MS Agent from: http://www.microsoft.com/msagent To do: -- 1. List

Quad Perspective Transformation

2007-02-01 Thread Kamilche
I have a need to tile a bitmap across an arbitrary quadrilateral, and apply perspective to it. The Python Imaging Library (PIL) has an undocumented function that might work, but I can't figure out how to make it work. You're supposed to pass it 8 parameters, a b c d e f g h . What I want is to

Re: Detect Unused Modules

2006-10-21 Thread Kamilche
Nice as it is, but why not use pylint to check this and many other coding style issues? I made this the first time I mangled some code because pychecker said some modules were not used when they really were. The module wasn't that complex, only 302 lines, but it got it wrong. --

Detect Unused Modules

2006-10-20 Thread Kamilche
''' DetectUnusedModules.py - Detect modules that were imported but not used in a file. When run directly, this class will check all files in the current directory. ''' import os import tokenize class PrintUnusedModules(object): state = 0 importlist = None linenumbers = None def

Refactoring Dilemma

2006-09-10 Thread Kamilche
''' I'm in the middle of a refactoring dilemma. I have several singletons that I'm turning into modules, for ease of access. The usual method is noted as 'Module 1' below. The new method is noted as 'Module 2'. Is there any reason NOT to do this that I may be unaware of? It's easier than

Re: easy way to dump a class instance?

2006-05-05 Thread Kamilche
Mark Harrison wrote: Is there a way to automatically print all the instance data in a class? print self.__dict__ -- http://mail.python.org/mailman/listinfo/python-list

String To Dict Problem

2006-03-26 Thread Kamilche
' it, but you know that will come up to bite me in the future. Does anyone have a thought on how I can turn what are basically function keyword arguments in string form, to a dict, without using exec or eval? --Kamilche -- http://mail.python.org/mailman/listinfo/python-list

Re: String To Dict Problem

2006-03-26 Thread Kamilche
Thanks! It's interesting, and nearly what I want, but not quite there. When I run my sample code through it, I get a syntax error because it's not a valid expression. If I were to put a 'dict(' in front and a ')' at the end, THEN it nearly works - but it gives me an 'Unsafe_Source_Error: Line 1.

Re: String To Dict Problem

2006-03-26 Thread Kamilche
Ah, finally, that's exactly what I need! Thanks bunches. I was attempting to modify your first code to fit my needs, but mine was much longer, and not yet working, a sure clue that yours is a better solution. :-D -- http://mail.python.org/mailman/listinfo/python-list

Re: image reduction script

2006-03-26 Thread Kamilche
Be sure and use mode = P instead of RGB, like you have in your other code. P is for palettized images. Don't palettize if you're storing as JPG, only if you're storing as PNG or some other format that can handle 256 color images. -- http://mail.python.org/mailman/listinfo/python-list

Re: image reduction script

2006-03-25 Thread Kamilche
To reduce the color depth of an image in PIL: im = im.convert(mode=P, palette=Image.ADAPTIVE) -- http://mail.python.org/mailman/listinfo/python-list

Re: Is there no end to Python?

2006-03-18 Thread Kamilche
Heheh, that sounds about right. :-D I personally haven't used the new stuff yet. Maybe I'm not experienced enough in Python yet to have encountered the need for them. I've played with them some, but every time I consider using them, something stops me. What stops me from using 'setattr' (an old

Is there no end to Python?

2006-03-17 Thread Kamilche
I have been programming in Python for years, and I'm STILL learning new features about the language. I'm looking for the best way to handle events with my own UI developed in PyGame, and I've programmed up 4 ways to do it so far, and have a couple more waiting to be done! Python is so amazingly

Re: Is there no end to Python?

2006-03-17 Thread Kamilche
Because Python doesn't take as many CPU cycles in your brain, it spares more time for 'big picture' ideas, such as the event handling framework I'm working on. -- http://mail.python.org/mailman/listinfo/python-list

Re: grayscale pixel based graphics with pygame

2006-03-08 Thread Kamilche
import pygame def main(): SIZE = (300, 200) WHITE = (255, 255, 255) pygame.init() # Create a new grayscale surface pic = pygame.Surface(SIZE, 0, 8) palette = tuple([(i, i, i) for i in range(256)]) pic.set_palette(palette) # Fill it with a gradient array =

Publish/subscribe event manager using weakrefs

2006-02-15 Thread Kamilche
''' event.py An event manager using publish/subscribe, and weakrefs. Any function can publish any event without registering it first, and any object can register interest in any event, even if it doesn't exist yet. The event manager uses weakrefs, so lists of listeners won't stop them from being

Re: how to get function names from the file

2006-02-15 Thread Kamilche
The following will return a dictionary containing the names and functions of all the public functions in the current module. If a function starts with an underscore _, it is considered private and not listed. def _ListFunctions(): import sys import types d = {} module =

Legality of using Fonts

2006-02-10 Thread Kamilche
! --Kamilche -- http://mail.python.org/mailman/listinfo/python-list

Re: Legality of using Fonts

2006-02-10 Thread Kamilche
Yeah, that's what I'm thinking, as well. Showing all the text on an image is one thing... using that image as the basis of a font engine is something different. Luckily, someone has sent me a link to a set of free TrueType fonts - http://www.gnome.org/fonts , the 'Vera' family. I guess I'll turn

Re: PIL and transparent GIFs

2006-02-01 Thread Kamilche
It can only read transparency, it can't write it. I went looking and found that out a couple weeks ago. -- http://mail.python.org/mailman/listinfo/python-list

Print dict in sorted order

2006-01-29 Thread Kamilche
I have a code snippet here that prints a dict in an arbitrary order. (Certain keys first, with rest appearing in sorted order). I didn't want to subclass dict, that's error-prone, and overkill for my needs. I just need something that returns a value like dict.__str__, with a key ordering I

Zooming Idle window

2006-01-19 Thread Kamilche
Does anyone know how to automatically zoom the Idle window when you start it up? I've tried passing command line parameters, adding code to PyShell, and more, to no effect. I suspect the following will be necessary, but I don't know where to put it: import ZoomHeight ZoomHeight.zoom_height(root)

Re: Another method of lazy, cached evaluation.

2006-01-18 Thread Kamilche
the picture is referenced. Good job! --Kamilche -- http://mail.python.org/mailman/listinfo/python-list

Re: Another method of lazy, cached evaluation.

2006-01-18 Thread Kamilche
If you wanted to avoid the __getattr__ __setattr__ speed hit, something like this would work. However, you have to not mind calling a function to get the data, instead of only getting the attribute: class Cache(object): _cache = {} def __init__(self, filename): self.filename =

Re: Guido at Google

2005-12-21 Thread Kamilche
Well, congrats to Google! I think they're the lucky ones, to get him, and you, both. :-) -- http://mail.python.org/mailman/listinfo/python-list

Still Loving Python

2005-12-13 Thread Kamilche
acceptance by the programming community at large. (I know about tKinter, no need to post links to it, thanks.) --Kamilche -- http://mail.python.org/mailman/listinfo/python-list

Re: Still Loving Python

2005-12-13 Thread Kamilche
Yeah, I have a system like that on my product. It's a data file loaded at code startup time, which results in a UI - no need to cut code to change the interface. It's saved me a lot of time. I also have a problem with 'designers'. If the GUI designer is as easy as making an interface was in VB6,

Re: OO refactoring trial ??

2005-06-28 Thread Kamilche
''' You might find this interesting. Note that the object creation in main() below could easily be read in from a text file instead, thus meeting your requirement of not knowing an item's class until runtime. Sample output: {'password': 'Your Password Here', 'type': 'A', 'logonid': 'Your Logonid

Re: Shift Confusion

2005-02-24 Thread Kamilche
Quite. Although you can sort of see how one might naively arrive at this conclusion: one 7-bit char takes 0...127, which when you put it into an 8-bit byte leaves 128...255 unused for a second char James Yep, that's what I was doing. Guess I was too tired to program usefully last night.

Re: web status display for long running program

2005-02-24 Thread Kamilche
with it! --Kamilche ''' import socket import select import datetime _HEADER = '\r\n'.join([ 'HTTP/1.0 %s', 'Server: Miniweb-0.1', 'Content-Type: text/html', 'Connection: close', 'Content-Length: %d', '', '', ]) _BODY = '\r\n'.join([ 'htmlheadtitle%s/title/head

Shift Confusion

2005-02-23 Thread Kamilche
I'm trying to pack two characters into a single byte, and the shifting in Python has me confused. Essentially, it should be possible to use a 'packed string' format in Python, where as long as the characters you're sending are in the ASCII range 0 to 127, two will fit in a byte. Here's the code.

Re: Help with embedding fully qualified script name

2005-02-14 Thread Kamilche
To avoid pathname headaches, I've taken to including the following 3 lines at the top of every script that will be double-clicked: import os, sys pathname, scriptname = os.path.split(sys.argv[0]) pathname = os.path.abspath(pathname) os.chdir(pathname) --

Re: Dynamic class methods misunderstanding

2005-01-28 Thread Kamilche
I see what you're attempting to do. However, your code, if it DID run, would result in a method being added to the object, not the object's class! Modify the class itself, not the object, as follows: |class Test: |def __init__(self): |self.method() | |def m(self): |print self |

Re: Open Folder in Desktop

2005-01-25 Thread Kamilche
Thanks, startfile worked great for me! -- http://mail.python.org/mailman/listinfo/python-list

Re: script to search ebay?

2005-01-25 Thread Kamilche
This script works. But why not make a 'Favorite Search' in ebay, and have it send you daily email for a year? --Kamilche |import urllib |import smtplib | |def main(): |# Perform the search |results = SearchEbay(['So long and thanks for all the fish', | 'NOMATCHFOUND

Re: Reload Tricks

2005-01-23 Thread Kamilche
Well, I look forward to seeing the new version. I have the old version of the Python cookbook, it was very useful! -- http://mail.python.org/mailman/listinfo/python-list

Reload Tricks

2005-01-21 Thread Kamilche
to be working... but now I'm wondering, what else did it not change? Can I expect more toes to be blown off? --Kamilche -- http://mail.python.org/mailman/listinfo/python-list

Re: Reload Tricks

2005-01-21 Thread Kamilche
That's a powerful advantage - not having to track class instances. Thanks for the tip! I just got done doing it 'my way' though, now I'll have to change it. It took me all day! :-D -- http://mail.python.org/mailman/listinfo/python-list

Re: Reload Tricks

2005-01-21 Thread Kamilche
Would it be possible to just not copy any attribute that starts and ends with '__'? Or are there some important attributes being copied? -- http://mail.python.org/mailman/listinfo/python-list

Re: Tkinter in thread hangs on windows but not on Linux

2005-01-18 Thread Kamilche
This example worked for me on Windows 2000, after inserting import threading from Tkinter import * import ScrolledText at the top. -- http://mail.python.org/mailman/listinfo/python-list

Re: Calling Function Without Parentheses!

2005-01-07 Thread Kamilche
Yeah, but still. If they even had the most basic check, like 'an object is being referred to on this line, but you're not doing anything with it' would be handy in catching that. When you use an object like that, usually you're doing something with it, like assigning it to a variable. --

Re: Calling Function Without Parentheses!

2005-01-07 Thread Kamilche
Uh, you're right! I wouldn't want to bog Python down with even more checking at run time. I guess I'm asking for syntax checks that are typically done only with compiled languages. It doesn't stop me from using Python, though! Since I don't have syntax checking, I find I have to test supporting

Re: Python! Is! Truly! Amazing!

2005-01-02 Thread Kamilche
, it matches my internal idea of 'pseudocode' to a T. Executable shorthand - does it get any better than that? --Kamilche -- http://mail.python.org/mailman/listinfo/python-list

Calling Function Without Parentheses!

2005-01-02 Thread Kamilche
What a debug nightmare! I just spent HOURS running my script through the debugger, sprinkling in log statements, and the like, tracking down my problem. I called a function without the ending parentheses. I sure do WISH Python would trap it when I try to do the following: MyFunc instead of:

Re: getattr() woes

2004-12-30 Thread Kamilche
Thomas Rast wrote: I've found out about a fundamental problem of attribute lookup, the hard way... Is there anything that can be done about this? It seems to me that the main problem is you're raising an AttributeError when an attribute is private. AttributeError is only raised when an

Re: More elegant way to cwd?

2004-12-28 Thread Kamilche
For library modules there are already other and more elegant means. -Peter Well, I want to make a script execute without error regardless of where the current working directory is, and without having to make the user modify their PYTHONPATH variable or install something in site-packages. Is