-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
63 lines (53 loc) · 1.46 KB
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""GUI Utilities
.. note:: This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
"""
import os
from qgis.PyQt.QtGui import QIcon
class GuiUtils:
"""
Utilities for GUI plugin components
"""
@staticmethod
def get_icon(icon: str) -> QIcon:
"""
Returns a plugin icon
:param icon: icon name (svg file name)
:return: QIcon
"""
path = GuiUtils.get_icon_svg(icon)
if not path:
return QIcon()
return QIcon(path)
@staticmethod
def get_icon_svg(icon: str) -> str:
"""
Returns a plugin icon's SVG file path
:param icon: icon name (svg file name)
:return: icon svg path
"""
path = os.path.join(
os.path.dirname(__file__),
'.',
'icons',
icon)
if not os.path.exists(path):
return ''
return path
@staticmethod
def get_ui_file_path(file: str) -> str:
"""
Returns a UI file's path
:param file: file name (uifile name)
:return: ui file path
"""
path = os.path.join(
os.path.dirname(__file__),
'..',
'ui',
file)
if not os.path.exists(path):
return ''
return path