-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathnewmemorylayer.py
More file actions
68 lines (60 loc) · 2.79 KB
/
newmemorylayer.py
File metadata and controls
68 lines (60 loc) · 2.79 KB
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
# -*- coding: utf-8 -*-
"""
/***************************************************************************
NewMemoryLayer
A QGIS plugin
Creates a memory layer
-------------------
begin : 2011-05-14
copyright : by Borys Jurgiel
email : info at borysjurgiel dot pl
***************************************************************************/
/***************************************************************************
* *
* 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.QtCore import QCoreApplication, QFileInfo, QLocale, QTranslator
from qgis.PyQt.QtGui import QAction, QIcon
from .newmemorylayerdialog import NewMemoryLayerDialog
class NewMemoryLayer:
def __init__(self, iface):
self.iface = iface
self.action = None
self.dlg = None
# i18n
pluginPath = QFileInfo(os.path.realpath(__file__)).path()
localeName = QLocale.system().name()
if QFileInfo(pluginPath).exists():
self.localePath = pluginPath + "/i18n/newmemorylayer_" + localeName + ".qm"
if QFileInfo(self.localePath).exists():
self.translator = QTranslator()
self.translator.load(self.localePath)
QCoreApplication.installTranslator(self.translator)
def initGui(self):
self.action = QAction(
QIcon(os.path.join(os.path.dirname(__file__), "layer-memory-create.png")),
QCoreApplication.translate("NewMemoryLayer", "New Memory Layer..."),
self.iface.mainWindow(),
)
self.action.setShortcut("Ctrl+W")
self.iface.registerMainWindowAction(self.action, "Ctrl+W")
self.action.triggered.connect(self.run)
self.iface.newLayerMenu().addAction(self.action)
self.iface.layerToolBar().addAction(self.action)
def unload(self):
if self.action:
self.action.triggered.disconnect(self.run)
self.iface.unregisterMainWindowAction(self.action)
self.iface.newLayerMenu().removeAction(self.action)
self.iface.layerToolBar().removeAction(self.action)
def run(self):
if not self.dlg:
self.dlg = NewMemoryLayerDialog()
self.dlg.show()
self.dlg.activateWindow()