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