AptListChangesGtk.py 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # vim:set fileencoding=utf-8 et ts=4 sts=4 sw=4:
  2. from apt_listchanges import frontend
  3. # check if gtk is available
  4. import gi
  5. gi.require_version('Gtk', '3.0')
  6. from gi.repository import Gtk, GObject, GLib
  7. import sys
  8. from ALChacks import *
  9. class gtk_frd(frontend):
  10. def flush_interface(self):
  11. while Gtk.events_pending():
  12. Gtk.main_iteration()
  13. def cb_close(self, widget):
  14. Gtk.main_quit()
  15. def __init__(self, *args):
  16. super().__init__(*args)
  17. self.builder = Gtk.Builder()
  18. self.builder.set_translation_domain("apt-listchanges")
  19. try:
  20. self.builder.add_from_file("apt-listchanges/apt-listchanges.ui")
  21. except GLib.Error:
  22. self.builder.add_from_file("/usr/share/apt-listchanges/apt-listchanges.ui")
  23. self.window_main = self.builder.get_object("window_main")
  24. handlers = {
  25. "on_button_close_clicked": self.cb_close,
  26. "on_window_main_destroy": self.cb_close,
  27. }
  28. self.progressbar_main = self.builder.get_object("progressbar_main")
  29. self.button_close = self.builder.get_object("button_close")
  30. self.label_header = self.builder.get_object("label_header")
  31. self.label_header_descr = self.builder.get_object("label_header_descr")
  32. self.label_header_descr.hide()
  33. self.textview_buf = self.builder.get_object("textview_main").get_buffer()
  34. self.set_title(_('apt-listchanges: Reading changelogs'))
  35. self.textview_buf.set_text('\n ' + _('Reading changelogs. Please wait.'))
  36. self.builder.connect_signals(handlers)
  37. self.flush_interface()
  38. def display_output(self,text):
  39. self.label_header_descr.show()
  40. self.button_close.set_sensitive(True)
  41. self.textview_buf.set_text(self._render(text))
  42. Gtk.main()
  43. def update_progress(self):
  44. if not hasattr(self,'progress'):
  45. # First call
  46. self.progress = 0.0
  47. self.progressbar_main.show()
  48. self.progress += 1.0
  49. self.progressbar_main.set_fraction(self.progress / self.packages_count)
  50. self.progressbar_main.set_text(("%i%%" % (self.progress*100 / self.packages_count)))
  51. self.flush_interface()
  52. def progress_done(self):
  53. self.progressbar_main.hide()
  54. self.flush_interface()
  55. def confirm(self):
  56. m = Gtk.MessageDialog(self.window_main,
  57. Gtk.DialogFlags.MODAL,
  58. Gtk.MessageType.QUESTION,
  59. Gtk.ButtonsType.YES_NO)
  60. m.set_default_response(Gtk.ResponseType.YES)
  61. m.set_markup("<big><b>%s</b></big>\n\n%s" % (_("Continue Installation?"), _("You can abort the installation if you select 'no'.")))
  62. if m.run() == Gtk.ResponseType.NO:
  63. return False
  64. return True
  65. def set_title(self, text):
  66. self.label_header.set_markup('<big><b>%s</b></big>' % text)
  67. self.window_main.set_title(text)