def _download(self, widget, row, col): global match_dict model = widget.get_model() name = str(model[row][1]).replace("<b>", "").replace("</b>", "") _logger.debug(_("Started download of activity: %s") % name) self._alert = NotifyAlert() self._alert.props.msg = _("The activity %s begins to download") % name self._alert.props.title = _("Download begins") self._activity.add_alert(self._alert) self._alert.connect('response', lambda x, i: self._activity.remove_alert(x)) # add to download self.download_list.add_download(name) self.download_list.di[self.download_list.pos] = name activity_id = -1 for n in match_dict: if match_dict[n] == name: activity_id = n break row = self.download_list.pos def launch(): utils.download_activity(int(activity_id), row, self.download_list.set_download_progress) if not (activity_id) == -1: t = threading.Timer(0, launch) t.start() self.download_list.pos = self.download_list.pos + 1 return True
def _alert(self, title, text=None, timeout=5): alert = NotifyAlert(timeout=timeout) alert.props.title = title alert.props.msg = text self.add_alert(alert) alert.connect('response', self._alert_cancel_cb) alert.show()
def alert(self, title=None, text=None, delay=5): alert = NotifyAlert(delay) alert.props.title = title alert.props.msg = text self.add_alert(alert) alert.connect('response', self._alert_ok) alert.show()
def _alert(self, title, text=None): from sugar.graphics.alert import NotifyAlert alert = NotifyAlert(timeout=5) alert.props.title = title alert.props.msg = text self.add_alert(alert) alert.connect('response', self._alert_cancel_cb) alert.show()
def __init__(self, parent, title, content, icon, timeout): SugarNotify.__init__(self, timeout) self._parent = parent self.props.title = title self.props.msg = content if icon is not None: icon = Icon(icon_name=icon) icon.show() self.props.icon = icon icon.props.pixel_size = style.SMALL_ICON_SIZE * 2 self.connect('response', self.remove_myself)
def alert(self, title, text=None): '''Show an alert above the activity.''' try: alert = NotifyAlert(timeout=10) except NameError: logging.warning('sugar.graphics.alert.NotifyAlert not present for %r, %r', title, text) return alert.props.title = title alert.props.msg = text self.add_alert(alert) alert.connect('response', self.__alert_cancel_cb) alert.show()
def export_to_kmz(self, player): """ Exports the given player to a KMZ file. @param player: the player to export. """ from datetime import datetime kmz_path = os.path.join(os.path.abspath('../../../'), '%s_%s.kmz' % (datetime.now().isoformat(), player.nickname)) kmz_path = kmz_path.replace(':', '_') export_path = self.export_to_kml(player) self._logger.debug(export_path) utils.create_zip(export_path, '', kmz_path) alert = NotifyAlert() alert.props.title = _('Export') alert.props.msg = _('KMZ export written to %s.' % kmz_path) self.view.activity.add_alert(alert) alert.connect('response', self.dismiss_alert_cb)
def save_image(self, widget): """ Save the curren phase to image and show alert """ w, h = self.get_size() pixbuf = gtk.gdk.Pixbuf(gtk.gdk.COLORSPACE_RGB, False, 8, int(w / 1.70), h - 55) shot = pixbuf.get_from_drawable(self.window, self.get_colormap(), w - int(w / 1.70), 55, 0, 0, int(w / 1.70), h - 55) path = os.path.join(activity.get_activity_root(), "instance", "shot.png") shot.save(path, "png") journal_entry = datastore.create() journal_entry.metadata['title'] = "%s %s" % \ (self.metadata['title'], _("Image")) journal_entry.metadata['icon-color'] = profile.get_color().to_string() journal_entry.metadata['mime_type'] = "image/png" journal_entry.set_file_path(path) datastore.write(journal_entry) journal_entry.destroy() # Alert HAS_ALERT = False try: from sugar.graphics.alert import NotifyAlert HAS_ALERT = True except: pass if HAS_ALERT: alert = NotifyAlert(5) alert.props.title =_('Image saved') alert.props.msg = _('An image of the current phase of the moon has been saved to the Journal') alert.connect('response', lambda x, y: self.remove_alert(x)) self.add_alert(alert)
def alert(self, title, text=None): """ Alert popup """ alert = NotifyAlert(timeout=10) alert.props.title = title alert.props.msg = text self._activity.add_alert(alert) alert.connect('response', self.alert_cancel_cb) alert.show()
def export_to_csv(self, button): """ Export all participating players into a csv file. """ import csv from datetime import datetime csv_path = os.path.join(os.path.abspath('../../../'), '%s_geo-export.csv' % (datetime.now().isoformat())) csv_path = csv_path.replace(':', '_') _LOG.debug('cvs_path: %s' % csv_path) csv_file = open(csv_path, "w") csv_writer = csv.writer(csv_file) header = ['Nickname', 'Trace', 'Fillcolor', 'Strokecolor', 'FeatureCollection'] csv_writer.writerow(header) for key in self.players.keys(): player = self.players[key] nick = player.nickname trace = list() for key in player.trace.keys(): trace.append((key, player.trace[key])) trace = str(trace.sort()) fill = player.color_fill stroke = player.color_stroke features = str(player.features) csv_writer.writerow((nick, trace, fill, stroke, features)) csv_file.flush() csv_file.close() alert = NotifyAlert() alert.props.title = _('Export') alert.props.msg = _('CSV export written to %s.' % csv_path) self.activity.add_alert(alert) alert.connect('response', self.dismiss_alert_cb)
def notify_alert(self, title, msg): """Raise standard notify alert""" alert = NotifyAlert(title=title, msg=msg) def response(alert, response_id, self): self.remove_alert(alert) alert.connect('response', response, self) alert.show_all() self.add_alert(alert)
def alert(self, title, text=None): '''Show an alert above the activity.''' try: alert = NotifyAlert(timeout=10) except NameError: logging.warning( 'sugar.graphics.alert.NotifyAlert not present for %r, %r', title, text) return alert.props.title = title alert.props.msg = text self.add_alert(alert) alert.connect('response', self.__alert_cancel_cb) alert.show()
def _load_button_cb(self, widget): chooser = ObjectChooser(parent=self) result = chooser.run() if result == gtk.RESPONSE_ACCEPT: try: jobject = chooser.get_selected_object() _file_path = str(jobject.get_file_path()) self.read_file(_file_path) alerta = NotifyAlert(10) alerta.props.title = _('Good!') alerta.props.msg = _('Book loaded') alerta.connect('response', lambda w, i: self.remove_alert(w)) self.add_alert(alerta) except IOError: alerta = NotifyAlert(10) alerta.props.title = 'Error' alerta.props.msg = _('Error in load book') alerta.connect('response', lambda w, i: self.remove_alert(w)) self.add_alert(alerta) else: return
class List(gtk.TreeView): def __init__(self, parent): gtk.TreeView.__init__(self) self._model = gtk.ListStore(str, str, str, str) self.set_model(self._model) self._activity = parent self.set_rules_hint(True) self.icon = CellRendererIcon(self) self.icon._buffer.width = style.zoom(100) self.icon._buffer.height = style.zoom(100) self.icon._xo_color = color self._name = gtk.CellRendererText() self.description = gtk.CellRendererText() self.status = gtk.CellRendererText() self.description.props.wrap_mode = True self.icon_column = gtk.TreeViewColumn(_("Icon")) self._name_column = gtk.TreeViewColumn(_("Activity")) self.description_column = gtk.TreeViewColumn(_("Description")) self.status_column = gtk.TreeViewColumn(_("Status")) self.icon_column.pack_start(self.icon, False) self._name_column.pack_start(self._name, True) self.description_column.pack_start(self.description, True) self.status_column.pack_start(self.status, False) self.icon_column.add_attribute(self.icon, 'icon_name', 0) self._name_column.add_attribute(self._name, "markup", 1) self.description_column.add_attribute(self.description, "markup", 2) self.status_column.add_attribute(self.status, "text", 3) self.current = 0 self.append_column(self.icon_column) self.append_column(self._name_column) self.append_column(self.description_column) self.append_column(self.status_column) self.download_list = DownloadList() self.connect("row-activated", self._download) self._parent = parent self.thread = None self.words = '' self._list = utils.get_store_list() self.can_search = True self.stopped = False self.show_all() def up(self): self.current += 1 def down(self): self.current -= 1 def _download(self, widget, row, col): global match_dict model = widget.get_model() name = str(model[row][1]).replace("<b>", "").replace("</b>", "") _logger.debug(_("Started download of activity: %s") % name) self._alert = NotifyAlert() self._alert.props.msg = _("The activity %s begins to download") % name self._alert.props.title = _("Download begins") self._activity.add_alert(self._alert) self._alert.connect('response', lambda x, i: self._activity.remove_alert(x)) # add to download self.download_list.add_download(name) self.download_list.di[self.download_list.pos] = name activity_id = -1 for n in match_dict: if match_dict[n] == name: activity_id = n break row = self.download_list.pos def launch(): utils.download_activity(int(activity_id), row, self.download_list.set_download_progress) if not (activity_id) == -1: t = threading.Timer(0, launch) t.start() self.download_list.pos = self.download_list.pos + 1 return True def stop_search(self, *args): self.stopped = True def _add_activity(self, info): iter = self._model.insert(self.current, info) ITERS.append(iter) self.up() def clear(self): for child in self.get_children(): self.remove(child) child = None def search(self, entry): if self.can_search: self.can_search = False self.w = entry.get_text().lower() self.clear() self.thread = threading.Thread(target=self._search) self.thread.start() else: self.stop_search() gobject.idle_add(self.search, entry) def _search(self): global match_dict match_dict = {} w = str(self.w) w = w.strip() _id = -1 for iter in ITERS: self._model.remove(iter) for activity in self._list: if self.stopped: break _id += 1 name = activity[1].lower() description = activity[2].lower() if (w in name) or (w in description): activity_widget = _gen_activity(_id, self) self._add_activity(activity_widget) self.can_search = True