Re: wxWindow GetPosition() bug???

2006-08-22 Thread Andre Poenitz
mardif <[EMAIL PROTECTED]> wrote:
> Hi,
> I've found a strange behavior in method GetPosition() of wxWindow class
> 
> ( and derived ).
> On windows, if you create a window object
> 
> frame = wx.Frame(None, -1, "TESTING")
> 
> and you set the position to:
> frame.SetPosition( (300, 45000) )
> 
> If you call method GetPosition, the result will be:
> frame.GetPosition()
> >>> (300, 32767)
> 
> 32767 is the integer limit. Why GetPosition() returns this value??? and
> 
> why on Unix Platform this problem was not found??
> 
> thx very much!

Traditionally, there was a 16(15?) bit limit for coordinates on X Window
systems.

Maybe the wx implementations tries to be smarter than X itself and
restricts the positions artificially. Maybe Windows has sch a limit 
itself...

I don't really know, other than 'never try to access coordinates
that are 'much' bigger than what is actually visible'...

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


Re: Loading module via full path

2006-08-22 Thread Andre Poenitz
Gary Herron <[EMAIL PROTECTED]> wrote:
> Andre Poenitz wrote:
>> Hi all.
>>
>> Is there a way to load a module given a full path to the module
>> without extending sys.path first?
>
> The standard module named "imp" can help you with this.

Thank you. I got stuck on http://docs.python.org/api/importing.html
(as I need it to be called from C(++)) and found no way to specify a path there
[and there aren't too many cross references in the python docs *sigh*]

I have now something similar to

class CPyObject
{
public:
  explicit CPyObject(PyObject * pObject) : m_pObject(pObject) { /*Check();*/ }
  ~CPyObject() { Py_XDECREF(m_pObject); }
  operator PyObject *() { return m_pObject; }
private:
  CPyObject(const CPyObject &);  // intentionally not implemented
  void operator=(const CPyObject &); // intentionally not implemented
  PyObject * m_pObject;
};

static PyObject * LoadModule(const char * mod, const char * path)
{
  CPyObject pyImpModule ( PyImport_Import(PyString_FromString("imp")) ); 

  CPyObject pyImpFindModuleFunc ( PyObject_GetAttrString(pyImpModule, 
"find_module") ); 
  CPyObject pyImpFindModuleArgs ( Py_BuildValue("s[s]", mod, path) );
  CPyObject pyImpFindModuleRes  ( PyObject_CallObject(pyImpFindModuleFunc, 
pyImpFindModuleArgs) ); 

  CPyObject pyImpLoadModuleFunc ( PyObject_GetAttrString(pyImpModule, 
"load_module") ); 
  CPyObject pyImpLoadModuleArgs ( Py_BuildValue("sOOO",
mod,
PyTuple_GetItem(pyImpFindModuleRes, 0),
PyTuple_GetItem(pyImpFindModuleRes, 1),
PyTuple_GetItem(pyImpFindModuleRes, 2)
  )); 
  return PyObject_CallObject(pyImpLoadModuleFunc, pyImpLoadModuleArgs);
}

which seems to do what I want even if it looks a bit too verbose for my taste 
and I
don't know whether I go the reference counting right.

Thanks for the hint,
Andre'
-- 
http://mail.python.org/mailman/listinfo/python-list


Re: Loading module via full path

2006-08-21 Thread Andre Poenitz
Andre Poenitz <[EMAIL PROTECTED]> wrote:
> Hi all.
> 
> Is there a way to load a module given a full path to the module
> without extending sys.path first?

Ok. imp.find_module() and imp.load_module() seem to do what I need.

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


Re: Stack trace in C

2006-08-21 Thread Andre Poenitz
Just <[EMAIL PROTECTED]> wrote:
> 
>> On Tue, 25 Jul 2006 14:20:41 +0200, Andre Poenitz  wrote:
>> >
>> >
>> >Bear with me - I am new to Python. (And redirect me to a more suitable
>> >newsgroup in case this one is not appropriate.)
>> >
>> >I am trying to embed Python into a C++ application and want to get back
>> >a backtrace in case of errors in the python code.
>> 
>> I think you'd have more luck with the traceback module, which has such
>> methods as format_exception and print_tb.
> 
> From C, PyErr_Print() is often handy (if only for debugging).

I'd like to display the backtrace i a fancy gui widget, and PyErr_Print
sends everything to stderr...

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


Re: Stack trace in C

2006-08-21 Thread Andre Poenitz
Jean-Paul Calderone <[EMAIL PROTECTED]> wrote:
> On Tue, 25 Jul 2006 14:20:41 +0200, Andre Poenitz <[EMAIL PROTECTED]> wrote:
>>
>>
>>Bear with me - I am new to Python. (And redirect me to a more suitable
>>newsgroup in case this one is not appropriate.)
>>
>>I am trying to embed Python into a C++ application and want to get back
>>a backtrace in case of errors in the python code.
> 
> I think you'd have more luck with the traceback module, which has such
> methods as format_exception and print_tb.

That's where I got my 'inspiration' from.

Unfortunately my attempt to translate this into C failed, and I can't
see the reason.

Thanks for the hint nevertheless

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


Loading module via full path

2006-08-21 Thread Andre Poenitz
Hi all.

Is there a way to load a module given a full path to the module
without extending sys.path first?

Andre'

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


Stack trace in C

2006-07-25 Thread Andre Poenitz


Bear with me - I am new to Python. (And redirect me to a more suitable
newsgroup in case this one is not appropriate.)

I am trying to embed Python into a C++ application and want to get back
a backtrace in case of errors in the python code.

This works well with e.g.

  import sys

  def u3():
xx() # raise an error

  def u2():
u3()

  def u1():
u2()

  def f():
try:
  u1()
except NameError:
  type, value, tb = sys.exc_info()
  #f = tb.tb_frame
  #while f:
  #   print f.f_lineno, f.f_code.co_name
  #   f = f.f_back
  #print "==="
  while tb:
  f = tb.tb_frame
  print f.f_lineno, f.f_code.co_name
  tb = tb.tb_next

  def d1():
f()

  def d2():
d1()

  d2()


on the python side.

However, I want to do that on the C side.


So far I have code similar to


  std::ostringstream msg;

  [...]
#if 1
// Branch 1
PyObject * exc_type = 0;
PyObject * exc_value = 0;
PyObject * exc_traceback = 0;
PyErr_Fetch(&exc_type, &exc_value, &exc_traceback);
PyObject * tb_frame = PyObject_GetAttrString(exc_traceback, "tb_frame");
#else
// Branch 2
PyObject * pName = PyString_FromString("sys");
PyObject * pModule = PyImport_Import(pName);
PyObject * pFunc = PyObject_GetAttrString(pModule, "exc_info");
PyObject * pResult = PyObject_CallObject(pFunc, NULL);
PyObject * tb_frame = PySequence_GetItem(pResult, 2);
#endif
while (tb_frame != Py_None) {
  PyObject * f_code = PyObject_GetAttrString(tb_frame, "f_code");
  PyObject * f_lineno = PyObject_GetAttrString(tb_frame, "f_lineno");
  int lineno = PyInt_AsLong(f_lineno);
  msg << " in line " << lineno << "\n";
  PyObject * tmp1 = PyObject_GetAttrString(tb_frame, "f_back");
  PyObject * tmp2 = PyObject_GetAttrString(tb_frame, "tb_next");
  // Now, neither tmp1 nor tmp2 is usable
  // tb_frame = tmpX;
}
  }


[Plus some reference counting/error checking code I left out] 

The 'Branch 1' version works for a sinmgle frame, but then tmp1 will be
None and tmp2 0 at the end of the iteration and so no further frames
are found.

The 'Branch 2' version creates immediatly tb_frame as None and
does not even enter the loop body once.

So what am I doing wrong? How do I get the equivalent of the python
code in C?
 
Andre'


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