2 Basic Viewer and ascii saver example
4 Copyright (C) 2008 Alberto Gomez-Casado (University of Twente).
6 This program is released under the GNU General Public License version 2.
8 So far outlet is useless. That's where viewers (well, only one now)
9 do the job. They query outlet for data of some type, process it and
10 give some elaborated output. Again the only thing they have to know
11 about outlet is how to call it and the 'line' format.
13 I put in the viewer plugin a list to keep them so it is possible to
14 create many. The basic operations in viewer.py
15 - vwnew: adds a new viewer to the list, and sets it so it defines
16 what type of data it will be interested in
17 - vwaction: tells the viewer to 'do stuff', that is, retrieve data
18 and process it. Just a wrapper call for the specific one of each
22 import liboutlet as lout
23 import libinput as linput
30 action=[] #alias to call the actual viewer function, makes it general
33 def setdtype(self, dt):
34 #determines wich type of data will be retrieved from outlet
38 #TODO should print only data matching 'type'
39 self.source.printbuf()
42 #retrieves data from outlet
43 self.data=self.source.read_type(self.dtype)
47 #example viewer, it just retrieves data and writes it to a text file
48 #probably this should be in viewer.py?
50 def __init__(self,outref):
52 #tells the viewer which outlet has the data (so far only one in hooke)
54 #this allows to call dump (or any other function, depending on the viewer) from the CLI using 'vwaction'
57 #retrieves and saves data
59 destination=linput.safeinput('Enter filename:',['results.txt'])
60 destfile=open(destination,'w+')
61 destfile.write('\n'.join(self.data))