Package gavo :: Package user :: Module plainui
[frames] | no frames]

Source Code for Module gavo.user.plainui

 1  """ 
 2  Observers for running interactive programs in the terminal. 
 3  """ 
 4   
 5  #c Copyright 2008-2019, the GAVO project 
 6  #c 
 7  #c This program is free software, covered by the GNU GPL.  See the 
 8  #c COPYING file in the source distribution. 
 9   
10   
11  from __future__ import print_function 
12   
13  from gavo import base 
14 15 16 -class StingyPlainUI(base.ObserverBase):
17 """An Observer swallowing infos, warnings, and the like. 18 19 This is to configure the UI. Enable it by calling 20 ``api.StingyPlainUI(api.ui)``. 21 """
22 - def __init__(self, eh):
23 self.curIndent = "" 24 base.ObserverBase.__init__(self, eh)
25
26 - def showMsg(self, msg):
27 print(self.curIndent+msg)
28
29 - def pushIndent(self):
30 self.curIndent = self.curIndent+" "
31
32 - def popIndent(self):
33 self.curIndent = self.curIndent[:-2]
34 35 @base.listensTo("SourceError")
36 - def announceSourceError(self, srcString):
37 self.showMsg("Failed source %s"%srcString)
38 39 @base.listensTo("Error")
40 - def printErrMsg(self, errMsg):
41 self.showMsg("*X*X* "+errMsg)
42
43 44 -class SemiStingyPlainUI(StingyPlainUI):
45 """A StingyPlainUI that at least displays warnings. 46 47 This is to configure the UI. Enable it by calling 48 ``api.SemiStingyPlainUI(api.ui)``. 49 """ 50 @base.listensTo("Warning")
51 - def printWarning(self, message):
52 self.showMsg("** WARNING: "+message)
53
54 55 -class PlainUI(SemiStingyPlainUI):
56 """An Observer spitting out most info to the screen. 57 58 This is to configure the UI. Enable it by calling ``api.PlainUI(api.ui)``. 59 """ 60 @base.listensTo("NewSource")
61 - def announceNewSource(self, srcString):
62 self.showMsg("Starting %s"%srcString) 63 self.pushIndent()
64 65 @base.listensTo("SourceFinished")
66 - def announceSourceFinished(self, srcString):
67 self.popIndent() 68 self.showMsg("Done %s, read %d"%(srcString, self.dispatcher.totalRead))
69 70 @base.listensTo("SourceError")
71 - def announceSourceError(self, srcString):
72 self.popIndent() 73 self.showMsg("Failed %s"%srcString)
74 75 @base.listensTo("Shipout")
76 - def announceShipout(self, noShipped):
77 self.showMsg("Shipped %d/%d"%( 78 noShipped, self.dispatcher.totalShippedOut))
79 80 @base.listensTo("IndexCreation")
81 - def announceIndexing(self, indexName):
82 self.showMsg("Create index %s"%indexName)
83 84 @base.listensTo("ScriptRunning")
85 - def announceScriptRunning(self, runner):
86 self.showMsg("%s excecuting script %s"%( 87 runner.__class__.__name__, runner.name))
88 89 @base.listensTo("Info")
90 - def printInfo(self, message):
91 self.showMsg(message)
92