[wxPython] Problem using wxShape.GetAttachment()

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

[wxPython] Problem using wxShape.GetAttachment()

Nicolas Chauvat-2
Hi all,

I did not find anything related in the archive (well, grep didn't. Would
be nice to be able to search directly the web archive without
downloading the files by the way :-), so here is my question:

I'm trying to use OGL and a piece of code I found in ogledit (doc.cpp
MyEvtHandler::OnBeginDragRight to be precise), but I'm having troubles to
figure out how to translate:

  double xp, yp;
  GetShape()->GetAttachmentPosition(attachment, &xp, &yp);
  dc.DrawLine((long) xp, (long) yp, (long) x, (long) y);
  GetShape()->GetCanvas()->CaptureMouse();

to python code.

I tried

        xp, yp = 0.0, 0.0
        shape.GetAttachmentPosition(attachment,xp,yp)
        dc.DrawLine(xp, yp, x, y)
        canvas.CaptureMouse()

and several other variants, but I keep getting errors about the number and
the type of the parameters. The error for the above sample of code is

Traceback (innermost last):
  File "gui.py", line 92, in OnBeginDragRight
    shape.GetAttachmentPosition(attachment,xp,yp,void)
  File "/usr/lib/python1.5/site-packages/wxPython/oglbasic.py", line 583,
in GetAttachmentPosition
    val = apply(oglbasicc.wxPyShape_GetAttachmentPosition,(self,) + _args,
_kwargs)
TypeError: Type error in argument 3 of wxPyShape_GetAttachmentPosition.
Expected _double_p.

So if I wanted to make my question more general, I would ask:

What is the python equivalent of a wxWindows function that looks like

bool GetAttachmentPosition(int attachment, double* x, double* y, int nth =
0, int noArcs = 1, wxLineShape* line = NULL)

Please cc: me for the answer. Thanks in advance.

-- Nicolas

 (o-  Hi, I'm a deadly e-mail virus, please copy me into your .signature
 /\   file to help me spread. :: Bonjour, je suis un dangereux virus. SVP
Y_/_  copiez-moi dans votre fichier .signature pour m'aider à me propager.    





_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

RE: [wxPython] Problem using wxShape.GetAttachment()

Jan Reimers-2


> ----------
> From: Nicolas Chauvat[SMTP:[hidden email]]
> Sent: Tuesday, February 15, 2000 10:18 AM
> To: [hidden email]
> Subject: [wxPython] Problem using wxShape.GetAttachment()
>
> Hi all,
>
> The error for the above sample of code is
>
> Traceback (innermost last):
>   File "gui.py", line 92, in OnBeginDragRight
>     shape.GetAttachmentPosition(attachment,xp,yp,void)
>   File "/usr/lib/python1.5/site-packages/wxPython/oglbasic.py", line 583,
> in GetAttachmentPosition
>     val = apply(oglbasicc.wxPyShape_GetAttachmentPosition,(self,) + _args,
> _kwargs)
> TypeError: Type error in argument 3 of wxPyShape_GetAttachmentPosition.
> Expected _double_p.
                    ^^^^^^^^^^^
SWIG creates its own type names for C/C++ types.  So you need a way to
create a double pointer.

      x=0.0 #in python

will create a python object of the type PyFloatObject which is not a SWIG
_double_p (double pointer).  So I can rephrase your question as:

How does one create C-type objects in wxPython?



> So if I wanted to make my question more general, I would ask:
>
> What is the python equivalent of a wxWindows function that looks like
>
> bool GetAttachmentPosition(int attachment, double* x, double* y, int nth =
> 0, int noArcs = 1, wxLineShape* line = NULL)
>
> Please cc: me for the answer. Thanks in advance.
>
> -- Nicolas
>
>  (o-  Hi, I'm a deadly e-mail virus, please copy me into your .signature
>  /\   file to help me spread. :: Bonjour, je suis un dangereux virus. SVP
> Y_/_  copiez-moi dans votre fichier .signature pour m'aider à me propager.
>
>
>
>
>
>
> _______________________________________________
> wxPython-users maillist  -  [hidden email]
> http://starship.python.net/mailman/listinfo/wxpython-users
>

_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

RE: [wxPython] Problem using wxShape.GetAttachment()

Nicolas Chauvat-2
In reply to this post by Nicolas Chauvat-2
On Tue, 15 Feb 2000, Mike  Fletcher wrote:

> I'm guessing, but since it's a position returning function, and those two
> args are pointers to memory, you're likely looking at:
>
> position = GetAttachmentPosition(int attachment, int nth = 0, int noArcs =
> 1, wxLineShape* line = NULL)

I forgot to mention that I tried that and it doesn't work, which is too
bad, because that's in my opinion the more natural one.
 
> If it works, let people know to change the docs to include a Python aside
> for the functions (there seem to be a lot of similar ones in the library).

Here is the error I get:

Traceback (innermost last):
  File "gui.py", line 91, in OnBeginDragRight
    position = shape.GetAttachmentPosition(attachment)
  File "/usr/lib/python1.5/site-packages/wxPython/oglbasic.py", line 583,
in GetAttachmentPosition
    val = apply(oglbasicc.wxPyShape_GetAttachmentPosition,(self,) + _args,
_kwargs)
TypeError: wxPyShape_GetAttachmentPosition requires at least 4 arguments;
2 given

Any other idea ?

-- Nicolas

 (o-  Hi, I'm a deadly e-mail virus, please copy me into your .signature
 /\   file to help me spread. :: Bonjour, je suis un dangereux virus. SVP
Y_/_  copiez-moi dans votre fichier .signature pour m'aider à me propager.    


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

RE: [wxPython] Problem using wxShape.GetAttachment()

Nicolas Chauvat-2
In reply to this post by Jan Reimers-2
On Tue, 15 Feb 2000, Jan Reimers wrote:

> SWIG creates its own type names for C/C++ types.  So you need a way to
> create a double pointer.
>
>       x=0.0 #in python
>
> will create a python object of the type PyFloatObject which is not a SWIG
> _double_p (double pointer).

Agreed. But there is no PyDoubleObject to my knowledge (in 1.5.2
documentation). Trying x=0.0 probably wasn't the best bet thought, even if
I expected it to magically turn it into a double (no, I never read the
source of the interpreter :-)

There is a PyLong_AsDouble function in the Python/C API, so I assume one
can get a C double from a python long int... at least when writing an
extension module. But how do I do that in my case ?

> So I can rephrase your question as:
>
> How does one create C-type objects in wxPython?

And your answer would be ? :-)

> > Please cc: me for the answer. Thanks in advance.

Now I'm on the list, don't bother cc'ing me any more. Thanks.

-- Nicolas

 (o-  Hi, I'm a deadly e-mail virus, please copy me into your .signature
 /\   file to help me spread. :: Bonjour, je suis un dangereux virus. SVP
Y_/_  copiez-moi dans votre fichier .signature pour m'aider à me propager.    



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] Problem using wxShape.GetAttachment()

Robin Dunn
In reply to this post by Nicolas Chauvat-2
>         xp, yp = 0.0, 0.0
>         shape.GetAttachmentPosition(attachment,xp,yp)
>         dc.DrawLine(xp, yp, x, y)
>         canvas.CaptureMouse()
>
> and several other variants, but I keep getting errors about the number and
> the type of the parameters. The error for the above sample of code is
>
> Traceback (innermost last):
>   File "gui.py", line 92, in OnBeginDragRight
>     shape.GetAttachmentPosition(attachment,xp,yp,void)
>   File "/usr/lib/python1.5/site-packages/wxPython/oglbasic.py", line 583,
> in GetAttachmentPosition
>     val = apply(oglbasicc.wxPyShape_GetAttachmentPosition,(self,) + _args,
> _kwargs)
> TypeError: Type error in argument 3 of wxPyShape_GetAttachmentPosition.
> Expected _double_p.


Sorry, those should have been converted to output parameters (so the values
will be returned in a tuple) in the SWIG wrapper, but I missed them.  I'll
get this fixed asap.

--
Robin Dunn
Software Craftsman
[hidden email]
http://AllDunn.com/robin/
http://AllDunn.com/wxPython/  Check it out!



_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

RE: [wxPython] Problem using wxShape.GetAttachment()

Jan Reimers-2
In reply to this post by Nicolas Chauvat-2
This may be a longshot but what about something like:

        p=wxRealPoint(0.0,0.0)
        shape.GetAttachmentPosition(attachment,p.x,p.y)


JR

> ----------
> From: Nicolas Chauvat[SMTP:[hidden email]]
> Sent: Tuesday, February 15, 2000 11:08 AM
> To: [hidden email]
> Subject: RE: [wxPython] Problem using wxShape.GetAttachment()
>
> On Tue, 15 Feb 2000, Jan Reimers wrote:
>
> > SWIG creates its own type names for C/C++ types.  So you need a way to
> > create a double pointer.
> >
> >       x=0.0 #in python
> >
> > will create a python object of the type PyFloatObject which is not a
> SWIG
> > _double_p (double pointer).
>
> Agreed. But there is no PyDoubleObject to my knowledge (in 1.5.2
> documentation). Trying x=0.0 probably wasn't the best bet thought, even if
> I expected it to magically turn it into a double (no, I never read the
> source of the interpreter :-)
>
> There is a PyLong_AsDouble function in the Python/C API, so I assume one
> can get a C double from a python long int... at least when writing an
> extension module. But how do I do that in my case ?
>
> > So I can rephrase your question as:
> >
> > How does one create C-type objects in wxPython?
>
> And your answer would be ? :-)
>
> > > Please cc: me for the answer. Thanks in advance.
>
> Now I'm on the list, don't bother cc'ing me any more. Thanks.
>
> -- Nicolas
>
>  (o-  Hi, I'm a deadly e-mail virus, please copy me into your .signature
>  /\   file to help me spread. :: Bonjour, je suis un dangereux virus. SVP
> Y_/_  copiez-moi dans votre fichier .signature pour m'aider à me propager.
>
>
>
>
> _______________________________________________
> wxPython-users maillist  -  [hidden email]
> http://starship.python.net/mailman/listinfo/wxpython-users
>

_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

RE: [wxPython] Problem using wxShape.GetAttachment()

Nicolas Chauvat-2
On Tue, 15 Feb 2000, Jan Reimers wrote:

> This may be a longshot but what about something like:
>
> p=wxRealPoint(0.0,0.0)
> shape.GetAttachmentPosition(attachment,p.x,p.y)

That didn't do it, so I'll wait for Robin Dunn's fix of the SWIG wrapper.

Thanks.

-- Nicolas

 (o-  Hi, I'm a deadly e-mail virus, please copy me into your .signature
 /\   file to help me spread. :: Bonjour, je suis un dangereux virus. SVP
Y_/_  copiez-moi dans votre fichier .signature pour m'aider à me propager.    




_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

[wxPython] How would one

Gary Greyling-2
In reply to this post by Nicolas Chauvat-2

Split a string into segments 60 chars long ?


the following does not work

re.split(".{0,59}",consensus)


where consensus would be a string like

CTTACGCAGTACTGAGTTACCGTAGTGTACGTCAGTAGTCGTACGTACGTACGTCGTA.........

--
Gary Greyling
Electric Genetics

_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] How would one

Nicolas Chauvat-2
> Split a string into segments 60 chars long ?
> where consensus would be a string like
>
> CTTACGCAGTACTGAGTTACCGTAGTGTACGTCAGTAGTCGTACGTACGTACGTCGTA.........

list = []
while consensus :
        list.append( consensus[:60] )
        consensus = consensus[60:]
#print list

-- Nicolas

 (o-  Hi, I'm a deadly e-mail virus, please copy me into your .signature
 /\   file to help me spread. :: Bonjour, je suis un dangereux virus. SVP
Y_/_  copiez-moi dans votre fichier .signature pour m'aider à me propager.    


_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] How would one

Robin Friedrich-2
In reply to this post by Gary Greyling-2
def splitter(consensus, seg_len=60):
    segs, remainder = divmod(len(consensus), seg_len)
    segments = []
    for i in range(segs):
        segments.append(consensus[i*seg_len:i*seg_len+seg_len])
    if remainder:
        segments.append(consensus[i*seg_len+seg_len:])
    return segments

----- Original Message -----
From: Gary Greyling <[hidden email]>
To: <[hidden email]>
Sent: Monday, February 21, 2000 1:18 PM
Subject: [wxPython] How would one


>
> Split a string into segments 60 chars long ?
>
>
> the following does not work
>
> re.split(".{0,59}",consensus)
>
>
> where consensus would be a string like
>
> CTTACGCAGTACTGAGTTACCGTAGTGTACGTCAGTAGTCGTACGTACGTACGTCGTA.........
>
> --
> Gary Greyling
> Electric Genetics
>
> _______________________________________________
> wxPython-users maillist  -  [hidden email]
> http://starship.python.net/mailman/listinfo/wxpython-users




_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users



Reply | Threaded
Open this post in threaded view
|

Re: [wxPython] How would one

Bill Eldridge-2
In reply to this post by Nicolas Chauvat-2

Or search Python for the thingy module at www.python.org, which
will let you treat a string as an array:

list = thingy.thingy()
list[:]='CATG' * 40
list[20:20]='TGAC' # (same as list.insert(20,'TGAC')
list[30:34]='' # Delete items 30,31,32,33
list.append( otherthingy)
list.sort()
list.reverse()


>From the docs:
-----------------------------------------------------------------
Thingies are (optionally) mutable strings, lists of bytes, in-memory
file
objects, and containers for buffer objects, all at the same time.  Why?
Well, why not?

Thingies support these list methods and operations:
        thingy.append(string)
        thingy.insert(index, string)
        thingy.count(char)
        thingy.index(char)
        thingy.remove(char)
        thingy.reverse()
        thingy.sort()
        thingy[index] = char
        thingy[lo:hi] = string
        string = thingy + 'meow'
        string = thingy * 42

And these file methods and attributes:
        thingy.write(string)
        thingy.writelines(list-of-strings)
        thingy.read([size])
        thingy.readline([size[, trim]])
        thingy.readlines(sizehint[, trim]])
        thingy.seek(position[, whence]])
        thingy.tell()
        thingy.truncate([size])
        thingy.flush()
        thingy.isatty()
        thingy.close()
        softspace, mode, name, closed, separator

etc. and so on.
Nicolas Chauvat wrote:

>
> > Split a string into segments 60 chars long ?
> > where consensus would be a string like
> >
> > CTTACGCAGTACTGAGTTACCGTAGTGTACGTCAGTAGTCGTACGTACGTACGTCGTA.........
>
> list = []
> while consensus :
>         list.append( consensus[:60] )
>         consensus = consensus[60:]
> #print list
>
> -- Nicolas
>
>  (o-  Hi, I'm a deadly e-mail virus, please copy me into your .signature
>  /\   file to help me spread. :: Bonjour, je suis un dangereux virus. SVP
> Y_/_  copiez-moi dans votre fichier .signature pour m'aider à me propager.
>
> _______________________________________________
> wxPython-users maillist  -  [hidden email]
> http://starship.python.net/mailman/listinfo/wxpython-users

--
Bill Eldridge
Radio Free Asia
[hidden email]

_______________________________________________
wxPython-users maillist  -  [hidden email]
http://starship.python.net/mailman/listinfo/wxpython-users