FunVIP 0.3.20__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
src/patch.py ADDED
@@ -0,0 +1,261 @@
1
+ # ete3 patch
2
+ # After using ete3 3.1.3, we don't need this anymore
3
+ from __future__ import absolute_import
4
+ from __future__ import print_function
5
+ import ete3
6
+ from copy import deepcopy
7
+
8
+
9
+ # Patch for ete3 3.1.2 colliding with higher version PyQt5
10
+ def save(scene, imgName, w=None, h=None, dpi=90, take_region=False, units="px"):
11
+ import colorsys
12
+ import random
13
+ import re
14
+ import types
15
+ from sys import stderr
16
+
17
+ from PyQt5 import QtGui, QtCore
18
+ from PyQt5.QtCore import (
19
+ Qt,
20
+ QPointF,
21
+ QRect,
22
+ QRectF,
23
+ QBuffer,
24
+ QByteArray,
25
+ QThread,
26
+ QIODevice,
27
+ QMetaObject,
28
+ QModelIndex,
29
+ QObject,
30
+ QRegExp,
31
+ QSize,
32
+ QSizeF,
33
+ QVariant,
34
+ ) # QString
35
+ from PyQt5.QtSvg import QGraphicsSvgItem, QSvgGenerator
36
+ from PyQt5.QtOpenGL import QGLFormat, QGLWidget
37
+ from PyQt5.QtPrintSupport import QPrinter
38
+ from PyQt5.QtWidgets import (
39
+ QAction,
40
+ QApplication,
41
+ QCheckBox,
42
+ QWidget,
43
+ QColorDialog,
44
+ QComboBox,
45
+ QDialog,
46
+ QDialogButtonBox,
47
+ QFileDialog,
48
+ QGraphicsEllipseItem,
49
+ QGraphicsItem,
50
+ QGraphicsItemGroup,
51
+ QGraphicsLineItem,
52
+ QGraphicsPathItem,
53
+ QGraphicsPixmapItem,
54
+ QGraphicsPolygonItem,
55
+ QGraphicsRectItem,
56
+ QGraphicsScene,
57
+ QGraphicsSimpleTextItem,
58
+ QGraphicsTextItem,
59
+ QGraphicsView,
60
+ QInputDialog,
61
+ QItemDelegate,
62
+ QLabel,
63
+ QLineEdit,
64
+ QListWidget,
65
+ QMainWindow,
66
+ QMenu,
67
+ QMenuBar,
68
+ QMessageBox,
69
+ QPushButton,
70
+ QSplitter,
71
+ QStatusBar,
72
+ QTableView,
73
+ QTextEdit,
74
+ QToolBar,
75
+ QVBoxLayout,
76
+ QWidget,
77
+ )
78
+
79
+ from PyQt5.QtGui import (
80
+ QBrush,
81
+ QColor,
82
+ QCursor,
83
+ QFont,
84
+ QFontMetrics,
85
+ QIcon,
86
+ QImage,
87
+ QPainter,
88
+ QPainterPath,
89
+ QPen,
90
+ QPixmap,
91
+ QPolygonF,
92
+ QRadialGradient,
93
+ QRegExpValidator,
94
+ QStandardItemModel,
95
+ QTransform,
96
+ )
97
+
98
+ QtCore.pyqtSignature = QtCore.pyqtSlot
99
+
100
+ from ete3.treeview.svg_colors import SVG_COLORS, COLOR_SCHEMES
101
+
102
+ import time
103
+
104
+ ipython_inline = False
105
+ if imgName == "%%inline":
106
+ ipython_inline = True
107
+ ext = "PNG"
108
+ elif imgName == "%%inlineSVG":
109
+ ipython_inline = True
110
+ ext = "SVG"
111
+ elif imgName.startswith("%%return"):
112
+ try:
113
+ ext = imgName.split(".")[1].upper()
114
+ except IndexError:
115
+ ext = "SVG"
116
+ imgName = "%%return"
117
+ else:
118
+ ext = imgName.split(".")[-1].upper()
119
+
120
+ main_rect = scene.sceneRect()
121
+ aspect_ratio = main_rect.height() / main_rect.width()
122
+
123
+ # auto adjust size
124
+ if not w and not h:
125
+ units = "px"
126
+ w = main_rect.width()
127
+ h = main_rect.height()
128
+ ratio_mode = Qt.KeepAspectRatio
129
+ elif w and h:
130
+ ratio_mode = Qt.IgnoreAspectRatio
131
+ elif h is None:
132
+ h = w * aspect_ratio
133
+ ratio_mode = Qt.KeepAspectRatio
134
+ elif w is None:
135
+ w = h / aspect_ratio
136
+ ratio_mode = Qt.KeepAspectRatio
137
+
138
+ # Adjust to resolution
139
+ if units == "mm":
140
+ if w:
141
+ w = w * 0.0393700787 * dpi
142
+ if h:
143
+ h = h * 0.0393700787 * dpi
144
+ elif units == "in":
145
+ if w:
146
+ w = w * dpi
147
+ if h:
148
+ h = h * dpi
149
+ elif units == "px":
150
+ pass
151
+ else:
152
+ raise Exception("wrong unit format")
153
+
154
+ x_scale, y_scale = w / main_rect.width(), h / main_rect.height()
155
+
156
+ if ext == "SVG":
157
+ svg = QSvgGenerator()
158
+ targetRect = QRectF(0, 0, w, h)
159
+ # print(f"DEBUG {w} {h}")
160
+ svg.setSize(QSize(int(w), int(h)))
161
+ svg.setViewBox(targetRect)
162
+ svg.setTitle("Generated with ETE http://etetoolkit.org")
163
+ svg.setDescription("Generated with ETE http://etetoolkit.org")
164
+
165
+ if imgName == "%%return":
166
+ ba = QByteArray()
167
+ buf = QBuffer(ba)
168
+ buf.open(QIODevice.WriteOnly)
169
+ svg.setOutputDevice(buf)
170
+ else:
171
+ svg.setFileName(imgName)
172
+
173
+ pp = QPainter()
174
+ pp.begin(svg)
175
+ scene.render(pp, targetRect, scene.sceneRect(), ratio_mode)
176
+ pp.end()
177
+ if imgName == "%%return":
178
+ compatible_code = str(ba)
179
+ print("from memory")
180
+ else:
181
+ compatible_code = open(imgName).read()
182
+ # Fix a very annoying problem with Radial gradients in
183
+ # inkscape and browsers...
184
+ compatible_code = compatible_code.replace("xml:id=", "id=")
185
+ compatible_code = re.sub(
186
+ 'font-size="(\d+)"', 'font-size="\\1pt"', compatible_code
187
+ )
188
+ compatible_code = compatible_code.replace("\n", " ")
189
+ compatible_code = re.sub("<g [^>]+>\s*</g>", "", compatible_code)
190
+ # End of fix
191
+ if ipython_inline:
192
+ from IPython.core.display import SVG
193
+
194
+ return SVG(compatible_code)
195
+
196
+ elif imgName == "%%return":
197
+ return x_scale, y_scale, compatible_code
198
+ else:
199
+ open(imgName, "w").write(compatible_code)
200
+
201
+ elif ext == "PDF" or ext == "PS":
202
+ if ext == "PS":
203
+ format = QPrinter.PostScriptFormat
204
+ else:
205
+ format = QPrinter.PdfFormat
206
+
207
+ printer = QPrinter(QPrinter.HighResolution)
208
+ printer.setResolution(dpi)
209
+ printer.setOutputFormat(format)
210
+ printer.setPageSize(QPrinter.A4)
211
+ printer.setPaperSize(QSizeF(int(w), int(h)), QPrinter.DevicePixel)
212
+ printer.setPageMargins(0, 0, 0, 0, QPrinter.DevicePixel)
213
+
214
+ # pageTopLeft = printer.pageRect().topLeft()
215
+ # paperTopLeft = printer.paperRect().topLeft()
216
+ # For PS -> problems with margins
217
+ # print paperTopLeft.x(), paperTopLeft.y()
218
+ # print pageTopLeft.x(), pageTopLeft.y()
219
+ # print printer.paperRect().height(), printer.pageRect().height()
220
+ # topleft = pageTopLeft - paperTopLeft
221
+
222
+ printer.setFullPage(True)
223
+ printer.setOutputFileName(imgName)
224
+ pp = QPainter(printer)
225
+ targetRect = QRectF(0, 0, w, h)
226
+ scene.render(pp, targetRect, scene.sceneRect(), ratio_mode)
227
+ else:
228
+ targetRect = QRectF(0, 0, w, h)
229
+ ii = QImage(w, h, QImage.Format_ARGB32)
230
+ ii.fill(QColor(Qt.white).rgb())
231
+ ii.setDotsPerMeterX(dpi / 0.0254) # Convert inches to meters
232
+ ii.setDotsPerMeterY(dpi / 0.0254)
233
+ pp = QPainter(ii)
234
+ pp.setRenderHint(QPainter.Antialiasing)
235
+ pp.setRenderHint(QPainter.TextAntialiasing)
236
+ pp.setRenderHint(QPainter.SmoothPixmapTransform)
237
+
238
+ scene.render(pp, targetRect, scene.sceneRect(), ratio_mode)
239
+ pp.end()
240
+ if ipython_inline:
241
+ ba = QByteArray()
242
+ buf = QBuffer(ba)
243
+ buf.open(QIODevice.WriteOnly)
244
+ ii.save(buf, "PNG")
245
+ from IPython.core.display import Image
246
+
247
+ return Image(ba.data())
248
+ elif imgName == "%%return":
249
+ ba = QByteArray()
250
+ buf = QBuffer(ba)
251
+ buf.open(QIODevice.WriteOnly)
252
+ ii.save(buf, "PNG")
253
+ return x_scale, y_scale, ba.toBase64()
254
+ else:
255
+ ii.save(imgName)
256
+
257
+ return w / main_rect.width(), h / main_rect.height()
258
+
259
+
260
+ def patch():
261
+ ete3.treeview.main.save = deepcopy(save)