Chris@158: # -*- coding: utf-8 -*- Chris@158: # Chris@158: # EasyMercurial Chris@158: # Chris@158: # Based on hgExplorer by Jari Korhonen Chris@158: # Copyright (c) 2010 Jari Korhonen Chris@158: # Copyright (c) 2010 Chris Cannam Chris@158: # Copyright (c) 2010 Queen Mary, University of London Chris@158: # Chris@158: # This program is free software; you can redistribute it and/or Chris@158: # modify it under the terms of the GNU General Public License as Chris@158: # published by the Free Software Foundation; either version 2 of the Chris@158: # License, or (at your option) any later version. See the file Chris@158: # COPYING included with this distribution for more information. Chris@158: Chris@158: import sys Chris@158: from mercurial import ui, getpass, util Chris@158: from mercurial.i18n import _ Chris@188: Chris@188: # The value assigned here may be modified during installation, by Chris@188: # replacing its default value with another one. We can't compare Chris@188: # against its default value, because then the comparison text would Chris@188: # get modified as well. So, compare using prefix only. Chris@188: # Chris@188: easyhg_import_path = 'NO_EASYHG_IMPORT_PATH' Chris@188: if not easyhg_import_path.startswith('NO_'): Chris@188: sys.path.append(easyhg_import_path) Chris@188: Chris@210: # Try to load the PyQt4 module that we need. If this fails, we should Chris@210: # bail out later (in uisetup), because if we bail out now, Mercurial Chris@210: # will just continue without us and report success. The invoking Chris@210: # application needs to be able to discover whether the module load Chris@210: # succeeded or not, so we need to ensure that Mercurial itself returns Chris@210: # failure if it didn't. Chris@210: # Chris@210: easyhg_pyqt_ok = True Chris@210: try: Chris@210: from PyQt4 import QtGui Chris@236: except ImportError: Chris@210: easyhg_pyqt_ok = False Chris@158: Chris@158: easyhg_qtapp = None Chris@158: Chris@158: def uisetup(ui): Chris@210: if not easyhg_pyqt_ok: Chris@210: raise util.Abort(_('Failed to load PyQt4 module required by easyhg.py')) Chris@158: ui.__class__.prompt = easyhg_prompt Chris@158: ui.__class__.getpass = easyhg_getpass Chris@160: global easyhg_qtapp Chris@158: easyhg_qtapp = QtGui.QApplication([]) Chris@158: Chris@158: def easyhg_prompt(self, msg, default="y"): Chris@158: if not self.interactive(): Chris@158: self.write(msg, ' ', default, "\n") Chris@158: return default Chris@158: if msg == _('user:'): Chris@358: msg = _('Username for remote repository:') Chris@258: d = QtGui.QInputDialog() Chris@258: d.setInputMode(QtGui.QInputDialog.TextInput) Chris@258: d.setTextEchoMode(QtGui.QLineEdit.Normal) Chris@264: d.setLabelText(msg) Chris@258: d.setWindowTitle(_('EasyMercurial: Information')) Chris@258: d.show() Chris@258: d.raise_() Chris@258: ok = d.exec_() Chris@258: r = d.textValue() Chris@158: if not ok: Chris@358: raise util.Abort(_('username entry cancelled')) Chris@158: if not r: Chris@158: return default Chris@158: return r Chris@158: Chris@158: def easyhg_getpass(self, prompt=None, default=None): Chris@158: if not self.interactive(): Chris@158: return default Chris@160: if not prompt or prompt == _('password:'): Chris@358: prompt = _('Password for remote repository:'); Chris@258: d = QtGui.QInputDialog() Chris@258: d.setInputMode(QtGui.QInputDialog.TextInput) Chris@258: d.setTextEchoMode(QtGui.QLineEdit.Password) Chris@258: d.setLabelText(prompt) Chris@258: d.setWindowTitle(_('EasyMercurial: Password')) Chris@258: d.show() Chris@258: d.raise_() Chris@258: ok = d.exec_() Chris@258: r = d.textValue() Chris@158: if not ok: Chris@358: raise util.Abort(_('password entry cancelled')) Chris@158: if not r: Chris@158: return default Chris@158: return r Chris@158: Chris@358: