Add custom parser, remove `parglare`. `gull` as a module.
Small fixes, update readme and examples
Use a new LocalNameSpace for every GullBuilder instance
GULL is an experiment in a lightweight UI description language for Gtk
This is a toy and not to be used in any seriuos way. You have been warned.
GULL parse a UI description from file and build the corresponding widget tree.
It's meant to be used as a library, where the user have to connect to event and add logic to the UI, but it can also run as a CLI for previewing the UI file.
python -m gull examples/example.gull
python -m gull examples/handy.gull
load(filename)
Load
filename
and return the top level object instance
load_string(string)
Load from string and return the top level object instance
Template.from_file(filename)
Class decorator. Load
filename
and use current class as toplevel object
Template.from_string(string)
Class decorator. Load from string and use current class as toplevel object
Load from file:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
import gull
def clicked(o):
o.set_label("OUCH!")
if __name__ == "__main__":
window = gull.load("test.gull")
window.show_all()
window.connect_after('destroy', Gtk.main_quit)
window.button1.connect('clicked', clicked)
Gtk.main()
Use template from string:
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk
from gull import Template
UI = """
Gtk.Window {
title : "Templated"
Gtk.VBox {
Gtk.Button {
id : button1
label : "Do Action"
on_clicked : do_action
}
Gtk.Button {
label : "Quit"
on_clicked : Gtk.main_quit
}
}
}
"""
@Template.from_string(UI)
class MyWindow(Gtk.Window):
def do_action(self, *args):
print("Action!")
if __name__ == "__main__":
window = MyWindow()
window.show_all()
Gtk.main()
The description language get inspiration from Qt's QML and from Gtk's XML UI language.
It can:
gi.repository
of PyGObjectsprops
attribute or via
set_<prop name>()
function, the first the code find. Values can be integers,
floats, strings, objects, id referecing other object in file, enum valuesimport Gtk 3.0;
loads gi.repository.Gtk
module in namespace, requiring version 3.0
Gtk
is set by default and is not required to import it explicitly.
import MyWidget;
looks for "MyWidget.gull" or python's MyWidget
module in import paths.
import
must be ended by a semicolon.
Gtk.Window { }
creates Gtk.Window
instance.
MyWidget { }
creates an instance of the widget tree from imported "MyWidget.gull"
Every file can have one or more import
s and exaclty one top-level object.
Gtk.Window {
title: "Example Application"
default_width: 600
default_height: 400
Gtk.Label {
id: mylabel
label: "Hello World"
}
}
creates a Gtk.Window
instance, sets some properties and add a child Gtk.Label
.
The special id
property sets the widget's name
property and allow to refer
to the object instnce by id elsewere in file.
It's also set as propert in top-level object instance returned by gull.load()
...
Gtk.Notebook {
Gtk.Label {
label: "Hello World"
packing {
tab_label: "Page 1"
}
}
}
...