annotate easyhg.py @ 425:ad106f5fe75f

Add "Ignore Files" and "Edit Ignored List" to Work menu (latter is subsumed from Advanced menu formerly). Also subsume Serve via HTTP into File menu as Share Repository, and add a more helpful description of it. Remove Advanced menu
author Chris Cannam
date Thu, 23 Jun 2011 10:58:32 +0100
parents 2d3f1e5d8638
children 8530c31536a7
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@369 27 # We have an installation path: append it twice, once with
Chris@369 28 # the Python version suffixed
Chris@372 29 version_suffix = "Py" + str(sys.version_info[0]) + "." + str(sys.version_info[1]);
Chris@372 30 sys.path.append(easyhg_import_path + "/" + version_suffix)
Chris@188 31 sys.path.append(easyhg_import_path)
Chris@188 32
Chris@210 33 # Try to load the PyQt4 module that we need. If this fails, we should
Chris@210 34 # bail out later (in uisetup), because if we bail out now, Mercurial
Chris@210 35 # will just continue without us and report success. The invoking
Chris@210 36 # application needs to be able to discover whether the module load
Chris@210 37 # succeeded or not, so we need to ensure that Mercurial itself returns
Chris@210 38 # failure if it didn't.
Chris@210 39 #
Chris@210 40 easyhg_pyqt_ok = True
Chris@210 41 try:
Chris@210 42 from PyQt4 import QtGui
Chris@236 43 except ImportError:
Chris@210 44 easyhg_pyqt_ok = False
Chris@158 45
Chris@158 46 easyhg_qtapp = None
Chris@158 47
Chris@158 48 def uisetup(ui):
Chris@210 49 if not easyhg_pyqt_ok:
Chris@210 50 raise util.Abort(_('Failed to load PyQt4 module required by easyhg.py'))
Chris@158 51 ui.__class__.prompt = easyhg_prompt
Chris@158 52 ui.__class__.getpass = easyhg_getpass
Chris@160 53 global easyhg_qtapp
Chris@158 54 easyhg_qtapp = QtGui.QApplication([])
Chris@158 55
Chris@158 56 def easyhg_prompt(self, msg, default="y"):
Chris@158 57 if not self.interactive():
Chris@158 58 self.write(msg, ' ', default, "\n")
Chris@158 59 return default
Chris@158 60 if msg == _('user:'):
Chris@358 61 msg = _('Username for remote repository:')
Chris@258 62 d = QtGui.QInputDialog()
Chris@258 63 d.setInputMode(QtGui.QInputDialog.TextInput)
Chris@258 64 d.setTextEchoMode(QtGui.QLineEdit.Normal)
Chris@264 65 d.setLabelText(msg)
Chris@258 66 d.setWindowTitle(_('EasyMercurial: Information'))
Chris@258 67 d.show()
Chris@258 68 d.raise_()
Chris@258 69 ok = d.exec_()
Chris@258 70 r = d.textValue()
Chris@158 71 if not ok:
Chris@358 72 raise util.Abort(_('username entry cancelled'))
Chris@158 73 if not r:
Chris@158 74 return default
Chris@158 75 return r
Chris@158 76
Chris@158 77 def easyhg_getpass(self, prompt=None, default=None):
Chris@158 78 if not self.interactive():
Chris@158 79 return default
Chris@160 80 if not prompt or prompt == _('password:'):
Chris@358 81 prompt = _('Password for remote repository:');
Chris@258 82 d = QtGui.QInputDialog()
Chris@258 83 d.setInputMode(QtGui.QInputDialog.TextInput)
Chris@258 84 d.setTextEchoMode(QtGui.QLineEdit.Password)
Chris@258 85 d.setLabelText(prompt)
Chris@258 86 d.setWindowTitle(_('EasyMercurial: Password'))
Chris@258 87 d.show()
Chris@258 88 d.raise_()
Chris@258 89 ok = d.exec_()
Chris@258 90 r = d.textValue()
Chris@158 91 if not ok:
Chris@358 92 raise util.Abort(_('password entry cancelled'))
Chris@158 93 if not r:
Chris@158 94 return default
Chris@158 95 return r
Chris@158 96
Chris@358 97