def rox_process_died(status): global rox_pid rox_pid = None box = g.MessageDialog(parent = None, flags = 0, type = g.MESSAGE_QUESTION, buttons = 0, message_format = _("ROX-Filer has terminated (crashed?)." "You should probably try to restart it.")) for stock, label, response in [ (g.STOCK_NO, _("Do nothing"), 0), (g.STOCK_EXECUTE, _("Run Xterm"), 1), (g.STOCK_REFRESH, _("_Restart"), 2)]: button = rox.ButtonMixed(stock, label) button.set_flags(g.CAN_DEFAULT) box.add_action_widget(button, response) button.show() box.set_default_response(2) r = box.run() box.destroy() if r == 2: run_rox_process() elif r == 1: os.spawnlp(os.P_NOWAIT, 'xterm', 'xterm')
def __init__(self): rox.Dialog.__init__(self) # TODO: Check if there's already a logout box... self.set_has_separator(False) vbox = self.vbox hbox = g.HButtonBox() hbox.set_border_width(2) hbox.set_layout(g.BUTTONBOX_END) vbox.pack_start(hbox, False, True, 0) button = op_button(_('_Halt'), 'rox-halt', session.o_halt.value, _('Attempting to halt the system...')) hbox.pack_end(button, False, True, 0) button = op_button(_('_Reboot'), g.STOCK_REFRESH, session.o_reboot.value, _('Attempting to restart the system...')) hbox.pack_end(button, False, True, 0) button = op_button(_('_Sleep'), 'rox-suspend', session.o_suspend.value, _('Attempting to enter suspend mode...'), self) hbox.pack_end(button, False, True, 0) vbox.pack_start( g.Label(_('Really logout?\n(unsaved data will be lost)')), True, True, 20) vbox.show_all() self.set_title(_('ROX-Session')) self.set_position(g.WIN_POS_CENTER) button = rox.ButtonMixed(g.STOCK_PREFERENCES, _("Session Settings")) button.show() self.add_action_widget(button, 1) self.add_button(g.STOCK_CANCEL, g.RESPONSE_CANCEL) button = rox.ButtonMixed(g.STOCK_QUIT, _("Logout")) button.set_flags(g.CAN_DEFAULT) button.show() self.add_action_widget(button, g.RESPONSE_YES) self.set_default_response(g.RESPONSE_YES)
def __init__(self, memo): g.MessageDialog.__init__( self, None, g.DIALOG_MODAL, g.MESSAGE_INFO, g.BUTTONS_NONE, _('Alarm set for %s:\n%s') % (time.ctime(memo.time), memo.message)) now = time.time() delay = memo.time - now earlyAlert = delay > 0 button = rox.ButtonMixed(g.STOCK_ZOOM_OUT, _('_Hide memo')) button.set_flags(g.CAN_DEFAULT) self.add_action_widget(button, HIDE) button.show() button = rox.ButtonMixed(g.STOCK_PROPERTIES, _('_Edit')) button.set_flags(g.CAN_DEFAULT) self.add_action_widget(button, EDIT) button.show() self.add_button(g.STOCK_OK, g.RESPONSE_OK) self.set_title('Memo:') self.set_modal(True) self.set_position(g.WIN_POS_CENTER) if earlyAlert: memo.state = Memo.EARLY else: memo.state = Memo.DONE from main import memo_list memo_list.notify_changed() self.memo = memo self.connect('response', self.response) self.set_default_response(g.RESPONSE_OK)
def _build_show_log(box, node, label): align = g.Alignment(0.5, 0.5, 0, 0) button = rox.ButtonMixed(g.STOCK_YES, _("Show message log")) align.add(button) button.connect('clicked', lambda b: log.show_log_window()) return [align]
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, memo=None): g.Dialog.__init__(self) self.set_has_separator(FALSE) self.add_button(g.STOCK_HELP, g.RESPONSE_HELP) if memo: self.add_button(g.STOCK_DELETE, DELETE) button = rox.ButtonMixed(g.STOCK_ZOOM_OUT, _('_Hide')) button.set_flags(g.CAN_DEFAULT) self.add_action_widget(button, HIDE) self.add_button(g.STOCK_CANCEL, g.RESPONSE_CANCEL) button = rox.ButtonMixed(g.STOCK_YES, _('_Set')) button.set_flags(g.CAN_DEFAULT) self.add_action_widget(button, g.RESPONSE_YES) self.memo = memo if memo: self.set_title(_("Edit memo:")) t = time.localtime(memo.time) else: self.set_title(_("Create memo:")) t = time.localtime(time.time() + 5 * 60) year, month, day, hour, minute, second, weekday, julian, dst = t self.hour = hour self.min = minute self.cal = g.Calendar() self.cal.select_month(month - 1, year) self.cal.select_day(day) at_box = self.make_at_box() self.advanced_box = self.make_advanced_box() text_frame = self.make_text_view() # Time/Date on the left, Text on the right hbox = g.HBox(FALSE, 0) self.vbox.pack_start(hbox, TRUE, TRUE, 0) self.vbox.pack_start(self.advanced_box, FALSE, TRUE, 0) # Date above time vbox = g.VBox(FALSE, 0) hbox.pack_start(vbox, FALSE, TRUE, 0) vbox.set_border_width(4) vbox.pack_start(self.cal, FALSE, TRUE, 0) spacer = g.Alignment() vbox.pack_start(spacer, FALSE, TRUE, 2) vbox.pack_start(at_box, FALSE, TRUE, 0) hbox.pack_start(text_frame, TRUE, TRUE, 0) self.vbox.show_all() if memo: buffer = self.text.get_buffer() try: buffer.insert_at_cursor(memo.message) except TypeError: buffer.insert_at_cursor(memo.message, -1) if memo and memo.at: self.at.set_active(TRUE) self.at.set_label(_('At')) self.advanced_box.set_sensitive(TRUE) if memo == None or memo.at == 0: self.at_box.hide() self.at.set_label(_('At') + "...") self.advanced_box.set_sensitive(FALSE) if memo: if memo.nosound: self.sound_choice.set_active(2) elif memo.soundfile is not None and memo.soundfile != "": self.sound_choice.set_active(1) self.sound_entry.set_filename(memo.soundfile) self.sound_entry.set_sensitive(TRUE) else: self.sound_choice.set_active(0) self.connect('response', self.response) self.text.grab_focus() self.set_default_response(g.RESPONSE_YES) self.connect('destroy', lambda w: refleak_bug_workaround.remove(self)) refleak_bug_workaround.append(self)
def add_button(dialog, stock_icon, action, response): button = rox.ButtonMixed(stock_icon, action) button.set_flags(g.CAN_DEFAULT) button.show() dialog.add_action_widget(button, response)
def __init__(self): g.Dialog.__init__(self) self.set_title(_('All memos')) self.set_has_separator(FALSE) self.add_button(g.STOCK_CLOSE, g.RESPONSE_CANCEL) frame = g.Frame() self.vbox.pack_start(frame, TRUE, TRUE, 0) frame.set_shadow_type(g.SHADOW_IN) hbox = g.HBox(FALSE, 0) frame.add(hbox) scroll = g.VScrollbar() hbox.pack_end(scroll, FALSE, TRUE, 0) self.list = g.TreeView(memo_list) hbox.pack_start(self.list, TRUE, TRUE, 0) self.list.set_scroll_adjustments(None, scroll.get_adjustment()) self.list.set_size_request(-1, 12) self.set_default_size(-1, 300) text = g.CellRendererText() toggle = g.CellRendererToggle() column = g.TreeViewColumn(_('Hide'), toggle, active=memos.HIDDEN) self.list.append_column(column) toggle.connect('toggled', lambda t, path: memo_list.toggle_hidden(path)) column = g.TreeViewColumn(_('Time'), text, text=memos.TIME) self.list.append_column(column) column = g.TreeViewColumn(_('Message'), text, text=memos.BRIEF) self.list.append_column(column) self.list.set_headers_visible(TRUE) sel = self.list.get_selection() sel.set_mode(g.SELECTION_MULTIPLE) def activate(view, path, column): memo = memo_list.get_memo_by_path(path) from EditBox import EditBox EditBox(memo).show() self.add_events(g.gdk.BUTTON_PRESS_MASK) self.list.connect('row-activated', activate) self.connect('response', self.response) self.set_default_response(g.RESPONSE_CANCEL) actions = g.HButtonBox() self.vbox.pack_start(actions, FALSE, TRUE, 0) actions.set_layout(g.BUTTONBOX_END) actions.set_border_width(5) actions.set_spacing(4) def new(b): from EditBox import EditBox EditBox().show() button = g.Button(stock=g.STOCK_NEW) actions.add(button) button.connect('clicked', new) 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() button = g.Button(stock=g.STOCK_DELETE) actions.add(button) button.connect('clicked', delete) def edit(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 len(memos) != 1: rox.alert(_('You need to select exactly one memo first!')) return from EditBox import EditBox EditBox(memos[0]).show() button = rox.ButtonMixed(g.STOCK_PROPERTIES, _('_Edit')) actions.add(button) button.connect('clicked', edit) self.show_all()
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)