Skip to content

Commit e4ae84f

Browse files
committed
- added utils.py
- renamed model.py as arraymodel.py - splited view.py in arraywidget.py, editor.py and comparator.py
1 parent 59904f1 commit e4ae84f

File tree

8 files changed

+1946
-1928
lines changed

8 files changed

+1946
-1928
lines changed

larray_editor/api.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
from __future__ import absolute_import, division, print_function
22

3-
import os
43
import sys
54
import traceback
65
from collections import OrderedDict
76
import numpy as np
87
import larray as la
98

109
from qtpy.QtWidgets import QApplication, QMainWindow
11-
from larray_editor.view import MappingEditor, ArrayEditor, SessionComparator, ArrayComparator, REOPEN_LAST_FILE
10+
from larray_editor.editor import REOPEN_LAST_FILE
1211

1312
__all__ = ['view', 'edit', 'compare', 'REOPEN_LAST_FILE']
1413

@@ -115,7 +114,13 @@ def edit(obj=None, title='', minvalue=None, maxvalue=None, readonly=False, depth
115114
if not title and obj is not REOPEN_LAST_FILE:
116115
title = get_title(obj, depth=depth + 1)
117116

118-
dlg = MappingEditor(parent) if obj is REOPEN_LAST_FILE or isinstance(obj, (str, la.Session)) else ArrayEditor(parent)
117+
if obj is REOPEN_LAST_FILE or isinstance(obj, (str, la.Session)):
118+
from larray_editor.editor import MappingEditor
119+
dlg = MappingEditor(parent)
120+
else:
121+
from larray_editor.editor import ArrayEditor
122+
dlg = ArrayEditor(parent)
123+
119124
if dlg.setup_and_check(obj, title=title, minvalue=minvalue, maxvalue=maxvalue, readonly=readonly):
120125
if parent or isinstance(dlg, QMainWindow):
121126
dlg.show()
@@ -187,9 +192,11 @@ def compare(*args, **kwargs):
187192
parent = _app.activeWindow()
188193

189194
if any(isinstance(a, la.Session) for a in args):
195+
from larray_editor.comparator import SessionComparator
190196
dlg = SessionComparator(parent)
191197
default_name = 'session'
192198
else:
199+
from larray_editor.comparator import ArrayComparator
193200
dlg = ArrayComparator(parent)
194201
default_name = 'array'
195202

@@ -332,6 +339,10 @@ def restore_display_hook():
332339
# edit('fake_path')
333340
# edit(REOPEN_LAST_FILE)
334341

342+
# edit(arr2)
343+
# compare(la.Session(arr2=arr2, arr3=arr3), la.Session(arr2=arr2 + 1.0, arr3=arr3 + 1.0))
344+
# compare(arr2, arr2 + 1.0)
345+
335346
# s = la.local_arrays()
336347
# view(s)
337348
# print('HDF')

larray_editor/model.py renamed to larray_editor/arraymodel.py

Lines changed: 6 additions & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -1,113 +1,14 @@
11
from __future__ import absolute_import, division, print_function
22

3-
import sys
43
import numpy as np
5-
import pandas as pd
64
import larray as la
75

8-
from qtpy.QtCore import (Qt, QVariant, QModelIndex, QAbstractTableModel)
9-
from qtpy.QtGui import (QFont, QColor)
10-
from qtpy.QtWidgets import (QMessageBox)
11-
from qtpy import PYQT5
12-
13-
PY2 = sys.version[0] == '2'
14-
15-
16-
def _get_font(family, size, bold=False, italic=False):
17-
weight = QFont.Bold if bold else QFont.Normal
18-
font = QFont(family, size, weight)
19-
if italic:
20-
font.setItalic(True)
21-
return to_qvariant(font)
22-
23-
def is_float(dtype):
24-
"""Return True if datatype dtype is a float kind"""
25-
return ('float' in dtype.name) or dtype.name in ['single', 'double']
26-
27-
def is_number(dtype):
28-
"""Return True is datatype dtype is a number kind"""
29-
return is_float(dtype) or ('int' in dtype.name) or ('long' in dtype.name) or ('short' in dtype.name)
30-
31-
# Spyder compat
32-
# -------------
33-
34-
# Note: string and unicode data types will be formatted with '%s' (see below)
35-
SUPPORTED_FORMATS = {
36-
'object': '%s',
37-
'single': '%.2f',
38-
'double': '%.2f',
39-
'float_': '%.2f',
40-
'longfloat': '%.2f',
41-
'float32': '%.2f',
42-
'float64': '%.2f',
43-
'float96': '%.2f',
44-
'float128': '%.2f',
45-
'csingle': '%r',
46-
'complex_': '%r',
47-
'clongfloat': '%r',
48-
'complex64': '%r',
49-
'complex128': '%r',
50-
'complex192': '%r',
51-
'complex256': '%r',
52-
'byte': '%d',
53-
'short': '%d',
54-
'intc': '%d',
55-
'int_': '%d',
56-
'longlong': '%d',
57-
'intp': '%d',
58-
'int8': '%d',
59-
'int16': '%d',
60-
'int32': '%d',
61-
'int64': '%d',
62-
'ubyte': '%d',
63-
'ushort': '%d',
64-
'uintc': '%d',
65-
'uint': '%d',
66-
'ulonglong': '%d',
67-
'uintp': '%d',
68-
'uint8': '%d',
69-
'uint16': '%d',
70-
'uint32': '%d',
71-
'uint64': '%d',
72-
'bool_': '%r',
73-
'bool8': '%r',
74-
'bool': '%r',
75-
}
76-
# =======================
77-
78-
def get_font(section):
79-
return _get_font('Calibri', 11)
80-
81-
def to_qvariant(obj=None):
82-
return obj
83-
84-
def from_qvariant(qobj=None, pytype=None):
85-
# FIXME: force API level 2 instead of handling this
86-
if isinstance(qobj, QVariant):
87-
assert pytype is str
88-
return pytype(qobj.toString())
89-
return qobj
90-
91-
def _(text):
92-
return text
93-
94-
def to_text_string(obj, encoding=None):
95-
"""Convert `obj` to (unicode) text string"""
96-
if PY2:
97-
# Python 2
98-
if encoding is None:
99-
return unicode(obj)
100-
else:
101-
return unicode(obj, encoding)
102-
else:
103-
# Python 3
104-
if encoding is None:
105-
return str(obj)
106-
elif isinstance(obj, str):
107-
# In case this function is not used properly, this could happen
108-
return obj
109-
else:
110-
return str(obj, encoding)
6+
from larray_editor.utils import (get_font, from_qvariant, to_qvariant, to_text_string,
7+
is_float, is_number, SUPPORTED_FORMATS)
8+
9+
from qtpy.QtCore import Qt, QModelIndex, QAbstractTableModel
10+
from qtpy.QtGui import QColor
11+
from qtpy.QtWidgets import QMessageBox
11112

11213

11314
LARGE_SIZE = 5e5

0 commit comments

Comments
 (0)