def button_press(self, tv, bev): if bev.type == gtk.gdk.BUTTON_PRESS and bev.button == 1: x, y = tv.window_to_buffer_coords(tv.get_window_type(bev.window), int(bev.x), int(bev.y)) itr = tv.get_iter_at_location(x, y) if itr and self.link_style in itr.get_tags(): if not itr.begins_tag(self.link_style): itr.backward_to_tag_toggle(self.link_style) end = itr.copy() end.forward_to_tag_toggle(self.link_style) target = itr.get_text(end).strip() import browser browser.open_in_browser(target)
def __init__(self, policy, iface, env): dialog.Dialog.__init__(self) self.sf_group_id = 76468 self.sf_artifact_id = 929902 self.set_title(_('Report a Bug')) self.set_modal(True) self.set_has_separator(False) self.policy = policy self.frames = [] vbox = gtk.VBox(False, 4) vbox.set_border_width(10) self.vbox.pack_start(vbox, True, True, 0) self.set_default_size(gtk.gdk.screen_width() / 2, -1) def frame(title, contents, buffer): fr = gtk.Frame() label = gtk.Label('') label.set_markup('<b>%s</b>' % title) fr.set_label_widget(label) fr.set_shadow_type(gtk.SHADOW_NONE) vbox.pack_start(fr, True, True, 0) align = gtk.Alignment(0, 0, 1, 1) align.set_padding(0, 0, 16, 0) fr.add(align) align.add(contents) self.frames.append((title, buffer)) def text_area(text = None, mono = False): swin = gtk.ScrolledWindow() swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS) swin.set_shadow_type(gtk.SHADOW_IN) tv = gtk.TextView() tv.set_wrap_mode(gtk.WRAP_WORD) swin.add(tv) if text: tv.get_buffer().insert_at_cursor(text) if mono: tv.modify_font(pango.FontDescription('mono')) tv.set_accepts_tab(False) return swin, tv.get_buffer() actual = text_area() frame(_("What doesn't work?"), *actual) expected = text_area() frame(_('What did you expect to happen?'), *expected) errors_box = gtk.VBox(False, 0) errors_swin, errors_buffer = text_area(mono = True) errors_box.pack_start(errors_swin, True, True, 0) buttons = gtk.HButtonBox() buttons.set_layout(gtk.BUTTONBOX_START) errors_box.pack_start(buttons, False, True, 4) get_errors = gtk.Button(_('Run it now and record the output')) get_errors.connect('clicked', lambda button: self.collect_output(errors_buffer)) buttons.add(get_errors) frame(_('Are any errors or warnings displayed?'), errors_box, errors_buffer) if dialog.last_error: errors_buffer.insert_at_cursor(str(dialog.last_error)) environ = text_area(env, mono = True) frame(_('Information about your setup'), *environ) browse_url = 'http://sourceforge.net/tracker/?group_id=%d&atid=%d' % (self.sf_group_id, self.sf_artifact_id) location_hbox = gtk.HBox(False, 4) location_hbox.pack_start(gtk.Label(_('Bugs reports will be sent to:')), False, True, 0) if hasattr(gtk, 'LinkButton'): import browser url_box = gtk.LinkButton(browse_url) url_box.connect('clicked', lambda button: browser.open_in_browser(browse_url)) else: url_box = gtk.Label(browse_url) url_box.set_selectable(True) location_hbox.pack_start(url_box, False, True, 0) vbox.pack_start(location_hbox, False, True, 0) self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) self.set_default_response(gtk.RESPONSE_OK) def resp(box, r): if r == gtk.RESPONSE_OK: text = '' for title, buffer in self.frames: start = buffer.get_start_iter() end = buffer.get_end_iter() text += '%s\n\n%s\n\n' % (title, buffer.get_text(start, end).strip()) title = _('Bug for %s') % iface.get_name() self.report_bug(title, text) self.destroy() dialog.alert(self, _("Your bug report has been sent. Thank you."), type = gtk.MESSAGE_INFO) else: self.destroy() self.connect('response', resp) self.show_all()
def __init__(self, policy, iface, env): dialog.Dialog.__init__(self) self.sf_group_id = 76468 self.sf_artifact_id = 929902 self.set_title(_('Report a Bug')) self.set_modal(True) self.set_has_separator(False) self.policy = policy self.frames = [] vbox = gtk.VBox(False, 4) vbox.set_border_width(10) self.vbox.pack_start(vbox, True, True, 0) self.set_default_size(gtk.gdk.screen_width() / 2, -1) def frame(title, contents, buffer): fr = gtk.Frame() label = gtk.Label('') label.set_markup('<b>%s</b>' % title) fr.set_label_widget(label) fr.set_shadow_type(gtk.SHADOW_NONE) vbox.pack_start(fr, True, True, 0) align = gtk.Alignment(0, 0, 1, 1) align.set_padding(0, 0, 16, 0) fr.add(align) align.add(contents) self.frames.append((title, buffer)) def text_area(text=None, mono=False): swin = gtk.ScrolledWindow() swin.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_ALWAYS) swin.set_shadow_type(gtk.SHADOW_IN) tv = gtk.TextView() tv.set_wrap_mode(gtk.WRAP_WORD) swin.add(tv) if text: tv.get_buffer().insert_at_cursor(text) if mono: tv.modify_font(pango.FontDescription('mono')) tv.set_accepts_tab(False) return swin, tv.get_buffer() actual = text_area() frame(_("What doesn't work?"), *actual) expected = text_area() frame(_('What did you expect to happen?'), *expected) errors_box = gtk.VBox(False, 0) errors_swin, errors_buffer = text_area(mono=True) errors_box.pack_start(errors_swin, True, True, 0) buttons = gtk.HButtonBox() buttons.set_layout(gtk.BUTTONBOX_START) errors_box.pack_start(buttons, False, True, 4) get_errors = gtk.Button(_('Run it now and record the output')) get_errors.connect('clicked', lambda button: self.collect_output(errors_buffer)) buttons.add(get_errors) frame(_('Are any errors or warnings displayed?'), errors_box, errors_buffer) if dialog.last_error: errors_buffer.insert_at_cursor(str(dialog.last_error)) environ = text_area(env, mono=True) frame(_('Information about your setup'), *environ) browse_url = 'http://sourceforge.net/tracker/?group_id=%d&atid=%d' % ( self.sf_group_id, self.sf_artifact_id) location_hbox = gtk.HBox(False, 4) location_hbox.pack_start(gtk.Label(_('Bugs reports will be sent to:')), False, True, 0) if hasattr(gtk, 'LinkButton'): import browser url_box = gtk.LinkButton(browse_url) url_box.connect('clicked', lambda button: browser.open_in_browser(browse_url)) else: url_box = gtk.Label(browse_url) url_box.set_selectable(True) location_hbox.pack_start(url_box, False, True, 0) vbox.pack_start(location_hbox, False, True, 0) self.add_button(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL) self.add_button(gtk.STOCK_OK, gtk.RESPONSE_OK) self.set_default_response(gtk.RESPONSE_OK) def resp(box, r): if r == gtk.RESPONSE_OK: text = '' for title, buffer in self.frames: start = buffer.get_start_iter() end = buffer.get_end_iter() text += '%s\n\n%s\n\n' % (title, buffer.get_text( start, end).strip()) title = _('Bug for %s') % iface.get_name() self.report_bug(title, text) self.destroy() dialog.alert(self, _("Your bug report has been sent. Thank you."), type=gtk.MESSAGE_INFO) else: self.destroy() self.connect('response', resp) self.show_all()