def __init__(self, xid): """xid is the sys.argv[1] passed to AppletRun.""" xid = long(xid) g.Plug.__init__(self, xid) self.socket = g.gdk.window_foreign_new(xid) rox.toplevel_ref() self.connect('destroy', rox.toplevel_unref)
def setup(): box = g.MessageDialog(None, g.DIALOG_MODAL, g.MESSAGE_QUESTION, g.BUTTONS_CANCEL, _('Do you want to make ROX a choice ' 'on your login screen (affects all users and ' 'requires the root password), or do you ' 'just want to set the session for your current ' 'user?\n\n' 'If you know the root password and use ' 'a graphical display manager such as gdm or kdm, ' 'you should probably choose that option.')) add_button(box, g.STOCK_HOME, _('Setup for user'), 1) add_button(box, g.STOCK_YES, _('Add to login'), 2) box.set_default_response(2) box.set_position(g.WIN_POS_CENTER) resp = box.run() box.destroy() if resp == 1: setup_home() elif resp == 2: tasks.Task(setup_login()) rox.toplevel_ref() rox.mainloop()
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 __init__(self, service_name=None, interface_name=None, object_path=None): """Constructor. service_name - namespaced name giving the service to provide, e.g. com.mydomain.MyApp interface_name - namespaced name defining the set of methods that may be called, e.g. net.sourceforge.rox.FileHandler. This is ignored but must still be specified for compatability with the DBus implementation object_path - determines the data the methods work on, 'Default'. These all must be None or the same as the class variables of the same name (so that rox.singleton.contact() can work as expected). This method increments the window count by one, so that the main loop will remain running even when no windows are open. """ assert hasattr(self, 'service_name') assert service_name is None or service_name==self.service_name assert interface_name is None or interface_name==self.interface_name assert object_path is None or object_path==self.object_path Server.__init__(self, self.service_name, self.interface_name, self.object_path) self.active=True rox.toplevel_ref()
def open(self): """Show the window, updating all the widgets at the same time. Use this instead of show().""" rox.toplevel_ref() for option in self.options: self.revert[option] = option.value self.update_widgets() self.update_revert() self.show()
def __init__(self, window, widgets): """Act as a proxy for window. Call toplevel_ref() and arrange for toplevel_unref to be called on destruction. The signal handlers are connected to this object.""" self._window=window assert self._window rox.toplevel_ref() self._window.connect('destroy', rox.toplevel_unref) widgets.signal_autoconnect(self)
def __init__(self, window, widgets): """Act as a proxy for window. Call toplevel_ref() and arrange for toplevel_unref to be called on destruction. The signal handlers are connected to this object.""" self._window = window assert self._window rox.toplevel_ref() self._window.connect('destroy', rox.toplevel_unref) widgets.signal_autoconnect(self)
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 _schedule(): assert not _run_queue rox.toplevel_ref() g.idle_add(_handle_run_queue)
def __init__(self, timeout): """Trigger after 'timeout' seconds (may be a fraction).""" Blocker.__init__(self) rox.toplevel_ref() g.timeout_add(long(timeout * 1000), self._timeout)
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, 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 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 _schedule(): assert not _run_queue rox.toplevel_ref() gobject.idle_add(_handle_run_queue)
def __init__(self, timeout): """Trigger after 'timeout' seconds (may be a fraction).""" Blocker.__init__(self) rox.toplevel_ref() gobject.timeout_add(long(timeout * 1000), self._timeout)
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, pathname): loading.XDSLoader.__init__(self, None) self.pathname = pathname self.wTree = gtk.glade.XML(gladefile, 'main') self.window = self.wTree.get_widget('main') self.window.connect('destroy', rox.toplevel_unref) self.xds_proxy_for(self.window) help = gtk.glade.XML(gladefile, 'main_help') help_box = help.get_widget('main_help') help_box.set_default_size(g.gdk.screen_width() / 4, g.gdk.screen_height() / 4) help_box.connect('delete-event', lambda box, ev: True) help_box.connect('response', lambda box, resp: box.hide()) def resp(box, resp): if resp == g.RESPONSE_HELP: help_box.present() elif resp == RESPONSE_SAVE_AND_TEST: self.save(self.test) elif resp == RESPONSE_SAVE: self.save() else: box.destroy() self.window.connect('response', resp) rox.toplevel_ref() key_menu = self.wTree.get_widget('feed_key') key_model = g.ListStore(str, str) key_menu.set_model(key_model) cell = g.CellRendererText() if gtk.pygtk_version >= (2, 8, 0): # Crashes with pygtk 2.6.1 cell.set_property('ellipsize', pango.ELLIPSIZE_MIDDLE) key_menu.pack_start(cell) key_menu.add_attribute(cell, 'text', 1) self.update_key_model() self.impl_model = g.TreeStore(str, object) impl_tree = self.wTree.get_widget('impl_tree') impl_tree.set_model(self.impl_model) text = g.CellRendererText() column = g.TreeViewColumn('', text) column.add_attribute(text, 'text', 0) impl_tree.append_column(column) impl_tree.enable_model_drag_source(gtk.gdk.BUTTON1_MASK, [element_target], gtk.gdk.ACTION_MOVE) impl_tree.enable_model_drag_dest([element_target], gtk.gdk.ACTION_MOVE) sel = impl_tree.get_selection() sel.set_mode(g.SELECTION_BROWSE) if os.path.exists(self.pathname): data, _, self.key = signing.check_signature(self.pathname) self.doc = minidom.parseString(data) self.update_fields() # Default to showing the versions tab self.wTree.get_widget('notebook').next_page() else: default_name = os.path.basename(self.pathname) if default_name.endswith('.xml'): default_name = default_name[:-4] self.doc = minidom.parseString(emptyFeed) self.key = None key_menu.set_active(0) self.update_fields() self.wTree.get_widget('feed_name').set_text(default_name) root = self.impl_model.get_iter_root() if root: sel.select_iter(root) self.wTree.get_widget('generate_key').connect('clicked', lambda b: self.generate_key()) self.wTree.get_widget('add_implementation').connect('clicked', lambda b: self.add_version()) self.wTree.get_widget('add_archive').connect('clicked', lambda b: self.add_archive()) self.wTree.get_widget('add_requires').connect('clicked', lambda b: self.add_requires()) self.wTree.get_widget('add_group').connect('clicked', lambda b: self.add_group()) self.wTree.get_widget('edit_properties').connect('clicked', lambda b: self.edit_properties()) self.wTree.get_widget('remove').connect('clicked', lambda b: self.remove_version()) impl_tree.connect('row-activated', lambda tv, path, col: self.edit_properties(path)) impl_tree.connect('drag-data-received', self.tree_drag_data_received)