Skip to content

Commit bacaece

Browse files
cydanilsebp
authored andcommitted
Add Expander example
Closes #181
1 parent 3730e76 commit bacaece

File tree

4 files changed

+72
-0
lines changed

4 files changed

+72
-0
lines changed

examples/expander_example.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import gi
2+
3+
gi.require_version("Gtk", "3.0")
4+
from gi.repository import Gtk
5+
6+
7+
class ExpanderExample(Gtk.Window):
8+
def __init__(self):
9+
Gtk.Window.__init__(self, title="Expander Demo")
10+
11+
self.set_size_request(350, 100)
12+
13+
vbox = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6)
14+
self.add(vbox)
15+
16+
text_expander = Gtk.Expander(
17+
label="This expander displays additional information"
18+
)
19+
text_expander.set_expanded(True)
20+
vbox.add(text_expander)
21+
22+
msg = """
23+
This message is quite long, complicated even:
24+
- It has a list with a sublist:
25+
- of 3 elements;
26+
- taking several lines;
27+
- with indentation.
28+
"""
29+
details = Gtk.Label(label=msg)
30+
text_expander.add(details)
31+
32+
widget_expander = Gtk.Expander(label="Expand for more controls")
33+
vbox.add(widget_expander)
34+
35+
expander_hbox = Gtk.HBox()
36+
widget_expander.add(expander_hbox)
37+
38+
expander_hbox.add(Gtk.Label(label="Text message"))
39+
expander_hbox.add(Gtk.Button(label="Click me"))
40+
41+
self.show_all()
42+
43+
44+
win = ExpanderExample()
45+
win.connect("destroy", Gtk.main_quit)
46+
win.show_all()
47+
Gtk.main()

images/expander_example.png

16 KB
Loading

source/expander.txt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
Expander
2+
========
3+
4+
Expanders allow to dynamically hide or show information within a window or
5+
dialog. An expander can take a single widget that will be displayed when
6+
expanded.
7+
8+
Expanders remain expanded until clicked again. When the state of an expander
9+
is changed, the "activate" signal is emitted.
10+
11+
An expander can be programmatically expanded or collapsed by passing `True` or
12+
`False` to :meth:`Gtk.Expander.set_expanded`. Note that doing so causes the
13+
"activate" signal to be emitted.
14+
15+
More than one widget, such as a :class:`Gtk.Label` and :class:`Gtk.Button`,
16+
can be added by appending them to a :class:`Gtk.Box`.
17+
18+
Example
19+
^^^^^^^
20+
21+
.. image:: ../images/expander_example.png
22+
23+
.. literalinclude:: ../examples/expander_example.py
24+
:linenos:

source/index.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ Contents:
4343
label
4444
entry
4545
button_widgets
46+
expander
4647
progressbar
4748
spinner
4849
treeview

0 commit comments

Comments
 (0)