def action(alert, response): self.remove_alert(alert) if response is not Gtk.ResponseType.OK: return try: f = open(file_path, 'r') # Test if the file is valid project. json.loads(f.read()) f.close() self.read_file(file_path) except: title = _('Load project from journal') if not journal: title = _('Load example') msg = _('Error: Cannot open Physics project from this file.') alert = NotifyAlert(5) alert.props.title = title alert.props.msg = msg alert.connect('response', lambda alert, response: self.remove_alert(alert)) self.add_alert(alert)
def _save_ogg_eos_cb(self, bus, message, pipe): bus.remove_signal_watch() pipe.set_state(Gst.State.NULL) title = '%s saved as audio' % self.metadata['title'] jobject = datastore.create() jobject.metadata['title'] = title jobject.metadata['keep'] = '0' jobject.metadata['mime_type'] = 'audio/ogg' jobject.file_path = self._ogg_tempfile.name datastore.write(jobject) self._wav_tempfile.close() self._ogg_tempfile.close() alert = NotifyAlert(10) alert.props.title = _('Audio recorded') alert.props.msg = _('The audio file was saved in the Journal') alert.connect('response', self.__alert_response_cb) self.add_alert(alert) return False
def _on_send_button_clicked_cb(self, button): identifier = str(int(time.time())) filename = '%s.zip' % identifier filepath = os.path.join(activity.get_activity_root(), filename) success = True try: self._collector.write_logs(archive=filepath, logbytes=0) except: success = False self.popdown(True) if not success: title = _('Logs not captured') msg = _('The logs could not be captured.') notify = NotifyAlert() notify.props.title = title notify.props.msg = msg notify.connect('response', _notify_response_cb, self._activity) self._activity.add_alert(notify) jobject = datastore.create() metadata = { 'title': _('log-%s') % filename, 'title_set_by_user': '******', 'suggested_filename': filename, 'mime_type': 'application/zip', } for k, v in metadata.items(): jobject.metadata[k] = v jobject.file_path = filepath datastore.write(jobject) self._last_log = jobject.object_id jobject.destroy() activity.show_object_in_journal(self._last_log) os.remove(filepath)
def _create_custom_food_cb(self, button): def _notification_alert_response_cb(alert, response_id, self): self.remove_alert(alert) name = self.name_entry.get_text() try: calories = int(self.calories_entry.get_text()) except: _logger.debug(self.calories_entry.get_text) calories = None pyramid = self.food_spinner.get_active() if name == '' or name == _('food name'): alert = NotifyAlert() alert.props.title = _('Add a new food item.') alert.connect('response', _notification_alert_response_cb, self) alert.props.msg = _('You must enter a name for the new food item.') self.add_alert(alert) alert.show() return elif calories is None or calories < 0: alert = NotifyAlert() alert.props.title = _('Add a new food item.') alert.connect('response', _notification_alert_response_cb, self) alert.props.msg = _('You must enter calories for the new food \ item.') self.add_alert(alert) alert.show() return elif self._custom_food_jobject is None: alert = NotifyAlert() alert.props.title = _('Add a new food item.') alert.connect('response', _notification_alert_response_cb, self) alert.props.msg = _('You must load an image for the new food \ item.') self.add_alert(alert) alert.show() return _logger.debug(self._custom_food_jobject.file_path) FOOD.append([name, calories, pyramid, 'apple.png']) self._game.word_card_append(self._game.food_cards, self._game.pixbuf) self._game.food_cards[-1].type = len(FOOD) - 1 self._game.food_cards[-1].set_label(name) self._game.picture_append(self._custom_food_jobject.file_path) self._game.small_picture_append(self._custom_food_jobject.file_path) alert = NotifyAlert() alert.props.title = _('Add a new food item.') alert.connect('response', _notification_alert_response_cb, self) alert.props.msg = _('%s has been loaded.') % (name) self.add_alert(alert) alert.show() self.name_entry.set_text(_('food name')) self.calories_entry.set_text(_('calories')) self._custom_food_image_path = None self._game.build_food_groups() self._game.new_game() self.metadata['name-%d' % (self._custom_food_counter)] = name self.metadata['calories-%d' % (self._custom_food_counter)] = \ str(calories) self.metadata['pyramid-%d' % (self._custom_food_counter)] = str(pyramid) self.metadata['jobject-%d' % (self._custom_food_counter)] = \ self._custom_food_jobject.object_id self._custom_food_counter += 1 _logger.debug('writing %d to counter' % (self._custom_food_counter)) self.metadata['counter'] = str(self._custom_food_counter) return