source: trunk/src/testing/ui/globals.py @ 4

Revision 4, 8.7 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

Line 
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# this file holds functions and constants used throughout the application
42
43import os.path, time, wx, sys
44
45# shortcut
46opj = os.path.join
47sys.path.append( opj(os.environ["SAGE_DIRECTORY"], "bin" ) )
48from sagePath import getUserPath, getPath, SAGE_DIR
49
50
51#------------------------------------------------------------------------
52#     COLORS 
53#------------------------------------------------------------------------
54
55# display
56tileColor = wx.Colour(102, 204, 204)
57
58# shapes
59shapeColor          = wx.Colour(153, 255, 255)
60shapeBorderColor    = wx.Colour(204, 153, 102)
61shapeTextColor      = "grey" 
62shapeSelectedTextColor = "white"
63shapeBorderColor    = wx.Colour(51,153,153)
64shapeHighlightColor = wx.Colour(255, 204, 102)
65shapeShadowColor    = wx.Colour(51, 102, 102)
66shapeSelectedBorderColor = wx.Colour(153,255,204)
67shapeSelectedColor  = wx.Colour(51,153,153)
68
69dialogColor = wx.Colour(51, 102, 102)
70
71# app panel
72appPanelColor = wx.Colour(0,51,52)
73
74# info panel
75infoPanelColor = wx.Colour(102,204,153)
76
77# performance panel
78perfButtonColor     = wx.Colour(0, 153, 153)
79perfButtonTextColor = wx.Colour(255, 255, 255)
80perfPanelColor = wx.Colour(102,204,153)
81
82
83
84#------------------------------------------------------------------------
85#     PATHS
86#------------------------------------------------------------------------
87
88def ConvertPath(path):
89    """Convert paths to the platform-specific separator"""
90    return apply(opj, tuple(path.split('\\')))
91
92
93DATA_DIR = getUserPath("sageui", "data")
94LOG_FILE = getUserPath("sageui", "output_log.txt")
95SAVED_STATES_DIR = getUserPath("saved-states")
96
97
98#------------------------------------------------------------------------
99#     DIALOG UTILITY FUNCTIONS
100#------------------------------------------------------------------------
101
102def ShowWriteFailedDialog(filename):
103    dialog = wx.MessageDialog(None, "Unable to write to file <"+filename+">. Check write permissions for the file or directory.",
104                              "Write Failed", wx.OK)
105    dialog.ShowModal()
106
107
108def Message(msg, title):
109    """ for thread safety """
110    wx.CallAfter(_ShowMessage, msg, title)
111
112def _ShowMessage(msg, title):
113    dlg = wx.MessageDialog(None, msg, title, style = wx.OK)
114    dlg.ShowModal()
115
116def ChoiceDialog(msg, title):
117    dlg = wx.MessageDialog(None, msg, title, style = wx.OK | wx.CANCEL)
118    if dlg.ShowModal() == wx.ID_OK:
119        return True
120    else:
121        return False
122
123
124def ShowColorDialog(previousColor=None):
125    """ takes in (r,g,b) tuple and returns the same """
126    if not previousColor == None:
127        colorData = wx.ColourData()
128        colorData.SetColour(previousColor)
129        dlg = wx.ColourDialog(None, colorData)
130    else:
131        dlg = wx.ColourDialog(None)
132
133    dlg.GetColourData().SetChooseFull(True)
134    if dlg.ShowModal() == wx.ID_OK:
135        color = dlg.GetColourData().GetColour()
136        dlg.Destroy()
137        return color
138    else:
139        dlg.Destroy()
140        return (-1,-1,-1)
141
142
143
144
145def doRun():
146    return True
147
148
149#------------------------------------------------------------------------
150#     FONTS 
151#------------------------------------------------------------------------
152
153def StandardFont(window = None):
154    if window == None:
155        ss = wx.SystemSettings
156        ssFont = ss.GetFont(wx.SYS_DEFAULT_GUI_FONT)
157        return ssFont
158    else:
159        winFont = window.GetFont()
160        return winFont
161   
162
163def BoldFont(window = None):
164    if window == None:
165        ss = wx.SystemSettings
166        ssFont = ss.GetFont(wx.SYS_DEFAULT_GUI_FONT)
167        ssFont.SetWeight(wx.BOLD)
168        return ssFont
169    else:
170        winFont = window.GetFont()
171        winFont.SetWeight(wx.BOLD)
172        return winFont
173
174
175
176#------------------------------------------------------------------------
177#    LOCATION OF THE SAGE SERVER
178#------------------------------------------------------------------------
179   
180SAGE_SERVER = "sage.sl.startap.net"
181def setSAGEServer(server):
182    global SAGE_SERVER
183    SAGE_SERVER = server
184
185def getSAGEServer():
186    return SAGE_SERVER
187   
188
189
190
191#------------------------------------------------------------------------
192#    LOCATION OF THE APP LAUNCHER
193#------------------------------------------------------------------------
194   
195APP_LAUNCHER = ""
196def setAppLauncher(server):
197    global APP_LAUNCHER
198    APP_LAUNCHER = server
199
200def getAppLauncher():
201    return APP_LAUNCHER
202
203
204
205#------------------------------------------------------------------------
206#    SAGE UI VERSION
207#------------------------------------------------------------------------
208
209global UI_VERSION
210def setUIVersion(v):
211    global UI_VERSION
212    UI_VERSION = v
213
214def getUIVersion():
215    return UI_VERSION
216
217
218
219
220#------------------------------------------------------------------------
221#     USERS DATA (data from sage server about all the connections)
222#------------------------------------------------------------------------
223
224global USERSDATA
225def setUsersData(d):
226    global USERSDATA
227    USERSDATA = d
228
229def getUsersData():
230    return USERSDATA
231
232
233
234#------------------------------------------------------------------------
235#    POINTER STATES AND TYPES
236#------------------------------------------------------------------------
237#### Sage Draw Object types
238POINTER_TYPE = 1
239
240
241#### MOUSE STATES
242PTR_NORMAL_STATE = 1
243PTR_MOVE_STATE   = 2
244PTR_RESIZE_STATE = 3
245
246
247
248
249#------------------------------------------------------------------------
250#    FOR RECORDING PERFROMANCE DATA TOTALS
251#------------------------------------------------------------------------
252global startTime
253startTime = -1
254def getTimeStamp():
255    global startTime
256    if startTime == -1:  # set the start time on first request... so that we start from 0
257        startTime = time.time()
258    return int(round(time.time() - startTime))
259
260
261
262#------------------------------------------------------------------------
263#    FOR MULTIPLE SAGE DISPLAYS ON ONE FSMANAGER
264#------------------------------------------------------------------------
265
266MIDDLE_DISP = -1
267LEFT_DISP = 0
268RIGHT_DISP = 1
269BOTTOM_DISP = 2
270TOP_DISP = 3
271
272
273class Bounds:
274    """ used in event conversion """
275    def __init__(self, left=0, right=0, top=0, bottom=0):
276        self.left = int(round(left))
277        self.right = int(round(right))
278        self.top = int(round(top))
279        self.bottom = int(round(bottom))
280
281    def setAll(self, left, right, top, bottom):
282        self.left = int(round(left))
283        self.right = int(round(right))
284        self.top = int(round(top))
285        self.bottom = int(round(bottom))
286
287    def getAll(self):
288        return self.left, self.right, self.top, self.bottom
289
290    def getWidth(self):
291        return self.right - self.left
292
293    def getHeight(self):
294        return self.bottom - self.top   # top is 0
295
296##     def isIn(self, x, y):
297##         """ returns True if the (x,y) is in Bounds, False otherwise """
298##         if self.left <= x and self.right >= x and self.bottom <= y and self.top >= y:
299##             return True
300##         else:
301##             return False
Note: See TracBrowser for help on using the repository browser.