def remove_page_from_widget(self, widget, scrolled, force=False): view = scrolled.get_children()[0] buffer = view.get_buffer() idx = self.notebook.get_children().index(scrolled) if not buffer.get_modified() or force: self.notebook.remove_page(idx) else: name = view.get_file_name() title = G.TEXT_SAVE_FILE.replace("****", name) msg = G.TEXT_IF_NOT_SAVE cancel = Gtk.Image.new_from_icon_name("dialog-cancel", Gtk.IconSize.MENU) no = Gtk.Image.new_from_icon_name("activity-stop", Gtk.IconSize.MENU) save = Gtk.Image.new_from_icon_name("filesave", Gtk.IconSize.MENU) self.alert = Alert() self.alert.props.title = title self.alert.props.msg = msg self.alert.add_button(Gtk.ResponseType.CANCEL, _("Cancel"), icon=cancel) self.alert.add_button(Gtk.ResponseType.NO, _("No save"), icon=no) self.alert.add_button(Gtk.ResponseType.YES, _("Save"), icon=save) self.alert.connect("response", self._alert_response, scrolled) self.vbox.pack_start(self.alert, False, False, 0) self.vbox.reorder_child(self.alert, 0) self.vbox.show_all()
def can_close(self): if self._force_close: return True elif downloadmanager.can_quit(): return True else: alert = Alert() alert.props.title = ngettext('Download in progress', 'Downloads in progress', downloadmanager.num_downloads()) message = ngettext('Stopping now will erase your download', 'Stopping now will erase your downloads', downloadmanager.num_downloads()) alert.props.msg = message cancel_icon = Icon(icon_name='dialog-cancel') cancel_label = ngettext('Continue download', 'Continue downloads', downloadmanager.num_downloads()) alert.add_button(Gtk.ResponseType.CANCEL, cancel_label, cancel_icon) stop_icon = Icon(icon_name='dialog-ok') alert.add_button(Gtk.ResponseType.OK, _('Stop'), stop_icon) stop_icon.show() self.add_alert(alert) alert.connect('response', self.__inprogress_response_cb) alert.show() self.present() return False
def __register_activate_cb(self, icon): alert = Alert() try: schoolserver.register_laptop() except RegisterError, e: alert.props.title = _('Registration Failed') alert.props.msg = '%s' % e
def __create_empty_file_cb(self, button): alert = Alert() alert.props.title = _('Create new file') alert.props.msg = _('Select the name of the file') # HACK alert._hbox.remove(alert._buttons_box) alert.entry = Gtk.Entry() alert._hbox.pack_start(alert.entry, True, True, 0) alert._buttons_box = Gtk.HButtonBox() alert._buttons_box.set_layout(Gtk.ButtonBoxStyle.END) alert._buttons_box.set_spacing(style.DEFAULT_SPACING) alert._hbox.pack_start(alert._buttons_box, True, True, 0) icon = Icon(icon_name='dialog-cancel') alert.add_button(Gtk.ResponseType.CANCEL, _('Cancel'), icon) icon = Icon(icon_name='dialog-ok') alert.add_button(Gtk.ResponseType.OK, _('Ok'), icon) alert.show_all() # self.add_alert(alert) alert.connect('response', self.__create_file_alert_cb)
def _show_journal_alert(self, title, msg): _stop_alert = Alert() _stop_alert.props.title = title _stop_alert.props.msg = msg if _HAS_BUNDLE_LAUNCHER: bundle = get_bundle(object_id=self._object_id) if bundle is not None: icon = Icon(file=bundle.get_icon()) label = _('Open with %s') % bundle.get_name() _stop_alert.add_button(Gtk.ResponseType.ACCEPT, label, icon) else: icon = Icon(icon_name='zoom-activity') label = _('Show in Journal') _stop_alert.add_button(Gtk.ResponseType.APPLY, label, icon) icon.show() ok_icon = Icon(icon_name='dialog-ok') _stop_alert.add_button(Gtk.ResponseType.OK, _('Ok'), ok_icon) ok_icon.show() # Remove other alerts for alert in self._alerts: self.remove_alert(alert) self.add_alert(_stop_alert) _stop_alert.connect('response', self.__stop_response_cb) _stop_alert.show()
def _object_chooser(self, mime_type, type_name): chooser = ObjectChooser() matches_mime_type = False response = chooser.run() if response == Gtk.ResponseType.ACCEPT: jobject = chooser.get_selected_object() metadata = jobject.metadata file_path = jobject.file_path if metadata['mime_type'] == mime_type: matches_mime_type = True else: alert = Alert() alert.props.title = _('Invalid object') alert.props.msg = \ _('The selected object must be a %s file' % (type_name)) ok_icon = Icon(icon_name='dialog-ok') alert.add_button(Gtk.ResponseType.OK, _('Ok'), ok_icon) ok_icon.show() alert.connect('response', lambda a, r: self.remove_alert(a)) self.add_alert(alert) alert.show() return matches_mime_type, file_path, metadata['title']
def __create_new_folder(self, entry): if entry.get_text(): try: path = os.path.join(self.folder, entry.get_text()) os.mkdir(path) self.folder = path except OSError as msg: if self.alert: self.vbox.remove(self.alert) self.alert = None self.alert = Alert() self.alert.props.title = G.TEXT_ERROR_CREATING_FOLDER self.alert.props.msg = msg image = Gtk.Image.new_from_stock( Gtk.STOCK_OK, Gtk.IconSize.MENU) self.alert.add_button(Gtk.ResponseType.NO, _("Ok"), icon=image) self.alert.connect("response", self.__alert_response) self.vbox.pack_start(self.alert, False, False, 0) self.vbox.reorder_child(self.alert, 1) item = entry.get_parent() self.toolbar.remove(item) self.button_new_folder.set_sensitive(True)
def __notify_response_cb(self, download, pspec): logging.debug('__notify_response_cb') response = download.get_response() # Check free space and cancel the download if there is not enough. total_size = response.get_content_length() logging.debug('Total size of the file: %s', total_size) enough_space = self.enough_space(total_size, path=self.temp_path) if not enough_space: logging.debug('Download canceled because of Disk Space') self.cancel() self._canceled_alert = Alert() self._canceled_alert.props.title = _('Not enough space ' 'to download') total_size_mb = total_size / 1024.0**2 free_space_mb = (self._free_available_space( path=self.temp_path) - SPACE_THRESHOLD) \ / 1024.0 ** 2 filename = response.get_suggested_filename() self._canceled_alert.props.msg = \ _('Download "%{filename}" requires %{total_size_in_mb}' ' MB of free space, only %{free_space_in_mb} MB' ' is available' % {'filename': filename, 'total_size_in_mb': format_float(total_size_mb), 'free_space_in_mb': format_float(free_space_mb)}) ok_icon = Icon(icon_name='dialog-ok') self._canceled_alert.add_button(Gtk.ResponseType.OK, _('Ok'), ok_icon) ok_icon.show() self._canceled_alert.connect('response', self.__canceled_response_cb) self._activity.add_alert(self._canceled_alert)
def __accept_clicked_cb(self, widget): if hasattr(self._section_view, "apply"): self._section_view.apply() if self._section_view.needs_restart: self._section_toolbar.accept_button.set_sensitive(False) self._section_toolbar.cancel_button.set_sensitive(False) alert = Alert() alert.props.title = _('Warning') alert.props.msg = _('Changes require restart') if self._section_view.props.is_cancellable: icon = Icon(icon_name='dialog-cancel') alert.add_button(Gtk.ResponseType.CANCEL, _('Cancel changes'), icon) icon.show() if self._current_option not in ('aboutme', 'backup'): icon = Icon(icon_name='dialog-ok') alert.add_button(Gtk.ResponseType.ACCEPT, _('Later'), icon) icon.show() icon = Icon(icon_name='system-restart') alert.add_button(Gtk.ResponseType.APPLY, _('Restart now'), icon) icon.show() self._vbox.pack_start(alert, False, False, 0) self._vbox.reorder_child(alert, 2) alert.connect('response', self.__response_cb) alert.show() else: self._show_main_view()
def _value_changed(self, cell, path, new_text, model, activity): _logger.debug("Change '%s' to '%s'" % (model[path][1], new_text)) is_number = True number = new_text.replace(",", ".") try: float(number) except ValueError: is_number = False if is_number: decimals = utils.get_decimals(str(float(number))) new_text = locale.format('%.' + decimals + 'f', float(number)) model[path][1] = str(new_text) self.emit("value-changed", str(path), number) elif not is_number: alert = Alert() alert.props.title = _('Invalid Value') alert.props.msg = \ _('The value must be a number (integer or decimal)') ok_icon = Icon(icon_name='dialog-ok') alert.add_button(Gtk.ResponseType.OK, _('Ok'), ok_icon) ok_icon.show() alert.connect('response', lambda a, r: activity.remove_alert(a)) activity.add_alert(alert) alert.show()
def _notify_successful_save(self, title='', msg=''): ''' Notify user when saves are completed ''' self._alert = Alert() self._alert.props.title = title self._alert.props.msg = msg self.add_alert(self._alert) self._alert.show()
def _incompatible(self): ''' Display abbreviated activity user interface with alert ''' toolbox = ToolbarBox() stop = StopButton(self) toolbox.toolbar.add(stop) self.set_toolbar_box(toolbox) title = _('Activity not compatible with this system.') msg = _('Please downgrade activity and try again.') alert = Alert(title=title, msg=msg) alert.add_button(0, 'Stop', Icon(icon_name='activity-stop')) self.add_alert(alert) label = Gtk.Label( _('Uh oh, WebKit2 is too old. ' 'Browse-200 and later require WebKit2 API 4.0, ' 'sorry!')) self.set_canvas(label) ''' Workaround: start Terminal activity, then type sugar-erase-bundle org.laptop.WebActivity then in My Settings, choose Software Update, which will offer older Browse. ''' alert.connect('response', self.__incompatible_response_cb) stop.connect('clicked', self.__incompatible_stop_clicked_cb, alert) self.show_all()
def _check_current_cell_text(self): """Check the user-entered text for the current cell. If it matches the expected value, also check to see if the user's filled in all blank cells and hence has won. """ # Check whether the answer is correct. If so, change the cell to be # uneditable. expected_num = self._calculate_pascal_number(self._current_cell) if int(self._current_cell_text) == expected_num: self._blank_cells.remove(self._current_cell) self._update_current_cell((-1, -1)) # Check whether all blank cells have been filled. if len(self._blank_cells) == 0: alert = Alert() alert.props.title = _('You\'ve won!') alert.props.msg = _('Well done! You\'ve completed the Pascal ' 'Triangle. Do you want to play again?') icon = Icon(icon_name='emblem-favorite') alert.props.icon = icon icon.show() icon = Icon(icon_name='add') alert.add_button(Gtk.ResponseType.ACCEPT, _('New Game'), icon) icon.show() alert.connect('response', self.__alert_response_cb) alert.show() self._alert = alert self.add_alert(alert)
def __register(self): self._box.remove_alert() alert = Alert() try: schoolserver.register_laptop() except RegisterError, e: alert.props.title = _('Registration Failed') alert.props.msg = '%s' % e
def _show_alert(self, message, title=None): alert = Alert() if title is None: title = _('Atention') alert.props.title = title alert.props.msg = message alert.add_button(Gtk.ResponseType.OK, _('Ok')) self.add_alert(alert) alert.connect('response', self._alert_response_cb)
def _alert(self, title, text=None): try: self.remove_alert(self.alert) finally: self.alert = Alert() self.alert.props.title = title self.alert.props.msg = text self.add_alert(self.alert) self.alert.connect('response', self._alert_cancel_cb) self.alert.show()
def __crashed_cb(self, browser): self.get_window().set_cursor(Gdk.Cursor(Gdk.CursorType.LEFT_PTR)) uri = browser.cached_uri logging.error('WebKit2 WebView at uri %r has crashed', uri) self.close_tab(browser.get_parent()) alert = Alert(title=_('This tab has crashed Browse: %s') % uri, msg=_('If you reopen the tab, it may just crash again')) alert.add_button(Gtk.ResponseType.OK, _('Reopen')) alert.add_button(Gtk.ResponseType.CANCEL, _('Disregard')) alert.connect('response', self.__crashed_alert_cb, uri) self._activity.add_alert(alert)
def _shared_cb(self, activity): self._logger.debug('My activity was shared') self.alert = Alert() self.alert.props.title = 'Shared Activity' self.alert.props.msg = 'Shared messages to be displayed here' self.add_alert(self.alert) self.initiating = True self._sharing_setup() self._logger.debug('This is my activity: making a tube...') id = self.tubes_chan[telepathy.CHANNEL_TYPE_TUBES].OfferDBusTube( SERVICE, {})
def _new_game_alert(self): alert = Alert() alert.props.title = _('New game') alert.props.msg = _('Do you want to play a new game?') icon = Icon(icon_name='dialog-cancel') alert.add_button(Gtk.ResponseType.CANCEL, _('Cancel'), icon) icon.show() ok_icon = Icon(icon_name='dialog-ok') alert.add_button(Gtk.ResponseType.OK, _('New game'), ok_icon) ok_icon.show() alert.connect('response', self.__game_alert_response_cb) self._parent.add_alert(alert) alert.show()
def __save_ebook_clicked_cb(self, button): alert = Alert() alert.props.title = _('Book creation') alert.props.msg = _('Do you want to add an image for the cover?') icon = Icon(icon_name='dialog-ok') alert.add_button(Gtk.ResponseType.YES, _('Yes'), icon) icon.show() icon = Icon(icon_name='dialog-cancel') alert.add_button(Gtk.ResponseType.NO, _('No'), icon) icon.show() alert.connect('response', self.__add_cover_response_cb, self._set_cover_and_create_book) self.add_alert(alert)
def _invalid_number_alert(activity): alert = Alert() alert.props.title = _('Invalid Value') alert.props.msg = _('The value must be a number (integer or decimal)') ok_icon = Icon(icon_name='dialog-ok') alert.add_button(Gtk.ResponseType.OK, _('Ok'), ok_icon) ok_icon.show() alert.connect('response', lambda a, r: activity.remove_alert(a)) activity.add_alert(alert) alert.show()
def _show_alert(self, title, msg): _stop_alert = Alert() _stop_alert.props.title = title _stop_alert.props.msg = msg _stop_alert.add_button(Gtk.ResponseType.OK, _('Ok'), Icon(icon_name='dialog-ok')) # Remove other alerts for alert in self._alerts: self.remove_alert(alert) self.add_alert(_stop_alert) _stop_alert.connect('response', self.__stop_response_cb) _stop_alert.show_all()
def _clear_game_bt(self, button): if self.activity.game.model.is_demo or \ len(self.activity.cardlist.pairs) == 0: self.clear_game() else: alert = Alert() alert.props.title = _('Clear all the tiles from the game?') icon = Icon(icon_name='dialog-ok') alert.add_button(1, _('Clear'), icon) icon = Icon(icon_name='dialog-cancel') alert.add_button(0, _('Do not clear'), icon) alert.connect('response', self._clear_game_alert_cb) self.activity.add_alert(alert)
def __activate_art4apps_game_cb(self, menu, category, language): self._art4apps_data = (category, language) if self.activity.game.model.is_demo: self._change_art4apps_game(category, language) else: alert = Alert() alert.props.title = _('Discard your modified game?') icon = Icon(icon_name='dialog-ok') alert.add_button(1, _('Discard'), icon) icon = Icon(icon_name='dialog-cancel') alert.add_button(0, _('Do not discard'), icon) alert.connect('response', self._change_art4apps_game_alert_cb) self.activity.add_alert(alert)
def __activate_game_cb(self, menu, i): self._game_selected_index = i if self.activity.game.model.is_demo: self._change_game() else: alert = Alert() alert.props.title = _('Discard your modified game?') icon = Icon(icon_name='dialog-ok') alert.add_button(1, _('Discard'), icon) icon = Icon(icon_name='dialog-cancel') alert.add_button(0, _('Do not discard'), icon) alert.connect('response', self._change_game_alert_cb) self.activity.add_alert(alert)
def __state_change_cb(self, download, gparamspec): state = self._download.get_status() if state == WebKit.DownloadStatus.STARTED: self._create_journal_object() self._object_id = self.dl_jobject.object_id alert = TimeoutAlert(9) alert.props.title = _('Download started') alert.props.msg = _('%s' % self._download.get_suggested_filename()) self._activity.add_alert(alert) alert.connect('response', self.__start_response_cb) alert.show() global _active_downloads _active_downloads.append(self) elif state == WebKit.DownloadStatus.FINISHED: self._stop_alert = Alert() self._stop_alert.props.title = _('Download completed') self._stop_alert.props.msg = \ _('%s' % self._download.get_suggested_filename()) open_icon = Icon(icon_name='zoom-activity') self._stop_alert.add_button(Gtk.ResponseType.APPLY, _('Show in Journal'), open_icon) open_icon.show() ok_icon = Icon(icon_name='dialog-ok') self._stop_alert.add_button(Gtk.ResponseType.OK, _('Ok'), ok_icon) ok_icon.show() self._activity.add_alert(self._stop_alert) self._stop_alert.connect('response', self.__stop_response_cb) self._stop_alert.show() self.dl_jobject.metadata['title'] = \ self._download.get_suggested_filename() self.dl_jobject.metadata['description'] = _('From: %s') \ % self._source self.dl_jobject.metadata['progress'] = '100' self.dl_jobject.file_path = self._dest_path # sniff for a mime type, no way to get headers from WebKit sniffed_mime_type = mime.get_for_file(self._dest_path) self.dl_jobject.metadata['mime_type'] = sniffed_mime_type datastore.write(self.dl_jobject, transfer_ownership=True, reply_handler=self.__internal_save_cb, error_handler=self.__internal_error_cb, timeout=360) elif state == WebKit.DownloadStatus.CANCELLED: self.cleanup()
def __duplicate_alert_response_cb(self, alert, response_id): self.get_toplevel().remove_alert(alert) if response_id == Gtk.ResponseType.OK: self.__set_busy_cursor(True) def internal_callback(new_alert): self.__copy_to_home_cb(None, new_alert) new_alert = Alert() new_alert.props.title = _("Duplicating activity...") self.get_toplevel().add_alert(new_alert) GObject.idle_add(internal_callback, new_alert)
def _show_missing_tracks_alert(self, tracks): self._alert = Alert() title = _('%s tracks not found.') % len(tracks) self._alert.props.title = title icon = Icon(icon_name='dialog-cancel') self._alert.add_button(Gtk.ResponseType.CANCEL, _('Dismiss'), icon) icon.show() icon = Icon(icon_name='dialog-ok') self._alert.add_button(Gtk.ResponseType.APPLY, _('Details'), icon) icon.show() self.add_alert(self._alert) self._alert.connect('response', self.__missing_tracks_alert_response_cb, tracks)
def _search_clicked_cb(self, widget): title = self.searchentry.get_text() wiki = self.wikimenu.combo.props.value if not title: return if book.wiki.find('%s (from %s)' % (title, wiki))[0]: alert = Alert() alert.props.title = _('Exists') alert.props.msg = _('"%s" article already exists' % title) alert.show() else: Timer(0, self._download, [title, wiki]).start()
def create_alert(self, path): alert = Alert() alert.props.title = _('This file is already exists.') alert.props.msg = _('%s already exists, Overwrite it?' % path) cancel = Gtk.Image.new_from_icon_name('dialog-cancel', Gtk.IconSize.MENU) save = Gtk.Image.new_from_icon_name('filesave', Gtk.IconSize.MENU) alert.add_button(Gtk.ResponseType.NO, _('Cancel'), icon=cancel) alert.add_button(Gtk.ResponseType.YES, _('Save'), icon=save) alert.connect('response', self.__alert_response, path) self.vbox.pack_start(alert, False, False, 0) self.vbox.reorder_child(alert, 1)