4
4
import sys
5
5
import numpy as np
6
6
7
- PY2 = sys .version [0 ] == '2'
8
-
9
7
from qtpy import PYQT5
10
8
from qtpy .QtCore import QVariant
11
9
from qtpy .QtGui import QIcon , QColor , QFont , QKeySequence
19
17
from matplotlib .backends .backend_qt4agg import NavigationToolbar2QT as NavigationToolbar
20
18
21
19
20
+ PY2 = sys .version [0 ] == '2'
21
+
22
22
# Note: string and unicode data types will be formatted with '%s' (see below)
23
23
SUPPORTED_FORMATS = {
24
24
'object' : '%s' ,
62
62
'bool' : '%r' ,
63
63
}
64
64
65
+
65
66
def _get_font (family , size , bold = False , italic = False ):
66
67
weight = QFont .Bold if bold else QFont .Normal
67
68
font = QFont (family , size , weight )
68
69
if italic :
69
70
font .setItalic (True )
70
71
return to_qvariant (font )
71
72
73
+
72
74
def is_float (dtype ):
73
75
"""Return True if datatype dtype is a float kind"""
74
76
return ('float' in dtype .name ) or dtype .name in ['single' , 'double' ]
75
77
78
+
76
79
def is_number (dtype ):
77
80
"""Return True is datatype dtype is a number kind"""
78
81
return is_float (dtype ) or ('int' in dtype .name ) or ('long' in dtype .name ) or ('short' in dtype .name )
79
82
83
+
80
84
def get_font (section ):
81
85
return _get_font ('Calibri' , 11 )
82
86
87
+
83
88
def to_qvariant (obj = None ):
84
89
return obj
85
90
91
+
86
92
def from_qvariant (qobj = None , pytype = None ):
87
93
# FIXME: force API level 2 instead of handling this
88
94
if isinstance (qobj , QVariant ):
89
95
assert pytype is str
90
96
return pytype (qobj .toString ())
91
97
return qobj
92
98
99
+
93
100
def _ (text ):
94
101
return text
95
102
103
+
96
104
def to_text_string (obj , encoding = None ):
97
105
"""Convert `obj` to (unicode) text string"""
98
106
if PY2 :
@@ -111,11 +119,13 @@ def to_text_string(obj, encoding=None):
111
119
else :
112
120
return str (obj , encoding )
113
121
122
+
114
123
def keybinding (attr ):
115
124
"""Return keybinding"""
116
125
ks = getattr (QKeySequence , attr )
117
126
return QKeySequence .keyBindings (ks )[0 ]
118
127
128
+
119
129
def create_action (parent , text , icon = None , triggered = None , shortcut = None , statustip = None ):
120
130
"""Create a QAction"""
121
131
action = QAction (text , parent )
@@ -130,6 +140,7 @@ def create_action(parent, text, icon=None, triggered=None, shortcut=None, status
130
140
# action.setShortcutContext(Qt.WidgetShortcut)
131
141
return action
132
142
143
+
133
144
def clear_layout (layout ):
134
145
for i in reversed (range (layout .count ())):
135
146
item = layout .itemAt (i )
@@ -139,6 +150,7 @@ def clear_layout(layout):
139
150
widget .deleteLater ()
140
151
layout .removeItem (item )
141
152
153
+
142
154
def get_idx_rect (index_list ):
143
155
"""Extract the boundaries from a list of indexes"""
144
156
rows = [i .row () for i in index_list ]
@@ -147,7 +159,6 @@ def get_idx_rect(index_list):
147
159
148
160
149
161
class IconManager (object ):
150
-
151
162
_icons = {'larray' : 'larray.ico' }
152
163
_icon_dir = os .path .join (os .path .dirname (os .path .realpath (__file__ )), 'images' )
153
164
@@ -162,6 +173,7 @@ def icon(self, ref):
162
173
# appropriate PySide.QtGui.QIcon.themeName() .
163
174
return QIcon .fromTheme (ref )
164
175
176
+
165
177
ima = IconManager ()
166
178
167
179
@@ -170,11 +182,11 @@ class LinearGradient(object):
170
182
I cannot believe I had to roll my own class for this when PyQt already
171
183
contains QLinearGradient... but you cannot get intermediate values out of
172
184
QLinearGradient!
173
-
185
+
174
186
Parameters
175
187
----------
176
188
stop_points: list/tuple, optional
177
- List containing pairs (stop_position, colors_HsvF).
189
+ List containing pairs (stop_position, colors_HsvF).
178
190
`colors` is a 4 elements list containing `hue`, `saturation`, `value` and `alpha-channel`
179
191
"""
180
192
def __init__ (self , stop_points = None ):
@@ -224,6 +236,7 @@ def __init__(self, canvas, parent=None):
224
236
self .setLayout (layout )
225
237
canvas .draw ()
226
238
239
+
227
240
def show_figure (parent , figure ):
228
241
canvas = FigureCanvas (figure )
229
242
main = PlotDialog (canvas , parent )
0 commit comments