def __init__(self): QMainWindow.__init__(self) self.setWindowIcon(get_icon(os.path.join(APP_RESOURCES, 'icons', 'python.png'))) self.setupUi(self) # Redirect output to GUI's QTextEdit sys.stdout = OutLog(self.outputTextEdit, sys.stdout) sys.stderr = OutLog(self.outputTextEdit, sys.stderr, QColor(255,0,0) ) settings = QSettings() size = settings.value("MainWindow/Size", QVariant(QSize(600, 500))).toSize() self.resize(size) position = settings.value("MainWindow/Position", QVariant(QPoint(0, 0))).toPoint() self.move(position) self.restoreState( settings.value("MainWindow/State").toByteArray()) self.logger = Logger('Zupport.GUIloader') self.logger.debugging = settings.value("Logging/debugging").toBool() # Set up a ZupportManager to deal with the plugins self.manager = Manager(self) self.plugins = {} # Set up the extents menu self.extent = ExtentContainer() self.menuExtent = QMenu("Extent") resolutions = self.extent.resolutions self.extenactiongroup = QActionGroup(self.menuExtent) noneaction = QAction("None", self.menuExtent) self.extenactiongroup.addAction(noneaction) self.menuExtent.addAction(noneaction) for resolution in resolutions: resolution_text = str(resolution) submenu = self.menuExtent.addMenu(resolution_text) self.menuExtent.addMenu(submenu) for area in self.extent.get_names(resolution): subaction = QAction(str(area) + ": %s" % resolution_text, submenu) subaction.setCheckable(True) self.extenactiongroup.addAction(subaction) submenu.addAction(subaction) noneaction.isChecked() self.menuSettings.addMenu(self.menuExtent) self.actionDebugging_messages.setChecked(self.logger.debugging) self.setWindowTitle("Zupport GUI") self.load_tools() self.toolTreeWidget.itemSelectionChanged.connect(self.update_ui) self.actionDebugging_messages.toggled.connect(self._set_debugging) self.menuExtent.triggered.connect(self.update_ui) self.actionLoad_tool.triggered.connect(self.show_tool_gui) self.toolTreeWidget.doubleClicked.connect(self.show_tool_gui)
# THIS MODULE SHOULD ONLY BE CALLED FROM ARCGIS TOOLBOX import os import arcpy from zupport.core import Job, Manager from zupport.plugins.fileio import FileGroupIterator from zupport.utilities import USER_DATA_DIR from zupport.utilities.dataframe import read_csv, ZCustom NAME = "rasigmoidal" manager = Manager() plugin = manager.get_plugin('zarcgis') if plugin and plugin.registered(NAME): # Input workspace inputws = arcpy.GetParameterAsText(0) #inputws = r"C:\Data\Staging\Output\MK_puusto\ositteet" # Wildcard wildcard = arcpy.GetParameterAsText(1) #wildcard = "*.img" # Template to be used template = arcpy.GetParameterAsText(2) #template = "<BODY1>_<ID1>_<BODY2>_<ID2>_<BODY3>" # Grouping tags grouptags = arcpy.GetParameterAsText(3) grouptags = grouptags.split(";") #grouptags = ['ID1', 'ID2']
class MainWindow(QMainWindow, Ui_MainWindow): '''Mainwindow for initial loading of different plugins. ''' def __init__(self): QMainWindow.__init__(self) self.setWindowIcon(get_icon(os.path.join(APP_RESOURCES, 'icons', 'python.png'))) self.setupUi(self) # Redirect output to GUI's QTextEdit sys.stdout = OutLog(self.outputTextEdit, sys.stdout) sys.stderr = OutLog(self.outputTextEdit, sys.stderr, QColor(255,0,0) ) settings = QSettings() size = settings.value("MainWindow/Size", QVariant(QSize(600, 500))).toSize() self.resize(size) position = settings.value("MainWindow/Position", QVariant(QPoint(0, 0))).toPoint() self.move(position) self.restoreState( settings.value("MainWindow/State").toByteArray()) self.logger = Logger('Zupport.GUIloader') self.logger.debugging = settings.value("Logging/debugging").toBool() # Set up a ZupportManager to deal with the plugins self.manager = Manager(self) self.plugins = {} # Set up the extents menu self.extent = ExtentContainer() self.menuExtent = QMenu("Extent") resolutions = self.extent.resolutions self.extenactiongroup = QActionGroup(self.menuExtent) noneaction = QAction("None", self.menuExtent) self.extenactiongroup.addAction(noneaction) self.menuExtent.addAction(noneaction) for resolution in resolutions: resolution_text = str(resolution) submenu = self.menuExtent.addMenu(resolution_text) self.menuExtent.addMenu(submenu) for area in self.extent.get_names(resolution): subaction = QAction(str(area) + ": %s" % resolution_text, submenu) subaction.setCheckable(True) self.extenactiongroup.addAction(subaction) submenu.addAction(subaction) noneaction.isChecked() self.menuSettings.addMenu(self.menuExtent) self.actionDebugging_messages.setChecked(self.logger.debugging) self.setWindowTitle("Zupport GUI") self.load_tools() self.toolTreeWidget.itemSelectionChanged.connect(self.update_ui) self.actionDebugging_messages.toggled.connect(self._set_debugging) self.menuExtent.triggered.connect(self.update_ui) self.actionLoad_tool.triggered.connect(self.show_tool_gui) self.toolTreeWidget.doubleClicked.connect(self.show_tool_gui) def closeEvent(self, event): settings = QSettings() settings.setValue("Logging/debugging", self.logger.debugging) settings.setValue("MainWindow/Size", QVariant(self.size())) settings.setValue("MainWindow/Position", QVariant(self.pos())) settings.setValue("MainWindow/State", QVariant(self.saveState())) def load_tools(self): plugins = self.manager.plugins for name, plugin in plugins.iteritems(): item = QTreeWidgetItem(QStringList(name.capitalize())) tool_items = [] for tool_name in plugin.tool_names(): tool_items.append(QTreeWidgetItem(QStringList(tool_name))) item.addChildren(tool_items) self.toolTreeWidget.addTopLevelItem(item) item.setExpanded(True) self.statusbar.showMessage("Succesfully loaded %s plugins" % len(plugins), 4000) def show_tool_gui(self): selected_tool = self.toolListWidget.currentItem() toolname = str(selected_tool.text()) parameters = self.manager.plugins[toolname] # Check if extent is available extent = self.extenactiongroup.checkedAction() if extent: extent = str(extent.text()) # Extent is a String of the form "area: resolution" area, resolution = extent.split(':') resolution = int(resolution) self.extent.resolution = resolution # This is a list of coordinates coordinates = self.extent.get_extent(area) # Create a string for the GUI coord_text = ', '.join([str(coord) for coord in coordinates]) self.manager.plugins[toolname].set_parameter_value('extent', coord_text) dataset = ToolLoader(toolname, parameters) if dataset.edit(): self.logger.debug('User pressed OK, proceeding to execution') self.manager.plugins[toolname] = dataset.get_parameters() # Run the tool if self.actionArcGIS.isChecked(): backend = 'arcgis' else: backend = 'osgeo' else: self.logger.debug('User pressed cancel') return self.manager.executetool(toolname, backend) def update_ui(self): if self.toolTreeWidget.currentItem(): self.actionLoad_tool.setEnabled(True) selected_tool = str(self.toolTreeWidget.currentItem().text(0)) help_text = self.manager.plugins[selected_tool].help self.helpTextEdit.setText(help_text) extent = self.extenactiongroup.checkedAction() if extent: self.extentLabel.setText("Current extent: %s" % extent.text()) @Slot() def on_actionAbout_triggered(self): QMessageBox.about(self, "About Zupport GUI", """<b>Zupport GUI</b> v %s <p>Copyright © 2011 Joona Lehtomaki <*****@*****.**>. All rights reserved. <p>Support zools for Zonation related pre- and post-processing operations.</p> <p>Python %s - Qt %s - PySide %s on %s</p>""" % ( __version__, platform.python_version(), QT_VERSION, PYQT_VERSION, platform.system())) @Slot() def on_actionOpen_log_triggered(self): logfile = os.path.join(USER_DATA_DIR, 'zupport.log') if os.path.exists(logfile): import webbrowser webbrowser.open(logfile) self.logger.debug('Opened log file %s' % logfile) else: msg = "Zupport log file cannot be found in default location %s" % os.path.dirname(logfile) self.logger.debug(msg) QMessageBox.warning(self, "File not found", msg, buttons=QMessageBox.Ok, defaultButton=QMessageBox.NoButton) def _set_debugging(self, toggle): self.logger.debugging = toggle
# THIS MODULE SHOULD ONLY BE CALLED FROM ARCGIS TOOLBOX import arcpy from zupport.core import Job, Manager from zupport.utilities import USER_DATA_DIR NAME = "crossselect" manager = Manager() plugin = manager.get_plugin('zarcgis') if plugin and plugin.registered(NAME): reference_raster = arcpy.GetParameterAsText(0) inputws = arcpy.GetParameterAsText(1) outws = arcpy.GetParameterAsText(2) include = arcpy.GetParameterAsText(3) include = include.split(",") exclude = arcpy.GetParameterAsText(4) exclude = exclude.split(",") try: if include != ['']: include = [int(value.strip()) for value in include] except ValueError, e: arcpy.AddError("Include values must be integers") try: if exclude != ['']: exclude = [int(value.strip()) for value in exclude] except ValueError, e:
# THIS MODULE SHOULD ONLY BE CALLED FROM ARCGIS TOOLBOX import arcpy from zupport.core import Job, Manager from zupport.utilities import USER_DATA_DIR NAME = "aggregate" manager = Manager() plugin = manager.get_plugin('zarcgis') if plugin and plugin.registered(NAME): manager.run_job(Job(NAME, batch=False, gui=True)) else: arcpy.AddError("Could not load Zupport tool: %s" % NAME) arcpy.AddMessage("See log file in %s for more information" % USER_DATA_DIR)
# THIS MODULE SHOULD ONLY BE CALLED FROM ARCGIS TOOLBOX import arcpy from zupport.core import Job, Manager from zupport.utilities import USER_DATA_DIR from zupport.utilities.dataframe import read_csv, ZCustom NAME = "calculaterastergroup" manager = Manager() plugin = manager.get_plugin('zarcgis') if plugin and plugin.registered(NAME): # Input workspace inputws = arcpy.GetParameterAsText(0) wildcard = arcpy.GetParameterAsText(1) template = arcpy.GetParameterAsText(2) grouptags = arcpy.GetParameterAsText(3) grouptags = grouptags.split(";") operator = arcpy.GetParameterAsText(4) outws = arcpy.GetParameterAsText(5) # These will be None if not provided reftable_file = arcpy.GetParameterAsText(6)
# THIS MODULE SHOULD ONLY BE CALLED FROM ARCGIS TOOLBOX import arcpy from zupport.core import Job, Manager from zupport.utilities import USER_DATA_DIR NAME = "batch_aggregate" manager = Manager() plugin = manager.get_plugin('zarcgis') if plugin and plugin.registered(NAME): job = Job(NAME) manager.add_job(job) manager.run_jobs() else: arcpy.AddError("Could not load Zupport tool: %s" % NAME) arcpy.AddMessage("See log file in %s for more information" % USER_DATA_DIR)
# THIS MODULE SHOULD ONLY BE CALLED FROM ARCGIS TOOLBOX import arcpy from zupport.core import Job, Manager from zupport.utilities import USER_DATA_DIR from zupport.utilities.dataframe import read_csv, ZCustom NAME = "calculaterastergroup" manager = Manager() plugin = manager.get_plugin('zarcgis') if plugin and plugin.registered(NAME): # Input workspace inputws = arcpy.GetParameterAsText(0) wildcard = arcpy.GetParameterAsText(1) template = arcpy.GetParameterAsText(2) grouptags = arcpy.GetParameterAsText(3) grouptags = grouptags.split(";") operator = arcpy.GetParameterAsText(4) outws = arcpy.GetParameterAsText(5) # These will be None if not provided reftable_file = arcpy.GetParameterAsText(6) reftable = read_csv(reftable_file, dialect=ZCustom)