diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-11-13 00:16:53 +0300 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2008-11-13 00:16:53 +0300 |
commit | bdfe7d89e2f1292644577972c716931b4ce3c6c3 (patch) | |
tree | d00eb50b749cb001e2b08272c91791e66740b05d /release/scripts/console.py | |
parent | 78a1c27c4a6abe0ed31ca93ad21910f3df04da56 (diff) | |
parent | 7e4db234cee71ead34ee81a12e27da4bd548eb4b (diff) |
Merge of trunk into blender 2.5:
svn merge https://svn.blender.org/svnroot/bf-blender/trunk/blender -r12987:17416
Issues:
* GHOST/X11 had conflicting changes. Some code was added in 2.5, which was
later added in trunk also, but reverted partially, specifically revision
16683. I have left out this reversion in the 2.5 branch since I think it is
needed there.
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=16683
* Scons had various conflicting changes, I decided to go with trunk version
for everything except priorities and some library renaming.
* In creator.c, there were various fixes and fixes for fixes related to the -w
-W and -p options. In 2.5 -w and -W is not coded yet, and -p is done
differently. Since this is changed so much, and I don't think those fixes
would be needed in 2.5, I've left them out.
* Also in creator.c: there was code for a python bugfix where the screen was not
initialized when running with -P. The code that initializes the screen there
I had to disable, that can't work in 2.5 anymore but left it commented as a
reminder.
Further I had to disable some new function calls. using src/ and python/, as
was done already in this branch, disabled function calls:
* bpath.c: error reporting
* BME_conversions.c: editmesh conversion functions.
* SHD_dynamic: disabled almost completely, there is no python/.
* KX_PythonInit.cpp and Ketsji/ build files: Mathutils is not there, disabled.
* text.c: clipboard copy call.
* object.c: OB_SUPPORT_MATERIAL.
* DerivedMesh.c and subsurf_ccg, stipple_quarttone.
Still to be done:
* Go over files and functions that were moved to a different location but could
still use changes that were done in trunk.
Diffstat (limited to 'release/scripts/console.py')
-rw-r--r-- | release/scripts/console.py | 89 |
1 files changed, 55 insertions, 34 deletions
diff --git a/release/scripts/console.py b/release/scripts/console.py index 7d9d8be5e9e..0e46f41f581 100644 --- a/release/scripts/console.py +++ b/release/scripts/console.py @@ -1,14 +1,14 @@ #!BPY """ -Name: 'Interactive Console' -Blender: 237 +Name: 'Interactive Python Console' +Blender: 245 Group: 'System' Tooltip: 'Interactive Python Console' """ -__author__ = "Campbell Barton AKA Ideasman" -__url__ = ["Author's homepage, http://members.iinet.net.au/~cpbarton/ideasman/", "blender", "elysiun", "Official Python site, http://www.python.org"] +__author__ = "Campbell Barton aka ideasman42" +__url__ = ["www.blender.org", "blenderartists.org", "www.python.org"] __bpydoc__ = """\ This is an interactive console, similar to Python's own command line interpreter. Since it is embedded in Blender, it has access to all Blender Python modules. @@ -26,8 +26,6 @@ Usage:<br> - Ctrl + Enter: auto compleate based on variable names and modules loaded -- multiple choices popup a menu;<br> - Shift + Enter: multiline functions -- delays executing code until only Enter is pressed. """ -__author__ = "Campbell Barton AKA Ideasman" -__url__ = ["http://members.iinet.net.au/~cpbarton/ideasman/", "blender", "elysiun"] # -------------------------------------------------------------------------- # ***** BEGIN GPL LICENSE BLOCK ***** @@ -63,12 +61,14 @@ __LINE_HISTORY__ = 500 global __FONT_SIZE__ -__FONT_SIZES__ = ( ('tiny', 10), ('small', 12), ('normal', 14), ('large', 16) ) +__FONT_SIZES__ = ( ('tiny', 10), ('small', 12), ('normalfix', 14), ('large', 16) ) __FONT_SIZE__ = 2 # index for the list above, normal default. global __CONSOLE_LINE_OFFSET__ __CONSOLE_LINE_OFFSET__ = 0 +cmdBuffer = [] # dosnt need to be global + ''' # Generic Blender functions def getActScriptWinRect(): @@ -161,19 +161,13 @@ def include(filename): return compile(filedata, filename, 'exec') # Writes command line data to a blender text file. -def writeCmdData(cmdLineList, type): - if type == 3: - typeList = [0,1,2, 3, None] # all - else: - typeList = [type] # so we can use athe lists 'in' methiod - +def writeCmdData(type): newText = Text.New('command_output.py', 1) - for myCmd in cmdLineList: - if myCmd.type in typeList: # user input - newText.write('%s\n' % myCmd.cmd) + if type == 3: newText.write('\n'.join( [ myCmd.cmd for myCmd in cmdBuffer ] )) + else: newText.write('\n'.join( [ myCmd.cmd for myCmd in cmdBuffer if myCmd.type is type] )) Draw.PupMenu('%s written' % newText.name) -def insertCmdData(cmdBuffer): +def insertCmdData(): texts = list(bpy.data.texts) textNames = [tex.name for tex in texts] if textNames: @@ -339,7 +333,6 @@ def handle_event(evt, val): # Insert Char into the cammand line def insCh(ch): # Instert a char - global cmdBuffer global cursor # Later account for a cursor variable cmdBuffer[-1].cmd = ('%s%s%s' % ( cmdBuffer[-1].cmd[:cursor], ch, cmdBuffer[-1].cmd[cursor:])) @@ -348,7 +341,7 @@ def handle_event(evt, val): # Define Complex Key Actions # #------------------------------------------------------------------------------# def actionEnterKey(): - global histIndex, cursor, cmdBuffer + global histIndex, cursor def getIndent(string): # Gather white space to add in the previous line @@ -414,44 +407,64 @@ def handle_event(evt, val): # Clear the output based on __LINE_HISTORY__ if len(cmdBuffer) > __LINE_HISTORY__: - cmdBuffer = cmdBuffer[-__LINE_HISTORY__:] + cmdBuffer[:__LINE_HISTORY__] = [] histIndex = cursor = -1 # Reset cursor and history def actionUpKey(): - global histIndex, cmdBuffer + global histIndex if abs(histIndex)+1 >= len(cmdBuffer): histIndex = -1 + + # When wrapping allow 1 plank lines + if cmdBuffer[-1].cmd != ' ': + cmdBuffer[-1].cmd = ' ' + return + + histIndex_orig = histIndex histIndex -= 1 - while cmdBuffer[histIndex].type != 0 and abs(histIndex) < len(cmdBuffer): + + while (cmdBuffer[histIndex].type != 0 and abs(histIndex) < len(cmdBuffer)) or \ + ( cmdBuffer[histIndex].cmd == cmdBuffer[histIndex_orig].cmd): histIndex -= 1 + if cmdBuffer[histIndex].type == 0: # we found one cmdBuffer[-1].cmd = cmdBuffer[histIndex].cmd def actionDownKey(): - global histIndex, cmdBuffer + global histIndex if histIndex >= -2: histIndex = -len(cmdBuffer) + + # When wrapping allow 1 plank lines + if cmdBuffer[-1].cmd != ' ': + cmdBuffer[-1].cmd = ' ' + return + + histIndex_orig = histIndex histIndex += 1 - while cmdBuffer[histIndex].type != 0 and histIndex != -2: + while (cmdBuffer[histIndex].type != 0 and histIndex != -2) or \ + ( cmdBuffer[histIndex].cmd == cmdBuffer[histIndex_orig].cmd): + histIndex += 1 + if cmdBuffer[histIndex].type == 0: # we found one cmdBuffer[-1].cmd = cmdBuffer[histIndex].cmd def actionRightMouse(): global __FONT_SIZE__ - choice = Draw.PupMenu('Console Menu%t|Write Input Data (white)|Write Output Data (blue)|Write Error Data (red)|Write All Text|%l|Insert Blender text|%l|Font Size|%l|Quit') + choice = Draw.PupMenu('Console Menu%t|Write Input Data (white)|Write Output Data (blue)|Write Error Data (red)|Write All Text|%l|Insert Blender text|%l|Font Size|%l|Clear Output|Quit') if choice == 1: - writeCmdData(cmdBuffer, 0) # type 0 user + writeCmdData(0) # type 0 user elif choice == 2: - writeCmdData(cmdBuffer, 1) # type 1 user output + writeCmdData(1) # type 1 user output elif choice == 3: - writeCmdData(cmdBuffer, 2) # type 2 errors + writeCmdData(2) # type 2 errors elif choice == 4: - writeCmdData(cmdBuffer, 3) # All + writeCmdData(3) # All elif choice == 6: - insertCmdData(cmdBuffer) # Insert text from Blender and run it. + insertCmdData() # Insert text from Blender and run it. elif choice == 8: # Fontsize. font_choice = Draw.PupMenu('Font Size%t|Large|Normal|Small|Tiny') @@ -465,8 +478,10 @@ def handle_event(evt, val): elif font_choice == 4: __FONT_SIZE__ = 0 Draw.Redraw() - - elif choice == 10: # Exit + elif choice == 10: # Clear all output + cmdBuffer[:] = [cmd for cmd in cmdBuffer if cmd.type == 0] # keep user input + Draw.Redraw() + elif choice == 11: # Exit Draw.Exit() @@ -777,7 +792,6 @@ __CONSOLE_VAR_DICT__ = {} # Initialize var dict # Print Startup lines, add __bpydoc__ to the console startup. -cmdBuffer = [] for l in __bpydoc__.split('<br>'): cmdBuffer.append( cmdLine(l, 1, None) ) @@ -821,12 +835,19 @@ def include_console(includeFile): def standard_imports(): # Write local to global __CONSOLE_VAR_DICT__ for reuse, + + exec('%s%s' % ('__CONSOLE_VAR_DICT__["bpy"]=', 'bpy')) + exec('%s%s' % ('__CONSOLE_VAR_DICT__["Blender"]=', 'Blender')) + for ls in (dir(), dir(Blender)): for __TMP_VAR_NAME__ in ls: # Execute the local > global coversion. exec('%s%s' % ('__CONSOLE_VAR_DICT__[__TMP_VAR_NAME__]=', __TMP_VAR_NAME__)) - exec('%s%s' % ('__CONSOLE_VAR_DICT__["bpy"]=', 'bpy')) + # Add dummy imports to input so output scripts to a text file work as expected + cmdBuffer.append(cmdLine('import bpy', 0, 1)) + cmdBuffer.append(cmdLine('import Blender', 0, 1)) # pretend we have been executed, as we kindof have. + cmdBuffer.append(cmdLine('from Blender import *', 0, 1)) if scriptDir and console_autoexec: include_console(console_autoexec) # pass the blender module |