<s> from __future__ import division <EOL> from PyQt4 import QtCore , QtGui <EOL> from vistrails . core . modules . vistrails_module import Module <EOL> from vistrails . packages . spreadsheet . basic_widgets import SpreadsheetCell <EOL> from vistrails . packages . spreadsheet . spreadsheet_cell import QCellWidget <EOL> import qgis . core <EOL> import qgis . gui <EOL> import itertools <EOL> import os <EOL> class RasterLayer ( Module ) : <EOL> _input_ports = [ ( '<STR_LIT:file>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:name>' , '<STR_LIT>' ) ] <EOL> _output_ports = [ ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> def __init__ ( self ) : <EOL> Module . __init__ ( self ) <EOL> self . qgis_obj = None <EOL> def compute ( self ) : <EOL> fname = self . get_input ( '<STR_LIT:file>' ) . name <EOL> if self . has_input ( '<STR_LIT:name>' ) : <EOL> name = self . get_input ( '<STR_LIT:name>' ) <EOL> else : <EOL> name = os . path . splitext ( os . path . basename ( fname ) ) [ <NUM_LIT:0> ] <EOL> self . qgis_obj = qgis . core . QgsRasterLayer ( fname , name ) <EOL> self . set_output ( '<STR_LIT>' , self ) <EOL> class VectorLayer ( Module ) : <EOL> _input_ports = [ ( '<STR_LIT:file>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT:name>' , '<STR_LIT>' ) ] <EOL> _output_ports = [ ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> def __init__ ( self ) : <EOL> Module . __init__ ( self ) <EOL> self . qgis_obj = None <EOL> def compute ( self ) : <EOL> fname = self . get_input ( '<STR_LIT:file>' ) . name <EOL> if self . has_input ( '<STR_LIT:name>' ) : <EOL> name = self . get_input ( '<STR_LIT:name>' ) <EOL> else : <EOL> name = os . path . splitext ( os . path . basename ( fname ) ) [ <NUM_LIT:0> ] <EOL> self . qgis_obj = qgis . core . QgsVectorLayer ( fname , name , "<STR_LIT>" ) <EOL> self . set_output ( '<STR_LIT>' , self ) <EOL> class QGISCell ( SpreadsheetCell ) : <EOL> """<STR_LIT>""" <EOL> _input_ports = [ ( '<STR_LIT>' , '<STR_LIT>' ) , <EOL> ( '<STR_LIT>' , '<STR_LIT>' ) ] <EOL> def __init__ ( self ) : <EOL> SpreadsheetCell . __init__ ( self ) <EOL> def compute ( self ) : <EOL> rasterLayers = self . force_get_input_list ( '<STR_LIT>' ) <EOL> vectorLayers = self . force_get_input_list ( '<STR_LIT>' ) <EOL> self . displayAndWait ( QGISCellWidget , ( rasterLayers , vectorLayers ) ) <EOL> class QGISCellWidget ( QCellWidget ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , parent = None ) : <EOL> """<STR_LIT>""" <EOL> QCellWidget . __init__ ( self , parent ) <EOL> centralLayout = QtGui . QVBoxLayout ( ) <EOL> self . setLayout ( centralLayout ) <EOL> centralLayout . setMargin ( <NUM_LIT:0> ) <EOL> centralLayout . setSpacing ( <NUM_LIT:0> ) <EOL> def updateContents ( self , inputPorts ) : <EOL> """<STR_LIT>""" <EOL> ( rasterLayers , vectorLayers ) = inputPorts <EOL> canvas = qgis . gui . QgsMapCanvas ( ) <EOL> canvas . show ( ) <EOL> canvas . setCanvasColor ( QtCore . Qt . white ) <EOL> canvas . enableAntiAliasing ( True ) <EOL> for layer in itertools . chain ( rasterLayers , vectorLayers ) : <EOL> print '<STR_LIT>' , layer . qgis_obj <EOL> qgis . core . QgsMapLayerRegistry . instance ( ) . addMapLayer ( layer . qgis_obj ) <EOL> canvas . setExtent ( rasterLayers [ <NUM_LIT:0> ] . qgis_obj . extent ( ) ) <EOL> canvas . setLayerSet ( [ qgis . gui . QgsMapCanvasLayer ( layer . qgis_obj ) <EOL> for layer in itertools . chain ( vectorLayers , <EOL> rasterLayers ) ] ) <EOL> self . layout ( ) . addWidget ( canvas ) <EOL> self . update ( ) <EOL> def grabWindowPixmap ( self ) : <EOL> """<STR_LIT>""" <EOL> return None <EOL> def dumpToFile ( self , filename ) : <EOL> pass <EOL> def saveToPDF ( self , filename ) : <EOL> pass <EOL> _modules = [ RasterLayer , VectorLayer , QGISCell , ] <EOL> def initialize ( ) : <EOL> qgis . core . QgsApplication . setPrefixPath ( <EOL> "<STR_LIT>" , True ) <EOL> qgis . core . QgsApplication . initQgis ( ) </s>
