2
# [SNIPPET_NAME: gtk3 app chooser and scale widget]
3
# [SNIPPET_CATEGORIES: gtk3]
4
# [SNIPPET_TAGS: widgets, gtk3]
5
# [SNIPPET_DESCRIPTION: GTK3 scale widget and app chooser example]
6
# [SNIPPET_AUTHOR: Oliver Marks ]
7
# [SNIPPET_LICENSE: GPL]
8
from gi.repository import Gtk, GLib, Gio
11
class application_gui:
12
"""Tutorial 04 text input, spin input, drop down options"""
16
#load in our glade interface
18
xml.add_from_file('tut07.glade')
20
#grab our widget using get_object this is the name of the widget from glade, window1 is the default name
21
self.window = xml.get_object('window1')
22
self.text = xml.get_object('entry1')
24
#load our widgets from the glade file
26
self.widgets['scale1'] = xml.get_object('scalebutton1')
27
self.widgets['scale2'] = xml.get_object('scalebutton2')
28
self.widgets['appchooseraudio'] = xml.get_object('appchooserbutton1')
29
self.widgets['appchoosertext'] = xml.get_object('appchooserbutton2')
31
self.widgets['appchooseraudio'].connect('changed', self.app_chooser)
32
self.widgets['appchoosertext'].connect('changed', self.app_chooser)
33
self.widgets['scale1'].connect('value-changed', self.scale)
34
self.widgets['scale2'].connect('value-changed', self.scale)
36
#connect to events, in this instance just quit our application
37
self.window.connect('delete_event', Gtk.main_quit)
38
self.window.connect('destroy', lambda quit: Gtk.main_quit())
40
#show the window else there is nothing to see :)
43
def app_chooser(self, widget):
44
list_view_model = widget.get_model()
45
active_iter_index = widget.get_active()
46
row_iter = list_view_model.get_iter(active_iter_index)
47
app_info = list_view_model.get_value(row_iter, 0)
49
gio_file = Gio.File.new_for_path('/tmp/tut07-appchooser-test.txt')
50
app_info.launch((gio_file,), None)
51
self.text.set_text(widget.get_name() + ' ' + app_info.get_name())
53
def scale(self, widget, value):
54
self.text.set_text(widget.get_name() + ' ' + str(value))
57
application = application_gui()