本文整理汇总了Python中qgis.PyQt.QtCore.QTranslator.load方法的典型用法代码示例。如果您正苦于以下问题:Python QTranslator.load方法的具体用法?Python QTranslator.load怎么用?Python QTranslator.load使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qgis.PyQt.QtCore.QTranslator
的用法示例。
在下文中一共展示了QTranslator.load方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from qgis.PyQt.QtCore import QTranslator [as 别名]
# 或者: from qgis.PyQt.QtCore.QTranslator import load [as 别名]
class QScatterPlugin:
def __init__(self, iface):
self.iface = iface
overrideLocale = QSettings().value('locale/overrideFlag', False, bool)
if not overrideLocale:
locale = QLocale.system().name()[:2]
else:
locale = QSettings().value('locale/userLocale', '')
qmPath = '{}/i18n/qscatter_{}.qm'.format(pluginPath, locale)
if os.path.exists(qmPath):
self.translator = QTranslator()
self.translator.load(qmPath)
QCoreApplication.installTranslator(self.translator)
def initGui(self):
self.actionRun = QAction(
self.tr('QScatter'), self.iface.mainWindow())
self.actionRun.setIcon(
QIcon(os.path.join(pluginPath, 'icons', 'qscatter.svg')))
self.actionRun.setWhatsThis(
self.tr('Interactive scatter plot'))
self.actionRun.setObjectName('runQScatter')
self.actionAbout = QAction(
self.tr('About...'), self.iface.mainWindow())
self.actionAbout.setIcon(
QgsApplication.getThemeIcon('/mActionHelpContents.svg'))
self.actionAbout.setWhatsThis(self.tr('About QScatter'))
self.actionRun.setObjectName('aboutQScatter')
self.iface.addPluginToVectorMenu(
self.tr('QScatter'), self.actionRun)
self.iface.addPluginToVectorMenu(
self.tr('QScatter'), self.actionAbout)
self.iface.addVectorToolBarIcon(self.actionRun)
self.actionRun.triggered.connect(self.run)
self.actionAbout.triggered.connect(self.about)
def unload(self):
self.iface.removePluginVectorMenu(
self.tr('QScatter'), self.actionRun)
self.iface.removePluginVectorMenu(
self.tr('QScatter'), self.actionAbout)
self.iface.removeVectorToolBarIcon(self.actionRun)
def run(self):
dlg = QScatterDialog(self.iface)
dlg.show()
dlg.exec_()
def about(self):
dlg = AboutDialog()
dlg.exec_()
def tr(self, text):
return QCoreApplication.translate('QScatter', text)
示例2: Cadastre
# 需要导入模块: from qgis.PyQt.QtCore import QTranslator [as 别名]
# 或者: from qgis.PyQt.QtCore.QTranslator import load [as 别名]
class Cadastre(object):
def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface
# initialize plugin directory
self.plugin_dir = str(Path(__file__).resolve().parent)
# initialize locale
locale = QSettings().value("locale/userLocale")[0:2]
localePath = os.path.join(self.plugin_dir, 'i18n', 'cadastre_{}.qm'.format(locale))
if os.path.exists(localePath):
self.translator = QTranslator()
self.translator.load(localePath)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
def initGui(self):
# Create action that will start plugin configuration
self.action = QAction(
QIcon(":/plugins/cadastre/icon.png"),
u"Cadastre", self.iface.mainWindow())
# connect the action to the run method
self.action.triggered.connect(self.run)
# Add toolbar button and menu item
self.iface.addToolBarIcon(self.action)
self.iface.addPluginToMenu(u"&Cadastre", self.action)
def unload(self):
# Remove the plugin menu item and icon
self.iface.removePluginMenu(u"&Cadastre", self.action)
self.iface.removeToolBarIcon(self.action)
示例3: getTranslate
# 需要导入模块: from qgis.PyQt.QtCore import QTranslator [as 别名]
# 或者: from qgis.PyQt.QtCore.QTranslator import load [as 别名]
def getTranslate(namePlugin, nameDir=None):
if nameDir is None:
nameDir = namePlugin
pluginPath = os.path.join('python', 'plugins', nameDir)
userPath = QFileInfo(QgsApplication.qgisUserDatabaseFilePath()).path()
userPluginPath = os.path.join(userPath, pluginPath)
systemPath = QgsApplication.prefixPath()
systemPluginPath = os.path.join(systemPath, pluginPath)
overrideLocale = QSettings().value('locale/overrideFlag', False, type=bool)
localeFullName = QLocale.system().name() if not overrideLocale else QSettings().value('locale/userLocale', '')
qmPathFile = os.path.join('i18n', '{0}_{1}.qm'.format(namePlugin, localeFullName))
pp = userPluginPath if QFileInfo(userPluginPath).exists() else systemPluginPath
translationFile = os.path.join(pp, qmPathFile)
if QFileInfo(translationFile).exists():
translator = QTranslator()
translator.load(translationFile)
QCoreApplication.installTranslator(translator)
QgsApplication.messageLog().logMessage(('Installed translation file {}'.format(translationFile)), 'Midvatten',
level=Qgis.Info)
return translator
else:
QgsApplication.messageLog().logMessage(
("translationFile {} didn't exist, no translation file installed!".format(translationFile)), 'Midvatten',
level=Qgis.Info)
示例4: geopunt4QgisAboutDialog
# 需要导入模块: from qgis.PyQt.QtCore import QTranslator [as 别名]
# 或者: from qgis.PyQt.QtCore.QTranslator import load [as 别名]
class geopunt4QgisAboutDialog(QDialog):
def __init__(self):
QDialog.__init__(self, None)
self.setWindowFlags( self.windowFlags() & ~Qt.WindowContextHelpButtonHint )
self.setWindowFlags( self.windowFlags() | Qt.WindowStaysOnTopHint)
# initialize locale
locale = QSettings().value("locale/userLocale", "en")
if not locale: locale == 'en'
else: locale = locale[0:2]
localePath = os.path.join(os.path.dirname(__file__), 'i18n',
'geopunt4qgis_{}.qm'.format(locale))
if os.path.exists(localePath):
self.translator = QTranslator()
self.translator.load(localePath)
QCoreApplication.installTranslator(self.translator)
if 'en' in locale:
self.htmlFile = os.path.join(os.path.dirname(__file__), 'i18n', 'about-en.html')
else:
#dutch is default
self.htmlFile = os.path.join(os.path.dirname(__file__), 'i18n', 'about-nl.html')
self._initGui()
def _initGui(self):
# Set up the user interface from Designer.
self.ui = Ui_aboutDlg()
self.ui.setupUi(self)
self.ui.buttonBox.addButton( QPushButton("Sluiten"), QDialogButtonBox.RejectRole )
with open(self.htmlFile,'r', encoding="utf-8") as html:
self.ui.aboutText.setHtml( html.read() )
示例5: __init__
# 需要导入模块: from qgis.PyQt.QtCore import QTranslator [as 别名]
# 或者: from qgis.PyQt.QtCore.QTranslator import load [as 别名]
class QConsolidatePlugin:
def __init__(self, iface):
self.iface = iface
locale = QgsApplication.locale()
qmPath = '{}/i18n/qconsolidate_{}.qm'.format(pluginPath, locale)
if os.path.exists(qmPath):
self.translator = QTranslator()
self.translator.load(qmPath)
QCoreApplication.installTranslator(self.translator)
def initGui(self):
self.actionRun = QAction(self.tr('QConsolidate'), self.iface.mainWindow())
self.actionRun.setIcon(QIcon(os.path.join(pluginPath, 'icons', 'qconsolidate.svg')))
self.actionRun.setObjectName('runQConsolidate')
self.actionAbout = QAction(self.tr('About QConsolidate…'), self.iface.mainWindow())
self.actionAbout.setIcon(QgsApplication.getThemeIcon('/mActionHelpContents.svg'))
self.actionRun.setObjectName('aboutQConsolidate')
self.iface.addPluginToMenu(self.tr('QConsolidate'), self.actionRun)
self.iface.addPluginToMenu(self.tr('QConsolidate'), self.actionAbout)
self.iface.addToolBarIcon(self.actionRun)
self.actionRun.triggered.connect(self.run)
self.actionAbout.triggered.connect(self.about)
self.taskManager = QgsApplication.taskManager()
def unload(self):
self.iface.removePluginMenu(self.tr('QConsolidate'), self.actionRun)
self.iface.removePluginMenu(self.tr('QConsolidate'), self.actionAbout)
self.iface.removeToolBarIcon(self.actionRun)
def run(self):
dlg = QConsolidateDialog()
if dlg.exec_():
task = dlg.task()
task.consolidateComplete.connect(self.completed)
task.errorOccurred.connect(self.errored)
self.taskManager.addTask(task)
def about(self):
d = AboutDialog()
d.exec_()
def tr(self, text):
return QCoreApplication.translate('QConsolidate', text)
def completed(self):
self.iface.messageBar().pushSuccess(self.tr('QConsolidate'), self.tr('Project consolidated successfully.'))
def errored(self, error):
self.iface.messageBar().pushWarning(self.tr('QConsolidate'), error)
示例6: SeptimaGeoSearch
# 需要导入模块: from qgis.PyQt.QtCore import QTranslator [as 别名]
# 或者: from qgis.PyQt.QtCore.QTranslator import load [as 别名]
class SeptimaGeoSearch(object):
def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface
# initialize plugin directory
self.plugin_dir = QFileInfo(QgsApplication.qgisUserDatabaseFilePath()).path() + "/python/plugins/" + __package__
# initialize locale. Default to Danish
self.config = QSettings()
localePath = ""
try:
locale = self.config.value("locale/userLocale")[0:2]
except:
locale = 'da'
if QFileInfo(self.plugin_dir).exists():
localePath = self.plugin_dir + "/i18n/" + locale + ".qt.qm"
if QFileInfo(localePath).exists():
self.translator = QTranslator()
self.translator.load(localePath)
if qVersion() > '4.3.3':
QgsApplication.installTranslator(self.translator)
# new config method
self.settings = Settings()
self.options_factory = OptionsFactory(self.settings)
self.options_factory.setTitle('Geosearch DK')
iface.registerOptionsWidgetFactory(self.options_factory)
def initGui(self):
# create the widget to display information
self.searchwidget = SearchBox(self.iface)
# create the dockwidget with the correct parent and add the valuewidget
self.searchdockwidget = QDockWidget(
"Geosearch DK", self.iface.mainWindow()
)
self.searchdockwidget.setObjectName("Geosearch DK")
self.searchdockwidget.setWidget(self.searchwidget)
# add the dockwidget to iface
self.iface.addDockWidget(
Qt.TopDockWidgetArea, self.searchdockwidget
)
# Make changed settings apply immediately
self.settings.settings_updated.connect(self.searchwidget.readconfig)
def unload(self):
self.searchwidget.unload() # try to avoid processing events, when QGIS is closing
self.iface.removeDockWidget(self.searchdockwidget)
self.iface.unregisterOptionsWidgetFactory(self.options_factory)
示例7: test_qgis_translations
# 需要导入模块: from qgis.PyQt.QtCore import QTranslator [as 别名]
# 或者: from qgis.PyQt.QtCore.QTranslator import load [as 别名]
def test_qgis_translations(self):
"""Test for qgis translations."""
file_path = safe_dir('i18n/inasafe_id.qm')
translator = QTranslator()
translator.load(file_path)
QCoreApplication.installTranslator(translator)
expected_message = (
'Tidak ada informasi gaya yang ditemukan pada lapisan %s')
real_message = QCoreApplication.translate(
'@default', 'No styleInfo was found for layer %s')
message = 'expected %s but got %s' % (expected_message, real_message)
self.assertEqual(expected_message, real_message, message)
示例8: test_qgis_translations
# 需要导入模块: from qgis.PyQt.QtCore import QTranslator [as 别名]
# 或者: from qgis.PyQt.QtCore.QTranslator import load [as 别名]
def test_qgis_translations(self):
"""Test that translations work."""
parent_path = os.path.join(__file__, os.path.pardir, os.path.pardir)
dir_path = os.path.abspath(parent_path)
file_path = os.path.join(
dir_path, 'i18n', 'af.qm')
translator = QTranslator()
translator.load(file_path)
QCoreApplication.installTranslator(translator)
expected_message = 'Goeie more'
real_message = QCoreApplication.translate("@default", 'Good morning')
self.assertEqual(real_message, expected_message)
示例9: NavTablePlugin
# 需要导入模块: from qgis.PyQt.QtCore import QTranslator [as 别名]
# 或者: from qgis.PyQt.QtCore.QTranslator import load [as 别名]
class NavTablePlugin(QObject):
def __init__(self, iface):
super().__init__()
# Save reference to the QGIS interface
self.iface = iface
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value("locale/userLocale")[0:2]
localePath = os.path.join(self.plugin_dir, 'i18n', 'navtable_{}.qm'.format(locale))
if os.path.exists(localePath):
self.translator = QTranslator()
self.translator.load(localePath)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
def initGui(self):
# Create action that will start plugin configuration
icon_path = os.path.join(self.plugin_dir, 'icon', 'icon.png')
self.action = QAction(
QIcon(icon_path),
u"Navtable", self.iface.mainWindow())
# connect the action to the run method
self.action.triggered.connect(self.run)
# Add toolbar button and menu item
self.iface.addToolBarIcon(self.action)
self.iface.addPluginToMenu(u"&Navtable", self.action)
def unload(self):
# Remove the plugin menu item and icon
self.iface.removePluginMenu(u"&Navtable", self.action)
self.iface.removeToolBarIcon(self.action)
def run(self):
self.layer = self.iface.activeLayer()
# Comprobamos si existe alguna capa y si esta es vectorial
if self.layer is None or not isinstance(self.layer, QgsVectorLayer):
self.iface.messageBar().pushMessage("Invalid Layer",
"NavTable only works on a vector layer",
level=Qgis.Warning)
else:
self.dlg = NTMainPanel(self.iface, self.layer)
self.dlg.show()
self.dlg.exec_()
示例10: QgisCloudPlugin
# 需要导入模块: from qgis.PyQt.QtCore import QTranslator [as 别名]
# 或者: from qgis.PyQt.QtCore.QTranslator import load [as 别名]
class QgisCloudPlugin(object):
def __init__(self, iface, version):
# Save reference to the QGIS interface
self.iface = iface
self.version = version
def initGui(self):
# Create action that will start plugin configuration
self.action = QAction(QIcon(":/plugins/qgiscloud/icon.png"), \
"Cloud Settings", self.iface.mainWindow())
self.action.triggered.connect(self.showHideDockWidget)
# Add toolbar button and menu item
self.iface.addToolBarIcon(self.action)
self.iface.addPluginToMenu("&Cloud", self.action)
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale_short = QSettings().value("locale/userLocale", type=str)[0:2]
locale_long = QSettings().value("locale/userLocale", type=str)
if QFileInfo(self.plugin_dir).exists():
if QFileInfo(self.plugin_dir + "/i18n/qgiscloudplugin_" + locale_short + ".qm").exists():
self.translator = QTranslator()
self.translator.load( self.plugin_dir + "/i18n/qgiscloudplugin_" + locale_short + ".qm")
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
elif QFileInfo(self.plugin_dir + "/i18n/qgiscloudplugin_" + locale_long + ".qm").exists():
self.translator = QTranslator()
self.translator.load( self.plugin_dir + "/i18n/qgiscloudplugin_" + locale_long + ".qm")
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
# # dock widget
self.dockWidget = QgisCloudPluginDialog(self.iface, self.version)
self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.dockWidget)
def unload(self):
# Remove the plugin menu item and icon
self.iface.removePluginMenu("&Cloud",self.action)
self.iface.removeToolBarIcon(self.action)
self.dockWidget.unload()
self.iface.removeDockWidget(self.dockWidget)
def showHideDockWidget(self):
if self.dockWidget.isVisible():
self.dockWidget.hide()
else:
self.dockWidget.show()
示例11: Translate
# 需要导入模块: from qgis.PyQt.QtCore import QTranslator [as 别名]
# 或者: from qgis.PyQt.QtCore.QTranslator import load [as 别名]
class Translate():
def __init__(self, pluginName):
def getFile():
overrideLocale = QSettings().value('locale/overrideFlag', False, type=bool)
localeFullName = QLocale.system().name() if not overrideLocale else QSettings().value('locale/userLocale', '')
qmPathFile = "i18n/{0}_{1}.qm".format( pluginName, localeFullName )
pluginPath = os.path.dirname(__file__)
translationFile = "{}/{}".format( pluginPath, qmPathFile )
return translationFile
self.translator = None
translationFile = getFile()
if QFileInfo( translationFile ).exists():
self.translator = QTranslator()
self.translator.load( translationFile )
QCoreApplication.installTranslator( self.translator )
示例12: __init__
# 需要导入模块: from qgis.PyQt.QtCore import QTranslator [as 别名]
# 或者: from qgis.PyQt.QtCore.QTranslator import load [as 别名]
class StatistPlugin:
def __init__(self, iface):
self.iface = iface
locale = QgsApplication.locale()
qmPath = "{}/i18n/statist_{}.qm".format(pluginPath, locale)
if os.path.exists(qmPath):
self.translator = QTranslator()
self.translator.load(qmPath)
QCoreApplication.installTranslator(self.translator)
def initGui(self):
self.actionRun = QAction(self.tr("Statist"), self.iface.mainWindow())
self.actionRun.setIcon(QIcon(os.path.join(pluginPath, "icons", "statist.png")))
self.actionRun.setObjectName("runStatist")
self.iface.registerMainWindowAction(self.actionRun, "Shift+S")
self.actionAbout = QAction(self.tr("About Statist…"), self.iface.mainWindow())
self.actionAbout.setIcon(QgsApplication.getThemeIcon("/mActionHelpContents.svg"))
self.actionRun.setObjectName("aboutStatist")
self.iface.addPluginToVectorMenu(self.tr("Statist"), self.actionRun)
self.iface.addPluginToVectorMenu(self.tr("Statist"), self.actionAbout)
self.iface.addVectorToolBarIcon(self.actionRun)
self.actionRun.triggered.connect(self.run)
self.actionAbout.triggered.connect(self.about)
def unload(self):
self.iface.unregisterMainWindowAction(self.actionRun)
self.iface.removePluginVectorMenu(self.tr("Statist"), self.actionRun)
self.iface.removePluginVectorMenu(self.tr("Statist"), self.actionAbout)
self.iface.removeVectorToolBarIcon(self.actionRun)
def run(self):
dlg = StatistDialog()
dlg.show()
dlg.exec_()
def about(self):
d = AboutDialog()
d.exec_()
def tr(self, text):
return QCoreApplication.translate("Statist", text)
示例13: __init__
# 需要导入模块: from qgis.PyQt.QtCore import QTranslator [as 别名]
# 或者: from qgis.PyQt.QtCore.QTranslator import load [as 别名]
class RasterTransparencyPlugin:
def __init__(self, iface):
self.iface = iface
locale = QgsApplication.locale()
qmPath = "{}/i18n/rastertransparency_{}.qm".format(pluginPath, locale)
if os.path.exists(qmPath):
self.translator = QTranslator()
self.translator.load(qmPath)
QCoreApplication.installTranslator(self.translator)
self.factory = TransparencyPanelFactory()
def initGui(self):
self.actionAbout = QAction(self.tr("About RasterTransparency…"), self.iface.mainWindow())
self.actionAbout.setIcon(QgsApplication.getThemeIcon("/mActionHelpContents.svg"))
self.actionAbout.setObjectName("aboutRasterTransparency")
self.actionAbout.triggered.connect(self.about)
self.iface.addPluginToRasterMenu(self.tr("Raster transparency"), self.actionAbout)
self.iface.registerMapLayerConfigWidgetFactory(self.factory)
def unload(self):
self.iface.removePluginRasterMenu(self.tr("Raster transparency"), self.actionAbout)
self.iface.unregisterMapLayerConfigWidgetFactory(self.factory)
def about(self):
d = AboutDialog()
d.exec_()
def tr(self, text):
return QCoreApplication.translate("RasterTransparency", text)
示例14: QuickMapServices
# 需要导入模块: from qgis.PyQt.QtCore import QTranslator [as 别名]
# 或者: from qgis.PyQt.QtCore.QTranslator import load [as 别名]
class QuickMapServices(object):
"""QGIS Plugin Implementation."""
def __init__(self, iface):
"""Constructor.
:param iface: An interface instance that will be passed to this class
which provides the hook by which you can manipulate the QGIS
application at run time.
:type iface: QgsInterface
"""
# Save reference to the QGIS interface
self.iface = iface
# initialize plugin directory
self.plugin_dir = get_file_dir(__file__)
# initialize locale
self.translator = QTranslator()
self.locale = Locale.get_locale()
locale_path = os.path.join(
self.plugin_dir,
'i18n',
'QuickMapServices_{}.qm'.format(self.locale))
if os.path.exists(locale_path):
r = self.translator.load(locale_path)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
self.custom_translator = CustomTranslator()
QCoreApplication.installTranslator(self.custom_translator)
# Create the dialog (after translation) and keep reference
self.info_dlg = AboutDialog()
# Check Contrib and User dirs
try:
ExtraSources.check_extra_dirs()
except:
error_message = self.tr('Extra dirs for %s can\'t be created: %s %s') % (PluginSettings.product_name(),
sys.exc_type,
sys.exc_value)
self.iface.messageBar().pushMessage(self.tr('Error'),
error_message,
level=QgsMessageBar.CRITICAL)
# Declare instance attributes
self.service_actions = []
self.service_layers = [] # TODO: id and smart remove
self._scales_list = None
# noinspection PyMethodMayBeStatic
def tr(self, message):
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
return QCoreApplication.translate('QuickMapServices', message)
def initGui(self):
#import pydevd
#pydevd.settrace('localhost', port=9921, stdoutToServer=True, stderrToServer=True, suspend=False)
# Register plugin layer type
self.tileLayerType = TileLayerType(self)
qgisRegistryInstance.addPluginLayerType(self.tileLayerType)
# Create menu
icon_path = self.plugin_dir + '/icons/mActionAddLayer.svg'
self.menu = QMenu(self.tr(u'QuickMapServices'))
self.menu.setIcon(QIcon(icon_path))
self.init_server_panel()
self.build_menu_tree()
# add to QGIS menu/toolbars
self.append_menu_buttons()
def _load_scales_list(self):
scales_filename = os.path.join(self.plugin_dir, 'scales.xml')
scales_list = []
# TODO: remake when fix: http://hub.qgis.org/issues/11915
# QgsScaleUtils.loadScaleList(scales_filename, scales_list, importer_message)
xml_root = ET.parse(scales_filename).getroot()
for scale_el in xml_root.findall('scale'):
scales_list.append(scale_el.get('value'))
return scales_list
@property
def scales_list(self):
if not self._scales_list:
self._scales_list = self._load_scales_list()
return self._scales_list
def set_nearest_scale(self):
#get current scale
curr_scale = self.iface.mapCanvas().scale()
#find nearest
nearest_scale = sys.maxsize
for scale_str in self.scales_list:
scale = scale_str.split(':')[1]
scale_int = int(scale)
if abs(scale_int-curr_scale) < abs(nearest_scale - curr_scale):
#.........这里部分代码省略.........
示例15: AzimuthDistanceCalculator
# 需要导入模块: from qgis.PyQt.QtCore import QTranslator [as 别名]
# 或者: from qgis.PyQt.QtCore.QTranslator import load [as 别名]
class AzimuthDistanceCalculator(object):
def __init__(self, iface):
# Save reference to the QGIS interface
self.iface = iface
# initialize plugin directory
self.plugin_dir = os.path.dirname(__file__)
# initialize locale
locale = QSettings().value("locale/userLocale")[0:2]
localePath = os.path.join(self.plugin_dir, 'i18n', 'azimuthdistancecalculator_{}.qm'.format(locale))
if os.path.exists(localePath):
self.translator = QTranslator()
self.translator.load(localePath)
if qVersion() > '4.3.3':
QCoreApplication.installTranslator(self.translator)
# Create the dialog (after translation) and keep reference
self.dlg = AzimuthDistanceCalculatorDialog(self.iface)
# Obtaining the map canvas
self.canvas = iface.mapCanvas()
# noinspection PyMethodMayBeStatic
def tr(self, message):
"""Get the translation for a string using Qt translation API.
We implement this ourselves since we do not inherit QObject.
:param message: String for translation.
:type message: str, QString
:returns: Translated version of message.
:rtype: QString
"""
# noinspection PyTypeChecker,PyArgumentList,PyCallByClass
return QCoreApplication.translate('azimuthdistancecalculator', message)
def initGui(self):
# Create action that will start plugin configuration
self.action = QAction(
QIcon(":/plugins/azimuthdistancecalculator/north.png"),
self.tr("Calculator"), self.iface.mainWindow())
# connect the action to the run method
self.action.triggered.connect(self.run)
# Add toolbar button and menu item
self.iface.addToolBarIcon(self.action)
self.iface.addPluginToMenu(self.tr("Azimuth and Distance Calculator"), self.action)
def unload(self):
# Remove the plugin menu item and icon
self.iface.removePluginMenu(self.tr("Azimuth and Distance Calculator"), self.action)
self.iface.removeToolBarIcon(self.action)
# run method that performs all the real work
def run(self):
# show the dialog
self.dlg.show()
# Run the dialog event loop
result = self.dlg.exec_()
# See if OK was pressed
if result == 1:
# do something useful (delete the line containing pass and
# substitute with your code)
pass