Help with wxPython

2005-08-12 Thread mitsura
Hi,

I have encountered an annoying problem with wx.Choice from wx.Python.
Basically, what I want to do is create a drop down box with a set of
choices (so far so good). The problem is that when the drop down box is
created, the first entry in the list of the drop down box is empty and
you need to drop down in the list to make your choice.
I was looking for an option that allows to set a default/preset choice
in the list.
This is important because I have written an apps where you can set the
properties of objects (cars) via drop down list and choose between a
set of pre-defined choices. However, if the set the properties of the
car (color, model, ...) via the Edit Properties windows but later you
which to change a properties it would be nice to see the choices you
made in de dropdown list and not a blank a first choice.

It seems trivial do.

Any help very much appreciated.

Kris

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


newbie Q: mouse clicks don't seem to get trapped

2005-09-05 Thread mitsura
Hi,

I want to display a window containing an image and when I move the
mouse over the image and click on the left Mb, I want to get the
position of the mouse on the image.
I listed the code to view the image below (so far so good) but for some
reason the EVT_LEFT_DOWN/UP does not work.

Any idea what might be wrong?

With kind regards,

Kris



"
class DisplayPicture(wx.Frame):
  cD = 0
  # bmp = stream that contains the picture (not a filename!)
  # w,h: widht, height of the picture
  def __init__(self, parent, id, title, bmp, w, h):
 wxFrame.__init__(self,parent,wxID_ANY, title, size = ( w, h),
style=wxDEFAULT_FRAME_STYLE)


 self.Bind(wx.EVT_LEFT_DOWN, self.OnLeftClick)
 self.Bind(wx.EVT_LEFT_UP, self.OnLeftClick)

 Panel=wx.Panel(self)
 wx.StaticBitmap(Panel, -1, bmp, (5, 5) )

 self.Show()
 
  def OnLeftClick(self, event):
  print "ok" 
"

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


left/right mouse button events not trapped

2005-09-06 Thread mitsura
Hi,

I have included a small listing. The test program opens a panel and
show a bitmap.
What I want is to when the mouse is over the bitmap panel, I want to
trap the left mouse click.
The purpose is to get the position of the mouse pointer on the bitmap.
However, for some reason, the left (I also tried right) mouse clicks
are not intercepted.
I new to Python and wxWindows so any help would be greatly appreciated.

With kind regards,

Kris
"
import  string
import  wx
import  images
import  os
import  cStringIO
import xml.sax

from wxPython.wx import *
from Main import opj

class DisplayPicture(wx.Frame):
  cD = 0

  def __init__(self, parent, id, title, bmp, w, h):
 wxFrame.__init__(self,parent,wxID_ANY, title, size = ( w, h),
style=wxDEFAULT_FRAME_STYLE)

 mD = 0

 self.Panel=wx.Panel(self)
 wx.StaticBitmap(self.Panel, -1, bmp, (5, 5) )

 """ FOR SOME REASON THE MOUSE CLICKS DON'T WORK!"""
 """ SHIT SHIT SHIT SHIT ... x 1000 """
 wx.EVT_LEFT_DOWN(self.Panel, self.OnLeftClick)
 wx.EVT_LEFT_UP(self.Panel, self.OnLeftClick)
 wx.EVT_LEFT_DCLICK(self.Panel, self.OnLeftClick)


 self.CreateStatusBar()
 self.Show()

 self.SetStatusText('Submap Coordinates:')

  def OnLeftClick(self, event):
  print "ok the mouse click works!"

class MyApp(wx.App):
cD = 0
def OnInit(self):
wx.InitAllImageHandlers()
return 1

#
# Main
#

if __name__ == "__main__":
app = MyApp(0)


data = open(opj('c:\winnt\Greenstone.bmp'), "rb").read()
stream = cStringIO.StringIO(data)
bmp = wx.BitmapFromImage( wx.ImageFromStream( stream ))
bmpW = bmp.GetWidth()
bmpH = bmp.GetHeight()
DisplayPicturePanel=DisplayPicture(None, -1, "Test MB", bmp, bmpW,
bmpH)
#MainFrame = DisplayPicture(None,-1,"Test Mouse Clicks")
 

app.MainLoop()
"

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


Re: left/right mouse button events not trapped

2005-09-06 Thread mitsura
Thanks Claudio! This really really made my day. I have been searching
for the problem for hours! Thanks again.

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


some advice about Python GUI apps

2005-09-14 Thread mitsura
Hi,

I am writing a program in Python and I am using wx.Python for the GUI.
I have no prior GUI and Python experience so that's why I turn to the
specialists for aid.
Basically, my app is a wx.tree object with items. You can click on each
item and set some properties of the item (Pydata). To set the
properties of an item you click on the item and then a 'Set item
properties' window pops up.
However, I am looking for a way that you can only open 1 property
window per item. If I click on an item the 'Set item properties'
windows open but when I return to the tree window and select the same
item, I can open an additional 'set properties' window. This leads to
all kind of C++ errors because these properties windows seems to
interfere for some reason. I don't have enough OO/Python/GUI knowledge
yet to fully understand what actually happens.
Basically, what I want is that when you want to open an items property
window and the window is alread open that in stead of opening a new
window, the window the is already open pops to the foreground. Any
ideay how I can implement this.

Another solution would be to start the properties windows in a
'synchronous' mode, meaning that if this window is open, that you can't
manipulate the tree window anymore (~like in Word when you open the
'open file' window, you can't edit your doc until you this window is
closed again).

I hope this makes some sense.

Any help much appreciated.

Kris

Ps.: any refs to good OO/Python GUI books are also welcome (or URLs)

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


Re: some advice about Python GUI apps

2005-09-14 Thread mitsura
Hi,

the properties of the items are just virtual properties like e.g.
color, icon, gender.
Just image that an item represent a human. You can then click on the
item and start a 'Set Human Properties' windows (a frame with a
Notebook object with multiple tabs).
In the 'Set Human Properties' window you then have multiple properties
you can set/change like e.g. hair color, gender, skin tone, ... stuff
like that.

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


XML SAX parser bug?

2006-01-19 Thread mitsura
Hi,

I think I ran into a bug in the XML SAX parser.

part of my program consist of reading a rather large XML file (about
10Mb) containing a few thousand elements.
I have the following problem. Sometimes that SAX parses misreads a
line.
Let me explain: the XML file contains a few thousand lines like this:
"
WINOSSPI:Storage@@n91c90a.cmc.com
"
where 'n91c90a.cmc.com' is the name of a system and thus changes per
system.
I a few cases, the SAX parser misreads the line. The parser sometimes
plits characters the line in:
"WINOSSPI:Storage@@n" and "91c90a.cmc.com".
I put a 'print characters' line in the 'characters' method of the
parser that is how I found out.
It only happens for a few of the thousand lines but you can imagine
that is very annoying.

I checked for errors in the XML file but the file seems ok.

Is this a bug or am I doing something wrong?
I am new to Python.

I am using Python 2.4.1, pyWin32 extension 2.4 and PyXML 0.8.4

Any help very much appreciated.

Kris

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


Re: XML SAX parser bug?

2006-01-19 Thread mitsura

Fredrik Lundh schreef:

> [EMAIL PROTECTED] wrote:
>
> > I think I ran into a bug in the XML SAX parser.
> >
> > part of my program consist of reading a rather large XML file (about
> > 10Mb) containing a few thousand elements.
> > I have the following problem. Sometimes that SAX parses misreads a
> > line.
> > Let me explain: the XML file contains a few thousand lines like this:
> > "
> > WINOSSPI:Storage@@n91c90a.cmc.com
> > "
> > where 'n91c90a.cmc.com' is the name of a system and thus changes per
> > system.
> > I a few cases, the SAX parser misreads the line. The parser sometimes
> > plits characters the line in:
> > "WINOSSPI:Storage@@n" and "91c90a.cmc.com".
> > I put a 'print characters' line in the 'characters' method of the
> > parser that is how I found out.
> > It only happens for a few of the thousand lines but you can imagine
> > that is very annoying.
> >
> > I checked for errors in the XML file but the file seems ok.
> >
> > Is this a bug or am I doing something wrong?
>
> it's not a bug; the parser is free to split up character runs (due to 
> buffering,
> entities or character references, etc).  it's up to you to merge character 
> runs
> into strings.
>
> 
Thanks for the feedback,

but how do I detect that the parser has split up the characters? I gues
I need to detect it in order to reconstruct the complete string

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


Help with conversion VB script to Python : COM objects

2006-06-26 Thread mitsura
Hi,

I need to re-write a VB script into Python (because I really don't like
VB).

The VB script is used to create a Windows COM object.
(I am more of Unix guy, so COM objects are a little bit alien for me).

At a certain point in the VB script, I have the following line:
objPolTypes = objPmad.Cvar(objPmad.GetPolicyTypeList)

Does anybody what the equivalent in Python would be?
I tried:
objPolTypes = objPmad.Cvar(objPmad.GetPolicyTypeList() )

but then I get the following error:
"
Traceback (most recent call last):
  File "C:\Python24\MyProgs\FodFin\test.py", line 11, in ?
objPolTypes = objPmad.cvar(objPmad.GetPolicyTypeList() )
  File "", line 2, in cvar
pywintypes.com_error: (-2147352571, 'Type mismatch.', None, 1)
"

I also tried :
objPolTypes = objPmad.GetPolicyTypeList()

this works but I end of with a list of COM object and have no clue how
to query/use them or what methods are defined for those type of
objects.

Any help really appreciated.

With kind regards,

KRis

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


Help with XML-SAX program ... it's driving me nuts ...

2006-01-31 Thread mitsura
Hi,

I need to read a simle XML file. For this I use the SAX parser. So far
so good.
The XML file consist out of number of "Service" object with each object
a set of attributes.

I read through the XML file and for each "" entry I create a
new service object.
When I am in the "" part of the XML file and I encounter
"" then I store these attributes into a Python dictionary.
At the end of the "" tag I create the actual object and pass
the attributes directory to it.
The strange thing is that for some reason, the attributes for all the
objects are being updated. I don't understand why this happens.

I included the code and a example of the XML file (kd.xml)
The output should be:
Obj:  name2 attribs:  {}
Obj:  name attribs:  {attrib1, val1, atttrib1.1, val1.1}
Obj:  name1 attribs:  {attrib2, val 2}

but it is:
Obj:  name2 attribs:  {}
Obj:  name attribs:  {}
Obj:  name1 attribs:  {}

It's driving me nuts. I have spend hours going through this very simple
code, but I can't find what's wrong.
Any help is really very much appreciated.

With kind regards,

Kris
XML File (kd.xml):
"


  
name
label
/opt/OV/www/htdocs/ito_op/images/service.32.gif

  

1

 Attrib1
 Val1


 Attrib1.1
 Val1.1

  
  
name1
label1
/opt/OV/www/htdocs/ito_op/images/service.32.gif

  

1

 Attrib2
 val 2

  
  
name2
label2
/opt/OV/www/htdocs/ito_op/images/service.32.gif

  

1
  

"
Program:
"
import  sys
import  string
import  images
import  os
import  cStringIO
import  xml.sax


from wxPython.wx import *
from Main import opj
from xml.sax.handler import *
from xml.sax import make_parser

class ServiceObj:

def __init__(self,name):

# Serivce object properties
self.name = name
self.attributes = {}

class OpenSNXML(ContentHandler):

# Service Object Tags
inService   = 0
inServiceAttribute  = 0
inServiceName   = 0
inAttributeName = 0
inAttributeValue= 0


objName = ""
objLabel= ""

attribs = {}
attribName  = ""
attribValue = ""

def startElement(self, name, attrs):

if name == "Service":
self.inService = 1

if self.inService == 1:
if name == "Attribute":
print "Attribute start"
self.inServiceAttribute = 1

if name == "Name" and ( self.inServiceAttribute == 0 ):
self.inServiceName = 1

if name == "Name" and (self.inServiceAttribute == 1):
self.inAttributeName = 1

if name == "Value" and (self.inServiceAttribute == 1):
self.inAttributeValue = 1

def characters(self, characters):
if self.inServiceName == 1:
self.objName = self.objName + characters

if self.inAttributeName == 1:
#print "Attribute Name: ", characters
self.attribName = self.attribName + characters

if self.inAttributeValue == 1:
#print "Attribute Value: ", characters
self.attribValue = self.attribValue + characters

def endElement(self, name):
mD = 1

if name == "Service":

self.inService = 0

# If the object already exists, update the existing 
object
if AllServiceObjectsFromXMLFile.has_key(self.objName):
#print "Object: ", self.objName, " already 
defined in exists in
dir"
obj = AllServiceObjectsFromXMLFile[self.objName]
else:
obj = ServiceObj(self.objName)

obj.attributes = self.attribs

AllServiceObjectsFromXMLFile[self.objName] = obj

del obj

self.objName = ""
self.attribs.clear()

if name == "Attribute":
self.inServiceAttribute = 0
print "Attrib name: ", self.attribName
print "Attrib value: ", self.attribValue

self.attribs[self.attribName] = self.attribValue
self.attribName = ""
self.attribValue = ""

print "Attrib dir: ", self.attribs
print "Attribute stop"

if name == "Name":
self.inServiceName = 0
 

Re: Help with XML-SAX program ... it's driving me nuts ...

2006-01-31 Thread mitsura
Thanks for the feedback!
I will certainly look at the elementtree stuff (I am new to Python so I
still need to find my way around)

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


wxTreeCtrl Q?

2006-02-01 Thread mitsura
Hi,

it is possible to change the font (bold, underline, italic) in the text
used in a wxTreeCtrl?
I looked in the wxPython demo but I can't find anything.

Any help much appreciated.

Kris

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


py2exe question

2006-02-03 Thread mitsura
Hi,

I just installed py2exe to create a binary of my Python script.
However, py2exe does not seem to create a binary from my .py script.
This is what I have done:
I create a setup.py script:
"
# setup.py
from distutils.core import setup
import py2exe

setup(name="APP1", scripts=["C:\\Python24\\_APP1.py"],)
"

I then ran "python setup.py py2exe"
I see a lot of stuff scrolling on the screen. A 'built' directory is
created. At the end I get a message saying that I may or may not need
to include some DLL (all windows system DLLs). and that's it. No error
message but also no binary.

When I remove 'scripts=["C:\\Python24\\_APP1.py"]' from the setup.py
file, I  get exactly the same result. The same output, no error, no
binary.

Any idea what I am doing wrong here? Where should the compiled binary
go?

Any help much appreciated.

Kris

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


how to copy a Python object

2006-02-07 Thread mitsura
Hi,

I am new to Python and OO programming.
I need to copy a Python object (of a class I made myself).
new_obj = old_object doesn't seem to work since apparently new_obj is
then a referrence to old_obj.

I found out that there is a module called 'copy' that allows you to do
a shallow or a deep copy.
I need a deep copy since my object contains dicts to other objects that
also need to be copied.

However, when I do new_object = copy.deepcopy(old_object) I get a
series of errors. The most important one:
"
TypeError: object.__new__(PySwigObject) is not safe, use
PySwigObject.__new__()
"

So any help much appreciated.

With kind regards,

Kris

I am using Python 2.4

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


Re: how to copy a Python object

2006-02-07 Thread mitsura
Already thanks for the reply,

but how to write your own copy operator? Won't you always be passing
referrences to new_obj?

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


PyXML SAX Q?

2006-02-15 Thread mitsura
Hi,

is it possible to use SAX to parse XML that is not in a file but in a
large string?
If I open my XML file and read the content into a string variable. Is
there a way I can pass it to the PyXML Sax handler?
The reason I want to know is that I need to parse XML that is generated
by a process on a Unix system. I can connect to the process via a
socket and the the XML but I need to store the XML somewhere before I
can parse it.
I could dump it to a file first and then hand it to the parser but that
seems unefficient.

Maybe I could read the XML from the socket directly into the parser.

Any ideas are welcome

With kind regards,

Kris

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


programmnig advise needed

2005-06-07 Thread mitsura
Hi,

I am writing a Python program that needs to read XML files and contruct
a tree object from the XML file (using wxTree).
The XML however is not an hiearchical XML file. It contains 
and  tags. The  tags link the elements
together.
Example:

  ... element 1 attributes


  ... element 2 attributes


  ... element 3 attributes


 element1
 element3


 element2
 element3


In this case  is the parent of the two other elements.
The XML files I receive often contain thousands of elements so the tree
structure can be very large. Futhermore, the XML files are not
'sorted', like in the example above, the 'root' element object entry
might be somewhere in the middle of the XML file.

I don't really now to code this so any suggestions are welcome.

With kind regards,

Kris

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


Re: programmnig advise needed

2005-06-08 Thread mitsura
Thanks for the feedback! It is a very good idea to use dictionaries. I
will try to implemented it this way.

Thanks,

Kris


Andrea Griffini schreef:
> On 7 Jun 2005 12:14:45 -0700, [EMAIL PROTECTED] wrote:
>
> >I am writing a Python program that needs to read XML files and contruct
> >a tree object from the XML file (using wxTree).
>
> Supposing your XML file has a single top level node (so that it's a
> legal XML file) then the following code should be able to read it...
>
> #
> from elementtree import ElementTree as ET
>
> class Node:
> def __init__(self, xmlnode):
> self.xmlnode = xmlnode
> self.children = []
>
> def loadtree(f):
> root = ET.parse(f).getroot()
> nodes = {}
> for x in root:
> if x.tag.startswith("element"):
> nodes[x.tag] = Node(x)
> for x in root.findall("association"):
> name = x.find("Name").text
> parent = x.find("Parent").text
> nodes[parent].children.append(nodes.pop(name))
> assert len(nodes) == 1
> return nodes.popitem()[1]
> ##
>
> The idea is to create a node with an empty list of
> logical children and then for every association
> removing the child node from the global pool (a dict
> indexed by node name) to place it in its parent.
> I assumed that the nodes are in random order, but
> that the associations are sorted bottom-up in
> the tree. If this is not the case then you should
> keep TWO dicts, removing from only one of them
> the children when you process an association,
> and looking up the parent in the *other* dict that
> is not changed during processing of associations.
> The dict from who you are removing the children
> will allow you to detect logical errors in the file
> (i.e. a node having two parents - you won't find
> that node in the dict the second time - and absence
> of a single root - you won't end up with a single
> element in the dict after processing all
> associations -).
> 
> HTH
> Andrea

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


wxPython Q? floating window

2006-03-14 Thread mitsura
Hi,

I have a question about wxPython.
On Windows systems, you can point your mouse over most items on your
desktop and a after a second or so, a small window will pop-up with
extra info about the thing your pointing at (try e.g. move your mouse
over the time in the right corner and a window will pop-up with the
date).
I was wondering this can be done with wxPython. I basically want to
create a wxTree object and when I point the mouse over the objects in
the tree I would like to have these kind of smal pop-up windows that
display more info about the object you are pointing at.

Any help much appreciated.

Kris

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


trying to grasp OO : newbie Q?

2006-04-13 Thread mitsura
Hi,

I just started with Python and I am new to OO programming.
Here is a simple code:
"
class Obj:
myVar = 1

def __init__(self):
myVar = 2

#


myObj = Obj()

print myObj.myVar
"

The output is of this script is '1'. I would except it to be '2'.
I not understanding something fundamentally here.

Can anybody explain?

With kind regards,

Kris

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


Re: trying to grasp OO : newbie Q?

2006-04-13 Thread mitsura
Thanks guys,

It is starting to make much more sense. Most documentation I find about
OO is very academic

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