annotate easyhg.py @ 204:d256cc418fa3

* Fix failure to enable Add button when a "Removed" file was selected
author Chris Cannam
date Tue, 04 Jan 2011 15:22:07 +0000
parents 07b908b4fa5f
children c5fceb3fe5b4
rev   line source
Chris@158 1 # -*- coding: utf-8 -*-
Chris@158 2 #
Chris@158 3 # EasyMercurial
Chris@158 4 #
Chris@158 5 # Based on hgExplorer by Jari Korhonen
Chris@158 6 # Copyright (c) 2010 Jari Korhonen
Chris@158 7 # Copyright (c) 2010 Chris Cannam
Chris@158 8 # Copyright (c) 2010 Queen Mary, University of London
Chris@158 9 #
Chris@158 10 # This program is free software; you can redistribute it and/or
Chris@158 11 # modify it under the terms of the GNU General Public License as
Chris@158 12 # published by the Free Software Foundation; either version 2 of the
Chris@158 13 # License, or (at your option) any later version. See the file
Chris@158 14 # COPYING included with this distribution for more information.
Chris@158 15
Chris@158 16 import sys
Chris@158 17 from mercurial import ui, getpass, util
Chris@158 18 from mercurial.i18n import _
Chris@188 19
Chris@188 20 # The value assigned here may be modified during installation, by
Chris@188 21 # replacing its default value with another one. We can't compare
Chris@188 22 # against its default value, because then the comparison text would
Chris@188 23 # get modified as well. So, compare using prefix only.
Chris@188 24 #
Chris@188 25 easyhg_import_path = 'NO_EASYHG_IMPORT_PATH'
Chris@188 26 if not easyhg_import_path.startswith('NO_'):
Chris@188 27 sys.path.append(easyhg_import_path)
Chris@188 28
Chris@158 29 from PyQt4 import QtGui
Chris@158 30
Chris@158 31 easyhg_qtapp = None
Chris@158 32
Chris@158 33 def uisetup(ui):
Chris@158 34 ui.__class__.prompt = easyhg_prompt
Chris@158 35 ui.__class__.getpass = easyhg_getpass
Chris@160 36 global easyhg_qtapp
Chris@158 37 easyhg_qtapp = QtGui.QApplication([])
Chris@158 38
Chris@158 39 def easyhg_prompt(self, msg, default="y"):
Chris@158 40 if not self.interactive():
Chris@158 41 self.write(msg, ' ', default, "\n")
Chris@158 42 return default
Chris@158 43 if msg == _('user:'):
Chris@158 44 msg = _('User:')
Chris@160 45 (r,ok) = QtGui.QInputDialog.getText(None, _('Information needed'),
Chris@158 46 msg, QtGui.QLineEdit.Normal)
Chris@158 47 if not ok:
Chris@158 48 raise util.Abort(_('response expected'))
Chris@158 49 if not r:
Chris@158 50 return default
Chris@158 51 return r
Chris@158 52
Chris@158 53 def easyhg_getpass(self, prompt=None, default=None):
Chris@158 54 if not self.interactive():
Chris@158 55 return default
Chris@160 56 if not prompt or prompt == _('password:'):
Chris@160 57 prompt = _('Password:');
Chris@160 58 (r,ok) = QtGui.QInputDialog.getText(None, _('Password'), prompt,
Chris@158 59 QtGui.QLineEdit.Password)
Chris@158 60 if not ok:
Chris@158 61 raise util.Abort(_('response expected'))
Chris@158 62 if not r:
Chris@158 63 return default
Chris@158 64 return r
Chris@158 65