Skip to content

Commit 8091b78

Browse files
committed
inline from_qvariant and to_qvariant as we do not really support Qt API v1 anyway
1 parent 3fa837e commit 8091b78

File tree

5 files changed

+29
-42
lines changed

5 files changed

+29
-42
lines changed

condarecipe/larray-editor/meta.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ requirements:
2727
- larray >=0.32
2828
- matplotlib
2929
- ipykernel !=5.0, !=5.1
30-
- pyqt
30+
- pyqt >=4.6 # for API v2
3131
- qtpy
3232

3333
test:

larray_editor/arraymodel.py

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import logging
33
from inspect import stack
44
import numpy as np
5-
from larray_editor.utils import (get_font, from_qvariant, to_qvariant, to_text_string,
5+
from larray_editor.utils import (get_font, to_text_string,
66
is_float, is_number, LinearGradient, SUPPORTED_FORMATS, scale_to_01range,
77
Product, is_number_value, get_sample, get_sample_indices, logger)
88
from qtpy.QtCore import Qt, QModelIndex, QAbstractTableModel, Signal
@@ -101,7 +101,7 @@ def flags(self, index):
101101
raise NotImplementedError()
102102

103103
def headerData(self, section, orientation, role=Qt.DisplayRole):
104-
return to_qvariant()
104+
return None
105105

106106
def data(self, index, role=Qt.DisplayRole):
107107
raise NotImplementedError()
@@ -157,23 +157,22 @@ def get_values(self, left=0, right=None):
157157

158158
def data(self, index, role=Qt.DisplayRole):
159159
if not index.isValid():
160-
return to_qvariant()
160+
return None
161161

162162
if role == Qt.TextAlignmentRole:
163-
return to_qvariant(int(Qt.AlignCenter | Qt.AlignVCenter))
163+
return int(Qt.AlignCenter | Qt.AlignVCenter)
164164
elif role == Qt.FontRole:
165165
return self.font
166166
elif role == Qt.BackgroundColorRole:
167167
color = QColor(Qt.lightGray)
168168
color.setAlphaF(.4)
169169
return color
170170
elif role == Qt.DisplayRole:
171-
value = self.get_value(index)
172-
return to_qvariant(value)
173-
elif role == Qt.ToolTipRole:
174-
return to_qvariant()
171+
return self.get_value(index)
172+
# elif role == Qt.ToolTipRole:
173+
# return None
175174
else:
176-
return to_qvariant()
175+
return None
177176

178177

179178
class LabelsArrayModel(AbstractArrayModel):
@@ -223,23 +222,22 @@ def get_values(self, left=0, top=0, right=None, bottom=None):
223222

224223
def data(self, index, role=Qt.DisplayRole):
225224
if not index.isValid():
226-
return to_qvariant()
225+
return None
227226

228227
if role == Qt.TextAlignmentRole:
229-
return to_qvariant(int(Qt.AlignCenter | Qt.AlignVCenter))
228+
return int(Qt.AlignCenter | Qt.AlignVCenter)
230229
elif role == Qt.FontRole:
231230
return self.font
232231
elif role == Qt.BackgroundColorRole:
233232
color = QColor(Qt.lightGray)
234233
color.setAlphaF(.4)
235234
return color
236235
elif role == Qt.DisplayRole:
237-
value = self.get_value(index)
238-
return to_qvariant(value)
239-
elif role == Qt.ToolTipRole:
240-
return to_qvariant()
236+
return self.get_value(index)
237+
# elif role == Qt.ToolTipRole:
238+
# return None
241239
else:
242-
return to_qvariant()
240+
return None
243241

244242

245243
class DataArrayModel(AbstractArrayModel):
@@ -375,14 +373,14 @@ def flags(self, index):
375373
def data(self, index, role=Qt.DisplayRole):
376374
"""Cell content"""
377375
if not index.isValid():
378-
return to_qvariant()
376+
return None
379377
# if role == Qt.DecorationRole:
380378
# return ima.icon('editcopy')
381379
# if role == Qt.DisplayRole:
382380
# return ""
383381

384382
if role == Qt.TextAlignmentRole:
385-
return to_qvariant(int(Qt.AlignRight | Qt.AlignVCenter))
383+
return int(Qt.AlignRight | Qt.AlignVCenter)
386384
elif role == Qt.FontRole:
387385
return self.font
388386

@@ -394,7 +392,7 @@ def data(self, index, role=Qt.DisplayRole):
394392
elif isinstance(value, str) and not isinstance(value, np.str_):
395393
return value
396394
else:
397-
return to_qvariant(self._format % value)
395+
return self._format % value
398396
elif role == Qt.BackgroundColorRole:
399397
if self.bgcolor_possible and self.bg_gradient is not None and value is not np.ma.masked:
400398
if self.bg_value is None:
@@ -418,8 +416,8 @@ def data(self, index, role=Qt.DisplayRole):
418416
v = self.bg_value[i, j]
419417
return self.bg_gradient[v]
420418
# elif role == Qt.ToolTipRole:
421-
# return to_qvariant("{}\n{}".format(repr(value),self.get_labels(index)))
422-
return to_qvariant()
419+
# return "{}\n{}".format(repr(value),self.get_labels(index))
420+
return None
423421

424422
def get_values(self, left=0, top=0, right=None, bottom=None, sample=False):
425423
width, height = self.total_rows, self.total_cols
@@ -567,5 +565,5 @@ def setData(self, index, value, role=Qt.EditRole):
567565
if not index.isValid() or self.readonly:
568566
return False
569567
i, j = index.row(), index.column()
570-
result = self.set_values(i, j, i + 1, j + 1, from_qvariant(value, str))
568+
result = self.set_values(i, j, i + 1, j + 1, value)
571569
return result is not None

larray_editor/arraywidget.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,7 @@
7878
QMessageBox, QMenu, QLabel, QSpinBox, QWidget, QToolTip, QShortcut, QScrollBar,
7979
QHBoxLayout, QVBoxLayout, QGridLayout, QSizePolicy, QFrame, QComboBox)
8080

81-
from larray_editor.utils import (keybinding, create_action, clear_layout, get_font, from_qvariant, to_qvariant,
82-
is_number, is_float, _, ima, LinearGradient)
81+
from larray_editor.utils import (keybinding, create_action, clear_layout, get_font, is_number, is_float, _, ima, LinearGradient)
8382
from larray_editor.arrayadapter import get_adapter
8483
from larray_editor.arraymodel import LabelsArrayModel, AxesArrayModel, DataArrayModel
8584
from larray_editor.combo import FilterComboBox
@@ -232,7 +231,7 @@ def createEditor(self, parent, option, index):
232231
if self.dtype.name == "bool":
233232
# toggle value
234233
value = not value
235-
model.setData(index, to_qvariant(value))
234+
model.setData(index, value)
236235
return
237236
elif value is not np.ma.masked:
238237
minvalue, maxvalue = self.minvalue, self.maxvalue
@@ -279,7 +278,7 @@ def on_editor_destroyed(self):
279278

280279
def setEditorData(self, editor, index):
281280
"""Set editor widget's data"""
282-
text = from_qvariant(index.model().data(index, Qt.DisplayRole), str)
281+
text = index.model().data(index, Qt.DisplayRole)
283282
editor.setText(text)
284283

285284

larray_editor/utils.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
pass
1212

1313
from qtpy import PYQT5
14-
from qtpy.QtCore import Qt, QVariant, QSettings
14+
from qtpy.QtCore import Qt, QSettings
1515
from qtpy.QtGui import QIcon, QColor, QFont, QKeySequence, QLinearGradient
1616
from qtpy.QtWidgets import QAction, QDialog, QVBoxLayout
1717

@@ -140,7 +140,7 @@ def _get_font(family, size, bold=False, italic=False):
140140
font = QFont(family, size, weight)
141141
if italic:
142142
font.setItalic(True)
143-
return to_qvariant(font)
143+
return font
144144

145145

146146
def is_float(dtype):
@@ -157,18 +157,6 @@ def get_font(section):
157157
return _get_font('Calibri', 11)
158158

159159

160-
def to_qvariant(obj=None):
161-
return obj
162-
163-
164-
def from_qvariant(qobj=None, pytype=None):
165-
# FIXME: force API level 2 instead of handling this
166-
if isinstance(qobj, QVariant):
167-
assert pytype is str
168-
return pytype(qobj.toString())
169-
return qobj
170-
171-
172160
def _(text):
173161
return text
174162

@@ -297,7 +285,7 @@ def __getitem__(self, key):
297285
col0, col1 = self.colors[pos_idx:pos_idx + 2]
298286
assert pos1 > pos0
299287
color = col0 + (col1 - col0) * (key - pos0) / (pos1 - pos0)
300-
return to_qvariant(QColor.fromHsvF(*color))
288+
return QColor.fromHsvF(*color)
301289

302290

303291
class PlotDialog(QDialog):

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ def readlocal(fname):
1515
SETUP_REQUIRES = []
1616
# pyqt cannot be installed via pypi. Dependencies (pyqt, qtpy and matplotlib) moved to conda recipe
1717
# requires larray >= 0.32 because of the LArray -> Array rename
18+
# TODO: add qtpy as dependency and mention pyqt or pyside
19+
# when using pyqt, we require at least pyqt >= 4.6 (for API v2)
1820
INSTALL_REQUIRES = ['larray >=0.32', 'ipykernel !=5.0, !=5.1']
1921
TESTS_REQUIRE = ['pytest']
2022

0 commit comments

Comments
 (0)