Integrate the console output into Blender's UI as a new space type
Closed, ArchivedPublic

Description

This patch is the first candidate that I consider good enough to submit.

The system works for both Windows and Linux a.t.m (I assume Mac and others
should just work because I am using normal POSIX calls to do the
redirection if the WIN32 defines are not set). Currently the following
is implemented:

1. Command line option -c to disable the redirection and print
everything to the console as before.

2. When -b is used the -c is implied. This should keep the existing
programs that rely on this flag working as normal.

3. On Windows a console will be shown when -c is used, otherwise the
console will be released (if you are already in a console it regains
user input, otherwise a console flashes briefly and then goes away).

4. Theming of the window (black BG, white text, blue select, red error). I am welcome to suggestions for changes to this. The scroll bar may need some thought.

5. Added a hotkey Ctrl-Shift-F11 (Text window is Shift-F11 so I thought it may be a good choice.

6. Simple header buttons for the Console Output (Copy/paste/clear)

There was a lot of talk on the ML about how this system can be further extended but I believe in its current form it can already deliver a lot of value. I will continue development after hashing out some requirements on the ML and documenting them in the wiki as I liked many of the ideas that came out of the discussions and would also like to see these features. I would however appreciate it if this can be commited after a review, because the patch is big and it is hard to maintain as I have constantly merge between my own source control and CVS (I do not have CVS write, but would like to;)



Details

Type
Patch

connecté
user_id=3164

Hello, I made a compilation with your patch, I post on blender.org testing forum ( http://blender.org/forum/viewtopic.php?t=8651 ) and Poutsa found a bug, when pressing Play in the render panel, the external console open, and it closed when closed the anim window.

Logged In: YES
user_id=470

Thanks for testing.

Fixed and uploaded a new patch.

Logged In: YES
user_id=470

Thanks for testing.

Fixed and uploaded a new patch.

Logged In: YES
user_id=470

Pressed submit too soon (twice it seems, I was trying to delete the extra files but don't have permission).

Anyway...

I made a new BLI_exec function that spawns an external program in a specific way. Should be used instead of system for cases like this. This can be extended later to capture output or communicate with commandline apps for the purpose of this internal console.

Logged In: YES
user_id=3212

It seems not to work for Mac OS X.

If I launch Blender by double-clicking the .app package, the output still goes to the console log (appears in Console.app) and nothing appears in Blender's console output window.

If I launch from the command line, Blender is fine until I do something that would send text to stdout (like running a Python script). At that point, Blender crashes and simply returns "Bus error" to stdout.

Good luck with this patch. It will be very nice when I don't have to switch between Blender and Console.app to see output.

Logged In: YES
user_id=470

Hi,

Sorry for taking so long to respond, got tied up with other stuff this last couple of weeks. I tried to look at this after getting an oppurtunity with Mac OS X Intel. Unfortunately it is quite a mission to get it to compile (and it wouldn't run once it did), so I'm giving up on that for now. I don't have access to Mac PPC so if somebody can debug into this for me I would appreciate it.

I am starting to think that I should change the default option to output to console as before and maybe completely remove the space in this case inside the UI. Should have something for the weekend.

Logged In: YES
user_id=4793

Admittedly a contrived and probably useless example, but this may?? indicate other problems :

I ran a little script to count from 1-5,000, and print the start and end times

The actual execution time for the script was over a minute ! (Some buffering issues?) .. while the 'end time' printed was ~.5 second :)

Also Ctrl-C appears to have no effect (with the mouse cursor over the integrated console window.

Mike
-------------------------
import Blender
start = Blender.sys.time()

for i in range(5000):
print i

end = Blender.sys.time()
diff = end - start
print 's=',start,'e=',end,'dif=',diff
-------------------------------------



Angemeldet: JA
user_id=4620

hi,

i like that patch, but i got an error too.
so if i startup blender from a console (kterm e.g.), and then i quit blender, the blender window is still open and does not repond to keyboard or mouse. i have to change to the console and press ctrl+c there to quit blender completely. i think it shouldnt happen :)

thx, the patch is great, didnt test it too much, but its great to have output from blender in a console space now, esp. for those who dont start blender via a console.

e.g. some error messages (crop+fields) will only appear in the console log.

yours
vizzy/verblendet

Logged In: YES
user_id=4793

I tried using the interactive console script, get this error message after a 'print' statement :

error: Traceback (most recent call last):
error: File "<string>", line 654, in handle_event
error: File "<string>", line 416, in actionEnterKey
error: File "<string>", line 291, in runUserCode
error: AttributeError: my_stdout instance has no attribute 'flush'

Mike

Logged In: YES
user_id=470

Okay, here goes...

I fixed a number of small things I found while reviewing the code, but on the three issues above:

1. Execution time for loop printing to console: I figured this one out, the same text structure and functions for the script window was used and the undo/redo system just did a crazy amount of work storing the undo buffer for every character added to a buffer. Disabling this enabled the execution to complete in the expected time (~.5s) and all output flushed to buffer at end of execution. I revised the code to do a redraw properly for when newlines are detected during script execution, but this increases the execution time considerably as the screen scrolls through the 5000 lines. It seems to spend most of the time in OpenGL swapping etc, so still investigating. May make this a setting for the console window (enable/disable output during script execution) if there is no easy way to optimize this.

2. Hang on exit: I seem to recall fixing this in console_patch4.zip when I tested everything on Linux. If this is the patch that you were using I will look into that again, or wait until I post a patch again and try it out again please.

3. Still investigating. Could reproduce.

Logged In: YES
user_id=470

On issue 3 above, found the problem as soon as I looked at it. Easy to fix.

Logged In: YES
user_id=470

Okay, here is another patch against current CVS that should fix most of the issues described here. I also cleaned up the code some more, tracked down one or two memory leaks and changed the default behaviour. The -c option now enables the console space in the UI (the other way round was obviously not a good idea) and without it Blender works as it does now (output to console).

I still need to figure out if it is possible to optimize the repainting after new lines as it is much slower than without it. If not then make it a option in the header butttons for the console window.

Also still need to implement Ctrl-C or equivalent for canceling long runs (may need to redirect stdin too which will come in handy for maybe integrating the interactive interpreter into this space).

Anyway, I hope that it may be possible for someone to commit this to CVS after some review as it would make it better for me to post quick patches to the system as well as maybe encourage more people to participate in this feature and investigate bugs (e.g. the one on Mac OSX). Note that without explicitely using the -c command line none of the code in the patch will be executed and Blender will operate normally.

Will post a Windows build soon too.

Logged In: YES
user_id=470

Windows Build can be found at: http://jb-online.net/?p=12

Logged In: YES
user_id=470

Windows Build can be found at: http://jb-online.net/?p=12

Logged In: YES
user_id=103

Hi Jbinto,

I can confirm it's desired functionality for Blender. I could use some feedback from python coders though... maybe they want a traditional console too. Also for debugging Blender, output prints in a traditional shell is important to keep. So at least I hope its an option?

Anyhoo; I'm the only one really experienced in adding new 'space types' and reviewing code for that. As you might have noticed, there's a huge line of reviews waiting still.
Also because we want to release soon, i'd propose to work on this after release is out, then the code can get tested well too.

Logged In: YES
user_id=470

Hi Ton,

Sounds good, I'm not really that much in a hurry to get it commited, as long as there is a possibility for it in the future. I was a little pushy on the commits in my initial msgs considering I can still clean things up a bit. Note however that in the patch's current state (5) the console window will only appear if the new -c command line flag is used, otherwise Blender operates as before.

Also I am rewriting the drawing code right now as I realized there is huge inefficiencies (unnecessary undo/redo etc.) in the code that I hijacked from the script editor drawing. This should also make it easier to extend and add new functionality (i.e. the stuff in the Wiki).

Logged In: YES
user_id=470

Hi,

Here is an updated patch against current CVS. I have work in progress to improve the speed of redraws significantly but this patch is just basically a sync of the number 5 patch attached here to current CVS, in the hope that it can get committed so that the patches/updated are easier to maintain. The blenderbuttons binary and generated C file are in it because I added a new icon for the console space and it is the main reason this patch is so big.

Note that the hotkeys.py patched kind of strangely, it removed all the lines and then replaced it, my guess is that it was due to Windows EOL (I was editing using nano on a Mac) formats which was submitted to CVS but did not look at it very closely, I just added a new line and made sure that I got all the changes that has been going into that file since, it should be ok.

There is still a bug on the Mac in that it hangs on exit if you use the -c command line, I will look into that soon.

Cheers,
Jacques




Logged In: YES
user_id=470

I fixed the hang on exits on Macs, just uploading the affected file as it is a new one (goes in source/blender/src) and the patch does not need to be regenerated.

Logged In: YES
user_id=103

I have time now (this/next week). Will try to get more reviews from our team first!

Logged In: YES
user_id=103

My agenda kept being polluted with other urgent stuff... and I try to not get a complete burnout too! :)
Anyhoo, this is still there to be reviewed, but I've promised to work on animation topics, finishing render pipeline, and transferring compositor maintenance first now... please don't give up!

Logged In: YES
user_id=470

Hi Ton,

I am glad that this is still under consideration, I have almost given up;)

Because it is hard to continually post patches for this here that will build against current CVS, let me know when it is imminent that you will be looking at it (maybe a day or so before) and I will get you a patch against recent CVS.

Thanks,
Jacques

Logged In: YES
user_id=470

Deleted old patches

As there is no message of closed patch here, I was wondering if this patch is still in Blender development plans.

And if there is any version of the patch updated to current SNV. I would like to test it with BGE.

Hi Dalai,

Since working on this initially I have become occupied elsewhere to such an extent that I had no time to spend on tinkering with Blender. Also I believe no one was significantly interested in this functionality to really evaluate my patches for possible inclusion in Blender (as you can see by the lack of responses to this in the Tracker).

That being said I have been considering getting back into Blender lately and I might consider picking up this patch again. I would like to have some indication from the core devs that they would consider this again for inclusion though.

Hi Jacques,

I would love to see a console builtin, it's one of the specs in 2.50 even. :)
(I want a console to print user operations in python syntax, including the option to execute)

However, before you start you might align first all your specs with what others will exect from a console. It should not be a regression to use it, something to carefully look at. (For example, find a way to thread it, for render output)

Ton Roosendaal (ton) closed this task as Archived.Sep 18 2008, 5:39 PM

Hi Ton,

Good to hear this, if that is the case then I will resume the work. Since I originally did this I've gained some experience on other fronts and think I will probably just use my patch as guidelines for a new implementation on top of the current SVN (after discussing specs and design on the mailing list of course).

The only thing is that I will not be able to do any real work until November since I will be in transit from next week throughout October, after which I should have quite a bit of free time to spend on this. Will post a status update then....