-
Notifications
You must be signed in to change notification settings - Fork 0
/
qgis2plugx.py
111 lines (93 loc) · 3.13 KB
/
qgis2plugx.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import os
from PyQt5.QtGui import QIcon
from PyQt5.QtWidgets import QAction
from PyQt5.QtCore import QSettings, QTranslator, QCoreApplication
from qgis.gui import QgisInterface
from ui.main_dialog import MainDialog
from ui.about_dialog import AboutDialog
PLUGIN_NAME = "QGIS2PlugX"
class QGIS2PlugX:
def __init__(self, iface: QgisInterface):
self.iface = iface
self.win = self.iface.mainWindow()
self.plugin_dir = os.path.dirname(__file__)
self.icon_path = os.path.join(self.plugin_dir, "imgs", "icon.png")
self.actions = []
self.menu = PLUGIN_NAME
self.toolbar = self.iface.addToolBar(PLUGIN_NAME)
self.toolbar.setObjectName(PLUGIN_NAME)
# QDialogを保存するためのクラス変数
self.main_dialog = None
self.about_dialog = None
locale = QSettings().value("locale/userLocale")[0:2]
locale_path = os.path.join(
self.plugin_dir, "i18n", "QGIS2PlugX_{}.qm".format(locale)
)
if os.path.exists(locale_path):
self.translator = QTranslator()
self.translator.load(locale_path)
QCoreApplication.installTranslator(self.translator)
def tr(self, message):
return QCoreApplication.translate("QGIS2PlugX", message)
def add_action(
self,
icon_path,
text,
callback,
enabled_flag=True,
add_to_menu=True,
add_to_toolbar=True,
status_tip=None,
whats_this=None,
parent=None,
):
icon = QIcon(icon_path)
action = QAction(icon, text, parent)
action.triggered.connect(callback)
action.setEnabled(enabled_flag)
if status_tip is not None:
action.setStatusTip(status_tip)
if whats_this is not None:
action.setWhatsThis(whats_this)
if add_to_toolbar:
self.toolbar.addAction(action)
if add_to_menu:
self.iface.addPluginToMenu(self.menu, action)
self.actions.append(action)
return action
def initGui(self):
self.add_action(
icon_path=self.icon_path,
text="QGIS2PlugX",
callback=self.show_dialog,
parent=self.win,
add_to_menu=False,
)
self.add_action(
icon_path=None,
text="Export",
callback=self.show_dialog,
parent=self.win,
add_to_toolbar=False,
)
self.add_action(
icon_path=None,
text="About",
callback=self.show_about,
parent=self.win,
add_to_toolbar=False,
)
def unload(self):
for action in self.actions:
self.iface.removePluginMenu(PLUGIN_NAME, action)
self.iface.removeToolBarIcon(action)
del self.toolbar
def show_dialog(self):
if self.main_dialog is None:
self.main_dialog = MainDialog()
self.main_dialog.show()
self.main_dialog.process_node()
def show_about(self):
if self.about_dialog is None:
self.about_dialog = AboutDialog()
self.about_dialog.show()