|
1 | 1 | from __future__ import absolute_import, division, print_function
|
2 | 2 |
|
3 |
| -import sys |
4 | 3 | import numpy as np
|
5 |
| -import pandas as pd |
6 | 4 | import larray as la
|
7 | 5 |
|
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 |
111 | 12 |
|
112 | 13 |
|
113 | 14 | LARGE_SIZE = 5e5
|
|
0 commit comments