signal.py 1.79 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
    
    def __init__(self,queryType, content) :
15
        if queryType in [Query.READDATA,Query.NEWSYNCFIGURE,Query.UPDATESYNCFIGURE,Query.SYNCFIGFORMATRAWDATA,Query.DELETESYNCFIGURE] :
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
            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 :
31
                self.content = content
32
33
            
            elif queryType == Query.SYNCFIGFORMATRAWDATA :
34
                self.content = content
35
36
37
38
39
40
                
            elif queryType == Query.DELETESYNCFIGURE :
                self.content = content
            else :
                print('unknown query type!')
                raise
41
42
43
44
45
46
47
48
49
50
51
52
        

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