comparison easyhg1.py @ 441:b616c9c6cfd2

Bring new-look easyhg.py into action
author Chris Cannam
date Tue, 28 Jun 2011 14:15:42 +0100
parents easyhg.py@8530c31536a7
children
comparison
equal deleted inserted replaced
440:0d779f3cb4bc 441:b616c9c6cfd2
1 # -*- coding: utf-8 -*-
2 #
3 # EasyMercurial
4 #
5 # Based on hgExplorer by Jari Korhonen
6 # Copyright (c) 2010 Jari Korhonen
7 # Copyright (c) 2010 Chris Cannam
8 # Copyright (c) 2010 Queen Mary, University of London
9 #
10 # This program is free software; you can redistribute it and/or
11 # modify it under the terms of the GNU General Public License as
12 # published by the Free Software Foundation; either version 2 of the
13 # License, or (at your option) any later version. See the file
14 # COPYING included with this distribution for more information.
15
16 import sys
17 from mercurial import ui, getpass, util
18 from mercurial.i18n import _
19
20 # The value assigned here may be modified during installation, by
21 # replacing its default value with another one. We can't compare
22 # against its default value, because then the comparison text would
23 # get modified as well. So, compare using prefix only.
24 #
25 easyhg_import_path = 'NO_EASYHG_IMPORT_PATH'
26 if not easyhg_import_path.startswith('NO_'):
27 # We have an installation path: append it twice, once with
28 # the Python version suffixed
29 version_suffix = "Py" + str(sys.version_info[0]) + "." + str(sys.version_info[1]);
30 sys.path.append(easyhg_import_path + "/" + version_suffix)
31 sys.path.append(easyhg_import_path)
32
33 # Try to load the PyQt4 module that we need. If this fails, we should
34 # bail out later (in uisetup), because if we bail out now, Mercurial
35 # will just continue without us and report success. The invoking
36 # application needs to be able to discover whether the module load
37 # succeeded or not, so we need to ensure that Mercurial itself returns
38 # failure if it didn't.
39 #
40 easyhg_pyqt_ok = True
41 try:
42 from PyQt4 import QtGui
43 except ImportError:
44 easyhg_pyqt_ok = False
45
46 easyhg_qtapp = None
47
48 def uisetup(ui):
49 if not easyhg_pyqt_ok:
50 raise util.Abort(_('Failed to load PyQt4 module required by easyhg.py'))
51 ui.__class__.prompt = easyhg_prompt
52 ui.__class__.getpass = easyhg_getpass
53 global easyhg_qtapp
54 easyhg_qtapp = QtGui.QApplication([])
55
56 def easyhg_prompt(self, msg, default="y"):
57 if not self.interactive():
58 self.write(msg, ' ', default, "\n")
59 return default
60 isusername = False
61 if msg == _('user:'):
62 msg = _('Username for remote repository:')
63 isusername = True
64 d = QtGui.QInputDialog()
65 d.setInputMode(QtGui.QInputDialog.TextInput)
66 d.setTextEchoMode(QtGui.QLineEdit.Normal)
67 d.setLabelText(msg)
68 d.setWindowTitle(_('EasyMercurial: Information'))
69 d.show()
70 d.raise_()
71 ok = d.exec_()
72 r = d.textValue()
73 if not ok:
74 if isusername:
75 raise util.Abort(_('username entry cancelled'))
76 else:
77 raise util.Abort(_('information entry cancelled'))
78 if not r:
79 return default
80 return r
81
82 def easyhg_getpass(self, prompt=None, default=None):
83 if not self.interactive():
84 return default
85 if not prompt or prompt == _('password:'):
86 prompt = _('Password for remote repository:');
87 d = QtGui.QInputDialog()
88 d.setInputMode(QtGui.QInputDialog.TextInput)
89 d.setTextEchoMode(QtGui.QLineEdit.Password)
90 d.setLabelText(prompt)
91 d.setWindowTitle(_('EasyMercurial: Password'))
92 d.show()
93 d.raise_()
94 ok = d.exec_()
95 r = d.textValue()
96 if not ok:
97 raise util.Abort(_('password entry cancelled'))
98 if not r:
99 return default
100 return r
101
102