def confirm_new_path(self, path): """User wants to save to this path. If it's different to the original path, check that it doesn't exist and ask for confirmation if it does. If document.save_last_stat is set, compare with os.stat for an existing file and warn about changes. Returns true to go ahead with the save.""" if not os.path.exists(path): return True if os.path.isdir(path): rox.alert(_("'%s' already exists as a directory.") % path) return False if path == self.initial_uri: if self.document.save_last_stat is None: return True # OK. Nothing to compare with. last = self.document.save_last_stat stat = os.stat(path) msg = [] if stat.st_mode != last.st_mode: msg.append(_("Permissions changed from %o to %o.") % \ (last.st_mode, stat.st_mode)) if stat.st_size != last.st_size: msg.append(_("Size was %d bytes; now %d bytes.") % \ (last.st_size, stat.st_size)) if stat.st_mtime != last.st_mtime: msg.append(_("Modification time changed.")) if not msg: return True # No change detected return rox.confirm("File '%s' edited by another program since last load/save. " "Really save (discarding other changes)?\n\n%s" % (path, '\n'.join(msg)), g.STOCK_DELETE) return rox.confirm(_("File '%s' already exists -- overwrite it?") % path, g.STOCK_DELETE, _('_Overwrite'))
def confirm_new_path(self, path): """User wants to save to this path. If it's different to the original path, check that it doesn't exist and ask for confirmation if it does. If document.save_last_stat is set, compare with os.stat for an existing file and warn about changes. Returns true to go ahead with the save.""" if not os.path.exists(path): return True if os.path.isdir(path): rox.alert(_("'%s' already exists as a directory.") % path) return False if path == self.initial_uri: if self.document.save_last_stat is None: return True # OK. Nothing to compare with. last = self.document.save_last_stat stat = os.stat(path) msg = [] if stat.st_mode != last.st_mode: msg.append(_("Permissions changed from %o to %o.") % \ (last.st_mode, stat.st_mode)) if stat.st_size != last.st_size: msg.append(_("Size was %d bytes; now %d bytes.") % \ (last.st_size, stat.st_size)) if stat.st_mtime != last.st_mtime: msg.append(_("Modification time changed.")) if not msg: return True # No change detected return rox.confirm( "File '%s' edited by another program since last load/save. " "Really save (discarding other changes)?\n\n%s" % (path, '\n'.join(msg)), g.STOCK_DELETE) return rox.confirm( _("File '%s' already exists -- overwrite it?") % path, g.STOCK_DELETE, _('_Overwrite'))
def create_session_script(path): """Create login script at 'path' and make it executable.""" if os.path.exists(path): if not rox.confirm("File '%s' already exists; overwrite?" % path): raise SystemExit() file(path, 'w').write(get_session_script()) os.chmod(path, 0755)
def get_generator(debug=None): """Return the current generator of thumbnails""" copy = dict(thumbnailers) thumbC = copy.pop(options.generator.value) if not thumbC.check_executable(): origbin = thumbC._binary for (name, cls) in copy.iteritems(): if cls.check_executable(): thumbC = cls msg = _( """VideoThumbnail could not find the program "%s", but another thumbnail generator is available. Should "%s" be used from now on?""" ) if rox.confirm(msg % (origbin, thumbC._binary), rox.g.STOCK_YES): options.generator.value = name rox.app_options.save() pass break else: msg = _( """VideoThumbnail could not find any usable thumbnail generator. You need to install either MPlayer (http://www.mplayerhq.hu) or Totem (http://www.gnome.org/projects/totem/).""" ) rox.croak(msg) if debug is None: debug = options.report.int_value # print debug return thumbC(debug)
def get_generator(debug=None): """Return the current generator of thumbnails""" copy=dict(thumbnailers) thumbC = copy.pop(options.generator.value) if not thumbC.check_executable(): origbin = thumbC._binary for (name, cls) in copy.iteritems(): if cls.check_executable(): thumbC = cls msg = _("""VideoThumbnail could not find the program "%s", but another thumbnail generator is available. Should "%s" be used from now on?""") if rox.confirm(msg % (origbin, thumbC._binary), rox.g.STOCK_YES): options.generator.value = name rox.app_options.save() pass break else: msg = _("""VideoThumbnail could not find any usable thumbnail generator. You need to install either MPlayer (http://www.mplayerhq.hu) or Totem (http://www.gnome.org/projects/totem/).""") rox.croak(msg) if debug is None: debug=options.report.int_value #print debug return thumbC(debug)
def edit_timer(timer): global edit_timer_box if edit_timer_box: edit_timer_box.destroy() if timer.end_time: if confirm(_('The timer is already set - clear it?'), g.STOCK_CLEAR): timer.clear_timer() return edit_timer_box = Dialog(title=_('Memo Timer'), parent=timer.get_toplevel(), flags=g.DIALOG_NO_SEPARATOR) def destroyed(box): global edit_timer_box assert edit_timer_box is box edit_timer_box = None edit_timer_box.connect('destroy', destroyed) def response(d, resp): if resp == int(g.RESPONSE_OK): timer.set_timer(min.value * 60 + sec.value) d.destroy() edit_timer_box.connect('response', response) vbox = g.VBox(False, 0) vbox.set_border_width(8) edit_timer_box.vbox.pack_start(vbox, True, True, 0) vbox.pack_start(g.Label(_('Set the count-down timer and click OK.')), True, True, 0) hbox = g.HBox(False, 0) vbox.pack_start(hbox, False, True, 8) min = g.Adjustment(0, 0, 999, 1, 1) spin = g.SpinButton(min) spin.set_digits(0) spin.set_activates_default(True) hbox.pack_start(spin, True, True, 0) hbox.pack_start(g.Label(_('min ')), False, True, 2) sec = g.Adjustment(0, 0, 59, 1, 1) spin = g.SpinButton(sec) spin.set_digits(0) spin.set_activates_default(True) hbox.pack_start(spin, True, True, 0) hbox.pack_start(g.Label(_('sec')), False, True, 2) edit_timer_box.add_button(g.STOCK_CANCEL, g.RESPONSE_CANCEL) edit_timer_box.add_button(g.STOCK_OK, g.RESPONSE_OK) edit_timer_box.set_default_response(g.RESPONSE_OK) edit_timer_box.show_all()
def offer_restart(): if wm_pid is None: return # Not yet started if rox.confirm( _("Your default window manager is now '%s'.\n" "Would you like to quit your current window manager and start the new " "one right now?") % get_window_manager()[0], g.STOCK_REFRESH, _('Restart')): global autorestart_wm autorestart_wm = True kill_wm()
def box(self, top, ops): block = top.parent print "Boxed in", block assert ops next = fail = None for op in ops: if op.next and op.next not in ops: if next: rox.alert("New block can't have two next exits!") next = op if op.fail and op.fail not in ops: if fail: rox.alert("New block can't have two fail exits!") fail = op if len(ops) == 1: if not rox.confirm('Put this node in a new block?', 'Create block'): return elif not rox.confirm('Put these %d nodes in a new block?' % len(ops), 'Create block'): return new_exits = (next and next.op.next, fail and fail.op.fail) if next: next.op.unlink('next', may_delete = False) if fail: fail.op.unlink('fail', may_delete = False) new = Block(block) prev = top.prev if prev.next == top: exit = 'next' else: exit = 'fail' prev.unlink(exit, may_delete = 0) prev.link_to(new, exit) top.set_parent(None) top.set_parent(new) new.start.link_to(top, 'next') if new_exits[0]: new.link_to(new_exits[0], 'next') if new_exits[1]: new.link_to(new_exits[1], 'fail')
def troubleshoot(): if not rox.confirm("Did you select 'ROX' from the login screen after " 'entering your username, but before entering your ' 'password?\n\n' "(if you installed to your home directory, you should have " "chosen an option named 'default' or 'last session')", g.STOCK_YES): return rox.croak(_("OK, I don't know what the problem is. Please ask on the " "rox-users mailing list. When we know what the problem is, we " "can add an extra check here to help out others in future." "\n\n" "http://rox.sourceforge.net/phpwiki/index.php/MailingLists\n" "(you can copy and paste that address into your browser)"))
def save_to_file(self, path): """Write data to file. Raise an exception on error. The default creates a temporary file, uses save_to_stream() to write to it, then renames it over the original. If the temporary file can't be created, it writes directly over the original.""" # Ensure the directory exists... parent_dir = os.path.dirname(path) if not os.path.isdir(parent_dir): from rox import fileutils try: fileutils.makedirs(parent_dir) except OSError: raise AbortSave(None) # (message already shown) import random tmp = 'tmp-' + ` random.randrange(1000000) ` tmp = os.path.join(parent_dir, tmp) def open_private(path): return os.fdopen(os.open(path, os.O_CREAT | os.O_WRONLY, 0600), 'wb') try: stream = open_private(tmp) except: # Can't create backup... try a direct write tmp = None stream = open_private(path) try: try: self.save_to_stream(stream) finally: stream.close() if tmp: os.rename(tmp, path) except: _report_save_error() if tmp and os.path.exists(tmp): if os.path.getsize(tmp) == 0 or \ rox.confirm(_("Delete temporary file '%s'?") % tmp, g.STOCK_DELETE): os.unlink(tmp) raise AbortSave(None) self.save_set_permissions(path) filer.examine(path)
def save_to_file(self, path): """Write data to file. Raise an exception on error. The default creates a temporary file, uses save_to_stream() to write to it, then renames it over the original. If the temporary file can't be created, it writes directly over the original.""" # Ensure the directory exists... parent_dir = os.path.dirname(path) if not os.path.isdir(parent_dir): from rox import fileutils try: fileutils.makedirs(parent_dir) except OSError: raise AbortSave(None) # (message already shown) import random tmp = 'tmp-' + `random.randrange(1000000)` tmp = os.path.join(parent_dir, tmp) def open_private(path): return os.fdopen(os.open(path, os.O_CREAT | os.O_WRONLY, 0600), 'wb') try: stream = open_private(tmp) except: # Can't create backup... try a direct write tmp = None stream = open_private(path) try: try: self.save_to_stream(stream) finally: stream.close() if tmp: os.rename(tmp, path) except: _report_save_error() if tmp and os.path.exists(tmp): if os.path.getsize(tmp) == 0 or \ rox.confirm(_("Delete temporary file '%s'?") % tmp, g.STOCK_DELETE): os.unlink(tmp) raise AbortSave(None) self.save_set_permissions(path) filer.examine(path)
def delete(b): sel = self.list.get_selection() memos = [] for iter in memo_list: if sel.iter_is_selected(iter): m = memo_list.get_memo_by_iter(iter) memos.append(m) if not memos: rox.alert(_('You need to select some memos first!')) return l = len(memos) if l == 1: message = _("Really delete memo '%s'?") % memos[0].brief else: message = _('Really delete %d memos?') % l box = g.MessageDialog(None, 0, g.MESSAGE_QUESTION, g.BUTTONS_CANCEL, message) if rox.confirm(message, g.STOCK_DELETE): for m in memos: memo_list.delete(m, update=0) memo_list.notify_changed()
def record(): if rox.confirm("Program failed - record a failure case?", g.STOCK_NO, 'Record'): self.view.record_at_point() return False
def quit(self, widget): if rox.confirm(_("Really quit the Weather applet?"), g.STOCK_QUIT): self.destroy()
def menu_clear_undo(self): if rox.confirm('Really clear the undo buffer?', g.STOCK_CLEAR): self.view.model.clear_undo()