Created
December 29, 2014 13:47
-
-
Save Jim-Holmstroem/d363cf700bc232061b55 to your computer and use it in GitHub Desktop.
Fixes parts of gtk's Jurassic imperative programming style
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from functools import partial | |
from collections import Iterable | |
def component(Component): | |
""" | |
{ | |
label = gtk.Label('label') | |
label.set_size_request(640, 480) | |
label.set_justify(gtk.JUSTIFY_FILL) | |
} => | |
{ | |
Label = component(gtk.Label) | |
label = Label( | |
'label', | |
size_request=(640, 480), | |
justify=gtk.JUSTIFY_FILL | |
) | |
} | |
""" | |
def new_style_component(*args, **kwargs): | |
component = Component(*args) | |
def set_property(name, values): | |
getattr( | |
component, | |
"set_{name}".format(name=name) | |
)( | |
*(values if isinstance(values, Iterable) else (values, )) | |
) | |
map(partial(apply, set_property), kwargs.iteritems()) | |
return component | |
return new_style_component |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://github.com/Jim-Holmstroem/FunctionalGTK