add copyrights information
[appstream:software-center.git] / appcenter / SimpleGtkbuilderApp.py
1 """
2  SimpleGladeApp.py
3  Module that provides an object oriented abstraction to pygtk and gtkbuilder
4  Copyright (C) 2009 Michael Vogt
5  based on ideas from SimpleGladeBuilder by Sandino Flores Moreno
6 """
7
8 # This library is free software; you can redistribute it and/or
9 # modify it under the terms of the GNU Lesser General Public
10 # License as published by the Free Software Foundation; either
11 # version 2.1 of the License, or (at your option) any later version.
12 #
13 # This library is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16 # Lesser General Public License for more details.
17 #
18 # You should have received a copy of the GNU Lesser General Public
19 # License along with this library; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
21 # USA
22
23 import os
24 import sys
25 import re
26
27 import gtk
28
29 # based on SimpleGladeApp
30 class SimpleGtkbuilderApp:
31
32     def __init__(self, path):
33         self.builder = gtk.Builder()
34         self.builder.add_from_file(path)
35         self.builder.connect_signals(self)
36         for o in self.builder.get_objects():
37             if issubclass(type(o), gtk.Buildable):
38                 name = gtk.Buildable.get_name(o)
39                 setattr(self, name, o)
40             else:
41                 print >>sys.stderr, "WARNING: can not get name for '%s'" % o
42
43     def run(self):
44         """
45         Starts the main loop of processing events checking for Control-C.
46
47         The default implementation checks wheter a Control-C is pressed,
48         then calls on_keyboard_interrupt().
49
50         Use this method for starting programs.
51         """
52         try:
53             gtk.main()
54         except KeyboardInterrupt:
55             self.on_keyboard_interrupt()
56
57     def on_keyboard_interrupt(self):
58         """
59         This method is called by the default implementation of run()
60         after a program is finished by pressing Control-C.
61         """
62         pass
63