/usr/share/sugar/extensions/deviceicon/display.py is in sugar-session 0.106.1-1.
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 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 | # Copyright (C) 2014 Sam Parkinson
# Copyright (C) 2015 Martin Abente Lahaye
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
from gettext import gettext as _
import math
from gi.repository import GLib
from gi.repository import Gtk
from gi.repository import GObject
from sugar3 import profile
from sugar3.graphics import style
from sugar3.graphics.icon import Icon
from sugar3.graphics.tray import TrayIcon
from sugar3.graphics.palette import Palette
from sugar3.graphics.palettemenu import PaletteMenuBox
from sugar3.graphics.palettemenu import PaletteMenuItem
from sugar3.graphics.palettemenu import PaletteMenuItemSeparator
from sugar3.graphics.xocolor import XoColor
from jarabe.frame.frameinvoker import FrameWidgetInvoker
from jarabe.model import brightness
from jarabe.model.screenshot import take_screenshot
from jarabe import frame
class DeviceView(TrayIcon):
FRAME_POSITION_RELATIVE = 160
def __init__(self, label):
self._color = profile.get_color()
self._label = label
TrayIcon.__init__(self, icon_name='brightness-100',
xo_color=self._color)
self.set_palette_invoker(FrameWidgetInvoker(self))
self.palette_invoker.props.toggle_palette = True
model = brightness.get_instance()
if model.get_path():
self._model = model
self._model.changed_signal.connect(self.__brightness_changed_cb)
self._update_output_info()
def create_palette(self):
palette = DisplayPalette()
palette.set_group_id('frame')
return palette
def _update_output_info(self, value=None):
if value is None:
value = self._model.get_brightness()
icon_number = math.ceil(
float(value) * 3 / self._model.get_max_brightness()) * 33
if icon_number == 99:
icon_number = 100
self.icon.props.icon_name = \
'brightness-{:03d}'.format(int(icon_number))
def __brightness_changed_cb(self, model, value):
self._update_output_info(value)
class BrightnessManagerWidget(Gtk.VBox):
TIMEOUT_DELAY = 100
def __init__(self, text, icon_name):
Gtk.VBox.__init__(self)
self._progress_bar = None
self._adjustment = None
icon = Icon(icon_size=Gtk.IconSize.MENU)
icon.props.icon_name = icon_name
icon.props.xo_color = XoColor('%s,%s' % (style.COLOR_WHITE.get_svg(),
style.COLOR_BUTTON_GREY.get_svg()))
icon.show()
label = Gtk.Label(text)
label.show()
grid = Gtk.Grid()
grid.set_column_spacing(style.DEFAULT_SPACING)
grid.attach(icon, 0, 0, 1, 1)
grid.attach(label, 1, 0, 1, 1)
grid.show()
alignment = Gtk.Alignment()
alignment.set(0.5, 0, 0, 0)
alignment.add(grid)
alignment.show()
self.add(alignment)
alignment = Gtk.Alignment()
alignment.set(0.5, 0, 0, 0)
alignment.set_padding(0, 0, style.DEFAULT_SPACING,
style.DEFAULT_SPACING)
self._model = brightness.get_instance()
self._model_changed_hid = \
self._model.changed_signal.connect(self.__brightness_changed_cb)
# if sugar-backlight-helper finds the device
if self._model.get_path():
adjustment = Gtk.Adjustment(
value=self._model.get_brightness(),
lower=0,
upper=self._model.get_max_brightness() + 1,
step_incr=self._model.get_step_amount(),
page_incr=self._model.get_step_amount(),
page_size=self._model.get_step_amount())
self._adjustment = adjustment
self._adjustment_timeout_id = None
self._adjustment_hid = \
self._adjustment.connect('value_changed', self.__adjusted_cb)
hscale = Gtk.HScale()
hscale.props.draw_value = False
hscale.set_adjustment(adjustment)
hscale.set_digits(0)
hscale.set_size_request(style.GRID_CELL_SIZE * 4, -1)
alignment.add(hscale)
hscale.show()
else:
self._progress_bar = Gtk.ProgressBar()
self._progress_bar.set_size_request(
style.zoom(style.GRID_CELL_SIZE * 4), -1)
alignment.props.top_padding = style.DEFAULT_PADDING
alignment.add(self._progress_bar)
self._progress_bar.show()
alignment.show()
self.add(alignment)
def __brightness_changed_cb(self, model, value):
self.update(value)
def update(self, value=None):
if value is None:
value = self._model.get_brightness()
if self._adjustment:
self._adjustment.handler_block(self._adjustment_hid)
self._adjustment.props.value = value
self._adjustment.handler_unblock(self._adjustment_hid)
else:
self._progress_bar.props.fraction = \
float(value) / self._model.get_max_brightness()
def __adjusted_cb(self, device, data=None):
if self._adjustment_timeout_id is not None:
GLib.source_remove(self._adjustment_timeout_id)
self._adjustment_timeout_id = GLib.timeout_add(
self.TIMEOUT_DELAY, self._adjust_brightness)
def _adjust_brightness(self):
self._model.handler_block(self._model_changed_hid)
self._model.set_brightness(int(self._adjustment.props.value))
self._model.handler_unblock(self._model_changed_hid)
self._adjustment_timeout_id = None
return False
class DisplayPalette(Palette):
def __init__(self):
Palette.__init__(self, label=_('My Display'))
self._screenshot = PaletteMenuItem(_('Take a screenshot'))
icon = Icon(icon_name='camera-external',
pixel_size=style.SMALL_ICON_SIZE)
self._screenshot.set_image(icon)
icon.show()
self._screenshot.connect('activate', self.__screenshot_cb)
self._screenshot.show()
self._box = PaletteMenuBox()
self._brightness_manager = None
# only add this widget if device available
if brightness.get_instance().get_path():
self._add_brightness_manager()
self._box.append_item(self._screenshot, 0, 0)
self._box.show()
self.set_content(self._box)
self.connect('popup', self.__popup_cb)
def _add_brightness_manager(self):
self._brightness_manager = BrightnessManagerWidget(_('Brightness'),
'brightness-100')
self._brightness_manager.show()
separator = PaletteMenuItemSeparator()
separator.show()
self._box.append_item(self._brightness_manager, 0, 0)
self._box.append_item(separator, 0, 0)
def __popup_cb(self, palette):
if self._brightness_manager is not None:
self._brightness_manager.update()
def __screenshot_cb(self, palette):
frame_ = frame.get_view()
frame_.hide()
GObject.idle_add(self.__take_screenshot_cb, frame_)
def __take_screenshot_cb(self, frame_):
if frame_.is_visible():
return True
take_screenshot()
frame_.show()
return False
def setup(tray):
tray.add_device(DeviceView(_('Display')))
|