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