View Issue Details

IDProjectCategoryView StatusLast Update
0000826FreeCADPatchpublic2013-05-14 11:20
Reporterzappl Assigned Towmayer  
PrioritynormalSeverityfeatureReproducibilityalways
Status closedResolutionfixed 
Product Version0.12 
Fixed in Version0.14 
Summary0000826: reading from the python console for using pdb
DescriptionAs discussed in the forum:
Using pdb within FreeCAD will show up another input dialog where I've to put my pdb commands. The most annoying thing about this is, one has to give my pdb commands by keyboard, but can't commit them via "return"; It's necessary to click "OK" instead - for every single step.
This makes the use of the python debugger quite complicated.

Additional InformationThe attached patch changes this behaviour.
Nested input line consumers (like pdb) will use the default python console for stdin. See commit message for additional implementation details.

Test within python console:
def func( arg = 10 ):
   import pdb; pdb.set_trace()
   for i in xrange(arg):
      print i

func()

Note: a possible cleanup of unused code is not done yet!
There is some code that's not needed any more.
 - class PythonInputField (and localization info?)
 - parts of class PythonStdin

TagsNo tags attached.
FreeCAD Information

Activities

2012-09-07 11:34

 

1264-changed-PythonStdin-s-readline-to-read-from-python-c.patch (Attachment missing)

wmayer

2012-09-07 21:36

administrator   ~0002357

Sorry, but something seems wrong with your patch because neither "git apply" nor the patch command work. git apply tells about errors on PythonConsole.cpp/.h and the patch command applies only a couple of changes but not all.

zappl

2012-09-07 22:41

reporter   ~0002358

Hmmm - strange. Well I'm gonna create another patch, considerig the latest git revision.
However his will have to wait until Monday. For now, have a nice WE.

wmayer

2012-09-08 08:35

administrator   ~0002360

OK, I solved it by myself. It was a simple whitespace problem and doing a "git apply --ignore-whitespace" fixed it.

Btw, the contribution is really great. Thanks again for your effort.

2012-09-10 13:37

 

0001-little-bugfix-move-cursor-to-end-for-printing-prompt.patch (Attachment missing)

zappl

2012-09-10 13:48

reporter   ~0002368

Glad it works for you, and you like it.
However, I alredy spotted a little bug in my changes. Well, that's life :->
I missed to set the cursor to the end for printing the prompt in mode "Special".
To be reproduced by:
* call a function containing a pdb.set_trace()
* make some steps, print arguments etc. (just to get something to history)
* type Up-key to get previous command, change it a bit, and press Enter
=> the prompt moves on while the cursor stays where it is.
Well, it's not a big deal and it doesn't seem to cause problems, but it looks strange.
So, please see the little patch I attached again.

wmayer

2012-09-11 07:11

administrator   ~0002377

I noticed a bug. When you try to close the application while the debugger is running the application doesn't exit.
To fix this the return value of loop.exec() needs to be checked because it's always -1 when you call it while the application is about to being closed. In this case I return the string "quit()" to close the debugger, then.

If you are in interactive "help" mode there was no problem.

Are there other interactive modes in Python other than debugger or help that needs to be checked?

zappl

2012-09-12 07:08

reporter   ~0002389

That's a really good point! Didn't think about that.
Simply returning "quit()" would do the trick in case of pdb, but it won't work for other cases, e.g. something like ...
while sys.stdin.readline(): print

Thus, I'd propose sending SIGINT to the python interpreter if loop.exec() returns with an error code (see latest patch).
As far as my tests go, this seems to work like a charm.

Btw: I'm trying to get this working generally, i.e. to make python scripts interruptable. But this is a bit more tricky, because i need another thread listening to keyPressEvents while the interpreter is running.

2012-09-12 07:09

 

0001-send-SIGINT-to-python-interpreter-if-QEventLoop-exit.patch (Attachment missing)

wmayer

2013-05-14 11:20

administrator   ~0003151

class PythonInputField has been removed

git show 8104548

Issue History

Date Modified Username Field Change
2012-09-07 11:34 zappl New Issue
2012-09-07 11:34 zappl File Added: 1264-changed-PythonStdin-s-readline-to-read-from-python-c.patch
2012-09-07 21:36 wmayer Note Added: 0002357
2012-09-07 22:41 zappl Note Added: 0002358
2012-09-08 08:35 wmayer Note Added: 0002360
2012-09-10 13:37 zappl File Added: 0001-little-bugfix-move-cursor-to-end-for-printing-prompt.patch
2012-09-10 13:48 zappl Note Added: 0002368
2012-09-11 07:11 wmayer Note Added: 0002377
2012-09-12 07:08 zappl Note Added: 0002389
2012-09-12 07:09 zappl File Added: 0001-send-SIGINT-to-python-interpreter-if-QEventLoop-exit.patch
2013-05-14 11:06 wmayer Status new => assigned
2013-05-14 11:06 wmayer Assigned To => wmayer
2013-05-14 11:20 wmayer Note Added: 0003151
2013-05-14 11:20 wmayer Status assigned => closed
2013-05-14 11:20 wmayer Resolution open => fixed
2013-05-14 11:20 wmayer Fixed in Version => 0.14