rss_feed

App chooer and scale buttons

homeHome
pagesGTK-3
pagespython
pageswidgets

App chooser & scale widgets

This example program demonstrates the use of appchooser buttons when selecting an application from the drop down launch the application loading a test text file, this could be a video or mp3 or any file type.

you can change the application list by modify the content type value in glade this then shows all registered apps for that content type.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#!/usr/bin/env python
from gi.repository import Gtk, GLib, Gio


class application_gui:
    """Tutorial 04 text input, spin input, drop down options"""
    count = 0

    def __init__(self):
        #load in our glade interface
        xml = Gtk.Builder()
        xml.add_from_file('tut07.glade')

        #grab our widget using get_object this is the name of the widget from glade, window1 is the default name
        self.window = xml.get_object('window1')
        self.text = xml.get_object('entry1')

        #load our widgets from the glade file
        self.widgets = {}
        self.widgets['scale1'] = xml.get_object('scalebutton1')
        self.widgets['scale2'] = xml.get_object('scalebutton2')
        self.widgets['appchooseraudio'] = xml.get_object('appchooserbutton1')
        self.widgets['appchoosertext'] = xml.get_object('appchooserbutton2')

        self.widgets['appchooseraudio'].connect('changed', self.app_chooser)
        self.widgets['appchoosertext'].connect('changed', self.app_chooser)
        self.widgets['scale1'].connect('value-changed', self.scale)
        self.widgets['scale2'].connect('value-changed', self.scale)

        #connect to events, in this instance just quit our application
        self.window.connect('delete_event', Gtk.main_quit)
        self.window.connect('destroy', lambda quit: Gtk.main_quit())

        #show the window else there is nothing to see :)
        self.window.show()

    def app_chooser(self, widget):
        list_view_model = widget.get_model()
        active_iter_index = widget.get_active()
        row_iter = list_view_model.get_iter(active_iter_index)
        app_info = list_view_model.get_value(row_iter, 0)
        
        gio_file = Gio.File.new_for_path('/tmp/tut07-appchooser-test.txt')
        app_info.launch((gio_file,), None)
        self.text.set_text(widget.get_name() + ' ' + app_info.get_name())

    def scale(self, widget, value):
        self.text.set_text(widget.get_name() + ' ' + str(value))


application = application_gui()
Gtk.main()