annotate easyhg.py @ 210:c5fceb3fe5b4

* OS/X: Add script to run external diff; add space around tab widget; textual fixes * Bail out of easyhg.py in uisetup rather than at extension load time if we can't load PyQt4 -- that way we find out about it in easyhg * Ensure editing the default path works even if hgrc doesn't yet exist; ensure path and branch are reset (to empty and default) if their respective files are absent
author Chris Cannam
date Wed, 05 Jan 2011 14:31:07 +0000
parents 07b908b4fa5f
children 960b782f0a64
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@210 29 # Try to load the PyQt4 module that we need. If this fails, we should
Chris@210 30 # bail out later (in uisetup), because if we bail out now, Mercurial
Chris@210 31 # will just continue without us and report success. The invoking
Chris@210 32 # application needs to be able to discover whether the module load
Chris@210 33 # succeeded or not, so we need to ensure that Mercurial itself returns
Chris@210 34 # failure if it didn't.
Chris@210 35 #
Chris@210 36 easyhg_pyqt_ok = True
Chris@210 37 try:
Chris@210 38 from PyQt4 import QtGui
Chris@210 39 except ImportError as err:
Chris@210 40 easyhg_pyqt_ok = False
Chris@158 41
Chris@158 42 easyhg_qtapp = None
Chris@158 43
Chris@158 44 def uisetup(ui):
Chris@210 45 if not easyhg_pyqt_ok:
Chris@210 46 raise util.Abort(_('Failed to load PyQt4 module required by easyhg.py'))
Chris@158 47 ui.__class__.prompt = easyhg_prompt
Chris@158 48 ui.__class__.getpass = easyhg_getpass
Chris@160 49 global easyhg_qtapp
Chris@158 50 easyhg_qtapp = QtGui.QApplication([])
Chris@158 51
Chris@158 52 def easyhg_prompt(self, msg, default="y"):
Chris@158 53 if not self.interactive():
Chris@158 54 self.write(msg, ' ', default, "\n")
Chris@158 55 return default
Chris@158 56 if msg == _('user:'):
Chris@158 57 msg = _('User:')
Chris@160 58 (r,ok) = QtGui.QInputDialog.getText(None, _('Information needed'),
Chris@158 59 msg, QtGui.QLineEdit.Normal)
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
Chris@158 66 def easyhg_getpass(self, prompt=None, default=None):
Chris@158 67 if not self.interactive():
Chris@158 68 return default
Chris@160 69 if not prompt or prompt == _('password:'):
Chris@160 70 prompt = _('Password:');
Chris@160 71 (r,ok) = QtGui.QInputDialog.getText(None, _('Password'), prompt,
Chris@158 72 QtGui.QLineEdit.Password)
Chris@158 73 if not ok:
Chris@158 74 raise util.Abort(_('response expected'))
Chris@158 75 if not r:
Chris@158 76 return default
Chris@158 77 return r
Chris@158 78