Web · Wiki · Activities · Blog · Lists · Chat · Meeting · Bugs · Git · Translate · Archive · People · Donate

Commit e2aa54257b05d77582f557c17a994ba93112a2c7

Add description button
  
1<?xml version="1.0" encoding="UTF-8"?>
2<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd"
3[
4 <!ENTITY fill_color "#FFFFFF">
5 <!ENTITY stroke_color "#A0A0A0">
6]>
7<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="55px" height="55px" viewBox="0px, 0px, 55px, 55px">
8 <g id="edit-description">
9 <path d="M19.849,50.763 C16.351,50.757 12.578,50.766 12.578,50.766 C12.578,50.766 12.016,50.75 11.391,50.359 C10.766,49.969 10.75,49.109 10.75,49.109 C10.75,49.109 10.767,46.339 10.768,43.613 C9.035,43.557 7.983,43.622 6.656,42.516 C6.656,42.516 5.985,41.844 6.078,41.062 C6.172,40.281 6.953,39.691 6.953,39.691 C8.243,39.106 9.485,40.004 10.769,40.088 L10.768,43.613 C13.038,43.782 16.125,43.625 17.297,42.531 C17.297,42.531 17.864,42.023 17.918,41.439 C17.972,40.855 17.719,40.359 17.719,40.359 C17.719,40.359 17.348,39.868 17.094,39.734 C16.84,39.6 16.337,39.441 15.594,39.656 C14.851,39.871 14.172,40.125 12.782,40.172 C11.391,40.219 10.769,40.088 10.769,40.088 L10.771,30.37 C9.037,30.314 7.984,30.435 6.656,29.328 C6.656,29.328 6.091,28.813 6.11,27.906 C6.129,26.999 6.746,26.4 7.604,26.277 C8.462,26.155 9.435,26.663 10.771,26.845 L10.771,30.37 C12.22,30.428 14.936,30.415 16.299,29.835 C17.569,29.296 17.646,29.017 17.867,28.54 C18.089,28.063 17.663,27.058 17.441,26.836 C17.22,26.615 16.64,26.172 15.959,26.308 C15.277,26.444 14.817,26.751 13.215,26.887 C11.614,27.024 10.771,26.845 10.771,26.845 L10.773,16.842 C9.039,16.786 7.969,16.811 6.641,15.703 C6.641,15.703 5.969,15.094 6.078,14.281 C6.188,13.469 6.953,12.92 6.953,12.92 C8.244,12.334 9.488,13.232 10.774,13.317 L10.773,16.842 C12.296,16.891 16.078,16.443 16.674,16.17 C17.271,15.897 17.611,15.727 17.85,15.079 C18.089,14.432 17.884,13.819 17.646,13.478 C17.407,13.137 16.743,12.66 16.112,12.711 C15.482,12.762 14.664,13.12 13.386,13.29 C12.108,13.461 10.774,13.317 10.774,13.317 C10.74,10.6 10.775,6.424 10.797,5.625 C10.819,4.826 11.653,4.281 12.397,4.25 C13.141,4.219 19.849,4.25 19.849,4.25 L19.849,50.763 z" stroke="none" fill="&fill_color;"/>
10 <path d="M37.539,50.772 L33.089,50.776 L23.815,50.769 L23.815,4.25 L41.993,4.25 C45.161,4.256 47.676,6.6 48.091,9.837 C44.391,14.527 42.021,17.643 38.267,22.561 C37.445,23.637 33.901,27.981 33.237,29.13 C32.572,30.279 30.721,35.315 29.512,38.128 C29.177,38.9 29.395,39.856 30.087,40.428 C31.004,40.961 31.524,40.868 31.887,40.825 C32.25,40.781 34.33,39.263 35.526,38.479 C37.099,37.449 38.952,36.632 40.38,35.399 C41.683,34.273 46.638,27.29 47.957,25.754 L48.087,25.587 L48.087,44.656 C48.09,48.043 45.921,50.777 43.001,50.779 z" stroke="none" fill="&fill_color;"/>
11 <path d="M52.796,13.98 C52.806,13.97 52.851,13.898 52.851,13.898 C52.893,13.827 52.92,13.743 52.92,13.651 C52.92,13.624 52.925,13.594 52.92,13.568 C52.881,13.233 52.598,12.832 52.192,12.511 C51.786,12.191 51.33,12.018 50.997,12.058 C50.854,12.076 50.654,12.222 50.654,12.222 L36.078,30.999 L34.517,34.851 C34.497,34.897 34.509,34.949 34.548,34.981 C34.587,35.012 34.64,35.017 34.682,34.989 L38.122,32.776 z" stroke="none" fill="&fill_color;"/>
12 </g>
13 <defs/>
14</svg>
  
3030from toolkit.toolbarbox import ToolbarButton
3131from toolkit.radiopalette import RadioPalette
3232from toolkit.radiopalette import RadioMenuButton
33from sugar.graphics import style
3334
3435_ = lambda msg: gettext.dgettext('sugar-toolkit', msg)
3536
160160 self.neighborhood.handler_unblock(self._neighborhood_handle)
161161
162162
163class KeepButton(ToolButton):
164
165 def __init__(self, activity, **kwargs):
166 ToolButton.__init__(self, **kwargs)
167 self.props.tooltip = _('Keep')
168 self.props.accelerator = '<Ctrl>S'
169
170 color = profile.get_color()
171 keep_icon = Icon(icon_name='document-save', xo_color=color)
172 keep_icon.show()
173
174 self.set_icon_widget(keep_icon)
175 self.connect('clicked', self.__keep_button_clicked_cb, activity)
176
177 def __keep_button_clicked_cb(self, button, activity):
178 activity.copy()
179
180
181163class TitleEntry(gtk.ToolItem):
182164
183165 def __init__(self, activity, **kwargs):
203203 return False
204204
205205
206class DescriptionItem(gtk.ToolItem):
207
208 def __init__(self, activity, **kwargs):
209 gtk.ToolItem.__init__(self)
210
211 description_button = ToolButton('edit-description')
212 description_button.show()
213 description_button.set_tooltip(_('Description'))
214 self._palette = description_button.get_palette()
215
216 description_box = gtk.HBox()
217 sw = gtk.ScrolledWindow()
218 sw.set_size_request(int(gtk.gdk.screen_width() / 2),
219 2 * style.GRID_CELL_SIZE)
220 sw.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
221 self._text_view = gtk.TextView()
222 self._text_view.set_left_margin(style.DEFAULT_PADDING)
223 self._text_view.set_right_margin(style.DEFAULT_PADDING)
224 text_buffer = gtk.TextBuffer()
225 if 'description' in activity.metadata:
226 text_buffer.set_text(activity.metadata['description'])
227 self._text_view.set_buffer(text_buffer)
228 self._text_view.connect('focus-out-event',
229 self.__description_changed_cb, activity)
230 sw.add(self._text_view)
231 description_box.pack_start(sw, False, True, 0)
232 self._palette.set_content(description_box)
233 description_box.show_all()
234
235 self.add(description_button)
236 description_button.connect('clicked',
237 self.__description_button_clicked_cb)
238
239 activity.metadata.connect('updated', self.__jobject_updated_cb)
240
241 def _get_text_from_buffer(self):
242 buf = self._text_view.get_buffer()
243 start_iter = buf.get_start_iter()
244 end_iter = buf.get_end_iter()
245 return buf.get_text(start_iter, end_iter, False)
246
247 def __jobject_updated_cb(self, jobject):
248 if self._text_view.has_focus():
249 return
250 if 'description' not in jobject:
251 return
252 if self._get_text_from_buffer() == jobject['description']:
253 return
254 buf = self._text_view.get_buffer()
255 buf.set_text(jobject['description'])
256
257 def __description_button_clicked_cb(self, button):
258 self._palette.popup(immediate=True, state=1)
259
260 def __description_changed_cb(self, widget, event, activity):
261 description = self._get_text_from_buffer()
262 if 'description' in activity.metadata and \
263 description == activity.metadata['description']:
264 return
265
266 activity.metadata['description'] = description
267 activity.save()
268 return False
269
270
206271class ActivityToolbar(gtk.Toolbar):
207272 """The Activity toolbar with the Journal entry title, sharing,
208 Keep and Stop buttons
273 and Stop buttons
209274
210275 All activities should have this toolbar. It is easiest to add it to your
211276 Activity by using the ActivityToolbox.
294294 self.insert(separator, -1)
295295 separator.show()
296296
297 if activity.metadata:
298 description_item = DescriptionItem(activity)
299 description_item.show()
300 self.insert(description_item, -1)
301
297302 self.share = ShareButton(activity)
298303 self.share.show()
299304 self.insert(self.share, -1)
300
301 self.keep = KeepButton(activity)
302 self.insert(self.keep, -1)
303 self.keep.show()
304305
305306 self.stop = StopButton(activity)
306307 self.insert(self.stop, -1)