2511.1.14
by Michael Terry
auto-pep8'd some warnings |
1 |
# UnitySupport.py
|
2511.1.11
by Michael Terry
more pep8 fixes |
2 |
# -*- Mode: Python; indent-tabs-mode: nil; tab-width: 4; coding: utf-8 -*-
|
2511.1.14
by Michael Terry
auto-pep8'd some warnings |
3 |
#
|
2105
by Michael Vogt
move unity support into its own class so that its optional |
4 |
# Copyright (c) 2011 Canonical
|
2511.1.14
by Michael Terry
auto-pep8'd some warnings |
5 |
#
|
2105
by Michael Vogt
move unity support into its own class so that its optional |
6 |
# Author: Michael Vogt <mvo@ubuntu.com>
|
2108
by Michael Vogt
UpdateManager/UnitySupport.py: update header |
7 |
# Bilal Akhtar <bilalakhtar@ubuntu.com>
|
2511.1.14
by Michael Terry
auto-pep8'd some warnings |
8 |
#
|
9 |
# This program is free software; you can redistribute it and/or
|
|
10 |
# modify it under the terms of the GNU General Public License as
|
|
2105
by Michael Vogt
move unity support into its own class so that its optional |
11 |
# published by the Free Software Foundation; either version 2 of the
|
12 |
# License, or (at your option) any later version.
|
|
2511.1.14
by Michael Terry
auto-pep8'd some warnings |
13 |
#
|
2105
by Michael Vogt
move unity support into its own class so that its optional |
14 |
# This program is distributed in the hope that it will be useful,
|
15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
17 |
# GNU General Public License for more details.
|
|
2511.1.14
by Michael Terry
auto-pep8'd some warnings |
18 |
#
|
2105
by Michael Vogt
move unity support into its own class so that its optional |
19 |
# You should have received a copy of the GNU General Public License
|
20 |
# along with this program; if not, write to the Free Software
|
|
21 |
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
22 |
# USA
|
|
23 |
||
24 |
import logging |
|
2164
by Michael Vogt
make UpdateManager/, tests/ pyflakes clean |
25 |
from gettext import gettext as _ |
2105
by Michael Vogt
move unity support into its own class so that its optional |
26 |
|
2511.1.11
by Michael Terry
more pep8 fixes |
27 |
HAVE_UNITY_SUPPORT = False |
2105
by Michael Vogt
move unity support into its own class so that its optional |
28 |
try: |
2741.1.1
by Jeremy Bicha
Add gi.require_version in a few more places to reduce the annoying warnings |
29 |
import gi |
30 |
gi.require_version('Dbusmenu', '0.4') |
|
31 |
gi.require_version('Unity', '7.0') |
|
2105
by Michael Vogt
move unity support into its own class so that its optional |
32 |
from gi.repository import Dbusmenu, Unity |
2511.1.11
by Michael Terry
more pep8 fixes |
33 |
HAVE_UNITY_SUPPORT = True |
2745.1.2
by flocculant
fix update manager value error crash |
34 |
except (ValueError, ImportError) as e: |
2598
by Colin Watson
Use logging.warning rather than deprecated logging.warn. |
35 |
logging.warning("can not import unity GI %s" % e) |
2105
by Michael Vogt
move unity support into its own class so that its optional |
36 |
|
2511.1.11
by Michael Terry
more pep8 fixes |
37 |
|
2105
by Michael Vogt
move unity support into its own class so that its optional |
38 |
class IUnitySupport(object): |
39 |
""" interface for unity support """
|
|
2511.1.11
by Michael Terry
more pep8 fixes |
40 |
def __init__(self, parent=None): |
41 |
pass
|
|
42 |
||
43 |
def set_urgency(self, urgent): |
|
44 |
pass
|
|
45 |
||
46 |
def set_install_menuitem_visible(self, visible): |
|
47 |
pass
|
|
48 |
||
49 |
def set_progress(self, progress): |
|
50 |
pass
|
|
51 |
||
2105
by Michael Vogt
move unity support into its own class so that its optional |
52 |
|
53 |
class UnitySupportImpl(IUnitySupport): |
|
54 |
""" implementation of unity support (if unity is available) """
|
|
55 |
||
2128
by Michael Vogt
show progress inside unity, thanks to Bilal Akhtar for the initial |
56 |
def __init__(self, parent=None): |
2105
by Michael Vogt
move unity support into its own class so that its optional |
57 |
# create launcher and quicklist
|
58 |
um_launcher_entry = Unity.LauncherEntry.get_for_desktop_id( |
|
59 |
"update-manager.desktop") |
|
60 |
self._unity = um_launcher_entry |
|
2128
by Michael Vogt
show progress inside unity, thanks to Bilal Akhtar for the initial |
61 |
if parent: |
62 |
self._add_quicklist(parent) |
|
63 |
||
64 |
def _add_quicklist(self, parent): |
|
2855
by Gianfranco Costamagna
Fix E117 over idented code |
65 |
quicklist = Dbusmenu.Menuitem.new() |
66 |
# install
|
|
67 |
self.install_dbusmenuitem = Dbusmenu.Menuitem.new() |
|
68 |
self.install_dbusmenuitem.property_set( |
|
69 |
Dbusmenu.MENUITEM_PROP_LABEL, |
|
70 |
_("Install All Available Updates")) |
|
71 |
self.install_dbusmenuitem.property_set_bool( |
|
72 |
Dbusmenu.MENUITEM_PROP_VISIBLE, True) |
|
73 |
self.install_dbusmenuitem.connect( |
|
74 |
"item-activated", parent.install_all_updates, None) |
|
75 |
quicklist.child_append(self.install_dbusmenuitem) |
|
76 |
# add it
|
|
77 |
self._unity.set_property("quicklist", quicklist) |
|
2511.1.14
by Michael Terry
auto-pep8'd some warnings |
78 |
|
2128
by Michael Vogt
show progress inside unity, thanks to Bilal Akhtar for the initial |
79 |
def set_progress(self, progress): |
80 |
""" set the progress [0,100] """
|
|
2511.1.11
by Michael Terry
more pep8 fixes |
81 |
self._unity.set_property("progress", progress / 100.0) |
2128
by Michael Vogt
show progress inside unity, thanks to Bilal Akhtar for the initial |
82 |
# hide progress when out of bounds
|
83 |
if progress < 0 or progress > 100: |
|
84 |
self._unity.set_property("progress_visible", False) |
|
85 |
else: |
|
86 |
self._unity.set_property("progress_visible", True) |
|
87 |
||
2135.1.1
by Evan Huus
Split unity urgency hints into seperate function and call those when we call the normal urgency hints |
88 |
def set_urgency(self, urgent): |
89 |
self._unity.set_property("urgent", urgent) |
|
2105
by Michael Vogt
move unity support into its own class so that its optional |
90 |
|
91 |
def set_install_menuitem_visible(self, visible): |
|
2511.1.11
by Michael Terry
more pep8 fixes |
92 |
self.install_dbusmenuitem.property_set_bool( |
93 |
Dbusmenu.MENUITEM_PROP_VISIBLE, visible) |
|
2105
by Michael Vogt
move unity support into its own class so that its optional |
94 |
|
95 |
||
96 |
# check what to export to the clients
|
|
97 |
if HAVE_UNITY_SUPPORT: |
|
98 |
UnitySupport = UnitySupportImpl |
|
99 |
else: |
|
2511.1.14
by Michael Terry
auto-pep8'd some warnings |
100 |
# we just provide the empty interface
|
2105
by Michael Vogt
move unity support into its own class so that its optional |
101 |
UnitySupport = IUnitySupport |