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 | import sys, string |
---|
42 | |
---|
43 | ### Class to hold sage application info |
---|
44 | ### An instance of this class should exist for every app Id on SAGE |
---|
45 | class SageApp : |
---|
46 | |
---|
47 | |
---|
48 | def __init__(self, name, windowId, left, right, bottom, top, sailID, zValue, orientation, displayId, appId, launcherId, title=""): |
---|
49 | self.left = left |
---|
50 | self.right = right |
---|
51 | self.top = top |
---|
52 | self.bottom = bottom |
---|
53 | self.sailID = sailID |
---|
54 | self.appName = name |
---|
55 | self.windowId = windowId |
---|
56 | self.appId = appId |
---|
57 | self.launcherId = launcherId |
---|
58 | self.zValue = zValue |
---|
59 | self.configNum = 0 |
---|
60 | self.title = title |
---|
61 | self.capture = -1 # which pointer captured it |
---|
62 | self.orientation = 0 # in degrees |
---|
63 | self.displayId = 0 |
---|
64 | |
---|
65 | |
---|
66 | def setAll(self, name, windowId, left, right, bottom, top, sailID, zValue, orientation, displayId, appId, launcherId): |
---|
67 | self.appName = name |
---|
68 | self.windowId = windowId |
---|
69 | self.appId = appId |
---|
70 | self.launcherId = launcherId |
---|
71 | self.left = left |
---|
72 | self.right = right |
---|
73 | self.bottom = bottom |
---|
74 | self.top = top |
---|
75 | self.sailID = sailID |
---|
76 | self.zValue = zValue |
---|
77 | self.orientation = orientation |
---|
78 | self.displayId = displayId |
---|
79 | #self.title = title |
---|
80 | |
---|
81 | |
---|
82 | def getLeft(self): |
---|
83 | return self.left |
---|
84 | |
---|
85 | def getRight(self): |
---|
86 | return self.right |
---|
87 | |
---|
88 | def getTop(self): |
---|
89 | return self.top |
---|
90 | |
---|
91 | def getBottom(self): |
---|
92 | return self.bottom |
---|
93 | |
---|
94 | def getId(self): |
---|
95 | return self.windowId |
---|
96 | |
---|
97 | def getAppId(self): |
---|
98 | return self.appId |
---|
99 | |
---|
100 | def getLauncherId(self): |
---|
101 | return self.launcherId |
---|
102 | |
---|
103 | def getConfigNum(self): |
---|
104 | return self.configNum |
---|
105 | |
---|
106 | def getTitle(self): |
---|
107 | return self.title |
---|
108 | |
---|
109 | def setTitle(self, newTitle): |
---|
110 | self.title = newTitle |
---|
111 | |
---|
112 | def getWidth(self): |
---|
113 | return self.right - self.left |
---|
114 | |
---|
115 | def getHeight(self): |
---|
116 | return self.top - self.bottom |
---|
117 | |
---|
118 | def getDisplayId(self): |
---|
119 | return self.displayId |
---|
120 | |
---|
121 | def getOrientation(self): |
---|
122 | return self.orientation |
---|
123 | |
---|
124 | def setName(self, appName): |
---|
125 | self.appName = appName |
---|
126 | |
---|
127 | def getName(self): |
---|
128 | return self.appName |
---|
129 | |
---|
130 | #### Get the application window values |
---|
131 | #### @return Returns a list Format: [<left>, <right>, <top>, <bottom>] |
---|
132 | def getBounds(self) : |
---|
133 | return [self.left, self.right, self.top, self.bottom] |
---|
134 | |
---|
135 | #### Get the app's sailID |
---|
136 | def getSailID(self): |
---|
137 | return self.sailID |
---|
138 | |
---|
139 | def setZvalue(self, value): |
---|
140 | self.zValue = value |
---|
141 | |
---|
142 | def getZvalue(self): |
---|
143 | return self.zValue |
---|
144 | |
---|
145 | def hasCapture(self): |
---|
146 | if self.capture == -1: |
---|
147 | return False |
---|
148 | else: |
---|
149 | return True |
---|
150 | |
---|
151 | def captureMouse(self, pointerId): |
---|
152 | self.capture = pointerId |
---|
153 | |
---|
154 | def releaseMouse(self): |
---|
155 | self.capture = -1 |
---|
156 | |
---|
157 | |
---|
158 | # checks whether (x,y) hit something on the shape |
---|
159 | # calculations are done in the sage coordinate system (bottom left = 0,0) |
---|
160 | # 0 = everything else... inside the app |
---|
161 | # -2 = hit but not on the corners (BOTTOM) |
---|
162 | # -1 = hit but not on the corners (TOP) |
---|
163 | # 1 = bottom left corner |
---|
164 | # 2 = top left corner |
---|
165 | # 3 = top right |
---|
166 | # 4 = bottom right |
---|
167 | def hitTest(self, x, y, cornerSize=250): |
---|
168 | |
---|
169 | # utility function |
---|
170 | def __inRegion(r): |
---|
171 | if x >= r[0] and x <= r[1] and y<=r[2] and y>=r[3]: |
---|
172 | return True |
---|
173 | return False |
---|
174 | |
---|
175 | (l,r,t,b,cs) = (self.left, self.right, self.top, self.bottom, cornerSize) |
---|
176 | |
---|
177 | # define the regions we need to test |
---|
178 | testRegions = {} # keyed by -2,-1,1,2,3,4 |
---|
179 | testRegions[-2] = (l+cs, r-cs, b+cs, b) |
---|
180 | testRegions[-1] = (l+cs, r-cs, t, t-cs) |
---|
181 | testRegions[1] = (l, l+cs, b+cs, b) |
---|
182 | testRegions[2] = (l, l+cs, t, t-cs) |
---|
183 | testRegions[3] = (r-cs, r, t, t-cs) |
---|
184 | testRegions[4] = (r-cs, r, b+cs, b) |
---|
185 | |
---|
186 | # now loop through the regions and test whether x,y is in it |
---|
187 | result = 0 |
---|
188 | for rid, r in testRegions.iteritems(): |
---|
189 | if __inRegion(r): |
---|
190 | return rid |
---|
191 | |
---|
192 | return result |
---|
193 | |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | |
---|
198 | |
---|
199 | |
---|
200 | ### a class to hold the information about all the available apps that SAGE supports |
---|
201 | class SageAppInitial: |
---|
202 | |
---|
203 | def __init__ (self, name, configNames): |
---|
204 | self._name = name |
---|
205 | self._configNames = configNames |
---|
206 | |
---|
207 | def GetName (self): |
---|
208 | return self._name |
---|
209 | |
---|
210 | def SetName (self, name): |
---|
211 | self._name = name |
---|
212 | |
---|
213 | def GetConfigNames(self): |
---|
214 | return self._configNames |
---|
215 | |
---|
216 | ## # execution configurations |
---|
217 | ## def AddConfig (self, name, stConfig): |
---|
218 | ## self._execConfigs[ len(self._execConfigs)+1 ] = (name, string.strip(stConfig)) |
---|
219 | |
---|
220 | ## def GetNumConfigs(self): |
---|
221 | ## return self._numConfigs |
---|
222 | |
---|
223 | ## def GetConfigHash (self): |
---|
224 | ## return self._execConfigs |
---|
225 | |
---|
226 | ## def GetConfig (self, configNum): |
---|
227 | ## if self._execConfigs.has_key( configNum ): |
---|
228 | ## return self._execConfigs[ configNum ] |
---|
229 | ## else: |
---|
230 | ## print "Error: No configuration number ", configNum |
---|
231 | ## return "No Configuration" |
---|
232 | |
---|
233 | ## # instances already started |
---|
234 | ## def AddInstanceId (self, instanceId): |
---|
235 | ## self._appInstanceIds.append( instanceId ) |
---|
236 | |
---|
237 | ## def GetInstanceIds (self): |
---|
238 | ## return self._appInstanceIds |
---|
239 | |
---|
240 | |
---|