Ticket #3419: test_paned.py

File test_paned.py, 1.9 KB (added by Calum, 5 years ago)
Line 
1#!/usr/bin/python3
2
3import sys
4import gi
5gi.require_version('Gtk', '3.0')
6from gi.repository import Gtk
7
8class AppWindow(Gtk.ApplicationWindow):
9
10 def __init__(self, *args, **kwargs):
11 super().__init__(*args, **kwargs)
12 self.set_border_width(10)
13 self.vpaned = Gtk.Paned.new(Gtk.Orientation.VERTICAL)
14 hpaned = Gtk.Paned.new(Gtk.Orientation.HORIZONTAL)
15 button0 = Gtk.Button.new_with_label("TabBar")
16 button1 = Gtk.Button.new_with_label("SideBar")
17 button2 = Gtk.Button.new_with_label("TreeView")
18 button0.connect("clicked", self.on_button_clicked)
19 button1.connect("clicked", self.on_button_clicked)
20 button2.connect("clicked", self.on_button_clicked)
21 self.vpaned.add1(hpaned)
22 self.vpaned.add2(button0)
23 hpaned.add1(button1)
24 hpaned.add2(button2)
25 self.add(self.vpaned)
26 self.set_size_request(400, 250)
27 self.show_all()
28
29 def on_button_clicked(self, button):
30 self.destroy()
31
32class Application(Gtk.Application):
33 conf_filepath = 'test_paned.conf'
34
35 def __init__(self, *args, **kwargs):
36 super().__init__(*args, application_id="org.example.myapp",
37 **kwargs)
38 self.window = None
39
40 def do_activate(self):
41 if not self.window:
42 self.window = AppWindow(application=self, title="Panes")
43 self.window.show_all()
44 self.window.present()
45 self.window.vpaned.connect('notify::position', self.on_position_event)
46 try:
47 with open(self.conf_filepath) as _f:
48 position = int(_f.read())
49 self.window.vpaned.set_position(position)
50 except FileNotFoundError:
51 pass
52
53 def on_position_event(self, widget, param):
54 print(widget.get_position())
55 with open(self.conf_filepath, 'w') as _f:
56 _f.write(str(widget.get_position()))
57
58if __name__ == "__main__":
59 app = Application()
60 app.run(sys.argv)