signal.py 1.91 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
class Signal (object):
    def __init__(self,content) :
        # every signal should have a content attribute
        self.content = content 

class Query(Signal) :
    
    READDATA             = 1
    NEWSYNCFIGURE        = 2
    UPDATESYNCFIGURE     = 3
    SYNCFIGFORMATRAWDATA = 4
12
    DELETESYNCFIGURE     = 5
13
14
    LISTDATA             = 6
    GETDATA              = 7
15
16
    
    def __init__(self,queryType, content) :
17
        if queryType in range(1,8) :
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
            self.queryType = queryType
            if queryType == Query.READDATA :
                if type(content) == dict :
                    self.content = content
                else :
                    print('parameter 2 of Query constructor is exspected to be of type dict')
                    raise
            elif queryType == Query.NEWSYNCFIGURE :
                if type(content) == dict : # same as 
                    self.content = content
                else :
                    print('parameter 2 of Query constructor is exspected to be of type dict')
                    raise
                    
            elif queryType == Query.UPDATESYNCFIGURE :
33
                self.content = content
34
35
            
            elif queryType == Query.SYNCFIGFORMATRAWDATA :
36
                self.content = content
37
38
39
                
            elif queryType == Query.DELETESYNCFIGURE :
                self.content = content
40
41
42
43
            elif queryType == Query.LISTDATA :
                self.content = content
            elif queryType == Query.GETDATA :
                self.content = content
44
45
46
            else :
                print('unknown query type!')
                raise
47
48
49
50
51
52
53
54
55
56
57
58
        

class Status(Signal):
    def __init__(self,value,error) :
        if (value == True) or (value == False) :
            self.value = value
        if (type(error) == str) :
            self.content = error

class Answer(Signal):
    def __init__(self,value) :
        self.content = value