From 859abc56143dc15ee19eac1c20aa1ef661939483 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Manuel=20Qui=C3=B1ones?= <manuq@laptop.org>
Date: Tue, 6 Nov 2012 15:44:30 -0300
Subject: [PATCH shell] Palettes: adjust to the new API - SL #4144
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Mail-Followup-To: <sugar-devel@lists.sugarlabs.org>
The API now allows to hide the implementation details using a
PaletteMenuBox as container.
Signed-off-by: Manuel Quiñones <manuq@laptop.org>
---
extensions/deviceicon/battery.py | 21 ++++++++++-------
extensions/deviceicon/network.py | 7 ++++--
extensions/deviceicon/speaker.py | 27 ++++++++++++----------
extensions/deviceicon/speech.py | 45 ++++++++++++++++++------------------
extensions/deviceicon/volume.py | 5 ++--
src/jarabe/desktop/favoritesview.py | 5 ++--
src/jarabe/desktop/networkviews.py | 5 ++--
src/jarabe/view/buddymenu.py | 3 ++-
src/jarabe/view/palettes.py | 46 +++++++++++++++++++++----------------
9 files changed, 93 insertions(+), 71 deletions(-)
diff --git a/extensions/deviceicon/battery.py b/extensions/deviceicon/battery.py
index 7fcca8d..0a1bf26 100644
a
|
b
|
from sugar3.graphics import style |
27 | 27 | from sugar3.graphics.icon import get_icon_state |
28 | 28 | from sugar3.graphics.tray import TrayIcon |
29 | 29 | from sugar3.graphics.palette import Palette |
| 30 | from sugar3.graphics.palettemenu import PaletteMenuBox |
30 | 31 | from sugar3.graphics.xocolor import XoColor |
31 | 32 | |
32 | 33 | from jarabe.frame.frameinvoker import FrameWidgetInvoker |
… |
… |
class BatteryPalette(Palette): |
116 | 117 | self._level = 0 |
117 | 118 | self._time = 0 |
118 | 119 | self._status = _STATUS_NOT_PRESENT |
| 120 | |
| 121 | self._progress_widget = PaletteMenuBox() |
| 122 | self.set_content(self._progress_widget) |
| 123 | self._progress_widget.show() |
| 124 | |
| 125 | inner_box = Gtk.VBox() |
| 126 | self._progress_widget.append_item(inner_box) |
| 127 | inner_box.show() |
| 128 | |
119 | 129 | self._progress_bar = Gtk.ProgressBar() |
120 | 130 | self._progress_bar.set_size_request( |
121 | 131 | style.zoom(style.GRID_CELL_SIZE * 4), -1) |
| 132 | inner_box.pack_start(self._progress_bar, True, True, 0) |
122 | 133 | self._progress_bar.show() |
| 134 | |
123 | 135 | self._status_label = Gtk.Label() |
| 136 | inner_box.pack_start(self._status_label, True, True, 0) |
124 | 137 | self._status_label.show() |
125 | 138 | |
126 | | vbox = Gtk.VBox() |
127 | | vbox.pack_start(self._progress_bar, True, True, 0) |
128 | | vbox.pack_start(self._status_label, True, True, 0) |
129 | | vbox.show() |
130 | | |
131 | | self._progress_widget = vbox |
132 | | self.set_content(self._progress_widget) |
133 | | |
134 | 139 | def set_info(self, percentage, seconds, status): |
135 | 140 | self._level = percentage |
136 | 141 | self._time = seconds |
diff --git a/extensions/deviceicon/network.py b/extensions/deviceicon/network.py
index 3351281..fbd0ef4 100644
a
|
b
|
import dbus |
34 | 34 | from sugar3.graphics.icon import get_icon_state |
35 | 35 | from sugar3.graphics import style |
36 | 36 | from sugar3.graphics.palette import Palette |
37 | | from sugar3.graphics.palettemenuitem import PaletteMenuItem |
38 | | from sugar3.graphics.palettemenuitem import PaletteMenuItemSeparator |
| 37 | from sugar3.graphics.palettemenu import PaletteMenuBox |
| 38 | from sugar3.graphics.palettemenu import PaletteMenuItem |
| 39 | from sugar3.graphics.palettemenu import PaletteMenuItemSeparator |
39 | 40 | from sugar3.graphics.toolbutton import ToolButton |
40 | 41 | from sugar3.graphics.tray import TrayIcon |
41 | 42 | from sugar3.graphics.icon import Icon |
… |
… |
class WirelessPalette(Palette): |
74 | 75 | self._channel_label.show() |
75 | 76 | |
76 | 77 | self._ip_address_label = Gtk.Label() |
| 78 | self._ip_address_label.props.xalign = 0.0 |
| 79 | self._ip_address_label.show() |
77 | 80 | |
78 | 81 | self._info = Gtk.VBox() |
79 | 82 | |
diff --git a/extensions/deviceicon/speaker.py b/extensions/deviceicon/speaker.py
index 8260d49..67c3f27 100644
a
|
b
|
from sugar3.graphics import style |
25 | 25 | from sugar3.graphics.icon import get_icon_state, Icon |
26 | 26 | from sugar3.graphics.tray import TrayIcon |
27 | 27 | from sugar3.graphics.palette import Palette |
28 | | from sugar3.graphics.palettemenuitem import PaletteMenuItem |
29 | | from sugar3.graphics.palettemenuitem import PaletteMenuItemSeparator |
| 28 | from sugar3.graphics.palettemenu import PaletteMenuBox |
| 29 | from sugar3.graphics.palettemenu import PaletteMenuItem |
| 30 | from sugar3.graphics.palettemenu import PaletteMenuItemSeparator |
30 | 31 | from sugar3.graphics.xocolor import XoColor |
31 | 32 | |
32 | 33 | from jarabe.frame.frameinvoker import FrameWidgetInvoker |
… |
… |
class SpeakerPalette(Palette): |
90 | 91 | |
91 | 92 | self._model = model |
92 | 93 | |
93 | | vbox = Gtk.VBox() |
94 | | self.set_content(vbox) |
95 | | vbox.show() |
| 94 | box = PaletteMenuBox() |
| 95 | self.set_content(box) |
| 96 | box.show() |
96 | 97 | |
97 | 98 | self._mute_item = PaletteMenuItem('') |
98 | 99 | self._mute_icon = Icon(icon_size=Gtk.IconSize.MENU) |
99 | 100 | self._mute_item.set_image(self._mute_icon) |
100 | | vbox.add(self._mute_item) |
| 101 | box.append_item(self._mute_item) |
101 | 102 | self._mute_item.show() |
102 | 103 | self._mute_item.connect('activate', self.__mute_activate_cb) |
103 | 104 | |
104 | 105 | separator = PaletteMenuItemSeparator() |
105 | | vbox.pack_start(separator, True, True, 0) |
| 106 | box.append_item(separator) |
106 | 107 | separator.show() |
107 | 108 | |
108 | 109 | vol_step = sound.VOLUME_STEP |
… |
… |
class SpeakerPalette(Palette): |
112 | 113 | step_incr=vol_step, |
113 | 114 | page_incr=vol_step, |
114 | 115 | page_size=vol_step) |
115 | | self._hscale = Gtk.HScale() |
116 | | self._hscale.set_adjustment(self._adjustment) |
117 | | self._hscale.set_digits(0) |
118 | | vbox.add(self._hscale) |
119 | | self._hscale.show() |
| 116 | |
| 117 | hscale = Gtk.HScale() |
| 118 | hscale.props.draw_value = False |
| 119 | hscale.set_adjustment(self._adjustment) |
| 120 | hscale.set_digits(0) |
| 121 | box.append_item(hscale) |
| 122 | hscale.show() |
120 | 123 | |
121 | 124 | self._adjustment_handler_id = \ |
122 | 125 | self._adjustment.connect('value_changed', |
diff --git a/extensions/deviceicon/speech.py b/extensions/deviceicon/speech.py
index 1f7bf02..a0a2ad1 100644
a
|
b
|
from gi.repository import GObject |
24 | 24 | from sugar3.graphics.icon import Icon |
25 | 25 | from sugar3.graphics.tray import TrayIcon |
26 | 26 | from sugar3.graphics.palette import Palette |
27 | | from sugar3.graphics.palettemenuitem import PaletteMenuItem |
28 | | from sugar3.graphics.palettemenuitem import PaletteMenuItemSeparator |
| 27 | from sugar3.graphics.palettemenu import PaletteMenuBox |
| 28 | from sugar3.graphics.palettemenu import PaletteMenuItem |
| 29 | from sugar3.graphics.palettemenu import PaletteMenuItemSeparator |
29 | 30 | from sugar3.graphics.xocolor import XoColor |
30 | 31 | from sugar3.graphics import style |
31 | 32 | |
… |
… |
class SpeechPalette(Palette): |
66 | 67 | self._manager.connect('stop', self._set_menu_state, 'stop') |
67 | 68 | self._manager.connect('pause', self._set_menu_state, 'pause') |
68 | 69 | |
69 | | vbox = Gtk.VBox() |
70 | | self.set_content(vbox) |
71 | | vbox.show() |
| 70 | box = PaletteMenuBox() |
| 71 | self.set_content(box) |
| 72 | box.show() |
72 | 73 | |
73 | 74 | self._play_icon = Icon(icon_name='player_play') |
74 | 75 | self._pause_icon = Icon(icon_name='player_pause') |
… |
… |
class SpeechPalette(Palette): |
77 | 78 | text_label=_('Say selected text')) |
78 | 79 | self._play_pause_menu.set_image(self._play_icon) |
79 | 80 | self._play_pause_menu.connect('activate', self.__play_activated_cb) |
80 | | vbox.pack_start(self._play_pause_menu, True, True, 0) |
| 81 | box.append_item(self._play_pause_menu) |
81 | 82 | self._play_pause_menu.show() |
82 | 83 | |
83 | 84 | self._stop_menu = PaletteMenuItem(icon_name='player_stop', |
84 | 85 | text_label=_('Stop playback')) |
85 | 86 | self._stop_menu.connect('activate', self.__stop_activated_cb) |
86 | 87 | self._stop_menu.set_sensitive(False) |
87 | | vbox.pack_start(self._stop_menu, True, True, 0) |
88 | | self._stop_menu.show() |
| 88 | box.append_item(self._stop_menu) |
89 | 89 | |
90 | 90 | separator = PaletteMenuItemSeparator() |
91 | | vbox.pack_start(separator, True, True, 0) |
| 91 | box.append_item(separator) |
92 | 92 | separator.show() |
93 | 93 | |
94 | 94 | pitch_label = Gtk.Label(_('Pitch')) |
95 | | vbox.pack_start(pitch_label, True, True, padding=style.DEFAULT_PADDING) |
| 95 | box.append_item(pitch_label, vertical_padding=0) |
96 | 96 | pitch_label.show() |
97 | 97 | |
98 | 98 | self._adj_pitch = Gtk.Adjustment(value=self._manager.get_pitch(), |
99 | 99 | lower=self._manager.MIN_PITCH, |
100 | 100 | upper=self._manager.MAX_PITCH) |
101 | | self._hscale_pitch = Gtk.HScale() |
102 | | self._hscale_pitch.set_adjustment(self._adj_pitch) |
103 | | self._hscale_pitch.set_draw_value(False) |
104 | 101 | |
105 | | vbox.pack_start(self._hscale_pitch, True, True, 0) |
106 | | self._hscale_pitch.show() |
| 102 | hscale_pitch = Gtk.HScale() |
| 103 | hscale_pitch.set_adjustment(self._adj_pitch) |
| 104 | hscale_pitch.set_draw_value(False) |
| 105 | |
| 106 | box.append_item(hscale_pitch, vertical_padding=0) |
| 107 | hscale_pitch.show() |
107 | 108 | |
108 | 109 | rate_label = Gtk.Label(_('Rate')) |
109 | | vbox.pack_start(rate_label, True, True, |
110 | | padding=style.DEFAULT_PADDING) |
| 110 | box.append_item(rate_label, vertical_padding=0) |
111 | 111 | rate_label.show() |
112 | 112 | |
113 | 113 | self._adj_rate = Gtk.Adjustment(value=self._manager.get_rate(), |
114 | 114 | lower=self._manager.MIN_RATE, |
115 | 115 | upper=self._manager.MAX_RATE) |
116 | | self._hscale_rate = Gtk.HScale() |
117 | | self._hscale_rate.set_adjustment(self._adj_rate) |
118 | | self._hscale_rate.set_draw_value(False) |
119 | 116 | |
120 | | vbox.pack_start(self._hscale_rate, True, True, 0) |
121 | | self._hscale_rate.show() |
| 117 | hscale_rate = Gtk.HScale() |
| 118 | hscale_rate.set_adjustment(self._adj_rate) |
| 119 | hscale_rate.set_draw_value(False) |
| 120 | |
| 121 | box.append_item(hscale_rate, vertical_padding=0) |
| 122 | hscale_rate.show() |
122 | 123 | |
123 | 124 | self._adj_pitch.connect('value_changed', self.__adj_pitch_changed_cb) |
124 | 125 | self._adj_rate.connect('value_changed', self.__adj_rate_changed_cb) |
diff --git a/extensions/deviceicon/volume.py b/extensions/deviceicon/volume.py
index 6930811..76cb41b 100644
a
|
b
|
from gi.repository import GConf |
24 | 24 | |
25 | 25 | from sugar3.graphics.tray import TrayIcon |
26 | 26 | from sugar3.graphics.xocolor import XoColor |
27 | | from sugar3.graphics.palettemenuitem import PaletteMenuItem |
28 | | from sugar3.graphics.palettemenuitem import PaletteMenuItemSeparator |
| 27 | from sugar3.graphics.palettemenu import PaletteMenuBox |
| 28 | from sugar3.graphics.palettemenu import PaletteMenuItem |
| 29 | from sugar3.graphics.palettemenu import PaletteMenuItemSeparator |
29 | 30 | from sugar3.graphics.icon import Icon |
30 | 31 | |
31 | 32 | from jarabe.journal import journalactivity |
diff --git a/src/jarabe/desktop/favoritesview.py b/src/jarabe/desktop/favoritesview.py
index 6e32363..152dd6e 100644
a
|
b
|
from gi.repository import GdkPixbuf |
29 | 29 | from sugar3.graphics import style |
30 | 30 | from sugar3.graphics.icon import Icon |
31 | 31 | from sugar3.graphics.icon import CanvasIcon |
32 | | from sugar3.graphics.palettemenuitem import PaletteMenuItem |
33 | | from sugar3.graphics.palettemenuitem import PaletteMenuItemSeparator |
| 32 | from sugar3.graphics.palettemenu import PaletteMenuBox |
| 33 | from sugar3.graphics.palettemenu import PaletteMenuItem |
| 34 | from sugar3.graphics.palettemenu import PaletteMenuItemSeparator |
34 | 35 | from sugar3.graphics.alert import Alert |
35 | 36 | from sugar3.graphics.xocolor import XoColor |
36 | 37 | from sugar3.activity import activityfactory |
diff --git a/src/jarabe/desktop/networkviews.py b/src/jarabe/desktop/networkviews.py
index f72b2d2..29dc131 100644
a
|
b
|
from sugar3.graphics import xocolor |
32 | 32 | from sugar3.graphics import style |
33 | 33 | from sugar3.graphics.icon import get_icon_state |
34 | 34 | from sugar3.graphics import palette |
35 | | from sugar3.graphics.palettemenuitem import PaletteMenuItem |
36 | | from sugar3.graphics.palettemenuitem import PaletteMenuItemSeparator |
| 35 | from sugar3.graphics.palettemenu import PaletteMenuBox |
| 36 | from sugar3.graphics.palettemenu import PaletteMenuItem |
| 37 | from sugar3.graphics.palettemenu import PaletteMenuItemSeparator |
37 | 38 | from sugar3 import profile |
38 | 39 | |
39 | 40 | from jarabe.view.pulsingicon import EventPulsingIcon |
diff --git a/src/jarabe/view/buddymenu.py b/src/jarabe/view/buddymenu.py
index 2579d96..9015fbe 100644
a
|
b
|
import glib |
24 | 24 | import dbus |
25 | 25 | |
26 | 26 | from sugar3.graphics.palette import Palette |
27 | | from sugar3.graphics.palettemenuitem import PaletteMenuItem |
| 27 | from sugar3.graphics.palettemenu import PaletteMenuBox |
| 28 | from sugar3.graphics.palettemenu import PaletteMenuItem |
28 | 29 | from sugar3.graphics.icon import Icon |
29 | 30 | |
30 | 31 | from jarabe.model import shell |
diff --git a/src/jarabe/view/palettes.py b/src/jarabe/view/palettes.py
index 5448bde..e3a53ad 100644
a
|
b
|
from gi.repository import Gtk |
25 | 25 | |
26 | 26 | from sugar3 import env |
27 | 27 | from sugar3.graphics.palette import Palette |
28 | | from sugar3.graphics.palettemenuitem import PaletteMenuItem |
29 | | from sugar3.graphics.palettemenuitem import PaletteMenuItemSeparator |
| 28 | from sugar3.graphics.palettemenu import PaletteMenuBox |
| 29 | from sugar3.graphics.palettemenu import PaletteMenuItem |
| 30 | from sugar3.graphics.palettemenu import PaletteMenuItemSeparator |
30 | 31 | from sugar3.graphics.menuitem import MenuItem |
31 | 32 | from sugar3.graphics.icon import Icon |
32 | 33 | from sugar3.graphics import style |
… |
… |
class CurrentActivityPalette(BasePalette): |
83 | 84 | if title and title != activity_name: |
84 | 85 | self.props.secondary_text = glib.markup_escape_text(title) |
85 | 86 | |
86 | | self.menu_box = Gtk.VBox() |
| 87 | self.menu_box = PaletteMenuBox() |
87 | 88 | |
88 | 89 | menu_item = PaletteMenuItem(_('Resume'), 'activity-start') |
89 | 90 | menu_item.connect('activate', self.__resume_activate_cb) |
90 | | self.menu_box.pack_start(menu_item, True, True, 0) |
| 91 | self.menu_box.append_item(menu_item) |
91 | 92 | |
92 | 93 | # TODO: share-with, keep |
93 | 94 | |
94 | 95 | menu_item = PaletteMenuItem(_('View Source'), 'view-source') |
95 | 96 | menu_item.connect('activate', self.__view_source__cb) |
96 | | self.menu_box.pack_start(menu_item, True, True, 0) |
| 97 | self.menu_box.append_item(menu_item) |
97 | 98 | |
98 | 99 | separator = PaletteMenuItemSeparator() |
99 | | self.menu_box.pack_start(menu_item, True, True, 0) |
| 100 | self.menu_box.append_item(menu_item) |
100 | 101 | separator.show() |
101 | 102 | |
102 | 103 | menu_item = PaletteMenuItem(_('Stop'), 'activity-stop') |
103 | 104 | menu_item.connect('activate', self.__stop_activate_cb) |
104 | | self.menu_box.pack_start(menu_item, True, True, 0) |
| 105 | self.menu_box.append_item(menu_item) |
105 | 106 | |
106 | 107 | self.set_content(self.menu_box) |
107 | 108 | self.menu_box.show_all() |
… |
… |
class ActivityPalette(Palette): |
141 | 142 | |
142 | 143 | xo_color = XoColor('%s,%s' % (style.COLOR_WHITE.get_svg(), |
143 | 144 | style.COLOR_TRANSPARENT.get_svg())) |
144 | | self.menu_box = Gtk.VBox() |
| 145 | self.menu_box = PaletteMenuBox() |
145 | 146 | menu_item = PaletteMenuItem(text_label=_('Start new'), |
146 | 147 | file_name=activity_info.get_icon(), |
147 | 148 | xo_color=xo_color) |
148 | 149 | menu_item.connect('activate', self.__start_activate_cb) |
149 | 150 | self.menu_box.pack_end(menu_item, True, True, 0) |
| 151 | menu_item.show() |
150 | 152 | self.set_content(self.menu_box) |
151 | 153 | self.menu_box.show_all() |
152 | 154 | |
… |
… |
class JournalPalette(BasePalette): |
169 | 171 | title = self._home_activity.get_title() |
170 | 172 | self.set_primary_text(glib.markup_escape_text(title)) |
171 | 173 | |
172 | | vbox = Gtk.VBox() |
173 | | self.set_content(vbox) |
174 | | vbox.show() |
| 174 | box = PaletteMenuBox() |
| 175 | self.set_content(box) |
| 176 | box.show() |
175 | 177 | |
176 | 178 | menu_item = PaletteMenuItem(_('Show contents')) |
177 | 179 | icon = Icon(file=self._home_activity.get_icon_path(), |
… |
… |
class JournalPalette(BasePalette): |
181 | 183 | icon.show() |
182 | 184 | |
183 | 185 | menu_item.connect('activate', self.__open_activate_cb) |
184 | | vbox.add(menu_item) |
| 186 | box.append_item(menu_item) |
185 | 187 | menu_item.show() |
186 | 188 | |
187 | 189 | separator = PaletteMenuItemSeparator() |
188 | | vbox.pack_start(separator, True, True, 0) |
| 190 | box.append_item(separator) |
189 | 191 | separator.show() |
190 | 192 | |
| 193 | inner_box = Gtk.VBox() |
| 194 | box.append_item(inner_box) |
| 195 | inner_box.show() |
| 196 | |
191 | 197 | self._progress_bar = Gtk.ProgressBar() |
192 | | vbox.add(self._progress_bar) |
| 198 | inner_box.add(self._progress_bar) |
193 | 199 | self._progress_bar.show() |
194 | 200 | |
195 | 201 | self._free_space_label = Gtk.Label() |
196 | 202 | self._free_space_label.set_alignment(0.5, 0.5) |
197 | | vbox.add(self._free_space_label) |
| 203 | inner_box.add(self._free_space_label) |
198 | 204 | self._free_space_label.show() |
199 | 205 | |
200 | 206 | self.connect('popup', self.__popup_cb) |
… |
… |
class VolumePalette(Palette): |
222 | 228 | path = mount.get_root().get_path() |
223 | 229 | self.props.secondary_text = glib.markup_escape_text(path) |
224 | 230 | |
225 | | self.content_box = Gtk.VBox() |
| 231 | self.content_box = PaletteMenuBox() |
226 | 232 | self.set_content(self.content_box) |
227 | 233 | self.content_box.show() |
228 | 234 | |
… |
… |
class VolumePalette(Palette): |
233 | 239 | icon.show() |
234 | 240 | |
235 | 241 | menu_item.connect('activate', self.__unmount_activate_cb) |
236 | | self.content_box.pack_start(menu_item, True, True, 0) |
| 242 | self.content_box.append_item(menu_item) |
237 | 243 | menu_item.show() |
238 | 244 | |
239 | 245 | separator = PaletteMenuItemSeparator() |
240 | | self.content_box.pack_start(separator, True, True, 0) |
| 246 | self.content_box.append_item(separator) |
241 | 247 | separator.show() |
242 | 248 | |
243 | 249 | self._progress_bar = Gtk.ProgressBar() |
244 | | self.content_box.pack_start(self._progress_bar, True, True, 0) |
| 250 | self.content_box.append_item(self._progress_bar) |
245 | 251 | self._progress_bar.show() |
246 | 252 | |
247 | 253 | self._free_space_label = Gtk.Label() |
248 | 254 | self._free_space_label.set_alignment(0.5, 0.5) |
249 | | self.content_box.pack_start(self._free_space_label, True, True, 0) |
| 255 | self.content_box.append_item(self._free_space_label) |
250 | 256 | self._free_space_label.show() |
251 | 257 | |
252 | 258 | self.connect('popup', self.__popup_cb) |