annotate easyhg.py @ 350:293d91cf44de bug_90

Double-click on modified files shows diff instead of annotation
author Chris Cannam
date Wed, 16 Mar 2011 12:26:03 +0000
parents 3b8501070c21
children ea6f76c0aa76
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@236 39 except ImportError:
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@258 58 d = QtGui.QInputDialog()
Chris@258 59 d.setInputMode(QtGui.QInputDialog.TextInput)
Chris@258 60 d.setTextEchoMode(QtGui.QLineEdit.Normal)
Chris@264 61 d.setLabelText(msg)
Chris@258 62 d.setWindowTitle(_('EasyMercurial: Information'))
Chris@258 63 d.show()
Chris@258 64 d.raise_()
Chris@258 65 ok = d.exec_()
Chris@258 66 r = d.textValue()
Chris@158 67 if not ok:
Chris@158 68 raise util.Abort(_('response expected'))
Chris@158 69 if not r:
Chris@158 70 return default
Chris@158 71 return r
Chris@158 72
Chris@158 73 def easyhg_getpass(self, prompt=None, default=None):
Chris@158 74 if not self.interactive():
Chris@158 75 return default
Chris@160 76 if not prompt or prompt == _('password:'):
Chris@160 77 prompt = _('Password:');
Chris@258 78 d = QtGui.QInputDialog()
Chris@258 79 d.setInputMode(QtGui.QInputDialog.TextInput)
Chris@258 80 d.setTextEchoMode(QtGui.QLineEdit.Password)
Chris@258 81 d.setLabelText(prompt)
Chris@258 82 d.setWindowTitle(_('EasyMercurial: Password'))
Chris@258 83 d.show()
Chris@258 84 d.raise_()
Chris@258 85 ok = d.exec_()
Chris@258 86 r = d.textValue()
Chris@158 87 if not ok:
Chris@158 88 raise util.Abort(_('response expected'))
Chris@158 89 if not r:
Chris@158 90 return default
Chris@158 91 return r
Chris@158 92