def install_send_to_types(types, application=None): """Install application in the SendTo menu for 1 or more types. application should be the full path to the AppDir. If application is None then it is the running program which will be installed. The user is asked to confirm the setting for each type.""" if len(types)<1: return if not application: application=rox.app_dir if application[0]!='/': application=os.path.abspath(application) win=InstallList(application, _('type handler'), 'SendTo', types, _("""The application can handle files of these types. Click on OK to add it to the SendTo menu for the type of file, and also the customized File menu."""), check=False) if win.run()!=rox.g.RESPONSE_ACCEPT: win.destroy() return types=win.get_active() for tname in types: type=lookup(tname) sname=rox.choices.save('SendTo/.%s_%s' % (type.media, type.subtype), win.aname) os.symlink(application, sname+'.tmp') os.rename(sname+'.tmp', sname) win.destroy()
def report_patherror(message, path): """Display a <Cancel>/<Retry>/<Examine> dialog. This will raise an OSError exception if the user selects Cancel, or will return successfully if the user chooses to retry.""" from rox import g, filer, toplevel_ref, toplevel_unref, ButtonMixed toplevel_ref() box = g.MessageDialog(None, 0, g.MESSAGE_QUESTION, g.BUTTONS_CANCEL, message) button = ButtonMixed(g.STOCK_REDO, _('Retry')) button.set_flags(g.CAN_DEFAULT) button.show() box.add_action_widget(button, g.RESPONSE_OK) button = ButtonMixed(g.STOCK_JUMP_TO, _('Examine')) button.set_flags(g.CAN_DEFAULT) button.show() box.add_action_widget(button, g.RESPONSE_APPLY) box.set_position(g.WIN_POS_CENTER) box.set_title(_('Error:')) box.set_default_response(g.RESPONSE_APPLY) while 1: resp = box.run() if resp != g.RESPONSE_APPLY: break filerpath = os.path.normpath(path) filer.show_file(filerpath) box.destroy() toplevel_unref() if resp != g.RESPONSE_OK: raise OSError, message
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 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 install_thumbnailer(types, application=None, overwrite=True): """Install application as the thumbnail handler for 1 or more types. application should be the full path to the AppDir. If application is None then it is the running program which will be installed. If overwrite is False then existing thumbnailerss will not be changed. The user is asked to confirm the setting for each type.""" _install_type_handler(types, "MIME-thumb", _("thumbnail handler"), application, overwrite, _("""Thumbnail handlers provide support for creating thumbnail images of types of file. The filer can generate thumbnails for most types of image (JPEG, PNG, etc.) but relies on helper applications for the others."""))
def drag_begin(self, drag_box, context): self.drag_in_progress = 1 self.destroy_on_drag_end = 0 self.using_xds = 0 self.data_sent = 0 try: pixbuf = self.icon.get_pixbuf() if pixbuf: drag_box.drag_source_set_icon_pixbuf(pixbuf) except: # This can happen if we set the broken image... import traceback traceback.print_exc() uri = self.entry.get_text() if uri: i = uri.rfind('/') if (i == -1): leaf = uri else: leaf = uri[i + 1:] else: leaf = _('Unnamed') _write_xds_property(context, leaf)
def __init__(self, uri): self.uri = uri Exception.__init__(self, _("The program '%s' cannot be run, as the " "0launch command is not available. " "It can be downloaded from here:\n\n" "http://0install.net/injector.html") % uri)
def __init__(self, uri): self.uri = uri Exception.__init__( self, _("The program '%s' cannot be run, as the " "0launch command is not available. " "It can be downloaded from here:\n\n" "http://0install.net/injector.html") % uri)
def install_run_action(types, application=None, overwrite=True, injint=None): """Install application as the run action for 1 or more types. application should be the full path to the AppDir. If application is None then it is the running program which will be installed. If overwrite is False then existing run actions will not be changed. The user is asked to confirm the setting for each type.""" _install_type_handler(types, "MIME-types", _("run action"), application, overwrite, run_action_msg, injint)
def install_run_action(types, application=None, overwrite=True): """Install application as the run action for 1 or more types. application should be the full path to the AppDir. If application is None then it is the running program which will be installed. If overwrite is False then existing run actions will not be changed. The user is asked to confirm the setting for each type.""" _install_type_handler(types, "MIME-types", _("run action"), application, overwrite, run_action_msg)
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 _makedirs_recursive(path, mode): """Recursive part of makedirs. Calls itself to ensure head of path exists, and then makes a new directory at path. Returns an Exception if it can't make a directory at path.""" if os.path.isdir(path): return head, tail = os.path.split(path) if not tail: head, tail = os.path.split(head) if head and tail: _makedirs_recursive(head, mode) while True: if os.path.exists(path): report_patherror( \ _("Could not create directory `%s' because a file already exists at that path.\n") % path, path) continue try: os.mkdir(path, mode) return except OSError, msg: report_patherror(("%s.\n" + _("Could not create directory `%s'.\n")) \ % (msg[1], path), path)
def install_mime_info(application, package_file = None): """Copy 'package_file' as ~/.local/share/mime/packages/<application>.xml. If package_file is None, install <app_dir>/<application>.xml. If already installed, does nothing. May overwrite an existing file with the same name (if the contents are different)""" application += '.xml' if not package_file: package_file = os.path.join(rox.app_dir, application) new_data = file(package_file).read() # See if the file is already installed package_dir = os.path.join('mime', 'packages') resource = os.path.join(package_dir, application) for x in basedir.load_data_paths(resource): try: old_data = file(x).read() except: continue if old_data == new_data: return # Already installed global _cache_uptodate _cache_uptodate = False # Not already installed; add a new copy try: # Create the directory structure... new_file = os.path.join(basedir.save_data_path(package_dir), application) # Write the file... file(new_file, 'w').write(new_data) # Update the database... if os.path.isdir('/uri/0install/zero-install.sourceforge.net'): command = '/uri/0install/zero-install.sourceforge.net/bin/update-mime-database' else: command = 'update-mime-database' if os.spawnlp(os.P_WAIT, command, command, basedir.save_data_path('mime')): os.unlink(new_file) raise Exception(_("The '%s' command returned an error code!\n" \ "Make sure you have the freedesktop.org shared MIME package:\n" \ "http://www.freedesktop.org/standards/shared-mime-info.html") % command) except: rox.report_exception()
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 save_to_file_in_entry(self): """Call this when the user clicks on an OK button you provide.""" uri = self.entry.get_text() path = get_local_path(escape(uri)) if path: if not self.confirm_new_path(path): return try: self.set_sensitive(False) try: self.document.save_to_file(path) finally: self.set_sensitive(True) self.set_uri(uri) self.save_done() except: _report_save_error() else: rox.info(_("Drag the icon to a directory viewer\n" "(or enter a full pathname)"))
def save_to_file_in_entry(self): """Call this when the user clicks on an OK button you provide.""" uri = self.entry.get_text() path = get_local_path(escape(uri)) if path: if not self.confirm_new_path(path): return try: self.set_sensitive(False) try: self.document.save_to_file(path) finally: self.set_sensitive(True) self.set_uri(uri) self.save_done() except: _report_save_error() else: rox.info( _("Drag the icon to a directory viewer\n" "(or enter a full pathname)"))
def show_exception(type, value, tb, auto_details=False): """Display this exception in an error box. The user has the options of ignoring the error, quitting the application and examining the exception in more detail. See also rox.report_exception().""" QUIT = 1 DETAILS = 2 SAVE = 3 brief = "".join(traceback.format_exception_only(type, value)) toplevel_ref() box = g.MessageDialog(None, 0, g.MESSAGE_ERROR, g.BUTTONS_NONE, brief) if not auto_details: button = ButtonMixed(g.STOCK_ZOOM_IN, _("_Details")) button.set_flags(g.CAN_DEFAULT) button.show() box.add_action_widget(button, DETAILS) box.add_button(g.STOCK_OK, g.RESPONSE_OK) box.set_default_response(g.RESPONSE_OK) box.set_position(g.WIN_POS_CENTER) box.set_title(_("Error")) reply = [] def response(box, resp): reply.append(resp) g.mainquit() box.connect("response", response) box.show() bug_report = "Traceback (most recent call last):\n" + "".join( traceback.format_stack(tb.tb_frame.f_back) + traceback.format_tb(tb) + traceback.format_exception_only(type, value) ) while 1: if auto_details: resp = DETAILS auto_details = False else: g.mainloop() resp = reply.pop() if resp == g.RESPONSE_OK or resp == g.RESPONSE_DELETE_EVENT: break if resp == SAVE: global savebox if savebox: savebox.destroy() def destroy(box): savebox = None from saving import StringSaver savebox = StringSaver(bug_report, "BugReport") savebox.connect("destroy", destroy) savebox.show() continue if resp == QUIT: sys.exit(1) assert resp == DETAILS box.set_response_sensitive(DETAILS, False) box.set_has_separator(False) button = ButtonMixed(g.STOCK_SAVE, _("_Bug Report")) button.set_flags(g.CAN_DEFAULT) button.show() box.add_action_widget(button, SAVE) box.action_area.set_child_secondary(button, True) button = ButtonMixed(g.STOCK_QUIT, _("Forced Quit")) button.set_flags(g.CAN_DEFAULT) button.show() box.add_action_widget(button, QUIT) box.action_area.set_child_secondary(button, True) ee = ExceptionExplorer(tb) box.vbox.pack_start(ee) ee.show() box.destroy() toplevel_unref()
def __init__(self, tb): g.Frame.__init__(self, _("Stack trace (innermost last)")) vbox = g.VBox(False, 0) self.add(vbox) inner = g.Frame() inner.set_shadow_type(g.SHADOW_IN) vbox.pack_start(inner, False, True, 0) self.savebox = None self.tb = tb self.model = g.ListStore(gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING, gobject.TYPE_STRING) tree = g.TreeView(self.model) inner.add(tree) cell = g.CellRendererText() column = g.TreeViewColumn("File", cell, text=ExceptionExplorer.FILE) cell.set_property("xalign", 1) tree.append_column(column) cell = g.CellRendererText() column = g.TreeViewColumn("Line", cell, text=ExceptionExplorer.LINE) tree.append_column(column) column = g.TreeViewColumn("Func", cell, text=ExceptionExplorer.FUNC) tree.append_column(column) column = g.TreeViewColumn("Code", cell, text=ExceptionExplorer.CODE) tree.append_column(column) inner.set_border_width(5) frames = [] while tb is not None: frames.insert(0, (tb.tb_frame, traceback.tb_lineno(tb))) tb = tb.tb_next f = self.tb.tb_frame if f: f = f.f_back # Skip the reporting frame while f is not None: frames.append((f, f.f_lineno)) f = f.f_back frames.reverse() new = None for f, lineno in frames: co = f.f_code filename = co.co_filename name = co.co_name line = linecache.getline(filename, lineno).strip() filename = os.path.basename(filename) new = self.model.append() self.model.set( new, ExceptionExplorer.FILE, filename, ExceptionExplorer.LINE, lineno, ExceptionExplorer.FUNC, name, ExceptionExplorer.CODE, line, ) def selected_frame(): selected = sel.get_selected() assert selected model, iter = selected frame, = model.get_path(iter) return frames[frame][0] vars = g.ListStore(str, str) sel = tree.get_selection() sel.set_mode(g.SELECTION_BROWSE) def select_frame(tree): vars.clear() for n, v in selected_frame().f_locals.iteritems(): value = ` v ` if len(value) > 500: value = value[:500] + " ..." new = vars.append() vars.set(new, 0, str(n), 1, value) sel.connect("changed", select_frame) # Area to show the local variables tree = g.TreeView(vars) vbox.pack_start(g.Label(_("Local variables in selected frame:")), False, True, 0) cell = g.CellRendererText() column = g.TreeViewColumn("Name", cell, text=0) cell.set_property("xalign", 1) tree.append_column(column) cell = g.CellRendererText() column = g.TreeViewColumn("Value", cell, text=1) tree.append_column(column) inner = g.ScrolledWindow() inner.set_size_request(-1, 200) inner.set_policy(g.POLICY_AUTOMATIC, g.POLICY_ALWAYS) inner.set_shadow_type(g.SHADOW_IN) inner.add(tree) inner.set_border_width(5) vbox.pack_start(inner, True, True, 0) if new: sel.select_iter(new) hbox = g.HBox(False, 4) hbox.set_border_width(5) vbox.pack_start(hbox, False, True, 0) hbox.pack_start(g.Label(">>>"), False, True, 0) expr = g.Entry() hbox.pack_start(expr, True, True, 0) def activate(entry): expr = entry.get_text() frame = selected_frame() try: info(` eval(expr, frame.f_locals, frame.f_globals) `) except: type, value = sys.exc_info()[:2] brief = "".join(traceback.format_exception_only(type, value)) alert(brief) entry.grab_focus() expr.connect("activate", activate) vbox.show_all()
def __init__(self, application, itype, dir, types, info=None, check=True, site=SITE): """Create the install list dialog. application - path to application to install itype - string describing the type of action to install dir - directory in Choices to store links in types - list of MIME types info - optional message to display below list check - if true (the default), check for existing entries""" rox.Dialog.__init__(self, title=_('Install %s') % itype, buttons=(rox.g.STOCK_CANCEL, rox.g.RESPONSE_CLOSE, rox.g.STOCK_OK, rox.g.RESPONSE_ACCEPT)) self.itype=itype self.dir=dir self.site=site self.types=types self.app=application self.aname=os.path.basename(application) self.check=check vbox=self.vbox swin = rox.g.ScrolledWindow() swin.set_size_request(-1, 160) swin.set_border_width(4) swin.set_policy(rox.g.POLICY_NEVER, rox.g.POLICY_ALWAYS) swin.set_shadow_type(rox.g.SHADOW_IN) vbox.pack_start(swin, True, True, 0) self.model = rox.g.ListStore(str, str, str, int, rox.g.gdk.Pixbuf, int, int) view = rox.g.TreeView(self.model) self.view = view swin.add(view) view.set_search_column(1) cell = rox.g.CellRendererPixbuf() column = rox.g.TreeViewColumn('', cell, pixbuf = _ICON) view.append_column(column) cell = rox.g.CellRendererText() column = rox.g.TreeViewColumn(_('Type'), cell, text = _TNAME) view.append_column(column) column.set_sort_column_id(_TNAME) cell = rox.g.CellRendererText() column = rox.g.TreeViewColumn(_('Name'), cell, text = _COMMENT) view.append_column(column) column.set_sort_column_id(_COMMENT) if check: cell = rox.g.CellRendererText() column = rox.g.TreeViewColumn(_('Current'), cell, text = _CURRENT) view.append_column(column) column.set_sort_column_id(_CURRENT) cell = rox.g.CellRendererToggle() cell.set_property('activatable', True) cell.connect('toggled', self.install_toggled, self.model) column = rox.g.TreeViewColumn(_('Install?'), cell, active = _INSTALL) view.append_column(column) column.set_sort_column_id(_INSTALL) cell = rox.g.CellRendererToggle() cell.connect('toggled', self.uninstall_toggled, self.model) column = rox.g.TreeViewColumn(_('Uninstall?'), cell, active = _UNINSTALL, activatable= _IS_OURS) view.append_column(column) column.set_sort_column_id(_UNINSTALL) view.get_selection().set_mode(rox.g.SELECTION_NONE) if info: hbox=rox.g.HBox(spacing=4) img=rox.g.image_new_from_stock(rox.g.STOCK_DIALOG_INFO, rox.g.ICON_SIZE_DIALOG) hbox.pack_start(img) lbl=rox.g.Label(info) lbl.set_line_wrap(True) hbox.pack_start(lbl) vbox.pack_start(hbox) vbox.show_all() self.load_types()
sname=save_path(SITE, dir, '%s_%s' % (mime_type.media, mime_type.subtype)) _install_at(sname, application, injint) types=win.get_uninstall() for tname in types: mime_type = mime.lookup(tname) sname=save_path(SITE, dir, '%s_%s' % (mime_type.media, mime_type.subtype)) os.remove(sname) finally: win.destroy() run_action_msg=_("""Run actions can be changed by selecting a file of the appropriate type in the Filer and selecting the menu option 'Set Run Action...'""") def install_run_action(types, application=None, overwrite=True, injint=None): """Install application as the run action for 1 or more types. application should be the full path to the AppDir. If application is None then it is the running program which will be installed. If overwrite is False then existing run actions will not be changed. The user is asked to confirm the setting for each type.""" _install_type_handler(types, "MIME-types", _("run action"), application, overwrite, run_action_msg, injint) def install_thumbnailer(types, application=None, overwrite=True, injint=None): """Install application as the thumbnail handler for 1 or more types. application should be the full path to the AppDir. If application is None then it is the running program which will
def __init__(self, options_group, options_xml, translation = None): """options_xml is an XML file, usually <app_dir>/Options.xml, which defines the layout of the OptionsBox. It contains an <options> root element containing (nested) <section> elements. Each <section> contains a number of widgets, some of which correspond to options. The build_* functions are used to create them. Example: <?xml version='1.0'?> <options> <section title='First section'> <label>Here are some options</label> <entry name='default_name' label='Default file name'> When saving an untitled file, use this name as the default. </entry> <section title='Nested section'> ... </section> </section> </options> """ assert isinstance(options_group, options.OptionGroup) if translation is None: import __main__ if hasattr(__main__.__builtins__, '_'): translation = __main__.__builtins__._ else: translation = lambda x: x self._ = translation g.Dialog.__init__(self) self.tips = g.Tooltips() self.set_has_separator(False) self.options = options_group self.set_title(('%s options') % options_group.program) self.set_position(g.WIN_POS_CENTER) button = rox.ButtonMixed(g.STOCK_UNDO, _('_Revert')) self.add_action_widget(button, REVERT) self.tips.set_tip(button, _('Restore all options to how they were ' 'when the window was opened')) self.add_button(g.STOCK_OK, g.RESPONSE_OK) doc = minidom.parse(options_xml) assert doc.documentElement.localName == 'options' self.handlers = {} # Option -> (get, set) self.revert = {} # Option -> old value self.build_window_frame() # Add each section n = 0 for section in doc.documentElement.childNodes: if section.nodeType != Node.ELEMENT_NODE: continue if section.localName != 'section': print "Unknown section", section continue self.build_section(section, None) n += 1 if n > 1: self.tree_view.expand_all() else: self.sections_swin.hide() self.updating = 0 def destroyed(widget): rox.toplevel_unref() if self.changed(): try: self.options.save() except: rox.report_exception() self.connect('destroy', destroyed) def got_response(widget, response): if response == g.RESPONSE_OK: self.destroy() elif response == REVERT: for o in self.options: o._set(self.revert[o]) self.update_widgets() self.options.notify() self.update_revert() self.connect('response', got_response)
def __init__(self, options_group, options_xml, translation=None): """options_xml is an XML file, usually <app_dir>/Options.xml, which defines the layout of the OptionsBox. It contains an <options> root element containing (nested) <section> elements. Each <section> contains a number of widgets, some of which correspond to options. The build_* functions are used to create them. Example: <?xml version='1.0'?> <options> <section title='First section'> <label>Here are some options</label> <entry name='default_name' label='Default file name'> When saving an untitled file, use this name as the default. </entry> <section title='Nested section'> ... </section> </section> </options> """ assert isinstance(options_group, options.OptionGroup) if translation is None: import __main__ if hasattr(__main__.__builtins__, '_'): translation = __main__.__builtins__._ else: translation = lambda x: x self._ = translation g.Dialog.__init__(self) self.tips = g.Tooltips() self.set_has_separator(False) self.options = options_group self.set_title(('%s options') % options_group.program) self.set_position(g.WIN_POS_CENTER) button = rox.ButtonMixed(g.STOCK_UNDO, _('_Revert')) self.add_action_widget(button, REVERT) self.tips.set_tip( button, _('Restore all options to how they were ' 'when the window was opened')) self.add_button(g.STOCK_OK, g.RESPONSE_OK) doc = minidom.parse(options_xml) assert doc.documentElement.localName == 'options' self.handlers = {} # Option -> (get, set) self.revert = {} # Option -> old value self.build_window_frame() # Add each section n = 0 for section in doc.documentElement.childNodes: if section.nodeType != Node.ELEMENT_NODE: continue if section.localName != 'section': print "Unknown section", section continue self.build_section(section, None) n += 1 if n > 1: self.tree_view.expand_all() else: self.sections_swin.hide() self.updating = 0 def destroyed(widget): rox.toplevel_unref() if self.changed(): try: self.options.save() except: rox.report_exception() self.connect('destroy', destroyed) def got_response(widget, response): if response == g.RESPONSE_OK: self.destroy() elif response == REVERT: for o in self.options: o._set(self.revert[o]) self.update_widgets() self.options.notify() self.update_revert() self.connect('response', got_response)
_install_at(sname, application, injint) types = win.get_uninstall() for tname in types: mime_type = mime.lookup(tname) sname = save_path(SITE, dir, '%s_%s' % (mime_type.media, mime_type.subtype)) os.remove(sname) finally: win.destroy() run_action_msg = _( """Run actions can be changed by selecting a file of the appropriate type in the Filer and selecting the menu option 'Set Run Action...'""" ) def install_run_action(types, application=None, overwrite=True, injint=None): """Install application as the run action for 1 or more types. application should be the full path to the AppDir. If application is None then it is the running program which will be installed. If overwrite is False then existing run actions will not be changed. The user is asked to confirm the setting for each type.""" _install_type_handler(types, "MIME-types", _("run action"), application, overwrite, run_action_msg, injint) def install_thumbnailer(types, application=None, overwrite=True, injint=None):
def __init__(self, document, uri, type='text/plain', discard=False, parent=None): """See SaveArea.__init__. parent was added in version 2.0.5. To support older versions, use set_transient_for. If discard is True then an extra discard button is added to the dialog.""" g.Dialog.__init__(self, parent=parent) self.set_has_separator(False) self.add_button(g.STOCK_CANCEL, g.RESPONSE_CANCEL) self.add_button(g.STOCK_SAVE, g.RESPONSE_OK) self.set_default_response(g.RESPONSE_OK) if discard: discard_area = g.HButtonBox() def discard_clicked(event): document.discard() self.destroy() button = rox.ButtonMixed(g.STOCK_DELETE, _('_Discard')) discard_area.pack_start(button, False, True, 2) button.connect('clicked', discard_clicked) button.unset_flags(g.CAN_FOCUS) button.set_flags(g.CAN_DEFAULT) self.vbox.pack_end(discard_area, False, True, 0) self.vbox.reorder_child(discard_area, 0) discard_area.show_all() self.set_title(_('Save As:')) self.set_position(g.WIN_POS_MOUSE) self.set_wmclass('savebox', 'Savebox') self.set_border_width(1) # Might as well make use of the new nested scopes ;-) self.set_save_in_progress(0) class BoxedArea(SaveArea): def set_uri(area, uri): SaveArea.set_uri(area, uri) if discard: document.discard() def save_done(area): document.save_done() self.destroy() def set_sensitive(area, sensitive): if self.window: # Might have been destroyed by now... self.set_save_in_progress(not sensitive) SaveArea.set_sensitive(area, sensitive) save_area = BoxedArea(document, uri, type) self.save_area = save_area save_area.show_all() self.build_main_area() i = uri.rfind('/') i = i + 1 # Have to do this here, or the selection gets messed up save_area.entry.grab_focus() g.Editable.select_region(save_area.entry, i, -1) # PyGtk bug #save_area.entry.select_region(i, -1) def got_response(widget, response): if self.save_in_progress: try: document.save_cancelled() except: rox.report_exception() return if response == int(g.RESPONSE_CANCEL): self.destroy() elif response == int(g.RESPONSE_OK): self.save_area.save_to_file_in_entry() elif response == int(g.RESPONSE_DELETE_EVENT): pass else: raise Exception('Unknown response!') self.connect('response', got_response) rox.toplevel_ref() self.connect('destroy', lambda w: rox.toplevel_unref())
def __init__(self, application, itype, dir, types, info=None, check=True, site=SITE): """Create the install list dialog. application - path to application to install itype - string describing the type of action to install dir - directory in Choices to store links in types - list of MIME types info - optional message to display below list check - if true (the default), check for existing entries""" rox.Dialog.__init__(self, title=_('Install %s') % itype, buttons=(rox.g.STOCK_CANCEL, rox.g.RESPONSE_CLOSE, rox.g.STOCK_OK, rox.g.RESPONSE_ACCEPT)) self.itype = itype self.dir = dir self.site = site self.types = types self.app = application self.aname = os.path.basename(application) self.check = check vbox = self.vbox swin = rox.g.ScrolledWindow() swin.set_size_request(-1, 160) swin.set_border_width(4) swin.set_policy(rox.g.POLICY_NEVER, rox.g.POLICY_ALWAYS) swin.set_shadow_type(rox.g.SHADOW_IN) vbox.pack_start(swin, True, True, 0) self.model = rox.g.ListStore(str, str, str, int, rox.g.gdk.Pixbuf, int, int) view = rox.g.TreeView(self.model) self.view = view swin.add(view) view.set_search_column(1) cell = rox.g.CellRendererPixbuf() column = rox.g.TreeViewColumn('', cell, pixbuf=_ICON) view.append_column(column) cell = rox.g.CellRendererText() column = rox.g.TreeViewColumn(_('Type'), cell, text=_TNAME) view.append_column(column) column.set_sort_column_id(_TNAME) cell = rox.g.CellRendererText() column = rox.g.TreeViewColumn(_('Name'), cell, text=_COMMENT) view.append_column(column) column.set_sort_column_id(_COMMENT) if check: cell = rox.g.CellRendererText() column = rox.g.TreeViewColumn(_('Current'), cell, text=_CURRENT) view.append_column(column) column.set_sort_column_id(_CURRENT) cell = rox.g.CellRendererToggle() cell.set_property('activatable', True) cell.connect('toggled', self.install_toggled, self.model) column = rox.g.TreeViewColumn(_('Install?'), cell, active=_INSTALL) view.append_column(column) column.set_sort_column_id(_INSTALL) cell = rox.g.CellRendererToggle() cell.connect('toggled', self.uninstall_toggled, self.model) column = rox.g.TreeViewColumn(_('Uninstall?'), cell, active=_UNINSTALL, activatable=_IS_OURS) view.append_column(column) column.set_sort_column_id(_UNINSTALL) view.get_selection().set_mode(rox.g.SELECTION_NONE) if info: hbox = rox.g.HBox(spacing=4) img = rox.g.image_new_from_stock(rox.g.STOCK_DIALOG_INFO, rox.g.ICON_SIZE_DIALOG) hbox.pack_start(img) lbl = rox.g.Label(info) lbl.set_line_wrap(True) hbox.pack_start(lbl) vbox.pack_start(hbox) vbox.show_all() self.load_types()
def __init__(self, tb): g.Frame.__init__(self, _('Stack trace (innermost last)')) vbox = g.VBox(False, 0) self.add(vbox) inner = g.Frame() inner.set_shadow_type(g.SHADOW_IN) vbox.pack_start(inner, False, True, 0) self.savebox = None self.tb = tb self.model = g.ListStore(gobject.TYPE_STRING, gobject.TYPE_INT, gobject.TYPE_STRING, gobject.TYPE_STRING, gobject.TYPE_STRING) tree = g.TreeView(self.model) inner.add(tree) cell = g.CellRendererText() column = g.TreeViewColumn('File', cell, text = ExceptionExplorer.LEAF) cell.set_property('xalign', 1) tree.append_column(column) cell = g.CellRendererText() column = g.TreeViewColumn('Line', cell, text = ExceptionExplorer.LINE) tree.append_column(column) column = g.TreeViewColumn('Func', cell, text = ExceptionExplorer.FUNC) tree.append_column(column) column = g.TreeViewColumn('Code', cell, text = ExceptionExplorer.CODE) tree.append_column(column) inner.set_border_width(5) frames = [] while tb is not None: frames.insert(0, (tb.tb_frame, traceback.tb_lineno(tb))) tb = tb.tb_next f = self.tb.tb_frame if f: f = f.f_back # Skip the reporting frame while f is not None: frames.append((f, f.f_lineno)) f = f.f_back frames.reverse() new = None for f, lineno in frames: co = f.f_code filename = co.co_filename name = co.co_name line = linecache.getline(filename, lineno).strip() leafname = os.path.basename(filename) new = self.model.append() self.model.set(new, ExceptionExplorer.LEAF, leafname, ExceptionExplorer.LINE, lineno, ExceptionExplorer.FUNC, name, ExceptionExplorer.CODE, line, ExceptionExplorer.FILE, filename) def selected_frame(): selected = sel.get_selected() assert selected model, titer = selected frame, = model.get_path(titer) return frames[frame][0] vars = g.ListStore(str, str) sel = tree.get_selection() sel.set_mode(g.SELECTION_BROWSE) def select_frame(tree): vars.clear() for n, v in selected_frame().f_locals.iteritems(): value = `v` if len(value) > 500: value = value[:500] + ' ...' new = vars.append() vars.set(new, 0, str(n), 1, value) sel.connect('changed', select_frame) def show_source(tree, path, column): line = self.model[path][ExceptionExplorer.LINE] file = self.model[path][ExceptionExplorer.FILE] import launch launch.launch('http://rox.sourceforge.net/2005/interfaces/Edit', '-l%d' % line, file) tree.connect('row-activated', show_source) # Area to show the local variables tree = g.TreeView(vars) vbox.pack_start(g.Label(_('Local variables in selected frame:')), False, True, 0) cell = g.CellRendererText() column = g.TreeViewColumn('Name', cell, text = 0) cell.set_property('xalign', 1) tree.append_column(column) cell = g.CellRendererText() column = g.TreeViewColumn('Value', cell, text = 1) tree.append_column(column) inner = g.ScrolledWindow() inner.set_size_request(-1, 200) inner.set_policy(g.POLICY_AUTOMATIC, g.POLICY_ALWAYS) inner.set_shadow_type(g.SHADOW_IN) inner.add(tree) inner.set_border_width(5) vbox.pack_start(inner, True, True, 0) if new: sel.select_iter(new) hbox = g.HBox(False, 4) hbox.set_border_width(5) vbox.pack_start(hbox, False, True, 0) hbox.pack_start(g.Label('>>>'), False, True, 0) expr = g.Entry() hbox.pack_start(expr, True, True, 0) def activate(entry): expr = entry.get_text() frame = selected_frame() try: info(`eval(expr, frame.f_locals, frame.f_globals)`) except: extype, value = sys.exc_info()[:2] brief = ''.join(traceback.format_exception_only(extype, value)) alert(brief) entry.grab_focus() expr.connect('activate', activate) vbox.show_all()
def show_exception(type, value, tb, auto_details = False): """Display this exception in an error box. The user has the options of ignoring the error, quitting the application and examining the exception in more detail. See also rox.report_exception().""" QUIT = 1 DETAILS = 2 SAVE = 3 brief = ''.join(traceback.format_exception_only(type, value)) toplevel_ref() box = g.MessageDialog(None, 0, g.MESSAGE_ERROR, g.BUTTONS_NONE, brief) if not auto_details: button = ButtonMixed(g.STOCK_ZOOM_IN, _('_Details')) button.set_flags(g.CAN_DEFAULT) button.show() box.add_action_widget(button, DETAILS) box.add_button(g.STOCK_HELP, g.RESPONSE_HELP) box.add_button(g.STOCK_OK, g.RESPONSE_OK) box.set_default_response(g.RESPONSE_OK) box.set_position(g.WIN_POS_CENTER) box.set_title(_('Error')) box.show() if tb: bug_report = 'Traceback (most recent call last):\n' + \ ''.join(traceback.format_stack(tb.tb_frame.f_back) + traceback.format_tb(tb) + traceback.format_exception_only(type, value)) else: bug_report = 'No stack trace.' while 1: if auto_details: resp = DETAILS auto_details = False else: resp = box.run() if resp == int(g.RESPONSE_OK) or resp == int(g.RESPONSE_DELETE_EVENT): break if resp == SAVE: global savebox if savebox: savebox.destroy() def destroy(box): global savebox # For pychecker savebox = None from saving import StringSaver savebox = StringSaver(bug_report, 'BugReport') savebox.connect('destroy', destroy) savebox.show() continue if resp == QUIT: sys.exit(1) elif resp == int(g.RESPONSE_HELP): _show_debug_help() continue assert resp == DETAILS box.set_response_sensitive(DETAILS, False) button = ButtonMixed(g.STOCK_SAVE, _('_Bug Report')) button.set_flags(g.CAN_DEFAULT) button.show() box.add_action_widget(button, SAVE) box.action_area.set_child_secondary(button, True) button = ButtonMixed(g.STOCK_QUIT, _('Forced Quit')) button.set_flags(g.CAN_DEFAULT) button.show() box.add_action_widget(button, QUIT) box.action_area.set_child_secondary(button, True) if tb: ee = ExceptionExplorer(tb) box.vbox.pack_start(ee) ee.show() else: no_trace = g.Label('No traceback object!') box.vbox.pack_start(no_trace) no_trace.show() box.destroy() toplevel_unref()
def __init__(self): Exception.__init__( self, _('Cannot load files from a remote machine ' '(multiple files, or target application/octet-stream not provided)' ))
def show_exception(type, value, tb, auto_details = False): """Display this exception in an error box. The user has the options of ignoring the error, quitting the application and examining the exception in more detail. See also rox.report_exception().""" QUIT = 1 DETAILS = 2 SAVE = 3 brief = ''.join(traceback.format_exception_only(type, value)) toplevel_ref() box = g.MessageDialog(None, 0, g.MESSAGE_ERROR, g.BUTTONS_NONE, brief) if not auto_details: button = ButtonMixed(g.STOCK_ZOOM_IN, _('_Details')) button.set_flags(g.CAN_DEFAULT) button.show() box.add_action_widget(button, DETAILS) box.add_button(g.STOCK_HELP, g.RESPONSE_HELP) box.add_button(g.STOCK_OK, g.RESPONSE_OK) box.set_default_response(g.RESPONSE_OK) box.set_position(g.WIN_POS_CENTER) box.set_title(_('Error')) reply = [] def response(box, resp): reply.append(resp) g.main_quit() box.connect('response', response) box.show() if tb: bug_report = 'Traceback (most recent call last):\n' + \ ''.join(traceback.format_stack(tb.tb_frame.f_back) + traceback.format_tb(tb) + traceback.format_exception_only(type, value)) else: bug_report = 'No stack trace.' while 1: if auto_details: resp = DETAILS auto_details = False else: g.main() resp = reply.pop() if resp == int(g.RESPONSE_OK) or resp == int(g.RESPONSE_DELETE_EVENT): break if resp == SAVE: global savebox if savebox: savebox.destroy() def destroy(box): global savebox # For pychecker savebox = None from saving import StringSaver savebox = StringSaver(bug_report, 'BugReport') savebox.connect('destroy', destroy) savebox.show() continue if resp == QUIT: sys.exit(1) elif resp == int(g.RESPONSE_HELP): _show_debug_help() continue assert resp == DETAILS box.set_response_sensitive(DETAILS, False) button = ButtonMixed(g.STOCK_SAVE, _('_Bug Report')) button.set_flags(g.CAN_DEFAULT) button.show() box.add_action_widget(button, SAVE) box.action_area.set_child_secondary(button, True) button = ButtonMixed(g.STOCK_QUIT, _('Forced Quit')) button.set_flags(g.CAN_DEFAULT) button.show() box.add_action_widget(button, QUIT) box.action_area.set_child_secondary(button, True) if tb: ee = ExceptionExplorer(tb) box.vbox.pack_start(ee) ee.show() else: no_trace = g.Label('No traceback object!') box.vbox.pack_start(no_trace) no_trace.show() box.destroy() toplevel_unref()
def __init__(self, document, uri, type = 'text/plain', discard = False, parent = None): """See SaveArea.__init__. parent was added in version 2.0.5. To support older versions, use set_transient_for. If discard is True then an extra discard button is added to the dialog.""" g.Dialog.__init__(self, parent = parent) self.set_has_separator(False) self.add_button(g.STOCK_CANCEL, g.RESPONSE_CANCEL) self.add_button(g.STOCK_SAVE, g.RESPONSE_OK) self.set_default_response(g.RESPONSE_OK) if discard: discard_area = g.HButtonBox() def discard_clicked(event): document.discard() self.destroy() button = rox.ButtonMixed(g.STOCK_DELETE, _('_Discard')) discard_area.pack_start(button, False, True, 2) button.connect('clicked', discard_clicked) button.unset_flags(g.CAN_FOCUS) button.set_flags(g.CAN_DEFAULT) self.vbox.pack_end(discard_area, False, True, 0) self.vbox.reorder_child(discard_area, 0) discard_area.show_all() self.set_title(_('Save As:')) self.set_position(g.WIN_POS_MOUSE) self.set_wmclass('savebox', 'Savebox') self.set_border_width(1) # Might as well make use of the new nested scopes ;-) self.set_save_in_progress(0) class BoxedArea(SaveArea): def set_uri(area, uri): SaveArea.set_uri(area, uri) if discard: document.discard() def save_done(area): document.save_done() self.destroy() def set_sensitive(area, sensitive): if self.window: # Might have been destroyed by now... self.set_save_in_progress(not sensitive) SaveArea.set_sensitive(area, sensitive) save_area = BoxedArea(document, uri, type) self.save_area = save_area save_area.show_all() self.build_main_area() i = uri.rfind('/') i = i + 1 # Have to do this here, or the selection gets messed up save_area.entry.grab_focus() g.Editable.select_region(save_area.entry, i, -1) # PyGtk bug #save_area.entry.select_region(i, -1) def got_response(widget, response): if self.save_in_progress: try: document.save_cancelled() except: rox.report_exception() return if response == int(g.RESPONSE_CANCEL): self.destroy() elif response == int(g.RESPONSE_OK): self.save_area.save_to_file_in_entry() elif response == int(g.RESPONSE_DELETE_EVENT): pass else: raise Exception('Unknown response!') self.connect('response', got_response) rox.toplevel_ref() self.connect('destroy', lambda w: rox.toplevel_unref())
def __init__(self): Exception.__init__(self, _('Cannot load files from a remote machine ' '(multiple files, or target application/octet-stream not provided)'))