source: src/mlx/gui/bugreport.py@ 1150:8c10b07807ed

python3
Last change on this file since 1150:8c10b07807ed was 999:e096a5638b87, checked in by István Váradi <ivaradi@…>, 5 years ago

Removed Gtk 2/3 constant definitions (re #347)

File size: 5.1 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 Gtk.DialogFlags.MODAL)
27
28 self.add_button(xstr("button_cancel"), Gtk.ResponseType.REJECT)
29 self._sendButton = self.add_button(xstr("button_send"), Gtk.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(Gtk.WrapMode.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(Gtk.PolicyType.AUTOMATIC,
73 Gtk.PolicyType.AUTOMATIC)
74 scrolledWindow.set_shadow_type(Gtk.ShadowType.IN)
75
76 alignment = Gtk.Alignment(xalign = 0.5, yalign = 0.0, xscale = 1.0, yscale = 1.0)
77 alignment.add(scrolledWindow)
78
79 contentVBox.pack_start(alignment, True, True, 4)
80
81 emailBox = Gtk.HBox()
82 contentVBox.pack_start(emailBox, False, False, 4)
83
84 label = Gtk.Label(xstr("bugreport_email"))
85 label.set_use_underline(True)
86 label.set_alignment(0.0, 0.5)
87
88 emailBox.pack_start(label, False, False, 0)
89
90 alignment = Gtk.Alignment()
91 emailBox.pack_start(alignment, False, False, 8)
92
93 self._email = email = Gtk.Entry()
94 email.set_tooltip_text(xstr("bugreport_email_tooltip"))
95 label.set_mnemonic_widget(email)
96 emailBox.pack_start(email, True, True, 0)
97
98
99 def run(self):
100 """Run the checklist editor dialog."""
101 self.set_sensitive(True)
102 self._description.set_sensitive(True)
103 self._updateButtons()
104 self._sendButton.grab_default()
105 self.show_all()
106 response = super(BugReportDialog, self).run()
107
108 print("response", response, Gtk.ResponseType.ACCEPT)
109 if response==Gtk.ResponseType.ACCEPT:
110 self._send()
111 else:
112 self.hide()
113
114 def _summaryChanged(self, entry):
115 """Called when the summary has changed."""
116 self._updateButtons()
117
118 def _updateButtons(self):
119 """Update the sensitivity of the buttoms."""
120 self._sendButton.set_sensitive(self._summary.get_text()!="")
121
122 def _send(self):
123 """Send the bug report."""
124 descriptionBuffer = self._description.get_buffer()
125 description = \
126 descriptionBuffer.get_text(descriptionBuffer.get_start_iter(),
127 descriptionBuffer.get_end_iter(),
128 False)
129 self.set_sensitive(False)
130 self._gui.sendBugReport(self._summary.get_text(),
131 description,
132 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.