Removed sha-bang from non-executable python files + whitespace cleanups.
[hooke.git] / hooke / libviewer.py
1 '''
2 Basic Viewer and ascii saver example
3
4 Copyright (C) 2008 Alberto Gomez-Casado (University of Twente).
5
6 This program is released under the GNU General Public License version 2.
7 '''
8
9 import liboutlet as lout
10 import libinput as linput
11
12
13 class Viewer(object):
14     source=[]
15     data=[]
16     dtype='all'
17     action=[]  #alias to call the actual viewer function, makes it general
18
19
20     def setdtype(self, dt):
21         #determines wich type of data will be retrieved from outlet
22         self.dtype=dt   
23
24     def show(self):
25         #TODO should print only data matching 'type'
26         self.source.printbuf()
27
28     def getdata(self):
29         #retrieves data from outlet
30         self.data=self.source.read_type(self.dtype)
31
32
33 class Ascii(Viewer):
34 #example viewer, it just retrieves data and writes it to a text file
35 #probably this should be in viewer.py?
36
37         def __init__(self,outref):
38                 self.source=outref
39                 #tells the viewer which outlet has the data (so far only one in hooke)
40                 self.action=self.dump
41                 #this allows to call dump (or any other function, depending on the viewer) from the CLI using 'vwaction'
42
43         def dump(self):
44                 #retrieves and saves data
45                 self.getdata()
46                 destination=linput.safeinput('Enter filename:',['results.txt'])
47                 destfile=open(destination,'w+')
48                 destfile.write('\n'.join(self.data))
49                 destfile.close()