class DiffLegendWindow(HIGDialog, object):
    def __init__(self, colors):
        # Shows colors and chars legend
        HIGDialog.__init__(self, title=_('Color Descriptions'),
                          buttons=(gtk.STOCK_OK, gtk.RESPONSE_ACCEPT))

        self.colors = colors
        self._create_widgets()
        self._pack_widgets()
        self._connect_widgets()

    def _create_widgets(self):
        self.table = HIGTable()
        
        self.unchanged_button = gtk.ColorButton(self.colors.unchanged)
        self.unchanged_label = gtk.Label(_("Property remained <b>U</b>nchanged"))
        
        self.added_button = gtk.ColorButton(self.colors.added)
        self.added_label = gtk.Label(_("Property was <b>A</b>dded"))
        
        self.modified_button = gtk.ColorButton(self.colors.modified)
        self.modified_label = gtk.Label(_("Property was <b>M</b>odified"))
        
        self.not_present_button = gtk.ColorButton(self.colors.not_present)
        self.not_present_label = gtk.Label(_("Property is <b>N</b>ot present"))

    def _pack_widgets(self):
        self.unchanged_label.set_use_markup(True)
        self.added_label.set_use_markup(True)
        self.modified_label.set_use_markup(True)
        self.not_present_label.set_use_markup(True)

        self.table.attach_label(self.unchanged_button, 0, 1, 0, 1)
        self.table.attach_entry(self.unchanged_label, 1, 2, 0, 1)

        self.table.attach_label(self.added_button, 0, 1, 1, 2)
        self.table.attach_entry(self.added_label, 1, 2, 1, 2)

        self.table.attach_label(self.modified_button, 0, 1, 2, 3)
        self.table.attach_entry(self.modified_label, 1, 2, 2, 3)

        self.table.attach_label(self.not_present_button, 0, 1, 3, 4)
        self.table.attach_entry(self.not_present_label, 1, 2, 3, 4)

        self.vbox.pack_start(self.table)
        self.vbox.show_all()

    def _connect_widgets(self):
        self.unchanged_button.connect("color-set", self.set_color, "unchanged")
        self.added_button.connect("color-set", self.set_color, "added")
        self.modified_button.connect("color-set", self.set_color, "modified")
        self.not_present_button.connect("color-set", self.set_color, "not_present")

    def set_color(self, widget, prop):
        self.colors.__setattr__(prop, widget.get_color())
Exemplo n.º 2
0
class CrashReport(HIGWindow):
    def __init__(self, summary, description):
        HIGWindow.__init__(self)
        gtk.Window.__init__(self)
        self.set_title(_('Crash Report'))
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)

        self.response_id = False

        self._create_widgets()
        self._pack_widgets()
        self._connect_widgets()

        self.summary = summary
        self.description = "\n----\n" + description

    def _create_widgets(self):
        self.vbox = HIGVBox()
        self.button_box = gtk.HButtonBox()

        self.email_label = gtk.Label(_("""\
An email address is optional. Sometimes we use it to get more information. If \
you provide an email address your report will be marked private so only \
project developers can read it.\
"""))
        self.email_entry = gtk.Entry()

        self.summary_entry = gtk.Entry()

        self.description_label = gtk.Label(_("\
What were you doing when the crash happened?\
"))
        self.description_scrolled = gtk.ScrolledWindow()
        self.description_text = gtk.TextView()

        self.bug_text = gtk.Label(_("""\
An unhandled exception has crashed Zenmap. This dialog allows you to tell us \
what you did to cause the crash and help us to fix it. Submitting the report \
will open a description of the new bug at the bug tracker. Feel free to edit \
the report to remove any identifying information such as your home directory.\
"""))

        self.btn_ok = gtk.Button(stock=gtk.STOCK_OK)
        self.btn_cancel = gtk.Button(stock=gtk.STOCK_CANCEL)

        self.hbox = HIGHBox()
        self.table = HIGTable()

    def _pack_widgets(self):
        self.description_label.set_line_wrap(True)
        self.description_label.set_alignment(0.0, 0.5)
        self.description_scrolled.add(self.description_text)
        self.description_scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.description_scrolled.set_size_request(400, 150)
        self.description_text.set_wrap_mode(gtk.WRAP_WORD)

        self.email_label.set_line_wrap(True)
        self.email_label.set_alignment(0.0, 0.5)

        self.bug_text.set_line_wrap(True)

        self.hbox.set_border_width(12)
        self.vbox.set_border_width(6)

        self.table.attach_label(gtk.Label(_("Summary")), 0, 1, 0, 1)
        self.table.attach_entry(self.summary_entry, 1, 2, 0, 1)

        self.table.attach_entry(self.description_label, 0, 2, 1, 2)
        self.table.attach_entry(self.description_scrolled, 0, 2, 2, 3)

        self.table.attach(self.email_label, 0, 2, 3, 4)
        self.table.attach_label(gtk.Label(_("Email")), 0, 1, 4, 5)
        self.table.attach_entry(self.email_entry, 1, 2, 4, 5)

        self.hbox._pack_expand_fill(self.bug_text)

        self.button_box.set_layout(gtk.BUTTONBOX_END)
        self.button_box.pack_start(self.btn_ok)
        self.button_box.pack_start(self.btn_cancel)

        self.vbox._pack_noexpand_nofill(self.hbox)
        self.vbox._pack_expand_fill(self.table)
        self.vbox._pack_noexpand_nofill(self.button_box)
        self.add(self.vbox)

    def _connect_widgets(self):
        self.btn_ok.connect("clicked", self.send_report)
        self.btn_cancel.connect("clicked", self.close)
        self.connect("delete-event", self.close)

    def send_report(self, widget):
        bug_register = BugRegister()
        description_text = self.description
        private = False
        if self.email != "":
            description_text += "\n\n" + self.email
            private = True
        report_url = bug_register.get_report_url(self.summary,
            description_text, private = private)

        # First we try reporting the bug with a web browser because that gives
        # better feedback on what happened. If that doesn't work try with
        # urllib2.
        try:
            webbrowser.open(report_url)
        except webbrowser.Error:
            try:
                urllib2.urlopen(report_url)
                ok_dialog = HIGAlertDialog(type=gtk.MESSAGE_INFO,
                    message_format=_("Bug reported"),
                    secondary_text=_("The bug was successfully reported."))
                ok_dialog.run()
                ok_dialog.destroy()
            except urllib2.URLError, e:
                cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
                    message_format=_("Bug not reported"),
                    secondary_text=_("This error occurred while trying to report the bug:\n\n" + str(e)))
                cancel_dialog.run()
                cancel_dialog.destroy()

        self.close()
class CrashReport(HIGWindow):
    def __init__(self, summary, description):
        HIGWindow.__init__(self)
        gtk.Window.__init__(self)
        self.set_title(_('Crash Report'))
        self.set_position(gtk.WIN_POS_CENTER_ALWAYS)
        
        self.response_id = False
        
        self._create_widgets()
        self._pack_widgets()
        self._connect_widgets()

        self.summary = summary
        self.description = description

    def _create_widgets(self):
        self.vbox = HIGVBox()
        self.button_box = gtk.HButtonBox()
        
        self.email_label = HIGHintSectionLabel(_("Email"),
                                               _("\
Optional. We occasionally contact the reporters of crashes in order to get \
more information."))
        self.email_entry = gtk.Entry()

        self.description_label = gtk.Label(_("\
At the top of this form please write what you were doing when the crash \
happened, as well as any other information you think is relevant."))
        self.description_scrolled = gtk.ScrolledWindow()
        self.description_text = gtk.TextView()

        self.bug_icon = gtk.Image()
        self.bug_text = gtk.Label(_("""\
This Bug Report dialog allows you to easily tell us about a problem that you \
may have found in %s. Doing so, you help us to help you, by fixing and \
improving %s faster than usual. Submitting the report will open a description \
of the new bug at the bug tracker.\
""" % (APP_DISPLAY_NAME, APP_DISPLAY_NAME)))

        self.btn_ok = gtk.Button(stock=gtk.STOCK_OK)
        self.btn_cancel = gtk.Button(stock=gtk.STOCK_CANCEL)

        self.hbox = HIGHBox()
        self.table = HIGTable()

    def _pack_widgets(self):
        self.description_label.set_line_wrap(True)
        self.description_label.set_alignment(0.0, 0.5)
        self.description_scrolled.add(self.description_text)
        self.description_scrolled.set_policy(gtk.POLICY_AUTOMATIC, gtk.POLICY_AUTOMATIC)
        self.description_scrolled.set_size_request(400, 150)
        self.description_text.set_wrap_mode(gtk.WRAP_WORD)

        self.bug_icon.set_from_stock(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_DIALOG)
        self.bug_icon.set_padding(10, 0)
        self.bug_text.set_line_wrap(True)

        self.hbox.set_border_width(12)
        self.vbox.set_border_width(6)
        
        self.table.attach_label(self.email_label, 0, 1, 0, 1)
        self.table.attach_entry(self.email_entry, 1, 2, 0, 1)

        self.table.attach_entry(self.description_label, 0, 2, 1, 2)
        self.table.attach_entry(self.description_scrolled, 0, 2, 2, 3)

        self.hbox._pack_noexpand_nofill(self.bug_icon)
        self.hbox._pack_expand_fill(self.bug_text)

        self.button_box.set_layout(gtk.BUTTONBOX_END)
        self.button_box.pack_start(self.btn_ok)
        self.button_box.pack_start(self.btn_cancel)
        
        self.vbox._pack_noexpand_nofill(self.hbox)
        self.vbox._pack_expand_fill(self.table)
        self.vbox._pack_noexpand_nofill(self.button_box)
        self.add(self.vbox)

    def _connect_widgets(self):
        self.btn_ok.connect("clicked", self.send_report)
        self.btn_cancel.connect("clicked", self.close)
        self.connect("delete-event", self.close)

    def send_report(self, widget):
        bug_register = BugRegister()
        report_url = bug_register.get_report_url(self.summary, "%s\n\nEmail: %s" % (self.description, self.email))

        # First we try reporting the bug with a web browser because that gives
        # better feedback on what happened. If that doesn't work try with
        # urllib2.
        try:
            webbrowser.open(report_url)
        except webbrowser.Error:
            try:
                urllib2.urlopen(report_url)
                ok_dialog = HIGAlertDialog(type=gtk.MESSAGE_INFO,
                    message_format=_("Bug reported"),
                    secondary_text=_("The bug was successfully reported."))
                ok_dialog.run()
                ok_dialog.destroy()
            except urllib2.URLError, e:
                cancel_dialog = HIGAlertDialog(type=gtk.MESSAGE_ERROR,
                    message_format=_("Bug not reported"),
                    secondary_text=_("This error occurred while trying to report the bug:\n\n" + str(e)))
                cancel_dialog.run()
                cancel_dialog.destroy()

        self.close()