~mcfletch/python-examples/fixes

« back to all changes in this revision

Viewing changes to python-examples/gtk3/tut07/tut07-appchooser-scale.py

  • Committer: Oliver Marks
  • Date: 2014-05-29 06:24:58 UTC
  • Revision ID: oly@digitaloctave.com-20140529062458-fha3e462ihbyuepl
creation and import of gtk3 examples

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
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
 
9
 
 
10
 
 
11
class application_gui:
 
12
    """Tutorial 04 text input, spin input, drop down options"""
 
13
    count = 0
 
14
 
 
15
    def __init__(self):
 
16
        #load in our glade interface
 
17
        xml = Gtk.Builder()
 
18
        xml.add_from_file('tut07.glade')
 
19
 
 
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')
 
23
 
 
24
        #load our widgets from the glade file
 
25
        self.widgets = {}
 
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')
 
30
 
 
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)
 
35
 
 
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())
 
39
 
 
40
        #show the window else there is nothing to see :)
 
41
        self.window.show()
 
42
 
 
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)
 
48
        
 
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())
 
52
 
 
53
    def scale(self, widget, value):
 
54
        self.text.set_text(widget.get_name() + ' ' + str(value))
 
55
 
 
56
 
 
57
application = application_gui()
 
58
Gtk.main()