File: AptListChangesGtk.py

package info (click to toggle)
apt-listchanges 3.24
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 1,352 kB
  • sloc: python: 1,710; xml: 650; makefile: 138; sh: 71; perl: 61
file content (84 lines) | stat: -rw-r--r-- 3,122 bytes parent folder | download
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# vim:set fileencoding=utf-8 et ts=4 sts=4 sw=4:
from apt_listchanges import frontend
from ALChacks import _

# check if gtk is available
import gi
gi.require_version('Gtk', '3.0')

from gi.repository import Gtk, GLib


class gtk_frd(frontend):
    def flush_interface(self):
        while Gtk.events_pending():
            Gtk.main_iteration()

    def cb_close(self, widget):
        Gtk.main_quit()

    def __init__(self, *args):
        super().__init__(*args)
        self.builder = Gtk.Builder()
        self.builder.set_translation_domain("apt-listchanges")
        try:
            self.builder.add_from_file("apt-listchanges/apt-listchanges.ui")
        except GLib.Error:
            self.builder.add_from_file("/usr/share/apt-listchanges/apt-listchanges.ui")
        self.window_main = self.builder.get_object("window_main")
        handlers = {
            "on_button_close_clicked": self.cb_close,
            "on_window_main_destroy": self.cb_close,
        }
        self.progressbar_main = self.builder.get_object("progressbar_main")
        self.button_close = self.builder.get_object("button_close")
        self.label_header = self.builder.get_object("label_header")
        self.label_header_descr = self.builder.get_object("label_header_descr")
        self.label_header_descr.hide()
        self.textview_buf = self.builder.get_object("textview_main").get_buffer()

        self.set_title(_('apt-listchanges: Reading changelogs'))
        self.textview_buf.set_text('\n  ' + _('Reading changelogs. Please wait.'))
        self.builder.connect_signals(handlers)
        self.flush_interface()

    def display_output(self,text):
        self.label_header_descr.show()
        self.button_close.set_sensitive(True)
        self.textview_buf.set_text(self._render(text))
        Gtk.main()

    def update_progress(self, diff = 1):
        if not diff:
            return
        if not hasattr(self,'progress'):
            # First call
            self.progress = 0.0
            self.progressbar_main.show()
        self.progress += diff
        self.progressbar_main.set_fraction(self.progress / self.packages_count)
        self.progressbar_main.set_text(("%i%%" % (self.progress*100 / self.packages_count)))
        self.flush_interface()

    def progress_done(self):
        self.progressbar_main.hide()
        self.flush_interface()

    def confirm(self):
        m = Gtk.MessageDialog(self.window_main,
                              Gtk.DialogFlags.MODAL,
                              Gtk.MessageType.QUESTION,
                              Gtk.ButtonsType.YES_NO)
        m.set_default_response(Gtk.ResponseType.YES)
        m.set_markup("<big><b>%s</b></big>\n\n%s" % (
            _("Continue Installation?"),
            _("Select <i>yes</i> to continue with the installation."
              "\nSelect <i>no</i> to abort the installation.")
            ))
        if m.run() == Gtk.ResponseType.NO:
            return False
        return True

    def set_title(self, text):
        self.label_header.set_markup('<big><b>%s</b></big>' % text)
        self.window_main.set_title(text)