|
3 | 3 |
|
4 | 4 | # guitest: skip |
5 | 5 |
|
6 | | -import os |
7 | 6 | import os.path as osp |
8 | 7 |
|
9 | 8 | from guidata.qthelpers import qt_app_context |
10 | 9 | from qtpy import QtCore as QC |
11 | 10 | from qtpy import QtGui as QG |
12 | 11 | from qtpy import QtWidgets as QW |
13 | 12 |
|
14 | | -PKG_PATH = osp.join(osp.dirname(__file__), os.pardir, os.pardir) |
15 | | -RES_PATH = osp.join(PKG_PATH, "resources") |
16 | | -WIDGETS_PATH = osp.join(PKG_PATH, "cdlclient", "widgets") |
17 | | - |
18 | | - |
19 | | -def imagefile_to_base64(filename: str) -> bytes: |
20 | | - """Convert image file to Base64-encoded bytes |
21 | | -
|
22 | | - Args: |
23 | | - filename: image filename |
24 | | -
|
25 | | - Returns: |
26 | | - Base64-encoded bytes |
27 | | - """ |
28 | | - image = QG.QImage(filename) |
29 | | - data = QC.QByteArray() |
30 | | - buf = QC.QBuffer(data) |
31 | | - image.save(buf, "PNG") |
32 | | - return data.toBase64().data() |
| 13 | +from cdlclient.widgets.qthelpers import PKG_PATH, imagefile_to_python_module |
33 | 14 |
|
34 | | - |
35 | | -def imagefile_to_python_module(filename: str, destmod: str) -> None: |
36 | | - """Convert image file to Python module |
37 | | -
|
38 | | - Args: |
39 | | - filename: image filename |
40 | | - destmod: destination module name |
41 | | - """ |
42 | | - data = imagefile_to_base64(filename) |
43 | | - destmod_path = osp.join(WIDGETS_PATH, destmod + ".py") |
44 | | - with open(destmod_path, "wb") as fn: |
45 | | - fn.write("# -*- coding: utf-8 -*-\n\n".encode("utf-8")) |
46 | | - fn.write("# pylint: skip-file\n\n".encode("utf-8")) |
47 | | - fn.write("DATA = b'".encode("utf-8")) |
48 | | - fn.write(data) |
49 | | - fn.write("'".encode("utf-8")) |
| 15 | +RES_PATH = osp.join(PKG_PATH, "resources") |
50 | 16 |
|
51 | 17 |
|
52 | 18 | def test_conv(filename: str, destmod: str) -> None: |
@@ -75,3 +41,4 @@ def test_conv(filename: str, destmod: str) -> None: |
75 | 41 |
|
76 | 42 | if __name__ == "__main__": |
77 | 43 | test_conv(osp.join(RES_PATH, "DataLab-Banner-200.png"), "datalab_banner") |
| 44 | + test_conv(osp.join(RES_PATH, "DataLab-Banner-200.png"), "datalab_banner") |
0 commit comments