3 *************************************************************************** 5 A script to automate creation of a new QGIS plugin using the plugin_template 6 -------------------------------------- 7 Date : Sun Sep 16 12:11:04 AKDT 2007 8 Copyright : (C) Copyright 2007 Martin Dobias 10 Original authors of Perl version: Gary Sherman and Tim Sutton 11 *************************************************************************** 13 * This program is free software; you can redistribute it and/or modify * 14 * it under the terms of the GNU General Public License as published by * 15 * the Free Software Foundation; either version 2 of the License, or * 16 * (at your option) any later version. * 18 ***************************************************************************/ 27 return os.path.join(
'plugin_template', file)
31 return os.path.join(pluginDir, file)
38 print(
"Checking that we are in the <qgis dir>/src/plugins/ directory....", end=
'')
40 pluginsDirectory = os.path.join(
'src',
'plugins')
42 if myDir[-len(pluginsDirectory):] == pluginsDirectory:
47 print(
"Please relocate to the plugins directory before attempting to run this script.")
52 print "Enter the directory name under qgis/src/plugins/ where your new plugin will be created." 53 print "We suggest using a lowercase underscore separated name e.g. clever_plugin" 54 print "Directory for the new plugin:",
56 pluginDir = raw_input()
59 print "Enter the name that will be used when creating the plugin library." 60 print "The name should be entered as a mixed case name with no spaces. e.g. CleverTool" 61 print "The plugin name will be used in the following ways:" 62 print "1) it will be 'lower cased' and used as the root of the generated lib name" 63 print " e.g. libqgis_plugin_clevertool" 64 print "2) in its upper cased form it will be used as the basis for class names, in particular" 65 print " CleverToolGuiBase <- The base class for the plugins configuration dialog / gui generated by uic" 66 print " CleverToolGui <- The concrete class for the plugins configuration dialog" 67 print "3) CleverTool <- The class that includes the plugin loader instructions and" 68 print " and calls to your custom application logic" 69 print "4) clevertool.h, clevertool.cpp etc. <- the filenames used to hold the above derived classes" 72 pluginName = raw_input()
73 pluginLCaseName = pluginName.lower()
76 print "Enter a short description (typically one line)" 77 print "e.g. The clever plugin does clever stuff in QGIS" 78 print "Plugin description:",
79 pluginDescription = raw_input()
82 print "Enter a plugin category. Category will help users" 83 print "to understand where to find plugin. E.g. if plugin" 84 print "will be available from Vector menu category is Vector" 85 print "Plugin category:",
86 pluginCategory = raw_input()
89 print "Enter the name of the application menu that will be created for your plugin" 92 menuName = raw_input()
95 print "Enter the name of the menu entry (under the menu that you have just defined) that" 96 print "will be used to invoke your plugin. e.g. Clever Plugin" 97 print "Menu item name:",
98 menuItemName = raw_input()
103 print "Summary of plugin parameters:" 104 print "---------------------------------------------" 105 print "Plugin directory: ", pluginDir
106 print "Name of the plugin: ", pluginName
107 print "Description of the plugin:", pluginDescription
108 print "Category of the plugin: ", pluginCategory
109 print "Menu name: ", menuName
110 print "Menu item name: ", menuItemName
112 print "Warning - Proceeding will make changes to CMakeLists.txt in this directory." 113 print "Create the plugin? [y/n]:",
115 createIt = raw_input()
117 if createIt.lower() !=
'y':
118 print "Plugin creation canceled, exiting" 128 shutil.copy(
template_file(
'README.whatnext'), os.path.join(pluginDir,
'README'))
129 shutil.copy(
template_file(
'plugin.qrc'), os.path.join(pluginDir, pluginLCaseName +
'.qrc'))
130 shutil.copy(
template_file(
'plugin.png'), os.path.join(pluginDir, pluginLCaseName +
'.png'))
131 shutil.copy(
template_file(
'plugin.cpp'), os.path.join(pluginDir, pluginLCaseName +
'.cpp'))
132 shutil.copy(
template_file(
'plugin.h'), os.path.join(pluginDir, pluginLCaseName +
'.h'))
133 shutil.copy(
template_file(
'plugingui.cpp'), os.path.join(pluginDir, pluginLCaseName +
'gui.cpp'))
134 shutil.copy(
template_file(
'plugingui.h'), os.path.join(pluginDir, pluginLCaseName +
'gui.h'))
135 shutil.copy(
template_file(
'pluginguibase.ui'), os.path.join(pluginDir, pluginLCaseName +
'guibase.ui'))
146 plugin_file(pluginDir, pluginLCaseName +
'gui.cpp'),
148 plugin_file(pluginDir, pluginLCaseName +
'guibase.ui')]
152 replacements = [(
'\\[pluginlcasename\\]', pluginLCaseName),
153 (
'\\[pluginname\\]', pluginName),
154 (
'\\[plugindescription\\]', pluginDescription),
155 (
'\\[plugincategory\\]', pluginCategory),
156 (
'\\[menuname\\]', menuName),
157 (
'\\[menuitemname\\]', menuItemName)]
167 for repl
in replacements:
168 content = re.sub(repl[0], repl[1], content)
177 f = open(
'CMakeLists.txt',
'a')
178 f.write(
'\nSUBDIRS (' + pluginDir +
')\n')
181 print "Your plugin %s has been created in %s, CMakeLists.txt has been modified." % (pluginName, pluginDir)
183 print "Once your plugin has successfully built, please see %s/README for" % pluginDir
184 print "hints on how to get started."
def plugin_file(pluginDir, file)