~ubuntu-core-dev/update-manager/main

« back to all changes in this revision

Viewing changes to UpdateManager/SimpleGtk3builderApp.py

  • Committer: Michael Vogt
  • Date: 2011-07-08 07:46:54 UTC
  • mfrom: (2146.2.16 pygi)
  • Revision ID: michael.vogt@ubuntu.com-20110708074654-nbcspqmsrlbxc6p0
merged from the pygi branch

Show diffs side-by-side

added added

removed removed

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