-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathScopePy_colours_and_shapes.py
More file actions
220 lines (151 loc) · 5.66 KB
/
Copy pathScopePy_colours_and_shapes.py
File metadata and controls
220 lines (151 loc) · 5.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# -*- coding: utf-8 -*-
"""
Created on Sat Nov 28 16:43:18 2015
@author: john
ScopePy colours and shapes library
=========================================
Separate library for colours and shapes and other graphical settings
Version
==============================================================================
$Revision:: 116 $
$Date:: 2015-11-16 07:36:25 -0500 (Mon, 1#$
$Author:: $
==============================================================================
"""
#==============================================================================
#%% License
#==============================================================================
"""
Copyright 2015 John Bainbridge
This file is part of ScopePy.
ScopePy is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
ScopePy is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with ScopePy. If not, see <http://www.gnu.org/licenses/>.
"""
#======================================================================
#%% Imports
#======================================================================
# Standard library
# Third party libraries
from PyQt4.QtCore import *
from PyQt4.QtGui import *
#==============================================================================
#%% Constants
#==============================================================================
#==============================================================================
#%% Markers
#==============================================================================
def make_markers(shape_code=None):
"""Create dictionary of markers
"""
markers = {}
# dot
# ------------------------------------------------------
dot = QPolygonF([QPointF(0.0,0.0),
QPointF(0.0,0.0)])
path = QPainterPath()
#path.addRect(-0.5,0.5,1,1)
path.addPolygon(dot)
path.closeSubpath()
#path.moveTo(0,0)
markers['.'] = path
# Square
# ------------------------------------------------------
rectangle = QPolygonF([QPointF(0.5,0.5),
QPointF(0.5,-0.5),
QPointF(-0.5,-0.5),
QPointF(-0.5,0.5)])
path = QPainterPath()
#path.addRect(-0.5,0.5,1,1)
path.addPolygon(rectangle)
path.closeSubpath()
path.moveTo(0,0)
markers['s'] = path
# Circle TODO : Doesn't plot in correct position
# ------------------------------------------------------
path = QPainterPath()
path.addEllipse(-0.5,-0.5,1,1)
#path.moveTo(-0.5,0.5)
markers['o'] = path
# Triangle pointing up
# ------------------------------------------------------
triangle = QPolygonF([QPointF(0.5,0.5),
QPointF(0.0,-0.5),
QPointF(-0.5,0.5)])
path = QPainterPath()
path.addPolygon(triangle)
path.closeSubpath()
path.moveTo(0,0)
markers['^'] = path
# Cross
# ------------------------------------------------------
horiz = QPolygonF([QPointF(-0.5,0.0),QPointF(0.5,0.0)])
vert = QPolygonF([QPointF(0,-0.5),QPointF(0,0.5)])
path = QPainterPath()
path.addPolygon(horiz)
path.addPolygon(vert)
markers['+'] = path
# ------------------------------------------------------
# Return dictionary of markers
# or individual marker if requested
if not shape_code:
return markers
elif shape_code in markers:
return markers[shape_code]
else:
# Default marker
return markers["o"]
#==============================================================================
#%% Colours
#==============================================================================
def default_palette():
"""
Return the default colour palette as a list of RGB numbers
Output
-----------
colour_list : list
Each item is an HTML style RGB string eg '#aa00ff'
"""
# Use Hue/Saturation/Value (HSV) model to generate the colours
# and then convert to RGB
Hues = [0,120,240]
Saturation = 255
Value = 255
# Make a cyclical palette that is essentially red/green/blue repeated
# but offsetting the hue by a constant amount each time
colour_list = []
for offset in range(0,120,20):
for hue in Hues:
colour_list.append( QColor.fromHsv(hue+offset,Saturation,Value).name() )
return colour_list
def rgb_str2num(rgb_str):
"""
Convert RGB string to RGB number using QT functions
Input
------
rgb_str : str
RGB string e.g. '#55ff00'
Output
-------
rgb_int : int
integer version of RGB string e.g.
Example
---------
>>> rgb_str2num('#55ff00')
4283825920
"""
# Make a QColor object and use it to do the conversion
c = QColor()
c.setNamedColor(rgb_str)
return c.rgb()
#==============================================================================
#%% Defaults
#==============================================================================
COLOURS = default_palette()