Package fife :: Package extensions :: Package pychan :: Module tools
[hide private]
[frames] | no frames]

Module tools

source code

Functional utilities designed for pychan use cases.

Functions [hide private]
 
applyOnlySuitable(func, *args, **kwargs)
This nifty little function takes another function and applies it to a dictionary of keyword arguments.
source code
 
callbackWithArguments(callback, *args, **kwargs)
Curries a function with extra arguments to create a suitable callback.
source code
 
attrSetCallback(**kwargs)
Generates an event callback that sets attributes on the widget it is called on.
source code
 
chainCallbacks(*args)
Chains callbacks to be called one after the other.
source code
 
repeatALot(n=1000)
Internal decorator used to profile some pychan functions.
source code
 
this_is_deprecated(func, message=None) source code
Function Details [hide private]

applyOnlySuitable(func, *args, **kwargs)

source code 

This nifty little function takes another function and applies it to a dictionary of keyword arguments. If the supplied function does not expect one or more of the keyword arguments, these are silently discarded. The result of the application is returned. This is useful to pass information to callbacks without enforcing a particular signature.

callbackWithArguments(callback, *args, **kwargs)

source code 

Curries a function with extra arguments to create a suitable callback.

If you don't know what this means, don't worry. It is designed for the case where you need different buttons to execute basically the same code with different argumnets.

Usage:

 # The target callback
 def printStuff(text):
     print text
 # Mapping the events
 gui.mapEvents({
     'buttonHello' : callbackWithArguments(printStuff,"Hello"),
     'buttonBye' : callbackWithArguments(printStuff,"Adieu")
 })

attrSetCallback(**kwargs)

source code 

Generates an event callback that sets attributes on the widget it is called on. This is especially useful for mouseEntered/Exited events - to create hover effects.

It takes a set of keyword arguments. The keys are treated as attribute names, which are then set to the corresponding value when the callback is called. Some key names are treated special - see below.

Usage - Example adapted from demo application:

       eventMap = {
               'creditsLink'  : showCreditsCallback,
               'creditsLink/mouseEntered' : attrSetCallback(
                     text = "Show credits!",
                     background_color = (255,255,0,255),
                     do__adaptLayout=True),
               'creditsLink/mouseExited'  : attrSetCallback(text = "Credits"),
       gui.mapEvents(eventMap)

Now when the mouse enters the creditsLink (a Label in our case), the following code will be executed:

       #widget is the creditsLink - given to the event callback.
       widget.text = "Show credits!"
       widget.background_color = (255,255,0,255)
       widget.adaptLayout()

The do__adaptLayout argument causes the method adaptLayout to be called. In fact any key starting with do__ results in such a method call. The order of execution of such calls is undefined.

Keys starting with an underscore raise a execptions.PrivateFunctionalityError.

chainCallbacks(*args)

source code 

Chains callbacks to be called one after the other.

Example Usage:

   def print_event(event=0):
     print event
   def print_widget(widget=0):
     print widget
   callback = tools.chainCallbacks(doSomethingUseful, print_event, print_widget)
   guiElement.capture(callback)

repeatALot(n=1000)

source code 

Internal decorator used to profile some pychan functions. Only use with functions without side-effect.

Usage:

       @repeatALot(n=10000)
       def findChild(self,**kwargs):
               ...