Krita Source Code Documentation
Loading...
Searching...
No Matches
krita.decorators Namespace Reference

Functions

 _callAll (plugin, functions, *args, **kwargs)
 
 _registerCallback (plugin, event, func)
 
 _simpleEventListener (func)
 
 init (func)
 
 pykritaEventHandler (event)
 
 unload (func)
 

Detailed Description

Decorators used in plugins

Function Documentation

◆ _callAll()

krita.decorators._callAll ( plugin,
functions,
* args,
** kwargs )
protected

Definition at line 37 of file decorators.py.

37def _callAll(plugin, functions, *args, **kwargs):
38 if plugin in functions:
39 for f in functions[plugin]:
40 try:
41 f(*args, **kwargs)
42 except:
43 traceback.print_exc()
44 sys.stderr.write('\n')
45 # TODO Return smth to a caller, so in case of
46 # failed initialization it may report smth to the
47 # C++ level and latter can show an error to the user...
48 continue
49
50

◆ _registerCallback()

krita.decorators._registerCallback ( plugin,
event,
func )
protected

Definition at line 60 of file decorators.py.

60def _registerCallback(plugin, event, func):
61 if plugin not in event.functions:
62 event.functions[plugin] = set()
63
64 event.functions[plugin].add(func)
65 return func
66
67
68@_simpleEventListener

◆ _simpleEventListener()

krita.decorators._simpleEventListener ( func)
protected

Definition at line 51 of file decorators.py.

51def _simpleEventListener(func):
52 # automates the most common decorator pattern: calling a bunch
53 # of functions when an event has occurred
54 func.functions = dict()
55 func.fire = functools.partial(_callAll, functions=func.functions)
56 func.clear = func.functions.clear
57 return func
58
59

◆ init()

krita.decorators.init ( func)
 The function will be called when particular plugin has loaded
    and the configuration has been initiated

Definition at line 69 of file decorators.py.

69def init(func):
70 ''' The function will be called when particular plugin has loaded
71 and the configuration has been initiated
72 '''
73 plugin = sys._getframe(1).f_globals['__name__']
74 qDebug('@init: {}/{}'.format(plugin, func.__name__))
75 return _registerCallback(plugin, init, func)
76
77
78@_simpleEventListener

References krita.decorators._registerCallback().

◆ pykritaEventHandler()

krita.decorators.pykritaEventHandler ( event)

Definition at line 30 of file decorators.py.

30def pykritaEventHandler(event):
31 def _decorator(func):
32 setattr(pykrita, event, func)
33 del func
34 return _decorator
35
36

◆ unload()

krita.decorators.unload ( func)
 The function will be called when particular plugin is being
    unloaded from memory. Clean up any widgets that you have added
    to the interface (toolviews etc).

    ATTENTION Be really careful trying to access any window, view
        or document from the @unload handler: in case of application
        quit everything is dead already!

Definition at line 79 of file decorators.py.

79def unload(func):
80 ''' The function will be called when particular plugin is being
81 unloaded from memory. Clean up any widgets that you have added
82 to the interface (toolviews etc).
83
84 ATTENTION Be really careful trying to access any window, view
85 or document from the @unload handler: in case of application
86 quit everything is dead already!
87 '''
88 plugin = sys._getframe(1).f_globals['__name__']
89 qDebug('@unload: {}/{}'.format(plugin, func.__name__))
90
91 def _module_cleaner():
92 qDebug('@unload/cleaner: {}/{}'.format(plugin, func.__name__))
93 if plugin in init.functions:
94 qDebug('@unload/init-cleaner: {}/{}'.format(plugin, func.__name__))
95 del init.functions[plugin]
96
97 func()
98
99 return _registerCallback(plugin, unload, _module_cleaner)

References krita.decorators._registerCallback().