[Tutor] WIn32 extension -= exposing methods with a windows handle

2008-06-21 Thread Mike Meisner
I would like to capture information from a multi-player internet game in order 
to tabulate player statistics.  Specifically, I need information from a chat 
box within the main play window.

Using the win32 extension (win32gui module: EnumWindows, EnumChildWIndows) I 
can obtain a handle to the chat box.  At that point, I don't see any apparent 
win32 functions to expose the methods available in the chat box and, thereby, 
extract the chat text information I need.

So, if I have the handle to a child window, does anyone know how to enumerate 
the attributes and methods for that window using Python or its extensions?  
(Since the window is not a Python generated window,  __dict__ doesn't work, or 
I am incorrectly using it:  w = CreateWindowFromHandle(hwnd); print 
w.__dict__).  Also, if I know that a particular method is supported by the 
window's class (e.g., GetText), can I use the window's handle to access the 
method (i.e., text =  hwnd.GetText) ?  Or, what is the correct syntax?

Thanks for your help.

Mike___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Problem with creating class instance

2008-07-09 Thread Mike Meisner
I've just started using classes in Python.

The basic goal is to develop a script that tracks individual player stats for 
poker tournaments.  This involves nesting a class within a class within a 
class.  The Player class incorporates a Stats class (three instances for three 
different game types) and the Stats class incorporates a Details class (three 
instances for three different game phases).

In creating a Player instance,  that instance can create the Stats class, but 
when creating the first instance within the Stats class of a Details class, it 
fails with the following traceback:

Traceback (most recent call last):
  File 
"C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 
309, in RunScript
debugger.run(codeObject, __main__.__dict__, start_stepping=0)
  File "C:\Python25\Lib\site-packages\pythonwin\pywin\debugger\__init__.py", 
line 60, in run
_GetCurrentDebugger().run(cmd, globals,locals, start_stepping)
  File "C:\Python25\Lib\site-packages\pythonwin\pywin\debugger\debugger.py", 
line 624, in run
exec cmd in globals, locals
  File "C:\Documents and Settings\Mike and Patsy\Desktop\pk\pkutilities.py", 
line 140, in 
initplayers(playernames)
  File "C:\Documents and Settings\Mike and Patsy\Desktop\pk\pkutilities.py", 
line 119, in initplayers
gameplayers[name] = Player(name)
  File "C:\Documents and Settings\Mike and Patsy\Desktop\pk\pkutilities.py", 
line 8, in __init__
self.stat[0] = Stats('holdem', name)
  File "C:\Documents and Settings\Mike and Patsy\Desktop\pk\pkutilities.py", 
line 29, in __init__
self.gamephase[0] = Details('full')
IndexError: list assignment index out of range


The appropriate code segments defining the classes and the calling function 
follow:

class Player():

def __init__(self,name):
self.name = name
self.stat[0] = Stats('holdem', name)
self.stat[1] = Stats('omahah', name)
self.stat[2] = Stats('omahahl', name)


class Stats():

def __init__(self, type, name):
self.name = name
self.gametype = type
self.totalgames = 0
self.totalgamestofinish = 0
self.totalfinish = 0
self.gamephase[0] = Details('full')# this is the line which fails
self.gamephase[1] = Details('mid')
self.gamephase[2] = Details('end')

class Details():
def __init__(self, type):
self.type = type
self.totalhands = 0
self.VPIPhands = 0
self.VPIPcount = 0
self.VPSBhands = 0
self.VPSBcount = 0
self.flopseen = 0
self.turnseen = 0
self.riverseen = 0
self.preflopraise = 0
self.flopraise = 0
self.turnraise = 0
self.riverraise = 0
self.winpreflop = 0
self.winflop = 0
self.winturn = 0
self.winriver = 0

# this is the function that creates the Player instance
def initplayers(playernames):
global db, gameplayers

db = shelve.open('playerstats.dat')
for i in range(len(playernames)):
name = playernames[i]
if db.has_key(name):
gameplayers[name] = db[name]
else:
gameplayers[name] = Player(name)   # this line creates the Player 
instance
db[name] = gameplayers[name]

I don't see how the "list assignment index" can be out of range, so I assume 
there's an earlier error that I can't find or a syntax error that I'm 
overlooking.

Can anyone point out where I'm going wrong?

And, if you can recommend a better way to organize the data, feel free.

Thanks for your help.

Mike
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] List indexing problem

2008-07-25 Thread Mike Meisner
I need to do some statistical analysis by binning values into an array.

Being new to Python, I tried to use a list of lists.  I've extracted just the 
minimum code that I'm having trouble with:

def testanalysis():
IP = []
temp = [[0, 0, 0],[0, 0, 0],[0, 0, 0]]
# initialize to zero
for i in range(20):
IP.append(temp)
# increment each of the first five elements by 1
for index in range(5):
for type in range(3):
for phase in range(3):
IP[index][type][phase] += 1

print IP 

The output is:

[[[5, 5, 5], [5, 5, 5], [5, 5, 5]], [[5, 5, 5], [5, 5, 5], [5, 5, 5]], [[5, 5, 
5], [5, 5, 5], [5, 5, 5]], [[5, 5, 5], [5, 5, 5], [5, 5, 5]], [[5, 5, 5], [5, 
5, 5], [5, 5, 5]], [[5, 5, 5], [5, 5, 5], [5, 5, 5]], [[5, 5, 5], [5, 5, 5], 
[5, 5, 5]], [[5, 5, 5], [5, 5, 5], [5, 5, 5]], [[5, 5, 5], [5, 5, 5], [5, 5, 
5]], [[5, 5, 5], [5, 5, 5], [5, 5, 5]], [[5, 5, 5], [5, 5, 5], [5, 5, 5]], [[5, 
5, 5], [5, 5, 5], [5, 5, 5]], [[5, 5, 5], [5, 5, 5], [5, 5, 5]], [[5, 5, 5], 
[5, 5, 5], [5, 5, 5]], [[5, 5, 5], [5, 5, 5], [5, 5, 5]], [[5, 5, 5], [5, 5, 
5], [5, 5, 5]], [[5, 5, 5], [5, 5, 5], [5, 5, 5]], [[5, 5, 5], [5, 5, 5], [5, 
5, 5]], [[5, 5, 5], [5, 5, 5], [5, 5, 5]], [[5, 5, 5], [5, 5, 5], [5, 5, 5]]]

What I wanted, of course, is to increment only the first 5 sub-lists to a value 
of 1 (not 5).

I'm obviously misunderstanding something fundamental about lists, list 
indexing, or both.

Is this enough information for someone to point out what I'm doing wrong?

Mike___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] List indexing problem

2008-07-25 Thread Mike Meisner

Thanks Steve.

It's obvious now that you've pointed it out.

Do you happen to know if there is an efficient way to initialize a  list 
like this without explicitly writing out each element?


Mike
- Original Message - 
From: "Steve Willoughby" <[EMAIL PROTECTED]>

To: "Mike Meisner" <[EMAIL PROTECTED]>
Cc: 
Sent: Friday, July 25, 2008 7:03 PM
Subject: Re: [Tutor] List indexing problem



Mike Meisner wrote:

I need to do some statistical analysis by binning values into an array.
 Being new to Python, I tried to use a list of lists.  I've extracted 
just the minimum code that I'm having trouble with:


What you need to remember is that Python works with *objects*, and 
variables are simply *references* to those objects.  So if I say

a = [1,2,3]
b = a

b and a both refer to the *SAME* list object (not two lists which happen 
to have the same elements).



temp = [[0, 0, 0],[0, 0, 0],[0, 0, 0]]


temp now refers to a list object containing 3 lists, each containing 3 
integers.



# initialize to zero
for i in range(20):
IP.append(temp)


Now IP contains 20 copies of references to the *same* list object.
So you were modifying the underlying list object which happens to be 
referenced many times in IP.






___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Printing Scripts with color/good formatting

2008-09-12 Thread Mike Meisner
I've been working with Python on two different machines:  under Windows XP and 
under 64-bit Vista.

In the XP version, the Python 32-bit editor prints my scripts using the color 
coding in the editor and a comfortable to read font.  Under Vista 64-bit, only 
the IDLE environment is available which prints my scripts without color and a 
larger, more difficult to read font (and there appears to be no way to 
customize the output).

Is there an open-source editor I could use with Vista to get the more 
attractive, color coded script printout that I get with the 32--bit system?

Thanks for your help.

Mike___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Immediately committing changes to shelve files

2008-10-26 Thread Mike Meisner
I'm running a number of test cases and saving their results in a shelve file.

A full run of the test cases takes about 36 hours.  During that time, if 
something interrupts the run (e.g., a power outage, which has happened), I find 
that none of the completed test cases have been committed to the shelve file 
even though, after each run, I make sure that the results are written to the 
in-memory database (i.e., db = shelve.open(filename) at the beginning of the 
test run; and db[key] = results after each test case).

Is there a way to force the results for a single test case to be written back 
to the shelve file?  Other than opening/closing the shelve after each test case 
run?

Thanks.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Scaling a Tkinter canvas widget

2008-10-26 Thread Mike Meisner
I would like to plot various datasets on a Tkinter canvas widget.

The problem is that each of my datasets have different x,y extremes.  For 
instance, one dataset may have xmin = 0, xmax = 300, ymin = 0, ymax = 300;  
whereas the next dataset may have xmin = -200, xmax = 1200, ymin = 2000, ymax = 
5000.  I need the whole canvas area to be available for plotting each dataset 
consecutively - i.e., plot one dataset, capture the image, clear the canvas and 
plot the next dataset with a new scale, etc.

As best I can tell the Tkinter canvas widget uses two coordinate systems:  1) 
the canvas coordinate system in pixels that runs from (0, 0) to (xmaxpixel, 
ymaxpixel), and 2) a window coordinate system that allows a wider range to 
enable scrolling the canvas within the window coordinate system.

What I'd like to do is simply scale the canvas coordinate system to fit the x,y 
extents of a dataset.  I can write a function to do this but it would be costly 
time-wise for plotting a large dataset (to say nothing of multiple large 
datasets).

My documentation for Tkinter is pretty sketchy.  I was hoping there was a 
canvas method I could use to re-scale the canvas widget before I plot each 
dataset, but there's nothing apparent in my documentation.

Is there someone familiar with Tkinter that would know how to re-scale a 
canvas?  Or, could tell me that there is no efficient way to do this other than 
writing a function to re-scale for each data point?

I'm sure that there are Python add-ins that would do what I want, but this is a 
quick one-time project and it's not worth the time to muck around with them 
compared to writing a scaling function.

Thanks for your help.
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


[Tutor] Open Source database software

2008-11-24 Thread Mike Meisner
Y'all have been so good with suggestions on my programming problems in the 
past, I wonder if anyone could provide a suggestion on a more general topic.

I'd like to get away from using Microsoft Access.  I have a number of Access 
databases to convert.

My needs are:

1.  A relational database management system for a single user (i.e, I don't 
need client/server and all the extra baggage that goes with it).  The RDMS must 
be able to handle graphics objects.

2.  Open source with a decent track record.

3.  A good GUI front end for creating the database, creating forms for user 
data input, queries, reports, etc.

4.  Smart enough to easily read and convert an Access (.mdb) database file.

5.  And, everything either in Python or with APIs that Python can easily use.

Has anyone used products that would meet my needs?

Thanks.

Mike

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor