[Bf-extensions-cvs] [2340495d] master: Intellisense for Text Editor: adress key register, cleanup
lijenstina
noreply at git.blender.org
Mon Jun 12 04:19:24 CEST 2017
Commit: 2340495df50b9a22b58ea40861ac2b32adca0211
Author: lijenstina
Date: Mon Jun 12 04:18:36 2017 +0200
Branches: master
https://developer.blender.org/rBAC2340495df50b9a22b58ea40861ac2b32adca0211
Intellisense for Text Editor: adress key register, cleanup
Bumped version to 0.2.1
Part of the T51547:
Solve the key registration / reload issues related to the
keys being registered and never removed
moved to the new key register system
text.test_line was used as the bl_idname of a Panel and an
Operator
Pep8 cleanup
Replace tabs with spaces
Fix crashes on empty text block - add a check for that case
Comment out the pdb runcall as it needs a specific function
or a object method not a string
Use the with method for the file creation
===================================================================
M text_intellisense.py
===================================================================
diff --git a/text_intellisense.py b/text_intellisense.py
index d981ce0b..45de1154 100644
--- a/text_intellisense.py
+++ b/text_intellisense.py
@@ -1,6 +1,5 @@
# ***** BEGIN GPL LICENSE BLOCK *****
#
-#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
@@ -20,8 +19,8 @@
bl_info = {
"name": "Intellisense for Text Editor",
"author": "Mackraken",
- "version": (0, 2),
- "blender": (2, 60, 0),
+ "version": (0, 2, 1),
+ "blender": (2, 78, 5),
"location": "Ctrl + Space at Text Editor",
"description": "Adds intellense to the Text Editor",
"warning": "Only works with 2.57 intellisense",
@@ -30,406 +29,466 @@ bl_info = {
"category": "Development"}
import bpy
+from bpy_extras import keyconfig_utils
+
def complete(context):
- from console import intellisense
- from console_python import get_console
+ from console import intellisense
+ from console_python import get_console
- sc = context.space_data
- text = sc.text
+ sc = context.space_data
+ text = sc.text
- region = context.region
- for area in context.screen.areas:
- if area.type=="CONSOLE":
- region = area.regions[1]
- break
+ region = context.region
+ for area in context.screen.areas:
+ if area.type == "CONSOLE":
+ region = area.regions[1]
+ break
- console = get_console(hash(region))[0]
+ console = get_console(hash(region))[0]
- line = text.current_line.body
- cursor = text.current_character
+ line = text.current_line.body
+ cursor = text.current_character
- result = intellisense.expand(line, cursor, console.locals, bpy.app.debug)
+ result = intellisense.expand(line, cursor, console.locals, bpy.app.debug)
- return result
+ return result
class Intellimenu(bpy.types.Menu):
- bl_label = ""
- bl_idname = "IntelliMenu"
+ bl_label = ""
+ bl_idname = "IntelliMenu"
- text = ""
+ text = ""
- def draw(self, context):
- layout = self.layout
- #Very ugly see how can i fix this
- options = complete(context)
+ def draw(self, context):
+ layout = self.layout
+ # Very ugly see how can i fix this
+ options = complete(context)
- options = options[2].split(" ")
- for op in options:
- layout.operator("text.intellioptions", text=op).text=op
+ options = options[2].split(" ")
+ for op in options:
+ layout.operator("text.intellioptions", text=op).text = op
-#This operator executes when hits Ctrl+Space at the text editor
-class Intellisense(bpy.types.Operator):
- #"""Tooltip"""
- bl_idname = "text.intellisense"
- bl_label = "Text Editor Intellisense"
+# This operator executes when hits Ctrl+Space at the text editor
- text = ""
+class Intellisense(bpy.types.Operator):
+ bl_idname = "text.intellisense"
+ bl_label = "Text Editor Intellisense"
-# @classmethod
-# def poll(cls, context):
-# return context.active_object is not None
+ text = ""
- def execute(self, context):
- sc = context.space_data
- text = sc.text
+ """
+ @classmethod
+ def poll(cls, context):
+ return context.active_object is not None
+ """
- if text.current_character>0:
- result = complete(context)
+ def execute(self, context):
+ sc = context.space_data
+ text = sc.text
- #print(result)
+ if text.current_character > 0:
+ result = complete(context)
- if result[2]=="":
- text.current_line.body = result[0]
- bpy.ops.text.move(type='LINE_END')
- else:
- bpy.ops.wm.call_menu(name=Intellimenu.bl_idname)
+ # print(result)
- return {'FINISHED'}
+ if result[2] == "":
+ text.current_line.body = result[0]
+ bpy.ops.text.move(type='LINE_END')
+ else:
+ bpy.ops.wm.call_menu(name=Intellimenu.bl_idname)
-#this operator completes the line with the options you choose from the menu
-class Intellioptions(bpy.types.Operator):
- #"""Tooltip"""
- bl_idname = "text.intellioptions"
- bl_label = "Intellisense options"
+ return {'FINISHED'}
- text = bpy.props.StringProperty()
- @classmethod
- def poll(cls, context):
- return context.active_object is not None
+# this operator completes the line with the options you choose from the menu
+class Intellioptions(bpy.types.Operator):
+ bl_idname = "text.intellioptions"
+ bl_label = "Intellisense options"
- def execute(self, context):
- sc = context.space_data
- text = sc.text
+ text = bpy.props.StringProperty()
- comp = self.text
- line = text.current_line.body
+ @classmethod
+ def poll(cls, context):
+ return context.active_object is not None
- lline = len(line)
- lcomp = len(comp)
+ def execute(self, context):
+ sc = context.space_data
+ text = sc.text
- #intersect text
- intersect = [-1,-1]
+ if not text:
+ self.report({'WARNING'},
+ "No Text-Block active. Operation Cancelled")
- for i in range(lcomp):
- val1 = comp[0:i+1]
+ return {"CANCELLED"}
- for j in range(lline):
- val2 = line[lline-j-1::]
- #print(" ",j, val2)
+ comp = self.text
+ line = text.current_line.body
- if val1==val2:
- intersect = [i, j]
- break
+ lline = len(line)
+ lcomp = len(comp)
- if intersect[0]>-1:
- newline = line[0:lline-intersect[1]-1]+comp
- else:
- newline = line + comp
+ # intersect text
+ intersect = [-1, -1]
- #print(newline)
- text.current_line.body = newline
+ for i in range(lcomp):
+ val1 = comp[0: i + 1]
- bpy.ops.text.move(type='LINE_END')
+ for j in range(lline):
+ val2 = line[lline - j - 1::]
+ # print(" ",j, val2)
+ if val1 == val2:
+ intersect = [i, j]
+ break
- return {'FINISHED'}
+ if intersect[0] > -1:
+ newline = line[0: lline - intersect[1] - 1] + comp
+ else:
+ newline = line + comp
-def send_console(context, all=0):
+ # print(newline)
+ text.current_line.body = newline
- sc = context.space_data
- text = sc.text
+ bpy.ops.text.move(type='LINE_END')
- console = None
+ return {'FINISHED'}
- for area in bpy.context.screen.areas:
- if area.type=="CONSOLE":
- from console_python import get_console
- console = get_console(hash(area.regions[1]))[0]
+def send_console(context, alls=0):
- if console==None:
- return {'FINISHED'}
+ sc = context.space_data
+ text = sc.text
- if all:
+ console = None
- for l in text.lines:
- console.push(l.body)
+ for area in bpy.context.screen.areas:
+ if area.type == "CONSOLE":
+ from console_python import get_console
- else:
- #print(console.prompt)
- console.push(text.current_line.body)
+ console = get_console(hash(area.regions[1]))[0]
+ if console is None:
+ return {'FINISHED'}
+ if alls:
+ for l in text.lines:
+ console.push(l.body)
+ else:
+ # print(console.prompt)
+ console.push(text.current_line.body)
class TestLine(bpy.types.Operator):
- #"""Tooltip"""
- bl_idname = "text.test_line"
- bl_label = "Test line"
+ bl_idname = "text.test_line"
+ bl_label = "Test line"
- all = bpy.props.BoolProperty(default=False)
+ all = bpy.props.BoolProperty(default=False)
+ """
+ @classmethod
+ def poll(cls, context):
+ return context.active_object is not None
+ """
+ def execute(self, context):
+ # print("test line")
-# @classmethod
-# def poll(cls, context):
-# return context.active_object is not None
+ # send_console(context, self.all)
+ sc = context.space_data
+ text = sc.text
- def execute(self, context):
- #print("test line")
+ if not text:
+ self.report({'WARNING'},
+ "No Text-Block active. Operation Cancelled")
- #send_console(context, self.all)
- sc = context.space_data
- text = sc.text
+ return {"CANCELLED"}
- line = text.current_line.body
- console = None
+ line = text.current_line.body
+ console = None
- for area in bpy.context.screen.areas:
- if area.type=="CONSOLE":
- from console_python import get_console
+ for area in bpy.context.screen.areas:
+ if area.type == "CONSOLE":
+ from console_python import get_console
- console = get_console(hash(area.regions[1]))[0]
+ console = get_console(hash(area.regions[1]))[0]
- if console==None:
- return {'FINISHED'}
+ if console is None:
+ return {'FINISHED'}
- command = ""
+ command = ""
- forindex = line.find("for ")
- if forindex >-1:
+ forindex = line.find("for ")
+ if forindex > -1:
- var = line[forindex+4:-1]
- var = var[0:var.find(" ")]
- state = line[line.rindex(" ")+1:-1]
+ var = line[forindex + 4: -1]
+ var = var[0: var.find(" ")]
+ state = line[line.rindex(" ") + 1: -1]
- command = var + " = " +state+"[0]"
+ command = var + " = " + state + "[0]"
+ else:
+ command = line
- else:
- command = line
+ # print(command)
+ try:
+ console.push(command)
+ except:
+ pass
- #print(command)
- try:
- console.push(command)
- except:
- pass
+ bpy.ops.text.line_break()
- bpy.ops.text.line_break()
+ return {'FINISHED'}
- return {'FINISHED'}
class SetBreakPoint(bpy.types.Operator):
- bl_idname = "text.set_breakpoint"
- bl_label = "Set Breakpoint"
-
- def execute(self, context):
-
- sc = bpy.context.space_data
- text = sc.text
-
- line = text.current_line
- br = " #breakpoint"
- #print(line.body.find(br))
- if line.body.find(br)>-1:
-
- line.body = line.body.replace(br, "")
- else:
-
- line.body += br
-
- return {'FINISHED'}
-
-class Debug(bpy.types.Operator):
- bl_idname = "text.debug"
- bl_label = "Debug"
-
- def execute(self, context):
-
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-extensions-cvs
mailing list