1 | ############################################################################
|
---|
2 | #
|
---|
3 | # SAGE UI - A Graphical User Interface for SAGE
|
---|
4 | # Copyright (C) 2005 Electronic Visualization Laboratory,
|
---|
5 | # University of Illinois at Chicago
|
---|
6 | #
|
---|
7 | # All rights reserved.
|
---|
8 | #
|
---|
9 | # Redistribution and use in source and binary forms, with or without
|
---|
10 | # modification, are permitted provided that the following conditions are met:
|
---|
11 | #
|
---|
12 | # * Redistributions of source code must retain the above copyright
|
---|
13 | # notice, this list of conditions and the following disclaimer.
|
---|
14 | # * Redistributions in binary form must reproduce the above
|
---|
15 | # copyright notice, this list of conditions and the following disclaimer
|
---|
16 | # in the documentation and/or other materials provided with the distribution.
|
---|
17 | # * Neither the name of the University of Illinois at Chicago nor
|
---|
18 | # the names of its contributors may be used to endorse or promote
|
---|
19 | # products derived from this software without specific prior written permission.
|
---|
20 | #
|
---|
21 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
---|
22 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
---|
23 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
---|
24 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
|
---|
25 | # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
---|
26 | # EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
---|
27 | # PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
28 | # PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
---|
29 | # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
---|
30 | # NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
---|
31 | # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
32 | #
|
---|
33 | # Direct questions, comments etc about SAGE UI to www.evl.uic.edu/cavern/forum
|
---|
34 | #
|
---|
35 | # Author: Ratko Jagodic
|
---|
36 | #
|
---|
37 | ############################################################################
|
---|
38 |
|
---|
39 |
|
---|
40 |
|
---|
41 | from globals import *
|
---|
42 | import time
|
---|
43 |
|
---|
44 | class SageDrawObject:
|
---|
45 | """ describes a base class for a sage draw object """
|
---|
46 | def __init__(self, objectId, objectType, sageGate):
|
---|
47 | self.objectId = objectId
|
---|
48 | self.objectType = objectType
|
---|
49 | self.visible = False
|
---|
50 | self.sageGate = sageGate
|
---|
51 |
|
---|
52 | def getId(self):
|
---|
53 | return self.objectId
|
---|
54 |
|
---|
55 | def getType(self):
|
---|
56 | return self.objectType
|
---|
57 |
|
---|
58 | def isVisible(self):
|
---|
59 | return self.visible
|
---|
60 |
|
---|
61 | def show(self):
|
---|
62 | if not self.visible:
|
---|
63 | self.visible = True
|
---|
64 | self.sageGate.showObject(self.objectId)
|
---|
65 |
|
---|
66 | def hide(self):
|
---|
67 | if self.visible:
|
---|
68 | self.visible = False
|
---|
69 | self.sageGate.hideObject(self.objectId)
|
---|
70 |
|
---|
71 |
|
---|
72 |
|
---|
73 |
|
---|
74 |
|
---|
75 | class PointerObject(SageDrawObject):
|
---|
76 | """ describes a sage draw object for pointers """
|
---|
77 | def __init__(self, objectId, sageGate):
|
---|
78 | SageDrawObject.__init__(self, objectId, POINTER_TYPE, sageGate)
|
---|
79 | self.clickPos = [-1,-1] # last click position [x,y]
|
---|
80 | self.lastRegion = [-1, None] # [regionId, app]
|
---|
81 | self.region = [-1, None] # [regionId, app]
|
---|
82 | self.state = PTR_NORMAL_STATE # controls all the drawing of the pointer
|
---|
83 | self.ptrState = PTR_NORMAL_STATE # only used to control the drawing of the cursor itself
|
---|
84 | self.leftDown = False
|
---|
85 | self.leftDownTime = 0.0
|
---|
86 |
|
---|
87 |
|
---|
88 | def updateRegion(self, regionId, app):
|
---|
89 | self.lastRegion = self.region
|
---|
90 | self.region = [regionId, app]
|
---|
91 |
|
---|
92 |
|
---|
93 | def showResizePointer(self):
|
---|
94 | self.ptrState = PTR_RESIZE_STATE
|
---|
95 | self.sageGate.showResizeMouse(self.objectId, self.region[0])
|
---|
96 |
|
---|
97 |
|
---|
98 | def reset(self):
|
---|
99 | self.ptrState = PTR_NORMAL_STATE
|
---|
100 | self.state = PTR_NORMAL_STATE
|
---|
101 | self.sageGate.resetMouseState(self.objectId)
|
---|
102 |
|
---|
103 |
|
---|
104 | def onMouseDown(self, app, regionId, x, y):
|
---|
105 | self.leftDown = True
|
---|
106 | self.leftDownTime = time.time()
|
---|
107 | self.clickPos = [x,y]
|
---|
108 | self.lastRegion = [regionId, app]
|
---|
109 | self.sageGate.sendMouseDown(self.objectId)
|
---|
110 |
|
---|
111 |
|
---|
112 | def onMouseUp(self):
|
---|
113 | self.leftDown = False
|
---|
114 | self.sageGate.sendMouseUp(self.objectId)
|
---|