~ubuntu-branches/ubuntu/precise/aptdaemon/precise

« back to all changes in this revision

Viewing changes to aptdaemon/gtk3widgets.py

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2011-08-17 08:11:43 UTC
  • mfrom: (1.3.6 upstream)
  • Revision ID: james.westby@ubuntu.com-20110817081143-lpvguqw7rd5rou8h
Tags: 0.43+bzr669-0ubuntu1
New bzr snapshot: Move from static gobject to GI GObject module, to be
compatible to upcoming pygobject 3.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
38
38
import re
39
39
 
40
40
import apt_pkg
41
 
import dbus
42
 
import dbus.mainloop.glib
43
 
import gobject
 
41
from gi.repository import GObject
44
42
from gi.repository import Gdk
45
43
from gi.repository import Gtk
46
44
from gi.repository import Pango
50
48
from enums import *
51
49
from defer import inline_callbacks, return_value
52
50
 
53
 
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
54
 
 
55
51
_ = lambda msg: gettext.dgettext("aptdaemon", msg)
56
52
 
57
53
(COLUMN_ID,
64
60
    aptdaemon transaction
65
61
    """
66
62
    def __init__(self, transaction=None, size=Gtk.IconSize.DIALOG):
67
 
        gobject.GObject.__init__(self)
 
63
        GObject.GObject.__init__(self)
68
64
        # note: icon_size is a property which you can't set with GTK 2, so use
69
65
        # a different name
70
66
        self._icon_size = size
77
73
    def set_transaction(self, transaction):
78
74
        """Connect to the given transaction"""
79
75
        for sig in self._signals:
80
 
            gobject.source_remove(sig)
 
76
            GObject.source_remove(sig)
81
77
        self._signals = []
82
78
        self._signals.append(transaction.connect("status-changed",
83
79
                                                 self._on_status_changed))
103
99
    """
104
100
    def set_transaction(self, transaction):
105
101
        for sig in self._signals:
106
 
            gobject.source_remove(sig)
 
102
            GObject.source_remove(sig)
107
103
        self._signals = []
108
104
        self._signals.append(transaction.connect("role-changed",
109
105
                                                 self._on_role_changed))
169
165
    def start_animation(self):
170
166
        """Start the animation"""
171
167
        if self.ticker == 0:
172
 
            self.ticker = gobject.timeout_add(200, self._advance)
 
168
            self.ticker = GObject.timeout_add(200, self._advance)
173
169
 
174
170
    def stop_animation(self):
175
171
        """Stop the animation"""
176
172
        if self.ticker != 0:
177
 
            gobject.source_remove(self.ticker)
 
173
            GObject.source_remove(self.ticker)
178
174
            self.ticker = 0
179
175
 
180
176
    def _advance(self):
215
211
    def set_transaction(self, transaction):
216
212
        """Connect the status label to the given aptdaemon transaction"""
217
213
        for sig in self._signals:
218
 
            gobject.source_remove(sig)
 
214
            GObject.source_remove(sig)
219
215
        self._signals = []
220
216
        self._on_role_changed(transaction, transaction.role)
221
217
        self._signals.append(transaction.connect("role-changed",
231
227
    Status label for the running aptdaemon transaction
232
228
    """
233
229
    def __init__(self, transaction=None):
234
 
        gobject.GObject.__init__(self)
 
230
        GObject.GObject.__init__(self)
235
231
        self.set_alignment(0, 0)
236
232
        self.set_ellipsize(Pango.EllipsizeMode.END)
237
233
        self._signals = []
241
237
    def set_transaction(self, transaction):
242
238
        """Connect the status label to the given aptdaemon transaction"""
243
239
        for sig in self._signals:
244
 
            gobject.source_remove(sig)
 
240
            GObject.source_remove(sig)
245
241
        self._signals = []
246
242
        self._signals.append(transaction.connect("status-changed",
247
243
                                                 self._on_status_changed))
263
259
    transactions
264
260
    """
265
261
    def __init__(self, transaction=None):
266
 
        gobject.GObject.__init__(self)
 
262
        GObject.GObject.__init__(self)
267
263
        self.set_ellipsize(Pango.EllipsizeMode.END)
268
264
        self.set_text(" ")
269
265
        self.set_pulse_step(0.05)
274
270
    def set_transaction(self, transaction):
275
271
        """Connect the progress bar to the given aptdaemon transaction"""
276
272
        for sig in self._signals:
277
 
            gobject.source_remove(sig)
 
273
            GObject.source_remove(sig)
278
274
        self._signals = []
279
275
        self._signals.append(transaction.connect("finished", self._on_finished))
280
276
        self._signals.append(transaction.connect("progress-changed",
317
313
class AptDetailsExpander(Gtk.Expander):
318
314
 
319
315
    def __init__(self, transaction=None, terminal=True):
320
 
        gobject.GObject.__init__(self, label=_("Details"))
 
316
        GObject.GObject.__init__(self, label=_("Details"))
321
317
        self.show_terminal = terminal
322
318
        self._signals = []
323
319
        self.set_sensitive(False)
343
339
    def set_transaction(self, transaction):
344
340
        """Connect the status label to the given aptdaemon transaction"""
345
341
        for sig in self._signals:
346
 
            gobject.source_remove(sig)
 
342
            GObject.source_remove(sig)
347
343
        self._signals.append(transaction.connect("status-changed",
348
344
                                          self._on_status_changed))
349
345
        self._signals.append(transaction.connect("terminal-attached-changed",
394
390
    def set_transaction(self, transaction):
395
391
        """Connect the status label to the given aptdaemon transaction"""
396
392
        for sig in self._signals:
397
 
            gobject.source_remove(sig)
 
393
            GObject.source_remove(sig)
398
394
        self._signals.append(transaction.connect("terminal-attached-changed",
399
395
                                          self._on_terminal_attached_changed))
400
396
        self._transaction = transaction
410
406
    transaction
411
407
    """
412
408
    def __init__(self, transaction=None):
413
 
        gobject.GObject.__init__(self)
 
409
        GObject.GObject.__init__(self)
414
410
        self.set_use_stock(True)
415
411
        self.set_label(Gtk.STOCK_CANCEL)
416
412
        self.set_sensitive(True)
421
417
    def set_transaction(self, transaction):
422
418
        """Connect the status label to the given aptdaemon transaction"""
423
419
        for sig in self._signals:
424
 
            gobject.source_remove(sig)
 
420
            GObject.source_remove(sig)
425
421
        self._signals = []
426
422
        self._signals.append(transaction.connect("finished", self._on_finished))
427
423
        self._signals.append(transaction.connect("cancellable-changed",
451
447
    COL_TEXT, COL_PROGRESS, COL_URI = range(3)
452
448
 
453
449
    def __init__(self, transaction=None):
454
 
        gobject.GObject.__init__(self)
455
 
        model = Gtk.ListStore(gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING)
 
450
        GObject.GObject.__init__(self)
 
451
        model = Gtk.ListStore(GObject.TYPE_STRING, GObject.TYPE_INT, GObject.TYPE_STRING)
456
452
        self.set_model(model)
457
453
        self.props.headers_visible = False
458
454
        self.set_rules_hint(True)
477
473
    def set_transaction(self, transaction):
478
474
        """Connect the download view to the given aptdaemon transaction"""
479
475
        for sig in self._signals:
480
 
            gobject.source_remove(sig)
 
476
            GObject.source_remove(sig)
481
477
        self._signals = []
482
478
        self._signals.append(transaction.connect("progress-download-changed",
483
479
                                                 self._on_download_changed))
538
534
    features a progress bar, cancel button, status icon and label
539
535
    """
540
536
 
541
 
    __gsignals__ = {"finished": (gobject.SIGNAL_RUN_FIRST,
542
 
                                 gobject.TYPE_NONE, ())}
 
537
    __gsignals__ = {"finished": (GObject.SIGNAL_RUN_FIRST,
 
538
                                 GObject.TYPE_NONE, ())}
543
539
 
544
540
    def __init__(self, transaction=None, parent=None, terminal=True,
545
541
                 debconf=True):
546
 
        gobject.GObject.__init__(self, parent=parent)
 
542
        GObject.GObject.__init__(self, parent=parent)
547
543
        self._expanded_size = None
548
544
        self.debconf = debconf
549
545
        # Setup the dialog
653
649
    def set_transaction(self, transaction):
654
650
        """Connect the dialog to the given aptdaemon transaction"""
655
651
        for sig in self._signals:
656
 
            gobject.source_remove(sig)
 
652
            GObject.source_remove(sig)
657
653
        self._signals = []
658
654
        self._signals.append(transaction.connect("role-changed",
659
655
                                                 self._on_role_changed))
716
712
        """
717
713
        if not buttons:
718
714
            buttons = (Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE)
719
 
        gobject.GObject.__init__(self, parent=parent)
 
715
        GObject.GObject.__init__(self, parent=parent)
720
716
        self.add_buttons(*buttons)
721
717
        self.set_resizable(True)
722
718
        self.set_border_width(6)
771
767
    """Dialog to ask for medium change."""
772
768
 
773
769
    def __init__(self, medium, drive, parent=None):
774
 
        gobject.GObject.__init__(self, parent=parent,
 
770
        GObject.GObject.__init__(self, parent=parent,
775
771
                                 type=Gtk.MessageType.INFO)
776
772
        #TRANSLATORS: %s represents the name of a CD or DVD
777
773
        text = _("CD/DVD '%s' is required") % medium
797
793
                 about packages
798
794
        parent -- set the dialog transient for the given Gtk.Window
799
795
        """
800
 
        gobject.GObject.__init__(self, parent=parent)
 
796
        GObject.GObject.__init__(self, parent=parent)
801
797
        self.add_button(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL)
802
798
        self.add_button(_("C_ontinue"), Gtk.ResponseType.OK)
803
799
        self.cache = cache
825
821
        self.label.set_alignment(0, 0)
826
822
        vbox_left.pack_start(self.label, False, True, 0)
827
823
        self.get_content_area().pack_start(hbox_base, True, True, 0)
828
 
        self.treestore = Gtk.TreeStore(gobject.TYPE_STRING)
 
824
        self.treestore = Gtk.TreeStore(GObject.TYPE_STRING)
829
825
        self.treeview = Gtk.TreeView.new_with_model(self.treestore)
830
826
        self.treeview.set_headers_visible(False)
831
827
        self.treeview.set_rules_hint(True)
1010
1006
 
1011
1007
    def __init__(self):
1012
1008
        self.textbuffer = Gtk.TextBuffer()
1013
 
        gobject.GObject.__init__(self, buffer=self.textbuffer)
 
1009
        GObject.GObject.__init__(self, buffer=self.textbuffer)
1014
1010
        self.set_property("editable", False)
1015
1011
        self.set_cursor_visible(False)
1016
1012
        tags = self.textbuffer.get_tag_table()
1077
1073
    Common base class for Apt*Dialog
1078
1074
    """
1079
1075
    def __init__(self, text, desc, type, details=None, parent=None):
1080
 
        gobject.GObject.__init__(self, parent=parent,
 
1076
        GObject.GObject.__init__(self, parent=parent,
1081
1077
                                 message_type=type,
1082
1078
                                 buttons=Gtk.ButtonsType.CLOSE)
1083
1079
        self.set_markup("<big><b>%s</b></big>\n\n%s" % (text, desc))