|
| 1 | +""" |
| 2 | +/*************************************************************************** |
| 3 | + MapServerExport - A QGIS plugin to export a saved project file |
| 4 | + to a MapServer map file |
| 5 | + ------------------- |
| 6 | + begin : 2008-01-07 |
| 7 | + copyright : (C) 2008 by Gary E.Sherman |
| 8 | + email : sherman at mrcc.com |
| 9 | + ***************************************************************************/ |
| 10 | +
|
| 11 | +/*************************************************************************** |
| 12 | + * * |
| 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. * |
| 17 | + * * |
| 18 | + ***************************************************************************/ |
| 19 | +""" |
| 20 | +# Import the PyQt and QGIS libraries |
| 21 | +from PyQt4.QtCore import * |
| 22 | +from PyQt4.QtGui import * |
| 23 | +from qgis.core import * |
| 24 | +# Initialize Qt resources from file resources.py |
| 25 | +import resources |
| 26 | +# Import the code for the dialog |
| 27 | +from mapserverexportdialog import MapServerExportDialog |
| 28 | +# Import the ms_export script that does the real work |
| 29 | +from ms_export import * |
| 30 | + |
| 31 | +class MapServerExport: |
| 32 | + |
| 33 | + def __init__(self, iface): |
| 34 | + # Save reference to the QGIS interface |
| 35 | + self.iface = iface |
| 36 | + |
| 37 | + def initGui(self): |
| 38 | + # Create action that will start plugin configuration |
| 39 | + self.action = QAction(QIcon(":/plugins/mapserver_export/icon.png"), \ |
| 40 | + "MapServer Export", self.iface.getMainWindow()) |
| 41 | + #self.action.setWhatsThis("Configuration for Zoom To Point plugin") |
| 42 | + # connect the action to the run method |
| 43 | + QObject.connect(self.action, SIGNAL("activated()"), self.run) |
| 44 | + |
| 45 | + # Add toolbar button and menu item |
| 46 | + self.iface.addToolBarIcon(self.action) |
| 47 | + self.iface.addPluginMenu("&MapServer Export...", self.action) |
| 48 | + |
| 49 | + def unload(self): |
| 50 | + # Remove the plugin menu item and icon |
| 51 | + self.iface.removePluginMenu("&Zoom to Point...",self.action) |
| 52 | + self.iface.removeToolBarIcon(self.action) |
| 53 | + |
| 54 | + # run method that performs all the real work |
| 55 | + def run(self): |
| 56 | + # create and show the MapServerExport dialog |
| 57 | + self.dlg = MapServerExportDialog() |
| 58 | + #dlg.setupUi(self) |
| 59 | + # fetch the last used values from settings and intialize the |
| 60 | + # dialog with them |
| 61 | + #settings = QSettings("MicroResources", "ZoomToPoint") |
| 62 | + #xValue = settings.value("coordinate/x") |
| 63 | + #dlg.ui.xCoord.setText(str(xValue.toString())) |
| 64 | + #yValue = settings.value("coordinate/y") |
| 65 | + #dlg.ui.yCoord.setText(str(yValue.toString())) |
| 66 | + #scale = settings.value("zoom/scale", QVariant(4)) |
| 67 | + #dlg.ui.spinBoxScale.setValue(scale.toInt()[0]) |
| 68 | + QObject.connect(self.dlg.ui.btnChooseFile, SIGNAL("clicked()"), self.setSaveFile) |
| 69 | + QObject.connect(self.dlg.ui.btnChooseProjectFile, SIGNAL("clicked()"), self.setProjectFile) |
| 70 | + QObject.connect(self.dlg.ui.chkExpLayersOnly, SIGNAL("clicked(bool)"), self.toggleLayersOnly) |
| 71 | + QObject.connect(self.dlg.ui.btnChooseFooterFile, SIGNAL("clicked()"), self.setFooterFile) |
| 72 | + QObject.connect(self.dlg.ui.btnChooseHeaderFile, SIGNAL("clicked()"), self.setHeaderFile) |
| 73 | + QObject.connect(self.dlg.ui.btnChooseTemplateFile, SIGNAL("clicked()"), self.setTemplateFile) |
| 74 | + |
| 75 | + self.dlg.show() |
| 76 | + result = self.dlg.exec_() |
| 77 | + # See if OK was pressed |
| 78 | + if result == 1: |
| 79 | + # get the settings from the dialog and export the map file |
| 80 | + print "Creating exporter using %s and %s" % (self.dlg.ui.txtQgisFilePath.text(), self.dlg.ui.txtMapFilePath.text()) |
| 81 | + exporter = Qgis2Map(self.dlg.ui.txtQgisFilePath.text(), self.dlg.ui.txtMapFilePath.text()) |
| 82 | + print "Setting options" |
| 83 | + exporter.setOptions( |
| 84 | + self.dlg.ui.cmbMapUnits.currentText(), |
| 85 | + self.dlg.ui.cmbMapImageType.currentText(), |
| 86 | + self.dlg.ui.txtMapName.text(), |
| 87 | + self.dlg.ui.txtMapWidth.text(), |
| 88 | + self.dlg.ui.txtMapHeight.text(), |
| 89 | + self.dlg.ui.txtWebTemplate.text(), |
| 90 | + self.dlg.ui.txtWebFooter.text(), |
| 91 | + self.dlg.ui.txtWebHeader.text() |
| 92 | + ) |
| 93 | + print "Calling writeMapFile" |
| 94 | + result = exporter.writeMapFile() |
| 95 | + QMessageBox.information(None, "MapServer Export Results", result) |
| 96 | + |
| 97 | + def setSaveFile(self): |
| 98 | + mapFile = QFileDialog.getSaveFileName(self.dlg, "Name for the map file", \ |
| 99 | + ".", "MapServer map files (*.map);;All files (*.*)","Filter list for selecting files from a dialog box") |
| 100 | + self.dlg.ui.txtMapFilePath.setText(mapFile) |
| 101 | + |
| 102 | + def setProjectFile(self): |
| 103 | + qgisProjectFile = QFileDialog.getOpenFileName(self.dlg, "Choose the QGIS Project file", \ |
| 104 | + ".", "QGIS Project Files (*.qgs);;All files (*.*)", "Filter list for selecting files from a dialog box") |
| 105 | + self.dlg.ui.txtQgisFilePath.setText(qgisProjectFile) |
| 106 | + |
| 107 | + def setTemplateFile(self): |
| 108 | + templateFile = QFileDialog.getOpenFileName(self.dlg, |
| 109 | + "Choose the MapServer template file", |
| 110 | + ".", |
| 111 | + "All files (*.*)", |
| 112 | + "Filter list for selecting files from a dialog box") |
| 113 | + self.dlg.ui.txtWebTemplate.setText(templateFile) |
| 114 | + |
| 115 | + def setHeaderFile(self): |
| 116 | + headerFile = QFileDialog.getOpenFileName(self.dlg, |
| 117 | + "Choose the MapServer header file", |
| 118 | + ".", |
| 119 | + "All files (*.*)", |
| 120 | + "Filter list for selecting files from a dialog box") |
| 121 | + self.dlg.ui.txtWebHeader.setText(headerFile) |
| 122 | + |
| 123 | + def setFooterFile(self): |
| 124 | + footerFile = QFileDialog.getOpenFileName(self.dlg, |
| 125 | + "Choose the MapServer footer file", |
| 126 | + ".", |
| 127 | + "All files (*.*)", |
| 128 | + "Filter list for selecting files from a dialog box") |
| 129 | + self.dlg.ui.txtWebFooter.setText(footerFile) |
| 130 | + |
| 131 | + def apply(self): |
| 132 | + # create the map file |
| 133 | + foo = 'bar' |
| 134 | + |
| 135 | + def toggleLayersOnly(self, isChecked): |
| 136 | + # disable other sections if only layer export is desired |
| 137 | + self.dlg.ui.txtMapName.setEnabled(not isChecked) |
| 138 | + self.dlg.ui.txtMapWidth.setEnabled(not isChecked) |
| 139 | + self.dlg.ui.txtMapHeight.setEnabled(not isChecked) |
| 140 | + self.dlg.ui.cmbMapUnits.setEnabled(not isChecked) |
| 141 | + self.dlg.ui.cmbMapImageType.setEnabled(not isChecked) |
| 142 | + self.dlg.ui.txtWebTemplate.setEnabled(not isChecked) |
| 143 | + self.dlg.ui.txtWebHeader.setEnabled(not isChecked) |
| 144 | + self.dlg.ui.txtWebFooter.setEnabled(not isChecked) |
| 145 | + self.dlg.ui.btnChooseFooterFile.setEnabled(not isChecked) |
| 146 | + self.dlg.ui.btnChooseHeaderFile.setEnabled(not isChecked) |
| 147 | + self.dlg.ui.btnChooseTemplateFile.setEnabled(not isChecked) |
0 commit comments