-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.py
73 lines (63 loc) · 2.01 KB
/
sample.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
import os
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from qgis.core import *
from qgis.gui import *
from sample_menu_01 import SampleMenu01
from sample_menu_02 import SampleMenu02
PLUGIN_NAME = "sample"
class Sample:
def __init__(self, iface):
self.iface = iface
self.win = self.iface.mainWindow()
self.plugin_dir = os.path.dirname(__file__)
self.actions = []
self.menu = PLUGIN_NAME
self.toolbar = self.iface.addToolBar(PLUGIN_NAME)
self.toolbar.setObjectName(PLUGIN_NAME)
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=None, text="Menu01", callback=self.show_menu_01, parent=self.win
)
self.add_action(
icon_path=None, text="Menu02", callback=self.show_menu_02, parent=self.win
)
def unload(self):
for action in self.actions:
self.iface.removePluginMenu(PLUGIN_NAME, action)
self.iface.removeToolBarIcon(action)
del self.toolbar
def show_menu_01(self):
self.sample_menu_01 = SampleMenu01()
self.sample_menu_01.show()
def show_menu_02(self):
self.sample_menu_02 = SampleMenu02()
self.sample_menu_02.show()