plugin.py 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. ###############################################################################
  2. #
  3. # Copyright (C) 2010 NextGIS (http://nextgis.org),
  4. # Alexander Bruy (alexander.bruy@gmail.com),
  5. # Maxim Dubinin (sim@gis-lab.info),
  6. #
  7. # Copyright (C) 2014 Tom Kralidis (tomkralidis@gmail.com)
  8. #
  9. # This source is free software; you can redistribute it and/or modify it under
  10. # the terms of the GNU General Public License as published by the Free
  11. # Software Foundation; either version 2 of the License, or (at your option)
  12. # any later version.
  13. #
  14. # This code is distributed in the hope that it will be useful, but WITHOUT ANY
  15. # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  16. # FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
  17. # details.
  18. #
  19. # You should have received a copy of the GNU General Public License along
  20. # with this program; if not, write to the Free Software Foundation, Inc.,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. #
  23. ###############################################################################
  24. import logging
  25. from qgis.PyQt.QtCore import QCoreApplication
  26. from qgis.PyQt.QtWidgets import QAction
  27. from qgis.PyQt.QtGui import QIcon
  28. from qgis.core import QgsApplication
  29. from MetaSearch.dialogs.maindialog import MetaSearchDialog
  30. from MetaSearch.util import get_help_url, open_url, StaticContext
  31. LOGGER = logging.getLogger('MetaSearch')
  32. class MetaSearchPlugin:
  33. """base plugin"""
  34. def __init__(self, iface):
  35. """init"""
  36. self.iface = iface
  37. self.context = StaticContext()
  38. self.action_run = None
  39. self.action_help = None
  40. self.dialog = None
  41. self.web_menu = '&MetaSearch'
  42. def initGui(self):
  43. """startup"""
  44. # run
  45. run_icon = QIcon('{}/{}'.format(self.context.ppath, 'images/MetaSearch.svg'))
  46. self.action_run = QAction(run_icon, 'MetaSearch',
  47. self.iface.mainWindow())
  48. self.action_run.setWhatsThis(
  49. QCoreApplication.translate('MetaSearch', 'MetaSearch plugin'))
  50. self.action_run.setStatusTip(QCoreApplication.translate(
  51. 'MetaSearch', 'Search Metadata Catalogs'))
  52. self.action_run.triggered.connect(self.run)
  53. self.iface.addWebToolBarIcon(self.action_run)
  54. self.iface.addPluginToWebMenu(self.web_menu, self.action_run)
  55. # help
  56. help_icon = QgsApplication.getThemeIcon('/mActionHelpContents.svg')
  57. self.action_help = QAction(help_icon, 'Help', self.iface.mainWindow())
  58. self.action_help.setWhatsThis(
  59. QCoreApplication.translate('MetaSearch', 'MetaSearch plugin help'))
  60. self.action_help.setStatusTip(QCoreApplication.translate(
  61. 'MetaSearch', 'Get Help on MetaSearch'))
  62. self.action_help.triggered.connect(self.help)
  63. self.iface.addPluginToWebMenu(self.web_menu, self.action_help)
  64. # prefab the dialog but not open it yet
  65. self.dialog = MetaSearchDialog(self.iface)
  66. def unload(self):
  67. """teardown"""
  68. # remove the plugin menu item and icon
  69. self.iface.removePluginWebMenu(self.web_menu, self.action_run)
  70. self.iface.removePluginWebMenu(self.web_menu, self.action_help)
  71. self.iface.removeWebToolBarIcon(self.action_run)
  72. def run(self):
  73. """open MetaSearch"""
  74. self.dialog.exec_()
  75. def help(self):
  76. """open help in user's default web browser"""
  77. open_url(get_help_url())