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@158
|
19 from PyQt4 import QtGui
|
Chris@158
|
20
|
Chris@158
|
21 easyhg_qtapp = None
|
Chris@158
|
22
|
Chris@158
|
23 def uisetup(ui):
|
Chris@158
|
24 ui.__class__.prompt = easyhg_prompt
|
Chris@158
|
25 ui.__class__.getpass = easyhg_getpass
|
Chris@160
|
26 global easyhg_qtapp
|
Chris@158
|
27 easyhg_qtapp = QtGui.QApplication([])
|
Chris@158
|
28
|
Chris@158
|
29 def easyhg_prompt(self, msg, default="y"):
|
Chris@158
|
30 if not self.interactive():
|
Chris@158
|
31 self.write(msg, ' ', default, "\n")
|
Chris@158
|
32 return default
|
Chris@158
|
33 if msg == _('user:'):
|
Chris@158
|
34 msg = _('User:')
|
Chris@160
|
35 (r,ok) = QtGui.QInputDialog.getText(None, _('Information needed'),
|
Chris@158
|
36 msg, QtGui.QLineEdit.Normal)
|
Chris@158
|
37 if not ok:
|
Chris@158
|
38 raise util.Abort(_('response expected'))
|
Chris@158
|
39 if not r:
|
Chris@158
|
40 return default
|
Chris@158
|
41 return r
|
Chris@158
|
42
|
Chris@158
|
43 def easyhg_getpass(self, prompt=None, default=None):
|
Chris@158
|
44 if not self.interactive():
|
Chris@158
|
45 return default
|
Chris@160
|
46 if not prompt or prompt == _('password:'):
|
Chris@160
|
47 prompt = _('Password:');
|
Chris@160
|
48 (r,ok) = QtGui.QInputDialog.getText(None, _('Password'), prompt,
|
Chris@158
|
49 QtGui.QLineEdit.Password)
|
Chris@158
|
50 if not ok:
|
Chris@158
|
51 raise util.Abort(_('response expected'))
|
Chris@158
|
52 if not r:
|
Chris@158
|
53 return default
|
Chris@158
|
54 return r
|
Chris@158
|
55
|