From dd17e899960bebe768c8971657e7c67207cc7af6 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Tue, 13 Apr 2010 01:14:35 -0700 Subject: [PATCH] views.actions: Add a command wrapper for run_command and use it This removes the GUI dependency from the RunConfigAction command object introduced in a09a151147315b471f54148c4b896ce7e959e4b9. Signed-off-by: David Aguilar --- cola/commands.py | 10 +++++++--- cola/signals.py | 1 + cola/views/actions.py | 5 +++++ cola/views/command.py | 33 ++++++++++++++++++++------------- 4 files changed, 33 insertions(+), 16 deletions(-) diff --git a/cola/commands.py b/cola/commands.py index e1162eb5..6660d8e4 100644 --- a/cola/commands.py +++ b/cola/commands.py @@ -1,6 +1,5 @@ import os import sys -import cola.views.command from cStringIO import StringIO @@ -613,8 +612,13 @@ class RunConfigAction(Command): flag_error=False, shell=True) else: - cola.views.command.git_command('sh', ['-c',cmdexpand]) - status = 0 + status, out, err = _factory.prompt_user(signals.run_command, + title, + 'sh', ['-c', cmdexpand]) + + _notifier.broadcast(signals.log_cmd, status, + 'stdout: %s\nstatus: %s\nstderr: %s' % + (out.rstrip(), status, err.rstrip())) if not opts.get('norescan'): self.model.update_status() diff --git a/cola/signals.py b/cola/signals.py index bcf62e65..e3c89aa6 100644 --- a/cola/signals.py +++ b/cola/signals.py @@ -37,6 +37,7 @@ rescan = 'rescan' reset_mode = 'reset_mode' review_branch_mode = 'review_branch_mode' run_config_action = 'run_config_action' +run_command = 'run_command' show_untracked = 'show_untracked' stage = 'stage' stage_diffs = 'stage_diffs' diff --git a/cola/views/actions.py b/cola/views/actions.py index 6b05cd88..979f2624 100644 --- a/cola/views/actions.py +++ b/cola/views/actions.py @@ -12,6 +12,7 @@ from cola import gitcmds from cola.qtutils import SLOT from cola.views import revselect from cola.views import standard +from cola.views import command def install_command_wrapper(parent): @@ -34,8 +35,12 @@ class ActionCommandWrapper(object): self.parent = parent self.callbacks = { signals.run_config_action: self._run_config_action, + signals.run_command: self._run_command, } + def _run_command(self, title, cmd, params): + return command.run_command(self.parent, title, cmd, params) + def _run_config_action(self, name, opts): dlg = ActionDialog(self.parent, name, opts) dlg.show() diff --git a/cola/views/command.py b/cola/views/command.py index 87a2f96b..7e5e1533 100644 --- a/cola/views/command.py +++ b/cola/views/command.py @@ -1,26 +1,29 @@ """ Provides the GitCommandWidget dialog. """ - from PyQt4 import QtGui from PyQt4 import QtCore from PyQt4.QtCore import SIGNAL + +from cola import core from cola import qtutils -import subprocess -import sys -import standard +from cola.views import standard -def git_command(command, params, parent=None): - """ Show a command widget """ + +def run_command(parent, title, command, params): + """Show a command widget """ view = GitCommandWidget(parent) view.setWindowModality(QtCore.Qt.ApplicationModal) view.set_command(command, params) + view.setWindowTitle(title) if not parent: qtutils.center_on_screen(view) view.run() view.show() - return view.exitstatus + status = view.exec_() + return (view.exitstatus, view.out, view.err) + -class GitCommandWidget(QtGui.QWidget): +class GitCommandWidget(standard.StandardDialog): ''' Nice TextView that reads the output of a command syncronously ''' # Keep us in scope otherwise PyQt kills the widget _instances = set() @@ -29,8 +32,16 @@ class GitCommandWidget(QtGui.QWidget): self._instances.remove(self) def __init__(self, parent=None): - QtGui.QWidget.__init__(self, parent) + standard.StandardDialog.__init__(self, parent=parent) self._instances.add(self) + self.resize(720, 420) + + # Construct the process + self.proc = QtCore.QProcess(self) + self.exitstatus = 0 + self.out = '' + self.err = '' + self._layout = QtGui.QVBoxLayout(self) self._layout.setContentsMargins(3, 3, 3, 3) @@ -56,10 +67,6 @@ class GitCommandWidget(QtGui.QWidget): self.button_box.addButton(self.button_close, QtGui.QDialogButtonBox.AcceptRole) self._layout.addWidget(self.button_box) - # Construct the process - self.proc = QtCore.QProcess(self) - self.exitstatus = 0 - # Connect the signals to the process self.connect(self.proc, SIGNAL("readyReadStandardOutput()"), self.readOutput) self.connect(self.proc, SIGNAL("readyReadStandardError()"), self.readErrors) -- 2.11.4.GIT