completion: display completions when Ctrl-Space is pressed
[git-cola.git] / cola / widgets / remotemessage.py
blob9c1811cf517a111d63e02bdf3d85ed12cceb215c
1 from qtpy.QtCore import Qt
3 from .. import qtutils
4 from ..i18n import N_
5 from . import defs
6 from . import standard
7 from . import text
10 def show(context, message):
11 """Display a window if the remote sent a message"""
12 if message:
13 view = RemoteMessage(context, message, parent=context.view)
14 view.show()
15 view.exec_()
18 def from_context(context):
19 """Return a closure for the `result` callback from RunTask.start()"""
21 def show_result(result):
22 """Display the asynchronous "result" when remote tasks complete"""
23 _, out, err = result
24 output = '\n\n'.join(x for x in (out, err) if x)
25 if output:
26 message = N_('Right-click links to open:') + '\n\n' + output
27 else:
28 message = output
30 return show(context, message)
32 return show_result
35 class RemoteMessage(standard.Dialog):
36 """Provides a dialog to display remote messages"""
38 def __init__(self, context, message, parent=None):
39 standard.Dialog.__init__(self, parent=parent)
40 self.context = context
41 self.model = context.model
43 self.setWindowTitle(N_('Remote Messages'))
44 if parent is not None:
45 self.setWindowModality(Qt.WindowModal)
47 self.text = text.VimTextEdit(context, parent=self)
48 self.text.set_value(message)
49 # Set a monospace font, as some remote git messages include ASCII art
50 self.text.setFont(qtutils.default_monospace_font())
52 self.close_button = qtutils.close_button()
53 self.close_button.setDefault(True)
55 self.bottom_layout = qtutils.hbox(
56 defs.no_margin, defs.button_spacing, qtutils.STRETCH, self.close_button
59 self.main_layout = qtutils.vbox(
60 defs.no_margin, defs.spacing, self.text, self.bottom_layout
62 self.setLayout(self.main_layout)
64 qtutils.connect_button(self.close_button, self.close)
66 self.resize(defs.scale(720), defs.scale(400))