Mercurial > fife-parpg
annotate engine/extensions/pychan/tools.py @ 298:07709bffab8f
*hope i fixed script-without-shebang part 3 the last one
author | LinuxDonald@33b003aa-7bff-0310-803a-e67f0ece8222 |
---|---|
date | Sun, 05 Jul 2009 19:11:53 +0000 |
parents | 54bfd1015b35 |
children | 33dd55160a9d |
rev | line source |
---|---|
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
1 # coding: utf-8 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
2 |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
3 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
4 Functional utilities designed for pychan use cases. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
5 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
6 |
163
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
7 import exceptions |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
8 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
9 ### Functools ### |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
10 |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
11 def applyOnlySuitable(func,*args,**kwargs): |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
12 """ |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
13 This nifty little function takes another function and applies it to a dictionary of |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
14 keyword arguments. If the supplied function does not expect one or more of the |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
15 keyword arguments, these are silently discarded. The result of the application is returned. |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
16 This is useful to pass information to callbacks without enforcing a particular signature. |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
17 """ |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
18 if hasattr(func,'im_func'): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
19 code = func.im_func.func_code |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
20 varnames = code.co_varnames[1:code.co_argcount]#ditch bound instance |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
21 else: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
22 code = func.func_code |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
23 varnames = code.co_varnames[0:code.co_argcount] |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
24 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
25 #http://docs.python.org/lib/inspect-types.html |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
26 if code.co_flags & 8: |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
27 return func(*args,**kwargs) |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
28 for name,value in kwargs.items(): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
29 if name not in varnames: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
30 del kwargs[name] |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
31 return func(*args,**kwargs) |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
32 |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
33 def callbackWithArguments(callback,*args,**kwargs): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
34 """ |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
35 Curries a function with extra arguments to |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
36 create a suitable callback. |
129
9a1529f9625e
* Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
37 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
38 If you don't know what this means, don't worry. |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
39 It is designed for the case where you need |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
40 different buttons to execute basically the same code |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
41 with different argumnets. |
129
9a1529f9625e
* Indentation patch by GreyGhost
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
0
diff
changeset
|
42 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
43 Usage:: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
44 # The target callback |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
45 def printStuff(text): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
46 print text |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
47 # Mapping the events |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
48 gui.mapEvents({ |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
49 'buttonHello' : callbackWithArguments(printStuff,"Hello"), |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
50 'buttonBye' : callbackWithArguments(printStuff,"Adieu") |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
51 }) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
52 """ |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
53 def real_callback(): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
54 callback(*args,**kwargs) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
55 return real_callback |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
56 |
163
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
57 def attrSetCallback(**kwargs): |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
58 """ |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
59 Generates an event callback that sets attributes on the widget |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
60 it is called on. This is especially useful for mouseEntered/Exited |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
61 events - to create hover effects. |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
62 |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
63 It takes a set of keyword arguments. The keys are treated as attribute names, |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
64 which are then set to the corresponding value when the callback is called. |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
65 Some key names are treated special - see below. |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
66 |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
67 Usage - Example adapted from demo application:: |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
68 eventMap = { |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
69 'creditsLink' : showCreditsCallback, |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
70 'creditsLink/mouseEntered' : attrSetCallback( |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
71 text = "Show credits!", |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
72 background_color = (255,255,0,255), |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
73 do__adaptLayout=True), |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
74 'creditsLink/mouseExited' : attrSetCallback(text = "Credits"), |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
75 gui.mapEvents(eventMap) |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
76 |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
77 Now when the mouse enters the creditsLink (a Label in our case), the following code will be executed:: |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
78 #widget is the creditsLink - given to the event callback. |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
79 widget.text = "Show credits!" |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
80 widget.background_color = (255,255,0,255) |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
81 widget.adaptLayout() |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
82 |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
83 The C{do__adaptLayout} argument causes the method C{adaptLayout} to be called. |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
84 In fact any key starting with C{do__} results in such a method call. The order |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
85 of execution of such calls is undefined. |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
86 |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
87 Keys starting with an underscore raise a L{execptions.PrivateFunctionalityError}. |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
88 """ |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
89 do_calls = [] |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
90 |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
91 for name in kwargs.keys(): |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
92 if name.startswith("_"): |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
93 raise exceptions.PrivateFunctionalityError(name) |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
94 if name.startswith("do__"): |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
95 do_calls.append(name[4:]) |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
96 del kwargs[name] |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
97 |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
98 def attrSet_callback(widget=None): |
163
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
99 for name,value in kwargs.items(): |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
100 setattr(widget,name,value) |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
101 for method_name in do_calls: |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
102 method = getattr(widget,method_name) |
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
103 method() |
205
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
104 return attrSet_callback |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
105 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
106 def chainCallbacks(*args): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
107 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
108 Chains callbacks to be called one after the other. |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
109 |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
110 Example Usage:: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
111 def print_event(event=0): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
112 print event |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
113 def print_widget(widget=0): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
114 print widget |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
115 callback = tools.chainCallbacks(doSomethingUseful, print_event, print_widget) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
116 guiElement.capture(callback) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
117 """ |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
118 callbacks = args |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
119 def chain_callback(event=0,widget=0): |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
120 for callback in callbacks: |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
121 applyOnlySuitable(callback, event=event, widget=widget) |
54bfd1015b35
* PyChan event handling rework (part I)
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
163
diff
changeset
|
122 return chain_callback |
163
31718fa356f8
Backported the attrSetCallback from pychan_rework.
phoku@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
129
diff
changeset
|
123 |
0
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
124 def this_is_deprecated(func,message=None): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
125 if message is None: |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
126 message = repr(func) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
127 def wrapped_func(*args,**kwargs): |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
128 print "PyChan: You are using the DEPRECATED functionality: %s" % message |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
129 return func(*args,**kwargs) |
4a0efb7baf70
* Datasets becomes the new trunk and retires after that :-)
mvbarracuda@33b003aa-7bff-0310-803a-e67f0ece8222
parents:
diff
changeset
|
130 return wrapped_func |