From 27b85fc8cff68bad1f47a30a351c3e53131e64ac Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sun, 19 Nov 2023 21:07:25 -0800 Subject: [PATCH] widgets: fold the remotemessage module into the log module We can do away with having a separate file by folding this functionality into the log module. Signed-off-by: David Aguilar --- cola/widgets/branch.py | 27 ++++++++--------- cola/widgets/log.py | 70 ++++++++++++++++++++++++++++++++++++++----- cola/widgets/remote.py | 4 +-- cola/widgets/remotemessage.py | 66 ---------------------------------------- 4 files changed, 78 insertions(+), 89 deletions(-) delete mode 100644 cola/widgets/remotemessage.py diff --git a/cola/widgets/branch.py b/cola/widgets/branch.py index 33c07a55..73360150 100644 --- a/cola/widgets/branch.py +++ b/cola/widgets/branch.py @@ -17,8 +17,8 @@ from .. import gitcmds from .. import hotkeys from .. import icons from .. import qtutils -from .text import LineEdit -from . import remotemessage +from . import log +from . import text def defer_func(parent, title, func, *args, **kwargs): @@ -433,7 +433,7 @@ class BranchesTreeWidget(standard.TreeWidget): N_('Executing action %s') % action, N_('Updating'), self ) if remote_messages: - result_handler = remotemessage.from_context(self.context) + result_handler = log.show_remote_messages(self.context) else: result_handler = None @@ -835,7 +835,7 @@ class BranchesFilterWidget(QtWidgets.QWidget): self.tree = tree hint = N_('Filter branches...') - self.text = LineEdit(parent=self, clear_button=True) + self.text = text.LineEdit(parent=self, clear_button=True) self.text.setToolTip(hint) self.setFocusProxy(self.text) self._filter = None @@ -843,26 +843,25 @@ class BranchesFilterWidget(QtWidgets.QWidget): self.main_layout = qtutils.hbox(defs.no_margin, defs.spacing, self.text) self.setLayout(self.main_layout) - text = self.text # pylint: disable=no-member - text.textChanged.connect(self.apply_filter) + self.text.textChanged.connect(self.apply_filter) self.tree.updated.connect(self.apply_filter, type=Qt.QueuedConnection) def apply_filter(self): - text = get(self.text) - if text == self._filter: + value = get(self.text) + if value == self._filter: return self._apply_bold(self._filter, False) - self._filter = text - if text: - self._apply_bold(text, True) + self._filter = value + if value: + self._apply_bold(value, True) - def _apply_bold(self, text, value): + def _apply_bold(self, value, is_bold): match = Qt.MatchContains | Qt.MatchRecursive - children = self.tree.findItems(text, match) + children = self.tree.findItems(value, match) for child in children: if child.childCount() == 0: font = child.font(0) - font.setBold(value) + font.setBold(is_bold) child.setFont(0, font) diff --git a/cola/widgets/log.py b/cola/widgets/log.py index 70636291..e0ffe941 100644 --- a/cola/widgets/log.py +++ b/cola/widgets/log.py @@ -9,7 +9,8 @@ from .. import core from .. import qtutils from ..i18n import N_ from . import defs -from .text import VimTextEdit +from . import text +from . import standard class LogWidget(QtWidgets.QFrame): @@ -20,7 +21,7 @@ class LogWidget(QtWidgets.QFrame): def __init__(self, context, parent=None, output=None): QtWidgets.QFrame.__init__(self, parent) - self.output_text = VimTextEdit(context, parent=self) + self.output_text = text.VimTextEdit(context, parent=self) self.highlighter = LogSyntaxHighlighter(self.output_text.document()) if output: self.set_output(output) @@ -31,7 +32,7 @@ class LogWidget(QtWidgets.QFrame): self.log(' Documentation: https://git-cola.readthedocs.io/en/latest/') self.log( ' Keyboard Shortcuts: ' - 'https://git-cola.github.io/share/doc/git-cola/hotkeys.html\n' + 'https://git-cola.gitlab.io/share/doc/git-cola/hotkeys.html\n' ) def clear(self): @@ -57,13 +58,13 @@ class LogWidget(QtWidgets.QFrame): msg = core.decode(msg) cursor = self.output_text.textCursor() cursor.movePosition(cursor.End) - text = self.output_text + text_widget = self.output_text # NOTE: the ': ' colon-SP-SP suffix is for the syntax highlighter prefix = core.decode(time.strftime('%Y-%m-%d %H:%M:%S: ')) # ISO-8601 for line in msg.split('\n'): cursor.insertText(prefix + line + '\n') cursor.movePosition(cursor.End) - text.setTextCursor(cursor) + text_widget.setTextCursor(cursor) def log(self, msg): """Add output to the log window""" @@ -81,7 +82,62 @@ class LogSyntaxHighlighter(QtGui.QSyntaxHighlighter): QPalette = QtGui.QPalette self.disabled_color = palette.color(QPalette.Disabled, QPalette.Text) - def highlightBlock(self, text): - end = text.find(': ') + def highlightBlock(self, block_text): + end = block_text.find(': ') if end > 0: self.setFormat(0, end + 1, self.disabled_color) + + +class RemoteMessage(standard.Dialog): + """Provides a dialog to display remote messages""" + + def __init__(self, context, message, parent=None): + standard.Dialog.__init__(self, parent=parent) + self.context = context + self.model = context.model + + self.setWindowTitle(N_('Remote Messages')) + if parent is not None: + self.setWindowModality(Qt.WindowModal) + + self.text = text.VimTextEdit(context, parent=self) + self.text.set_value(message) + # Set a monospace font, as some remote git messages include ASCII art + self.text.setFont(qtutils.default_monospace_font()) + + self.close_button = qtutils.close_button() + self.close_button.setDefault(True) + + self.bottom_layout = qtutils.hbox( + defs.no_margin, defs.button_spacing, qtutils.STRETCH, self.close_button + ) + + self.main_layout = qtutils.vbox( + defs.no_margin, defs.spacing, self.text, self.bottom_layout + ) + self.setLayout(self.main_layout) + + qtutils.connect_button(self.close_button, self.close) + + self.resize(defs.scale(720), defs.scale(400)) + + +def show_remote_messages(context): + """Return a closure for the `result` callback from RunTask.start()""" + + def show_remote_messages_callback(result): + """Display the asynchronous "result" when remote tasks complete""" + _, out, err = result + output = '\n\n'.join(x for x in (out, err) if x) + if output: + message = N_('Right-click links to open:') + '\n\n' + output + else: + message = output + + # Display a window if the remote sent a message + if message: + view = RemoteMessage(context, message, parent=context.view) + view.show() + view.exec_() + + return show_remote_messages_callback diff --git a/cola/widgets/remote.py b/cola/widgets/remote.py index 15ecfd31..b956afdc 100644 --- a/cola/widgets/remote.py +++ b/cola/widgets/remote.py @@ -14,8 +14,8 @@ from .. import icons from .. import qtutils from .. import utils from . import defs +from . import log from . import standard -from . import remotemessage FETCH = 'FETCH' @@ -644,7 +644,7 @@ class RemoteActionDialog(standard.Dialog): # Use a thread to update in the background task = ActionTask(model_action, remote, kwargs) if remote_messages: - result = remotemessage.from_context(self.context) + result = log.show_remote_messages(self.context) else: result = None self.runtask.start( diff --git a/cola/widgets/remotemessage.py b/cola/widgets/remotemessage.py deleted file mode 100644 index 9c1811cf..00000000 --- a/cola/widgets/remotemessage.py +++ /dev/null @@ -1,66 +0,0 @@ -from qtpy.QtCore import Qt - -from .. import qtutils -from ..i18n import N_ -from . import defs -from . import standard -from . import text - - -def show(context, message): - """Display a window if the remote sent a message""" - if message: - view = RemoteMessage(context, message, parent=context.view) - view.show() - view.exec_() - - -def from_context(context): - """Return a closure for the `result` callback from RunTask.start()""" - - def show_result(result): - """Display the asynchronous "result" when remote tasks complete""" - _, out, err = result - output = '\n\n'.join(x for x in (out, err) if x) - if output: - message = N_('Right-click links to open:') + '\n\n' + output - else: - message = output - - return show(context, message) - - return show_result - - -class RemoteMessage(standard.Dialog): - """Provides a dialog to display remote messages""" - - def __init__(self, context, message, parent=None): - standard.Dialog.__init__(self, parent=parent) - self.context = context - self.model = context.model - - self.setWindowTitle(N_('Remote Messages')) - if parent is not None: - self.setWindowModality(Qt.WindowModal) - - self.text = text.VimTextEdit(context, parent=self) - self.text.set_value(message) - # Set a monospace font, as some remote git messages include ASCII art - self.text.setFont(qtutils.default_monospace_font()) - - self.close_button = qtutils.close_button() - self.close_button.setDefault(True) - - self.bottom_layout = qtutils.hbox( - defs.no_margin, defs.button_spacing, qtutils.STRETCH, self.close_button - ) - - self.main_layout = qtutils.vbox( - defs.no_margin, defs.spacing, self.text, self.bottom_layout - ) - self.setLayout(self.main_layout) - - qtutils.connect_button(self.close_button, self.close) - - self.resize(defs.scale(720), defs.scale(400)) -- 2.11.4.GIT