source: src/mlx/gui/bugreport.py@ 919:2ce8ca39525b

python3
Last change on this file since 919:2ce8ca39525b was 919:2ce8ca39525b, checked in by István Váradi <ivaradi@…>, 4 years ago

Ran 2to3

File size: 5.0 KB
Line 
1
2from .common import *
3
4from mlx.i18n import xstr
5import mlx.const as const
6import mlx.config as config
7
8import os
9
10#------------------------------------------------------------------------------
11
12## @package mlx.gui.bugreport
13#
14# The bug report dialog
15#
16# This module implements the bug report dialog.
17
18#------------------------------------------------------------------------------
19
20class BugReportDialog(gtk.Dialog):
21 """The dialog to report a bug."""
22 def __init__(self, gui):
23 super(BugReportDialog, self).__init__(WINDOW_TITLE_BASE + " - " +
24 xstr("bugreport_title"),
25 gui.mainWindow,
26 DIALOG_MODAL)
27
28 self.add_button(xstr("button_cancel"), RESPONSETYPE_REJECT)
29 self._sendButton = self.add_button(xstr("button_send"), RESPONSETYPE_ACCEPT)
30 self._sendButton.set_can_default(True)
31 self._gui = gui
32
33 contentArea = self.get_content_area()
34
35 contentAlignment = gtk.Alignment(xalign = 0.5, yalign = 0.5,
36 xscale = 0.0, yscale = 0.0)
37 contentAlignment.set_padding(padding_top = 4, padding_bottom = 16,
38 padding_left = 8, padding_right = 8)
39
40 contentArea.pack_start(contentAlignment, False, False, 0)
41
42 contentVBox = gtk.VBox()
43 contentAlignment.add(contentVBox)
44
45 label = gtk.Label(xstr("bugreport_summary"))
46 label.set_use_underline(True)
47 label.set_alignment(0.0, 0.5)
48
49 contentVBox.pack_start(label, False, False, 4)
50
51 self._summary = summary = gtk.Entry()
52 summary.connect("changed", self._summaryChanged)
53 summary.set_tooltip_text(xstr("bugreport_summary_tooltip"))
54 summary.set_width_chars(80)
55 label.set_mnemonic_widget(summary)
56 contentVBox.pack_start(summary, True, True, 4)
57
58 label = gtk.Label(xstr("bugreport_description"))
59 label.set_use_underline(True)
60 label.set_alignment(0.0, 0.5)
61
62 contentVBox.pack_start(label, False, False, 4)
63
64 self._description = description = gtk.TextView()
65 description.set_tooltip_text(xstr("bugreport_description_tooltip"))
66 description.set_wrap_mode(WRAP_WORD)
67 label.set_mnemonic_widget(description)
68
69 scrolledWindow = gtk.ScrolledWindow()
70 scrolledWindow.add(description)
71 scrolledWindow.set_size_request(-1, 200)
72 scrolledWindow.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC)
73 scrolledWindow.set_shadow_type(SHADOW_IN)
74
75 alignment = gtk.Alignment(xalign = 0.5, yalign = 0.0, xscale = 1.0, yscale = 1.0)
76 alignment.add(scrolledWindow)
77
78 contentVBox.pack_start(alignment, True, True, 4)
79
80 emailBox = gtk.HBox()
81 contentVBox.pack_start(emailBox, False, False, 4)
82
83 label = gtk.Label(xstr("bugreport_email"))
84 label.set_use_underline(True)
85 label.set_alignment(0.0, 0.5)
86
87 emailBox.pack_start(label, False, False, 0)
88
89 alignment = gtk.Alignment()
90 emailBox.pack_start(alignment, False, False, 8)
91
92 self._email = email = gtk.Entry()
93 email.set_tooltip_text(xstr("bugreport_email_tooltip"))
94 label.set_mnemonic_widget(email)
95 emailBox.pack_start(email, True, True, 0)
96
97
98 def run(self):
99 """Run the checklist editor dialog."""
100 self.set_sensitive(True)
101 self._description.set_sensitive(True)
102 self._updateButtons()
103 self._sendButton.grab_default()
104 self.show_all()
105 response = super(BugReportDialog, self).run()
106
107 print("response", response, RESPONSETYPE_ACCEPT)
108 if response==RESPONSETYPE_ACCEPT:
109 self._send()
110 else:
111 self.hide()
112
113 def _summaryChanged(self, entry):
114 """Called when the summary has changed."""
115 self._updateButtons()
116
117 def _updateButtons(self):
118 """Update the sensitivity of the buttoms."""
119 self._sendButton.set_sensitive(self._summary.get_text()!="")
120
121 def _send(self):
122 """Send the bug report."""
123 descriptionBuffer = self._description.get_buffer()
124 description = \
125 descriptionBuffer.get_text(descriptionBuffer.get_start_iter(),
126 descriptionBuffer.get_end_iter(),
127 False)
128 description = text2unicode(description)
129 self.set_sensitive(False)
130 self._gui.sendBugReport(text2unicode(self._summary.get_text()),
131 description,
132 text2unicode(self._email.get_text()),
133 self._bugReportSent)
134
135 def _bugReportSent(self, returned, result):
136 """Called when the bug report was sent."""
137 self.set_sensitive(True)
138 self._description.set_sensitive(True)
139 if returned and result.success:
140 self.hide()
141 self._summary.set_text("")
142 self._description.get_buffer().set_text("")
143 self._email.set_text("")
144 else:
145 self.run()
Note: See TracBrowser for help on using the repository browser.