Skip to content

Instantly share code, notes, and snippets.

@Jim-Holmstroem
Created December 29, 2014 13:47
Show Gist options
  • Save Jim-Holmstroem/d363cf700bc232061b55 to your computer and use it in GitHub Desktop.
Save Jim-Holmstroem/d363cf700bc232061b55 to your computer and use it in GitHub Desktop.
Fixes parts of gtk's Jurassic imperative programming style
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
@Jim-Holmstroem
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment