def __init__(self): self.tooltip = g.Tooltips() if tip.value == "": self.tooltip.disable() self.vbox = g.VBox(spacing=2) self.line1_label = g.Label("") if line1.value != "": self.vbox.add(self.line1_label) self.line2_label = g.Label("") if line2.value != "": self.vbox.add(self.line2_label) self.set_border_width(5) self.add(self.vbox) rox.app_options.add_notify(self.options_changed) self.add_events(g.gdk.BUTTON_PRESS_MASK) self.connect("button-press-event", self.button_press) self.connect("destroy", self.destroyed) self.update_clock() self.timeout = gobject.timeout_add(1000, self.update_clock) self.show_all()
def build_location_option_widget(box, node, label, option): label_widget = g.Label(label) value_widget = g.Label() button = g.Button(stock=g.STOCK_FIND) box.may_add_tip(button, node) box.handlers[option] = (lambda: str(value_widget.get_label()), lambda: value_widget.set_label(option.value)) def button_clicked(button): def dialog_response(dialog, response): if response == g.RESPONSE_ACCEPT: selection = dialog.result_list.get_selection() model, it = selection.get_selected() if it: code = model.get_value(it, 1) if code: name = str(model.get_value(it, 0)) value_widget.set_label("%s (%s)" % (str(code), name)) dialog.destroy() box.check_widget(option) dialog = LocationSearchDialog() dialog.connect('response', dialog_response) dialog.show() button.connect('clicked', button_clicked) hbox = g.HBox(spacing = 5) hbox.pack_start(label_widget) hbox.pack_start(value_widget) hbox.pack_start(button) return [hbox]
def build_numentry(self, node, label, option): """<numentry name='...' label='...' min='0' max='100' step='1'>Tooltip</numentry>. Lets the user choose a number from min to max.""" minv = int(node.getAttribute('min')) maxv = int(node.getAttribute('max')) step = node.getAttribute('step') if step: step = int(step) else: step = 1 unit = self._(node.getAttribute('unit')) hbox = g.HBox(False, 4) if label: widget = g.Label(label) widget.set_alignment(1.0, 0.5) hbox.pack_start(widget, False, True, 0) spin = g.SpinButton(g.Adjustment(minv, minv, maxv, step)) spin.set_width_chars(max(len(str(minv)), len(str(maxv)))) hbox.pack_start(spin, False, True, 0) self.may_add_tip(spin, node) if unit: hbox.pack_start(g.Label(unit), False, True, 0) self.handlers[option] = (lambda: str(spin.get_value()), lambda: spin.set_value(option.int_value)) spin.connect('value-changed', lambda w: self.check_widget(option)) return [hbox]
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 do_entry(self, node, label, option): "Helper function for entry and secretentry widgets" box = g.HBox(False, 4) entry = g.Entry() if label: label_wid = g.Label(label) label_wid.set_alignment(1.0, 0.5) box.pack_start(label_wid, False, True, 0) box.pack_start(entry, True, True, 0) else: box = None self.may_add_tip(entry, node) entry.connect('changed', lambda e: self.check_widget(option)) def get(): return entry.get_chars(0, -1) def set(): entry.set_text(option.value) self.handlers[option] = (get, set) return (entry, [box or entry])
def build_label(self, node, label): widget = g.Label(self._(data(node))) help = int(node.getAttribute('help') or '0') if help: widget.set_alignment(0, 0.5) else: widget.set_alignment(0, 1) widget.set_justify(g.JUSTIFY_LEFT) widget.set_line_wrap(True) if help: hbox = g.HBox(False, 4) image = g.Image() image.set_from_stock(g.STOCK_DIALOG_INFO, g.ICON_SIZE_BUTTON) align = g.Alignment(0, 0, 0, 0) align.add(image) hbox.pack_start(align, False, True, 0) hbox.pack_start(widget, False, True, 0) spacer = g.EventBox() spacer.set_size_request(6, 6) return [hbox, spacer] return [widget]
def make_text_view(self): # The TextView / time of day settings vbox = g.VBox(FALSE, 0) l = g.Label(_('Message:')) l.set_alignment(0, 1) l.set_padding(0, 4) vbox.pack_start(l, FALSE, TRUE, 0) frame = g.Frame() vbox.pack_start(frame, TRUE, TRUE, 0) frame.set_shadow_type(g.SHADOW_IN) hbox = g.HBox(FALSE, 0) frame.add(hbox) text = g.TextView() hbox.pack_start(text, TRUE, TRUE, 0) text.set_wrap_mode(g.WRAP_WORD) scrollbar = g.VScrollbar() adj = scrollbar.get_adjustment() text.set_scroll_adjustments(None, adj) hbox.pack_start(scrollbar, FALSE, TRUE, 0) text.set_size_request(200, 200) self.text = text return vbox
def make_at_box(self): # The time of day setting hbox = g.HBox(FALSE, 0) self.at = g.CheckButton(_('At')) hbox.pack_start(self.at, FALSE, TRUE, 4) self.at.connect('toggled', self.at_toggled) at_box = g.HBox(FALSE, 0) self.at_box = at_box hbox.pack_start(at_box, FALSE, TRUE, 0) arrow = Arrow(g.ARROW_LEFT, self.adj_time, -60) at_box.pack_start(arrow, FALSE, TRUE, 0) arrow = Arrow(g.ARROW_RIGHT, self.adj_time, 60) at_box.pack_start(arrow, FALSE, TRUE, 0) self.time_display = g.Label(str_time(self.hour, self.min)) self.time_display.set_padding(4, 0) frame = g.Frame() frame.add(self.time_display) at_box.pack_start(frame, FALSE, TRUE, 0) arrow = Arrow(g.ARROW_LEFT, self.adj_time, -1) at_box.pack_start(arrow, FALSE, TRUE, 0) arrow = Arrow(g.ARROW_RIGHT, self.adj_time, 1) at_box.pack_start(arrow, FALSE, TRUE, 0) return hbox
def build_filechooser(self, node, label, option): """<filechooser name='...' label='...'/>Tooltip</filechooser>. Lets the user choose a file (using a GtkFileChooser or by drag-and-drop). Note: requires GTK >= 2.6 """ filebutton = g.FileChooserButton(label) eb = g.EventBox() eb.add(filebutton) self.may_add_tip(eb, node) clearbutton = g.Button(stock=g.STOCK_CLEAR) hbox = g.HBox(False, 4) if label: hbox.pack_start(g.Label(label + ":"), False, True, 0) hbox.pack_start(eb, True, True, 0) hbox.pack_start(clearbutton, False, True, 0) self.handlers[option] = (lambda: filebutton.get_filename(), lambda: filebutton.set_filename(option.value)) filebutton.connect('selection-changed', lambda w: self.check_widget(option)) def clear(w): filebutton.set_filename("") self.check_widget(option) clearbutton.connect('clicked', clear) return [hbox or eb]
def op_button(text, stock, command, message, dialog=None): button = g.Button() hbox = g.HBox(False, 0) button.add(hbox) image = g.Image() image.set_from_stock(stock, g.ICON_SIZE_BUTTON) hbox.pack_start(image, False, True, 4) label = g.Label('') label.set_text_with_mnemonic(text) label.set_alignment(0, 0.5) hbox.pack_start(label, True, True, 0) # No need for clickable buttons if no command is set tmp = command.strip() if tmp: def invoke(button): print >> sys.stderr, message os.system(command) if dialog: dialog.response(g.RESPONSE_ACCEPT) button.connect('clicked', invoke) else: button.set_sensitive(False) button.unset_flags(g.CAN_FOCUS) return button
def make_sized_label(self, label, suffix=""): """Create a GtkLabel and add it to the current size-group, if any""" widget = g.Label(label) if self.current_size_group: widget.set_alignment(1.0, 0.5) group = self.get_size_group(self.current_size_group + suffix) group.add_widget(widget) return widget
def __init__(self, option_box, option, title): g.Button.__init__(self) self.option_box = option_box self.option = option self.title = title self.label = g.Label('<font>') self.add(self.label) self.dialog = None self.connect('clicked', self.clicked)
def do_box(self, node, label, widget): "Helper function for building hbox, vbox and frame widgets." if label: widget.pack_start(g.Label(label), False, True, 4) for child in node.childNodes: if child.nodeType == Node.ELEMENT_NODE: self.build_widget(child, widget) return [widget]
def build_colour(self, node, label, option): "<colour name='...' label='...'>Tooltip</colour>" button = ColourButton(self, option, label) self.may_add_tip(button, node) hbox = g.HBox(False, 4) hbox.pack_start(g.Label(label), False, True, 0) hbox.pack_start(button, False, True, 0) self.handlers[option] = (button.get, button.set) return [hbox]
def __init__(self, log): g.Window.__init__(self, g.WINDOW_POPUP) #self.set_resizable(False) self.set_name('log_window') self.realize() self.add_events(g.gdk.BUTTON_PRESS_MASK) self.connect('button-press-event', self.clicked) self.log = log self.label = g.Label(buffer) self.label.set_alignment(0.0, 0.0) self.add(self.label) #label.add_events(g.gdk.BUTTON_PRESS_MASK) self.label.show()
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 build_menu(self, node, label, option): """Build an OptionMenu widget, only one item of which may be selected. <menu name='...' label='...'> <item value='...' label='...'/> <item value='...' label='...'/> </menu>""" values = [] option_menu = g.OptionMenu() menu = g.Menu() option_menu.set_menu(menu) if label: box = g.HBox(False, 4) label_wid = g.Label(label) label_wid.set_alignment(1.0, 0.5) box.pack_start(label_wid, False, True, 0) box.pack_start(option_menu, True, True, 0) else: box = None #self.may_add_tip(option_menu, node) for item in node.getElementsByTagName('item'): value = item.getAttribute('value') assert value label_item = item.getAttribute('label') or value menu.append(g.MenuItem(label_item)) values.append(value) option_menu.connect('changed', lambda e: self.check_widget(option)) def get(): return values[option_menu.get_history()] def set(): try: option_menu.set_history(values.index(option.value)) except ValueError: print "Value '%s' not in combo list" % option.value self.handlers[option] = (get, set) return [box or option_menu]
def build_i18n_message(box, node, label): widget = g.Label( _("""Note that you must save your choices, log out and log back in for the new language setting to take full effect.""")) widget.set_alignment(0, 0.5) widget.set_justify(g.JUSTIFY_LEFT) widget.set_line_wrap(True) hbox = g.HBox(False, 4) image = g.image_new_from_stock(g.STOCK_DIALOG_INFO, g.ICON_SIZE_BUTTON) align = g.Alignment(0, 0, 0, 0) align.add(image) hbox.pack_start(align, False, True, 0) hbox.pack_start(widget, False, True, 0) return [hbox]
def build_section(self, section, parent): """Create a new page for the notebook and a new entry in the sections tree, and build all the widgets inside the page.""" page = g.VBox(False, 4) page.set_border_width(4) self.notebook.append_page(page, g.Label('unused')) iter = self.sections.append(parent) self.sections.set(iter, 0, self._(section.getAttribute('title')), 1, self.notebook.page_num(page)) for node in section.childNodes: if node.nodeType != Node.ELEMENT_NODE: continue name = node.localName if name == 'section': self.build_section(node, iter) else: self.build_widget(node, page) page.show_all()
def choose_wm(message): box = rox.Dialog('Choose a window manager', None, g.DIALOG_MODAL | g.DIALOG_NO_SEPARATOR) box.add_button(g.STOCK_CLOSE, g.RESPONSE_CANCEL) box.add_button(g.STOCK_EXECUTE, g.RESPONSE_OK) box.set_position(g.WIN_POS_CENTER) box.vbox.pack_start(g.Label(message), True, True, 0) box.set_default_response(g.RESPONSE_OK) entry = g.Entry() entry.set_activates_default(True) box.vbox.pack_start(entry, False, True, 0) entry.set_text(get_window_manager()[0] or '') box.vbox.show_all() if box.run() == int(g.RESPONSE_OK): settings.settings.set('ROX/WindowManager', entry.get_text()) box.destroy() start() else: box.destroy()
def build_unknown(self, node, label, option=None): return [g.Label("Unknown widget type <%s>" % node.localName)]
def __init__(self, program, purpose, version, author, website): g.Dialog.__init__(self) self.website = website def close(iw, event=None, data=None): iw.hide() self.connect("delete_event", close) hbox = g.HBox() self.vbox.pack_start(hbox) hbox.show() try: path = os.path.join(rox.app_dir, '.DirIcon') pixbuf = g.gdk.pixbuf_new_from_file(path) icon = g.Image() icon.set_from_pixbuf(pixbuf) hbox.pack_start(icon) icon.show() except: #rox.report_exception() pass table = g.Table(5, 2) hbox.pack_start(table) label = g.Label("Program") table.attach(label, 0, 1, 0, 1) frame = g.Frame() frame.set_shadow_type(g.SHADOW_IN) table.attach(frame, 1, 2, 0, 1) label = g.Label(program or '') frame.add(label) label = g.Label("Purpose") table.attach(label, 0, 1, 1, 2) frame = g.Frame() frame.set_shadow_type(g.SHADOW_IN) table.attach(frame, 1, 2, 1, 2) label = g.Label(purpose or '') frame.add(label) label = g.Label("Version") table.attach(label, 0, 1, 2, 3) frame = g.Frame() frame.set_shadow_type(g.SHADOW_IN) table.attach(frame, 1, 2, 2, 3) label = g.Label(version or '') frame.add(label) label = g.Label("Authors") table.attach(label, 0, 1, 3, 4) frame = g.Frame() frame.set_shadow_type(g.SHADOW_IN) table.attach(frame, 1, 2, 3, 4) label = g.Label(author or '') frame.add(label) label = g.Label("Web site") table.attach(label, 0, 1, 5, 6) if website: button = g.Button(website) table.attach(button, 1, 2, 5, 6) def goto_website(widget, iw): webbrowser.open(iw.website) button.connect("clicked", goto_website, self) else: frame = g.Frame() frame.set_shadow_type(g.SHADOW_IN) table.attach(frame, 1, 2, 5, 6) hbox = self.action_area button = g.Button(stock=g.STOCK_CLOSE) hbox.pack_start(button) def dismiss(widget, iw): iw.hide() button.connect("clicked", dismiss, self) button.show() self.vbox.show_all()
def build_fixedlist(self, node, label, option): """<fixedlist name='...' label='...' selection='single|none|multiple'>Tooltip<listitem label='...'/><listitem label='...'/></fixedlist>""" select = str_attr(node, 'selection', 'single') cont = g.VBox(False, 4) cont._rox_lib_expand = True if label: label_wid = g.Label(label) cont.pack_start(label_wid, False, True, 0) label_wid.show() swin = g.ScrolledWindow() swin.set_border_width(4) swin.set_policy(g.POLICY_NEVER, g.POLICY_ALWAYS) swin.set_shadow_type(g.SHADOW_IN) #swin.set_size_request(-1, 128) cont.pack_start(swin, True, True, 0) model = g.ListStore(str) view = g.TreeView(model) swin.add(view) selection = view.get_selection() if select == 'none': selection.set_mode(g.SELECTION_NONE) elif select == 'multiple': selection.set_mode(g.SELECTION_MULTIPLE) else: selection.set_mode(g.SELECTION_SINGLE) select = 'single' def sel_changed(sel, box): box.check_widget(option) selection.connect('changed', sel_changed, self) cell = g.CellRendererText() column = g.TreeViewColumn('', cell, text=0) view.append_column(column) for item in node.getElementsByTagName('listitem'): label = item.getAttribute('label') iter = model.append() model.set(iter, 0, label) self.may_add_tip(swin, node) def make_sel(model, path, iter, l): l.append(str(model.get_value(iter, 0))) def get(): mode = view.get_selection().get_mode() if mode == int(g.SELECTION_NONE): return [] elif mode == int(g.SELECTION_SINGLE): model, iter = view.get_selection().get_selected() return [str(model.get_value(iter, 0))] v = [] view.get_selection().selected_foreach(make_sel, v) return v def set(): sel = view.get_selection() mode = sel.get_mode() sel.unselect_all() for v in option.list_value: iter = model.get_iter_first() while iter: if v == model.get_value(iter, 0): sel.select_iter(iter) break iter = model.iter_next(iter) self.handlers[option] = (get, set) return [cont]
def set_weather(self, weather): if self.table: self.box.remove(self.table) self.table = g.Table(8, self.ndays * 2) self.box.add(self.table) self.weather = weather self.set_title( (_("Weather Forecast for ") + self.weather.info.location)) nday = 0 for forecast in self.weather.forecasts[:self.ndays]: label = g.Label() label.set_markup("<b>" + _(forecast.day) + "</b>") self.table.attach(label, nday * 2, nday * 2 + 2, 0, 1) label = g.Label() label.set_markup("<b>" + _(forecast.date) + "</b>") self.table.attach(label, nday * 2, nday * 2 + 2, 1, 2) label = g.Label(forecast.low + " - " + forecast.hi + " °" + self.weather.units.temperature) self.table.attach(label, nday * 2, nday * 2 + 2, 2, 3) image = g.Image() pixbuf = get_weather_icon(forecast.day_info.icon) image.set_from_pixbuf(pixbuf) event_box = g.EventBox() event_box.add(image) tooltips.set_tip(event_box, _(forecast.day_info.description)) self.table.attach(event_box, nday * 2, nday * 2 + 1, 3, 4) label = g.Label(_(forecast.day_info.wind_dir)) event_box = g.EventBox() event_box.add(label) tooltips.set_tip(event_box, _("Wind direction")) self.table.attach(event_box, nday * 2, nday * 2 + 1, 4, 5) label = g.Label( "%s %s" % (forecast.day_info.wind_speed, self.weather.units.speed)) event_box = g.EventBox() event_box.add(label) tooltips.set_tip(event_box, _("Wind speed")) self.table.attach(event_box, nday * 2, nday * 2 + 1, 5, 6) label = g.Label(forecast.day_info.humidity + "%") event_box = g.EventBox() event_box.add(label) tooltips.set_tip(event_box, _("Humidity")) self.table.attach(event_box, nday * 2, nday * 2 + 1, 6, 7) label = g.Label(forecast.day_info.rain + " %") event_box = g.EventBox() event_box.add(label) tooltips.set_tip(event_box, _("Rain")) self.table.attach(event_box, nday * 2, nday * 2 + 1, 7, 8) image = g.Image() pixbuf = get_weather_icon(forecast.night_info.icon) image.set_from_pixbuf(pixbuf) event_box = g.EventBox() event_box.add(image) tooltips.set_tip(event_box, _(forecast.night_info.description)) self.table.attach(event_box, nday * 2 + 1, nday * 2 + 2, 3, 4) label = g.Label(_(forecast.night_info.wind_dir)) event_box = g.EventBox() event_box.add(label) tooltips.set_tip(event_box, _("Wind direction")) self.table.attach(event_box, nday * 2 + 1, nday * 2 + 2, 4, 5) label = g.Label( "%s %s" % (forecast.night_info.wind_speed, self.weather.units.speed)) event_box = g.EventBox() event_box.add(label) tooltips.set_tip(event_box, _("Wind speed")) self.table.attach(event_box, nday * 2 + 1, nday * 2 + 2, 5, 6) label = g.Label(forecast.night_info.humidity + "%") event_box = g.EventBox() event_box.add(label) tooltips.set_tip(event_box, _("Humidity")) self.table.attach(event_box, nday * 2 + 1, nday * 2 + 2, 6, 7) label = g.Label(forecast.night_info.rain + " %") event_box = g.EventBox() event_box.add(label) tooltips.set_tip(event_box, _("Rain")) self.table.attach(event_box, nday * 2 + 1, nday * 2 + 2, 7, 8) nday += 1 self.box.show_all()
def __init__(self, memo_list): rox.Window.__init__(self) MenuWindow.__init__(self) self.set_wmclass('Memo', 'Memo') self.set_title('Memo') self.set_resizable(False) if hasattr(self, 'set_deletable'): self.set_deletable(False) #self.set_type_hint(g.gdk.WINDOW_TYPE_HINT_DIALOG) self.tips = g.Tooltips() if main_sticky.int_value: self.stick() self.memo_list = memo_list self.last_day = None self.prime_in_progress = False vbox = g.VBox(FALSE, 0) self.add(vbox) hbox = g.HBox(False, 0) vbox.pack_start(hbox, expand = False) self.time_label = g.Label('') self.time_button = g.Button() self.time_button.add(self.time_label) self.time_button.unset_flags(g.CAN_FOCUS) hbox.pack_start(self.time_button, expand = True) hbox.pack_start(timer.TimerButton(), expand = False) self.list = g.TreeView(memo_list.visible) vbox.pack_start(self.list, expand = TRUE) self.list.unset_flags(g.CAN_FOCUS) cell = g.CellRendererText() column = g.TreeViewColumn('Time', cell, text = 0) cell.set_property('xalign', 1) self.list.append_column(column) cell = g.CellRendererText() column = g.TreeViewColumn('Message', cell, text = 1) self.list.append_column(column) self.list.set_headers_visible(FALSE) sel = self.list.get_selection() sel.set_mode(g.SELECTION_NONE) def activate(view, path, column): memo = memo_list.visible.get_memo_by_path(path) from EditBox import EditBox EditBox(memo).show() self.add_events(g.gdk.BUTTON_PRESS_MASK) self.list.connect('button-press-event', self.button_press) self.list.connect('row-activated', activate) self.time_button.add_events(g.gdk.BUTTON1_MOTION_MASK) self.time_button.connect('button-press-event', self.button_press) self.time_button.connect('motion-notify-event', self.button_motion) self.time_button.connect('clicked', self.time_button_clicked) self.update() gobject.timeout_add(10000, self.update) # Update clock self.timeout = None # For next alarm self.alert_box = None self.show_all_box = None self.save_box = None self.prime() # If we had more than one window, we'd need a remove too... memo_list.connect("MemoListChanged", self.prime) app_options.add_notify(self.options_changed) vbox.show_all()
def __init__(self, vertical=False): rox.setup_app_options("Weather", 'Options.xml', "dtomas") self.o_update_interval = options.Option("update_interval", 15) self.o_location = options.Option("location_code", "GMXX0049 (Hamburg, Germany)") self.o_units = options.Option("units", "m") self.o_forecast_days = options.Option("forecast_days", 4) rox.app_options.notify() self.forecast_window = None if vertical: box = g.VBox() else: box = g.HBox() self.image = g.Image() self.label = g.Label("n.a.") box.pack_start(self.image) box.pack_start(self.label) box.set_border_width(2) self.add(box) self.size = 0 self.set_image('-') self.menu = g.Menu() self.weather = Weather() item = g.ImageMenuItem(g.STOCK_HELP) item.connect("activate", self.show_help) self.menu.add(item) item = g.ImageMenuItem(g.STOCK_DIALOG_INFO) item.connect("activate", self.show_info) self.menu.add(item) self.menu.append(g.SeparatorMenuItem()) item = g.ImageMenuItem(_("Forecast")) item.get_image().set_from_file( os.path.join(rox.app_dir, 'icons', 'forecast.png')) item.connect("activate", self.show_forecast) self.menu.append(item) item = g.ImageMenuItem(g.STOCK_REFRESH) item.connect("activate", self.update_now) self.menu.append(item) self.menu.append(g.SeparatorMenuItem()) item = g.ImageMenuItem(g.STOCK_PREFERENCES) item.connect("activate", self.show_options) self.menu.append(item) self.menu.append(g.SeparatorMenuItem()) item = g.ImageMenuItem(g.STOCK_QUIT) item.connect("activate", self.quit) self.menu.append(item) self.menu.show_all() self.add_events(g.gdk.BUTTON_PRESS_MASK) self.connect("button-press-event", self.button_pressed) self.connect("destroy", self.destroyed) rox.app_options.add_notify(self.options_changed) self.image_resizing = False tooltips.set_tip(self, 'n.a.') self.update_event = 0 self.connect('size-allocate', self.size_allocate) self.connect_after('map-event', self.map_event)
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, 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()