Krita Source Code Documentation
Loading...
Searching...
No Matches
krita.sceditor.console.PythonCompleter Class Reference
+ Inheritance diagram for krita.sceditor.console.PythonCompleter:

Public Member Functions

 __init__ (self, namespace)
 
 attr_matches (self, text)
 
 complete (self, text, state)
 
 global_matches (self, text)
 

Public Attributes

 matches
 
 namespace
 

Detailed Description

Definition at line 214 of file console.py.

Constructor & Destructor Documentation

◆ __init__()

krita.sceditor.console.PythonCompleter.__init__ ( self,
namespace )

Definition at line 216 of file console.py.

216 def __init__(self, namespace):
217 self.namespace = namespace
218

Member Function Documentation

◆ attr_matches()

krita.sceditor.console.PythonCompleter.attr_matches ( self,
text )

Definition at line 243 of file console.py.

243 def attr_matches(self, text):
244 def get_class_members(cls):
245 ret = dir(cls)
246 if hasattr(cls, '__bases__'):
247 for base in cls.__bases__:
248 ret = ret + get_class_members(base)
249 return ret
250 import re
251 m = re.match(r"(\w+(\.\w+)*)\.(\w*)", text)
252 if not m:
253 return
254 expr, attr = m.group(1, 3)
255 object = eval(expr, self.namespace)
256 words = dir(object)
257 if hasattr(object, '__class__'):
258 words.append('__class__')
259 words = words + get_class_members(object.__class__)
260 matches = []
261 n = len(attr)
262 for word in words:
263 if word[:n] == attr and word != "__builtins__":
264 matches.append("%s.%s" % (expr, word))
265 return matches
266
267

References KisPipeBrushParasite.dim, KisSpinBoxUnitManager.dim, FlattenSpec.dim, xcfLayer.dim, krita.sceditor.console.PythonCompleter.namespace, and krita.sceditor.console.PythonConsole.namespace.

◆ complete()

krita.sceditor.console.PythonCompleter.complete ( self,
text,
state )

Definition at line 219 of file console.py.

219 def complete(self, text, state):
220 if state == 0:
221 if "." in text:
222 self.matches = self.attr_matches(text)
223 else:
224 self.matches = self.global_matches(text)
225 try:
226 return self.matches[state]
227 except IndexError:
228 return None
229

◆ global_matches()

krita.sceditor.console.PythonCompleter.global_matches ( self,
text )

Definition at line 230 of file console.py.

230 def global_matches(self, text):
231 import keyword
232 import __builtin__
233 matches = []
234 n = len(text)
235 for list in [keyword.kwlist,
236 __builtin__.__dict__,
237 self.namespace]:
238 for word in list:
239 if word[:n] == text and word != "__builtins__":
240 matches.append(word)
241 return matches
242

References krita.sceditor.console.PythonCompleter.namespace, and krita.sceditor.console.PythonConsole.namespace.

Member Data Documentation

◆ matches

krita.sceditor.console.PythonCompleter.matches

Definition at line 222 of file console.py.

◆ namespace

krita.sceditor.console.PythonCompleter.namespace

Definition at line 217 of file console.py.


The documentation for this class was generated from the following file: