safe.gui.tools.batch.batch_dialog module

InaSAFE Disaster risk assessment tool developed by AusAid - Script runner dialog.

Contact : ole.moller.nielsen@gmail.com

Note

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

class safe.gui.tools.batch.batch_dialog.BatchDialog(parent=None, iface=None, dock=None)[source]

Bases: PyQt4.QtGui.QDialog, Ui_BatchDialogBase

Script Dialog for InaSAFE.

choose_directory(line_edit, title)[source]

Show a directory selection dialog. This function will show the dialog then set line_edit widget text with output from the dialog.

Parameters:
  • line_edit (QLineEdit) – Widget whose text should be updated.
  • title (str, QString) – title of dialog
create_pdf(title, output_directory, impact_layer, count=0, index=None)[source]

Create PDF report from impact layer.

Create map & table report PDF based from impact_layer data.

Parameters:
  • title (str) – Report title.
  • output_directory (str) – Output directory.
  • impact_layer (QgsMapLayer) – Impact layer instance.
  • count (int) – The number of scenarios that were run.
  • index (int, None) – A sequential number to place at the beginning of the file name.
See also:
Dock.printMap()
disable_busy_cursor()[source]

Disable the hourglass cursor.

enable_busy_cursor()[source]

Set the hourglass enabled.

on_output_directory_chooser_clicked()[source]

Autoconnect slot activated when tbOutputDiris clicked

on_scenario_directory_radio_toggled(flag)[source]

Autoconnect slot activated when scenario_directory_radio is checked.

Parameters:flag (bool) – Flag indicating whether the checkbox was toggled on or off.
on_source_directory_chooser_clicked()[source]

Autoconnect slot activated when tbSourceDir is clicked

populate_table(scenario_directory)[source]

Populate table with files from scenario_directory directory.

Parameters:scenario_directory (QString) – Path where .txt & .py reside.
report_path(directory, title, count=0, index=None)[source]

Get PDF report filename given directory, title and optional index.

Parameters:
  • directory (str) – Directory of pdf report file.
  • title (str) – Title of report.
  • count (int) – The number of scenario run.
  • index (int, None) – A sequential number for the beginning of the file name.
Returns:

A tuple containing the pdf report filenames like this: (‘/home/foo/data/title.pdf’, ‘/home/foo/data/title_table.pdf’)

Return type:

tuple

reset_status()[source]

Set all scenarios’ status to empty in the table

restore_state()[source]

Restore GUI state from configuration file

run_all_clicked()[source]

Run all scenario when pbRunAll is clicked.

run_scenario(items)[source]

Run a simple scenario.

Parameters:items (dict) – A dictionary containing the scenario configuration as table items.
Returns:True if success, otherwise return False.
Return type:bool
run_script(filename)[source]

Run a python script in QGIS to exercise InaSAFE functionality.

This functionality was originally intended for verifying that the key elements are InaSAFE are loading correctly and available. However, the utility of this function is such that you can run any arbitrary python scripts with it. As such you can use it it automate activities in QGIS, for example automatically running an impact assessment in response to an event.

Parameters:filename (str) – the script filename.
run_selected_clicked()[source]

Run the selected scenario.

run_task(task_item, status_item, count=0, index='')[source]

Run a single task.

Parameters:
  • task_item (QTableWidgetItem) – Table task_item containing task name / details.
  • status_item (QTableWidgetItem) – Table task_item that holds the task status.
  • count – Count of scenarios that have been run already.
  • index (int) – The index for the table item that will be run.
Returns:

Flag indicating if the task succeeded or not.

Return type:

bool

save_state()[source]

Save current state of GUI to configuration file

show_help()[source]

Show context help for the batch dialog.

show_parser_results(parsed_list, unparsed_list)[source]

Compile a formatted list of un/successfully parsed files.

Parameters:
  • parsed_list (list(str)) – A list of files that were parsed successfully.
  • unparsed_list (list(str)) – A list of files that were not parsable.
Returns:

A formatted message outlining what could be parsed.

Return type:

str

show_report(report_path)[source]

Show batch report file in batchReportFileName using an external app.

This method uses QDesktop services to display the report (typically using gedit or similar text editor).

Parameters:report_path (str) – Path to the file of batch report.
update_default_output_dir()[source]

Update output dir if set to default

write_report(report, pass_count, fail_count)[source]

Write a report status of Batch Runner.

For convenience, the name will use current time.

Parameters:
  • report (list) – A list of each scenario and its status.
  • pass_count (int) – Number of passing scenarios.
  • fail_count (int) – Number of failed scenarios.
Returns:

A string containing the path to the report file.

Return type:

str

Raises:

IOError

safe.gui.tools.batch.batch_dialog.append_row(table, label, data)[source]

Append new row to table widget.

Parameters:
  • table (QTableWidget) – The table that shall have the row added to it.
  • label (str) – Label for the row.
  • data (str) – custom data associated with label value.
safe.gui.tools.batch.batch_dialog.read_scenarios(filename)[source]

Read keywords dictionary from file

Parameters:filename – Name of file holding scenarios .
:return Dictionary of with structure like this
{{ ‘foo’ : { ‘a’: ‘b’, ‘c’: ‘d’},
{ ‘bar’ : { ‘d’: ‘e’, ‘f’: ‘g’}}

A scenarios file may look like this:

[jakarta_flood] hazard: /path/to/hazard.tif exposure: /path/to/exposure.tif function: function_id aggregation: /path/to/aggregation_layer.tif extent: minx, miny, maxx, maxy
Notes:
path for hazard, exposure, and aggregation are relative to scenario file path