Fall back to the text interface if qt is not available (closes #84939)

Instead of defaulting to qt and erroring out if it's not there, try both interfaces in turn and use the first one we find if the user didn't set a preference.

authorJulien Cristau <julien.cristau@logilab.fr>
changeset6257f4fa274b
branchdefault
phasepublic
hiddenno
parent revision#655120b1239b [application] do not fail when started outside a repository with ``bin/hgview``(closes #79255)
child revision#4a4bf50245b0 [fix core] raise ApplicationError and do not display traceback for NotImplementedErro (closes #78004 #83307)
files modified by this revision
hgviewlib/application.py
hgviewlib/config.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1324304769 -3600
# Mon Dec 19 15:26:09 2011 +0100
# Node ID 6257f4fa274b0f165be7fc2cdb667d28d8ad1c1e
# Parent 655120b1239ba7d4ddefcb5182b74fc0618b6077
Fall back to the text interface if qt is not available (closes #84939)

Instead of defaulting to qt and erroring out if it's not there, try both
interfaces in turn and use the first one we find if the user didn't set
a preference.

diff --git a/hgviewlib/application.py b/hgviewlib/application.py
@@ -114,22 +114,31 @@
1 
2      config = HgConfig(repo.ui)
3      if not opts.interface:
4          opts.interface = config.getInterface()
5 
6 -    try:
7 -        if opts.interface in ('raw', 'curses'):
8 +    Application = None
9 +    if not opts.interface or opts.interface == 'qt':
10 +        try:
11 +            from hgviewlib.qt4.application import HgViewQtApplication as Application
12 +            opts.interface = 'qt'
13 +        except ImportError:
14 +            pass
15 +    if not opts.interface or opts.interface in ('raw', 'curses'):
16 +        try:
17              from hgviewlib.curses.application import HgViewUrwidApplication as Application
18 -        elif opts.interface == 'qt':
19 -            from hgviewlib.qt4.application import HgViewQtApplication as Application
20 -        else:
21 -            fnerror('Unknown interface: "%s"' % opts.interface)
22 +            opts.interface = 'raw'
23 +        except ImportError:
24 +            pass
25 +    if not opts.interface:
26 +        fnerror('No interface found')
27 +    if not Application:
28 +        fnerror('Interface is not available: %s' % opts.interface)
29 +    try:
30          app = Application(repo, opts, args)
31      except ApplicationError, err:
32          fnerror(str(err))
33 -    except ImportError:
34 -        fnerror('Interface is not available: %s' % opts.interface)
35 
36      sys.exit(app.exec_())
37 
38  def main():
39      """
diff --git a/hgviewlib/config.py b/hgviewlib/config.py
@@ -239,11 +239,11 @@
40          mqhidetags: hide mq tags
41          """
42          return self.ui.config(self.section, 'mqhidetags', default)
43 
44      @cached
45 -    def getInterface(self, default='qt'):
46 +    def getInterface(self, default=None):
47          """
48          interface: which GUI interface to use (among "qt", "raw" and "curses")
49          """
50          return self.ui.config(self.section, 'interface', default)
51