/usr/share/pyshared/AptUrl/gtk/GtkUI.py is in apturl 0.5.1ubuntu3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 | from gi.repository import Gtk
from gi.repository import Gdk
from gi.repository import GObject
GObject.threads_init()
import subprocess
import sys
import os
import os.path
import apt_pkg
from AptUrl.UI import AbstractUI
from AptUrl import Helpers
from AptUrl.Helpers import _
from backend import get_backend
class GtkUI(AbstractUI):
def __init__(self):
Gtk.init_check(sys.argv)
# create empty dialog
self.dia_xml = Gtk.Builder()
self.dia_xml.set_translation_domain("apturl")
self.dia_xml.add_from_file('/usr/share/apturl/apturl-gtk.ui')
self.dia = self.dia_xml.get_object('confirmation_dialog')
self.dia.realize()
self.backend = get_backend(self.dia)
self.backend.connect("action-done", self._on_backend_done)
def _on_backend_done(self, backend, action, authorized, success):
self.dia.set_sensitive(True)
Gtk.main_quit()
# generic dialogs
def _get_dialog(self, dialog_type, summary, msg="", buttons=Gtk.ButtonsType.CLOSE):
" internal helper for dialog construction "
d = Gtk.MessageDialog(parent=self.dia,
flags=Gtk.DialogFlags.MODAL,
type=dialog_type,
buttons=buttons)
d.set_title("")
d.set_markup("<big><b>%s</b></big>\n\n%s" % (summary, msg))
d.set_icon(Gtk.IconTheme.get_default().load_icon('deb', 16, False))
d.set_keep_above(True)
d.realize()
d.get_window().set_functions(Gdk.WMFunction.MOVE)
return d
def error(self, summary, msg=""):
d = self._get_dialog(Gtk.MessageType.ERROR, summary, msg)
d.run()
d.destroy()
return False
def message(self, summary, msg="", title=""):
d = self._get_dialog(Gtk.MessageType.INFO, summary, msg)
d.set_title(title)
d.run()
d.destroy()
return True
def yesNoQuestion(self, summary, msg, title="", default='no'):
d = self._get_dialog(Gtk.MessageType.QUESTION, summary, msg,
buttons=Gtk.ButtonsType.YES_NO)
d.set_title(title)
res = d.run()
d.destroy()
if res != Gtk.ResponseType.YES:
return False
return True
# specific dialogs
def askEnableChannel(self, channel, channel_info_html):
summary = _("Enable additional software channel")
msg = _("Do you want to enable the following "
"software channel: '%s'?") % channel
d = self._get_dialog(Gtk.MessageType.QUESTION, summary, msg,
buttons=Gtk.ButtonsType.YES_NO)
if channel_info_html:
try:
from gi.repository import WebKit
v=WebKit.WebView()
v.load_string(channel_info_html, "text/html", "utf-8", "file:/")
sw = Gtk.ScrolledWindow()
sw.add(v)
d.get_content_area().pack_start(sw, True, True, 0)
sw.set_size_request(400, 200)
sw.show_all()
except ImportError:
pass
res = d.run()
d.destroy()
if res != Gtk.ResponseType.YES:
return False
return True
def doEnableSection(self, sections):
cmd = ["gksu", "--desktop",
"/usr/share/applications/software-properties.desktop",
"--",
"software-properties-gtk",
"-e", "%s" % ' '.join(sections)]
try:
output = subprocess.Popen(cmd, stdout=subprocess.PIPE).communicate()[0]
except OSError, e:
print >>sys.stderr, "Execution failed:", e
return True
#FIXME: Very ugly, but gksu doesn't return the correct exit states
if not output.startswith("Enabled the "):
return False
return True
def doEnableChannel(self, channelpath, channelkey):
cmd = ["gksu",
"--desktop", "/usr/share/applications/gnome-app-install.desktop",
"--",
"install", "--mode=644","--owner=0",channelpath,
apt_pkg.Config.FindDir("Dir::Etc::sourceparts")]
res=subprocess.call(cmd)
if not res == 0:
return False
# install the key as well
if os.path.exists(channelkey):
cmd = ["gksu",
"--desktop",
"/usr/share/applications/gnome-app-install.desktop",
"--",
"apt-key", "add",channelkey]
res=subprocess.call(cmd)
if not res == 0:
return False
return True
def askInstallPackage(self, package, summary, description, homepage):
# populate the dialog
dia = self.dia
dia_xml = self.dia_xml
header = _("Install additional software?")
body = _("Do you want to install package '%s'?") % package
dia.set_keep_above(True)
dia.set_title('')
header_label = dia_xml.get_object('header_label')
header_label.set_markup("<b><big>%s</big></b>" % header)
body_label = dia_xml.get_object('body_label')
body_label.set_label(body)
description_text_view = dia_xml.get_object('description_text_view')
tbuf = Gtk.TextBuffer()
desc = "%s\n\n%s" % (summary, Helpers.format_description(description))
tbuf.set_text(desc)
description_text_view.set_buffer(tbuf)
dia.set_icon(Gtk.IconTheme.get_default().load_icon('deb', 16, False))
# check if another package manager is already running
# FIXME: just checking for the existance of the file is
# not sufficient, it need to be tested if it can
# be locked via apt_pkg.GetLock()
# - but that needs to run as root
# - a dbus helper might be the best answer here
#args = (update_button_status, dia_xml.get_object("yes_button"),
# dia_xml.get_object("infolabel"))
#args[0](*args[1:])
#timer_id = GObject.timeout_add(750, *args )
# show the dialog
res = dia.run()
#GObject.source_remove(timer_id)
if res != Gtk.ResponseType.YES:
dia.hide()
return False
# don't set on-top while installing
dia.set_keep_above(False)
return True
# progress etc
def doUpdate(self):
self.backend.update()
self.dia.set_sensitive(False)
Gtk.main()
def doInstall(self, apturl):
self.backend.commit([apturl.package], [], False)
self.dia.set_sensitive(False)
Gtk.main()
if __name__ == "__main__":
ui = GtkUI()
ui.error("foo","bar")
|