예제 #1
0
class RuGeocoderPlugin:
    def __init__(self, iface):
        # Save reference to the QGIS interface
        self.iface = iface
        self.__converter_dlg = ConverterDialog()
        self.__geocoder_dlg = BatchGeocodingDialog()

        # i18n support
        override_locale = QSettings().value('locale/overrideFlag', False, type=bool)
        if not override_locale:
            locale_full_name = QLocale.system().name()
        else:
            locale_full_name = QSettings().value('locale/userLocale', '', type=unicode)

        self.locale_path = '%s/i18n/rugeocoder_%s.qm' % (_current_path, locale_full_name[0:2])
        if QFileInfo(self.locale_path).exists():
            self.translator = QTranslator()
            self.translator.load(self.locale_path)
            QCoreApplication.installTranslator(self.translator)

    def initGui(self):
        # Setup signals
        self.action_convert = QAction(QIcon(':/plugins/rugeocoderplugin/convert.png'),
                                      QCoreApplication.translate('RuGeocoder', 'Convert CSV to SHP'),
                                      self.iface.mainWindow())
        QObject.connect(self.action_convert, SIGNAL("triggered()"), self.run_convert)

        self.action_batch_geocoding = QAction(QIcon(':/plugins/rugeocoderplugin/icon.png'),
                                              QCoreApplication.translate('RuGeocoder', 'Batch geocoding'),
                                              self.iface.mainWindow())
        QObject.connect(self.action_batch_geocoding, SIGNAL('triggered()'), self.run_batch)

        # Add toolbar button and menu item
        self.iface.addToolBarIcon(self.action_convert)
        self.iface.addPluginToMenu('&RuGeocoder', self.action_convert)

        self.iface.addToolBarIcon(self.action_batch_geocoding)
        self.iface.addPluginToMenu('&RuGeocoder', self.action_batch_geocoding)

    def unload(self):
        # Remove the plugin menu item and icon
        self.iface.removePluginMenu('&RuGeocoder', self.action_convert)
        self.iface.removeToolBarIcon(self.action_convert)

        self.iface.removePluginMenu('&RuGeocoder', self.action_batch_geocoding)
        self.iface.removeToolBarIcon(self.action_batch_geocoding)

    def run_convert(self):
        if not self.__converter_dlg.isVisible():
            self.__converter_dlg = ConverterDialog()
            self.__converter_dlg.show()
            self.__converter_dlg.exec_()

    def run_batch(self):
        if not self.__geocoder_dlg.isVisible():
            self.__geocoder_dlg = BatchGeocodingDialog()
            self.__geocoder_dlg.show()
            self.__geocoder_dlg.exec_()
 def test_behaviour(self):
     """Test behaviour of elements in the dialog
     """
     myDialog = ConverterDialog(PARENT)
     myDialog.cBDefaultOutputLocation.setEnabled(True)
     my_grid_path = os.path.join(TESTDATA, "grid.xml")
     myDialog.leInputPath.setText(my_grid_path)
     input_path = myDialog.leInputPath.text()
     output_path = myDialog.leOutputPath.text()
     assert myDialog.isEnabled(), "Output location should be disabled"
     expected_output_path = input_path[:-3] + "tif"
     assert output_path == expected_output_path, "Expected %s got %s" % (expected_output_path, output_path)
예제 #3
0
 def test_behaviour(self):
     """Test behaviour of elements in the dialog
     """
     myDialog = ConverterDialog(PARENT)
     myDialog.cBDefaultOutputLocation.setEnabled(True)
     my_grid_path = os.path.join(TESTDATA, 'grid.xml')
     myDialog.leInputPath.setText(my_grid_path)
     input_path = myDialog.leInputPath.text()
     output_path = myDialog.leOutputPath.text()
     assert myDialog.isEnabled(), 'Output location should be disabled'
     expected_output_path = input_path[:-3] + 'tif'
     assert output_path == expected_output_path, \
         'Expected %s got %s' % (expected_output_path, output_path)
 def test_Converting(self):
     """Test converting a file
     """
     myDialog = ConverterDialog(PARENT)
     myDialog.test_mode = True
     myDialog.cBDefaultOutputLocation.setEnabled(False)
     my_grid_path = os.path.join(TESTDATA, "grid.xml")
     my_output_raster = unique_filename(prefix="result_grid", suffix=".tif", dir=temp_dir("test"))
     myDialog.cBLoadLayer.setEnabled(True)
     myDialog.leInputPath.setText(my_grid_path)
     myDialog.leOutputPath.setText(my_output_raster)
     myButton = myDialog.buttonBox.button(QDialogButtonBox.Ok)
     QTest.mouseClick(myButton, Qt.LeftButton)
     assert os.path.exists(my_output_raster), "Raster is not created"
예제 #5
0
    def __init__(self, iface):
        # Save reference to the QGIS interface
        self.iface = iface

        # i18n support
        override_locale = QSettings().value('locale/overrideFlag', False, type=bool)
        if not override_locale:
            locale_full_name = QLocale.system().name()
        else:
            locale_full_name = QSettings().value('locale/userLocale', '', type=unicode)

        self.locale_path = '%s/i18n/rugeocoder_%s.qm' % (_current_path, locale_full_name[0:2])
        if QFileInfo(self.locale_path).exists():
            self.translator = QTranslator()
            self.translator.load(self.locale_path)
            QCoreApplication.installTranslator(self.translator)

        # menu && toolbars
        self.menu_name = self.tr(u'&RuGeocoder')
        self.toolbar = self.iface.addToolBar(self.menu_name)
        self.toolbar.setObjectName(u'RuGeocoderToolbar')

        # instances
        self.__converter_dlg = ConverterDialog()
        self.__geocoder_dlg = BatchGeocodingDialog()

        # Dock tree panel
        self.__quick_tlb = QuickGeocodingToolbox(self.iface)
        self.iface.addDockWidget(PluginSettings.dock_area(), self.__quick_tlb)
        self.__quick_tlb.setFloating(PluginSettings.dock_floating())
        self.__quick_tlb.resize(PluginSettings.dock_size())
        self.__quick_tlb.move(PluginSettings.dock_pos())
        self.__quick_tlb.setVisible(PluginSettings.dock_visibility())
        self.__quick_tlb.set_active_geocoder(PluginSettings.dock_geocoder_name())
        self.__quick_tlb.setWindowIcon(QIcon(path.join(_current_path, 'edit-find-project.png')))
예제 #6
0
 def Xtest_Converting(self):
     """Test converting a file
     """
     myDialog = ConverterDialog(PARENT)
     myDialog.test_mode = True
     myDialog.cBDefaultOutputLocation.setEnabled(False)
     my_grid_path = os.path.join(TESTDATA, 'grid.xml')
     my_output_raster = unique_filename(prefix='result_grid',
                                        suffix='.tif',
                                        dir=temp_dir('test'))
     myDialog.cBLoadLayer.setEnabled(True)
     myDialog.leInputPath.setText(my_grid_path)
     myDialog.leOutputPath.setText(my_output_raster)
     myButton = myDialog.buttonBox.button(QDialogButtonBox.Ok)
     QTest.mouseClick(myButton, Qt.LeftButton)
     assert os.path.exists(my_output_raster), 'Raster is not created'
예제 #7
0
    def __init__(self, iface):
        # Save reference to the QGIS interface
        self.iface = iface

        # i18n support
        override_locale = QSettings().value('locale/overrideFlag',
                                            False,
                                            type=bool)
        if not override_locale:
            locale_full_name = QLocale.system().name()
        else:
            locale_full_name = QSettings().value('locale/userLocale',
                                                 '',
                                                 type=unicode)

        self.locale_path = '%s/i18n/rugeocoder_%s.qm' % (_current_path,
                                                         locale_full_name[0:2])
        if QFileInfo(self.locale_path).exists():
            self.translator = QTranslator()
            self.translator.load(self.locale_path)
            QCoreApplication.installTranslator(self.translator)

        # menu && toolbars
        self.menu_name = self.tr(u'&RuGeocoder')
        self.toolbar = self.iface.addToolBar(self.menu_name)
        self.toolbar.setObjectName(u'RuGeocoderToolbar')

        # instances
        self.__converter_dlg = ConverterDialog()
        self.__geocoder_dlg = BatchGeocodingDialog()

        # Dock tree panel
        self.__quick_tlb = QuickGeocodingToolbox(self.iface)
        self.iface.addDockWidget(PluginSettings.dock_area(), self.__quick_tlb)
        self.__quick_tlb.setFloating(PluginSettings.dock_floating())
        self.__quick_tlb.resize(PluginSettings.dock_size())
        self.__quick_tlb.move(PluginSettings.dock_pos())
        self.__quick_tlb.setVisible(PluginSettings.dock_visibility())
        self.__quick_tlb.set_active_geocoder(
            PluginSettings.dock_geocoder_name())
        self.__quick_tlb.setWindowIcon(
            QIcon(path.join(_current_path, 'edit-find-project.png')))
예제 #8
0
 def converter(self):
     if self.converterdlg is not None:
         self.converterdlg.raise_()
         self.converterdlg.activateWindow()
         return
     self.converterdlg = ConverterDialog()
     self.converterdlg.open_sig.connect(self.open)
     self.converterdlg.show()
     # Run the dialog event loop
     self.converterdlg.exec_()
     self.converterdlg = None
예제 #9
0
 def test_initDialog(self):
     """Test for showing table in the first."""
     myDialog = ConverterDialog(PARENT)
     assert myDialog is not None, 'Dialog is failed to created'
     # testing populate algorithm
     expected_algorithms = ['Nearest', 'Invdist']
     assert myDialog.cboAlgorithm.count() == len(expected_algorithms), \
         'Number of algorithm is not same'
     for i in list(xrange(len(expected_algorithms))):
         assert expected_algorithms[i] == str(
             myDialog.cboAlgorithm.itemText(i)), \
             ('Algorithm is not same, expect %s got %s') % \
             (expected_algorithms[i], myDialog.cboAlgorithm.itemText(i))
예제 #10
0
    def __init__(self, iface):
        # Save reference to the QGIS interface
        self.iface = iface
        self.__converter_dlg = ConverterDialog()
        self.__geocoder_dlg = BatchGeocodingDialog()

        # i18n support
        override_locale = QSettings().value('locale/overrideFlag', False, type=bool)
        if not override_locale:
            locale_full_name = QLocale.system().name()
        else:
            locale_full_name = QSettings().value('locale/userLocale', '', type=unicode)

        self.locale_path = '%s/i18n/rugeocoder_%s.qm' % (_current_path, locale_full_name[0:2])
        if QFileInfo(self.locale_path).exists():
            self.translator = QTranslator()
            self.translator.load(self.locale_path)
            QCoreApplication.installTranslator(self.translator)
예제 #11
0
class RuGeocoderPlugin:

    # noinspection PyMethodMayBeStatic
    def tr(self, message):
        # noinspection PyTypeChecker,PyArgumentList,PyCallByClass
        return QCoreApplication.translate('RuGeocoder', message)


    def __init__(self, iface):
        # Save reference to the QGIS interface
        self.iface = iface

        # i18n support
        override_locale = QSettings().value('locale/overrideFlag', False, type=bool)
        if not override_locale:
            locale_full_name = QLocale.system().name()
        else:
            locale_full_name = QSettings().value('locale/userLocale', '', type=unicode)

        self.locale_path = '%s/i18n/rugeocoder_%s.qm' % (_current_path, locale_full_name[0:2])
        if QFileInfo(self.locale_path).exists():
            self.translator = QTranslator()
            self.translator.load(self.locale_path)
            QCoreApplication.installTranslator(self.translator)

        # menu && toolbars
        self.menu_name = self.tr(u'&RuGeocoder')
        self.toolbar = self.iface.addToolBar(self.menu_name)
        self.toolbar.setObjectName(u'RuGeocoderToolbar')

        # instances
        self.__converter_dlg = ConverterDialog()
        self.__geocoder_dlg = BatchGeocodingDialog()

        # Dock tree panel
        self.__quick_tlb = QuickGeocodingToolbox(self.iface)
        self.iface.addDockWidget(PluginSettings.dock_area(), self.__quick_tlb)
        self.__quick_tlb.setFloating(PluginSettings.dock_floating())
        self.__quick_tlb.resize(PluginSettings.dock_size())
        self.__quick_tlb.move(PluginSettings.dock_pos())
        self.__quick_tlb.setVisible(PluginSettings.dock_visibility())
        self.__quick_tlb.set_active_geocoder(PluginSettings.dock_geocoder_name())
        self.__quick_tlb.setWindowIcon(QIcon(path.join(_current_path, 'edit-find-project.png')))


    def initGui(self):
        # Actions
        self.action_convert = QAction(QIcon(path.join(_current_path, 'convert.png')),
                                      QCoreApplication.translate('RuGeocoder', 'Convert CSV to SHP'),
                                      self.iface.mainWindow())
        QObject.connect(self.action_convert, SIGNAL("triggered()"), self.run_convert)

        self.action_batch_geocoding = QAction(QIcon(path.join(_current_path, 'icon.png')),
                                              QCoreApplication.translate('RuGeocoder', 'Batch geocoding'),
                                              self.iface.mainWindow())
        QObject.connect(self.action_batch_geocoding, SIGNAL('triggered()'), self.run_batch)

        self.action_quick_geocoding = self.__quick_tlb.toggleViewAction()
        self.action_quick_geocoding.setIcon(QIcon(path.join(_current_path, 'edit-find-project.png')))
        self.action_quick_geocoding.setText(QCoreApplication.translate('RuGeocoder', '&Quick geocoding toolbox'))

        # Add toolbar button and menu item
        self.toolbar.addAction(self.action_convert)
        self.iface.addPluginToWebMenu(self.menu_name, self.action_convert)

        self.toolbar.addAction(self.action_batch_geocoding)
        self.iface.addPluginToWebMenu(self.menu_name, self.action_batch_geocoding)

        self.toolbar.addSeparator()

        self.toolbar.addAction(self.action_quick_geocoding)
        self.iface.addPluginToWebMenu(self.menu_name, self.action_quick_geocoding)

        #import pydevd
        #pydevd.settrace('localhost', port=9921, stdoutToServer=True, stderrToServer=True, suspend=False)


    def unload(self):
        # Remove the plugin menu item and icon
        self.iface.removePluginWebMenu(self.menu_name, self.action_convert)
        self.iface.removePluginWebMenu(self.menu_name, self.action_batch_geocoding)
        self.iface.removePluginWebMenu(self.menu_name, self.action_quick_geocoding)

        self.action_convert = None
        self.action_batch_geocoding = None
        self.action_quick_geocoding = None
        self.toolbar = None

        mw = self.iface.mainWindow()
        PluginSettings.set_dock_area(mw.dockWidgetArea(self.__quick_tlb))
        PluginSettings.set_dock_floating(self.__quick_tlb.isFloating())
        PluginSettings.set_dock_pos(self.__quick_tlb.pos())
        PluginSettings.set_dock_size(self.__quick_tlb.size())
        PluginSettings.set_dock_visibility(self.__quick_tlb.isVisible())
        PluginSettings.set_dock_geocoder_name(self.__quick_tlb.get_active_geocoder_name())

        self.iface.removeDockWidget(self.__quick_tlb)
        del self.__quick_tlb



    def run_convert(self):
        if not self.__converter_dlg.isVisible():
            self.__converter_dlg = ConverterDialog()
            self.__converter_dlg.show()
            self.__converter_dlg.exec_()

    def run_batch(self):
        if not self.__geocoder_dlg.isVisible():
            self.__geocoder_dlg = BatchGeocodingDialog()
            self.__geocoder_dlg.show()
            self.__geocoder_dlg.exec_()
예제 #12
0
 def run_convert(self):
     if not self.__converter_dlg.isVisible():
         self.__converter_dlg = ConverterDialog()
         self.__converter_dlg.show()
         self.__converter_dlg.exec_()
예제 #13
0
class RuGeocoderPlugin:

    # noinspection PyMethodMayBeStatic
    def tr(self, message):
        # noinspection PyTypeChecker,PyArgumentList,PyCallByClass
        return QCoreApplication.translate('RuGeocoder', message)

    def __init__(self, iface):
        # Save reference to the QGIS interface
        self.iface = iface

        # i18n support
        override_locale = QSettings().value('locale/overrideFlag',
                                            False,
                                            type=bool)
        if not override_locale:
            locale_full_name = QLocale.system().name()
        else:
            locale_full_name = QSettings().value('locale/userLocale',
                                                 '',
                                                 type=unicode)

        self.locale_path = '%s/i18n/rugeocoder_%s.qm' % (_current_path,
                                                         locale_full_name[0:2])
        if QFileInfo(self.locale_path).exists():
            self.translator = QTranslator()
            self.translator.load(self.locale_path)
            QCoreApplication.installTranslator(self.translator)

        # menu && toolbars
        self.menu_name = self.tr(u'&RuGeocoder')
        self.toolbar = self.iface.addToolBar(self.menu_name)
        self.toolbar.setObjectName(u'RuGeocoderToolbar')

        # instances
        self.__converter_dlg = ConverterDialog()
        self.__geocoder_dlg = BatchGeocodingDialog()

        # Dock tree panel
        self.__quick_tlb = QuickGeocodingToolbox(self.iface)
        self.iface.addDockWidget(PluginSettings.dock_area(), self.__quick_tlb)
        self.__quick_tlb.setFloating(PluginSettings.dock_floating())
        self.__quick_tlb.resize(PluginSettings.dock_size())
        self.__quick_tlb.move(PluginSettings.dock_pos())
        self.__quick_tlb.setVisible(PluginSettings.dock_visibility())
        self.__quick_tlb.set_active_geocoder(
            PluginSettings.dock_geocoder_name())
        self.__quick_tlb.setWindowIcon(
            QIcon(path.join(_current_path, 'edit-find-project.png')))

    def initGui(self):
        # Actions
        self.action_convert = QAction(
            QIcon(path.join(_current_path, 'convert.png')),
            QCoreApplication.translate('RuGeocoder', 'Convert CSV to SHP'),
            self.iface.mainWindow())
        QObject.connect(self.action_convert, SIGNAL("triggered()"),
                        self.run_convert)

        self.action_batch_geocoding = QAction(
            QIcon(path.join(_current_path, 'icon.png')),
            QCoreApplication.translate('RuGeocoder', 'Batch geocoding'),
            self.iface.mainWindow())
        QObject.connect(self.action_batch_geocoding, SIGNAL('triggered()'),
                        self.run_batch)

        self.action_quick_geocoding = self.__quick_tlb.toggleViewAction()
        self.action_quick_geocoding.setIcon(
            QIcon(path.join(_current_path, 'edit-find-project.png')))
        self.action_quick_geocoding.setText(
            QCoreApplication.translate('RuGeocoder',
                                       '&Quick geocoding toolbox'))

        # Add toolbar button and menu item
        self.toolbar.addAction(self.action_convert)
        self.iface.addPluginToWebMenu(self.menu_name, self.action_convert)

        self.toolbar.addAction(self.action_batch_geocoding)
        self.iface.addPluginToWebMenu(self.menu_name,
                                      self.action_batch_geocoding)

        self.toolbar.addSeparator()

        self.toolbar.addAction(self.action_quick_geocoding)
        self.iface.addPluginToWebMenu(self.menu_name,
                                      self.action_quick_geocoding)

        #import pydevd
        #pydevd.settrace('localhost', port=9921, stdoutToServer=True, stderrToServer=True, suspend=False)

    def unload(self):
        # Remove the plugin menu item and icon
        self.iface.removePluginWebMenu(self.menu_name, self.action_convert)
        self.iface.removePluginWebMenu(self.menu_name,
                                       self.action_batch_geocoding)
        self.iface.removePluginWebMenu(self.menu_name,
                                       self.action_quick_geocoding)

        self.action_convert = None
        self.action_batch_geocoding = None
        self.action_quick_geocoding = None
        self.toolbar = None

        mw = self.iface.mainWindow()
        PluginSettings.set_dock_area(mw.dockWidgetArea(self.__quick_tlb))
        PluginSettings.set_dock_floating(self.__quick_tlb.isFloating())
        PluginSettings.set_dock_pos(self.__quick_tlb.pos())
        PluginSettings.set_dock_size(self.__quick_tlb.size())
        PluginSettings.set_dock_visibility(self.__quick_tlb.isVisible())
        PluginSettings.set_dock_geocoder_name(
            self.__quick_tlb.get_active_geocoder_name())

        self.iface.removeDockWidget(self.__quick_tlb)
        del self.__quick_tlb

    def run_convert(self):
        if not self.__converter_dlg.isVisible():
            self.__converter_dlg = ConverterDialog()
            self.__converter_dlg.show()
            self.__converter_dlg.exec_()

    def run_batch(self):
        if not self.__geocoder_dlg.isVisible():
            self.__geocoder_dlg = BatchGeocodingDialog()
            self.__geocoder_dlg.show()
            self.__geocoder_dlg.exec_()
예제 #14
0
 def run_convert(self):
     if not self.__converter_dlg.isVisible():
         self.__converter_dlg = ConverterDialog()
         self.__converter_dlg.show()
         self.__converter_dlg.exec_()
예제 #15
0
class iSimGis:

    def __init__(self, iface):
        # Save reference to the QGIS interface
        self.iface = iface
        # reference to map canvas
        self.canvas = self.iface.mapCanvas() 
        # this QGIS tool emits as QgsPoint after each click on the map canvas
        self.clickTool = QgsMapToolEmitPoint(self.canvas)
        # create a pan tool
        self.toolPan = QgsMapToolPan(self.canvas)
        #comverter dialog
        self.converterdlg = None
        # initialize plugin directory
        self.plugin_dir = path.dirname(__file__)
        # initialize locale
        locale = QSettings().value("locale/userLocale")[0:2]
        localePath = path.join(self.plugin_dir, 'i18n', 'isimgis_{}.qm'.format(locale))
        if path.exists(localePath):
            self.translator = QTranslator()
            self.translator.load(localePath)
            if qVersion() > '4.3.3':
                QCoreApplication.installTranslator(self.translator)
        QSettings().setValue( "/Projections/defaultBehaviour", "useGlobal" )
        # crs
        self.crs = QgsCoordinateReferenceSystem(3168)

    def initGui(self):

        self.new_action = QAction(
            QIcon(":/plugins/isimgis/icons/notepad-icon.png"),
            u"create an empty shapefile directory", self.iface.mainWindow())

        self.open_action = QAction(
            QIcon(":/plugins/isimgis/icons/open.png"),
            u"open iSim shapefile directory", self.iface.mainWindow())

        self.converter_action = QAction(
            QIcon(":/plugins/isimgis/icons/converter.png"),
            u"iSim converter", self.iface.mainWindow())

        self.add_action = QAction(
            QIcon(":/plugins/isimgis/icons/add.png"),
            u"add features to current active layer.", self.iface.mainWindow())

        self.delete_action = QAction(
            QIcon(":/plugins/isimgis/icons/delete.png"),
            u"delete features from current active layer.", self.iface.mainWindow())

        # connect the action to the run method
        self.new_action.triggered.connect(self.new)
        self.open_action.triggered.connect(self.open)
        self.converter_action.triggered.connect(self.converter)
        self.add_action.triggered.connect(self.addFeature)
        self.delete_action.triggered.connect(self.deleteFeature)

        # Add toolbar button and menu item
        self.iface.addToolBarIcon(self.new_action)
        self.iface.addToolBarIcon(self.open_action)
        self.iface.addToolBarIcon(self.converter_action)
        self.iface.addToolBarIcon(self.add_action)
        self.iface.addToolBarIcon(self.delete_action)
        self.iface.addPluginToMenu(u"&iSimGis", self.new_action)
        self.iface.addPluginToMenu(u"&iSimGis", self.open_action)
        self.iface.addPluginToMenu(u"&iSimGis", self.converter_action)
        self.iface.addPluginToMenu(u"&iSimGis", self.add_action)
        self.iface.addPluginToMenu(u"&iSimGis", self.delete_action)

        self.clickTool.canvasClicked.connect(self.addNewFeature)

    def unload(self):
        # Remove the plugin menu item and icon
        self.iface.removePluginMenu(u"&iSimGis", self.open_action)
        self.iface.removePluginMenu(u"&iSimGis", self.converter_action)
        self.iface.removePluginMenu(u"&iSimGis", self.add_action)
        self.iface.removeToolBarIcon(self.open_action)
        self.iface.removeToolBarIcon(self.converter_action)
        self.iface.removeToolBarIcon(self.add_action)

    def new(self):
        sh_dir = QFileDialog.getExistingDirectory(None, 'Create new iSim Shapefile Directory', getenv('HOME'))
        if sh_dir == "":
            return
        prefix = path.basename(sh_dir)

        # find the template
        current_full_path = path.realpath(__file__)
        current_dir, current_file = path.split(current_full_path)
        template_dir = path.join(current_dir, "template")

        xml_path = path.join(template_dir, "template.xml")
        xmlToShapefile = XmlToShapefile(xml_path, sh_dir, ["x", "y"])
        xmlToShapefile.run()

        # open layer
        self.open(sh_dir)


    def open(self, sh_dir):
        if isinstance(sh_dir, bool) or sh_dir == "":
            sh_dir = QFileDialog.getExistingDirectory(None, 'Open iSim Shapefile Directory', getenv('HOME'))
            if sh_dir == "":
                return
        for filenames in listdir(sh_dir):
            full_path = path.join(sh_dir, filenames)
            names = filenames.split(".")
            if path.isfile(full_path) and names[1] == "shp":
                layer = QgsVectorLayer(full_path, names[0], "ogr")
                if layer.isValid():
                    layer.setCrs(self.crs)
                    QgsMapLayerRegistry.instance().addMapLayer(layer)

    # open convert dialog
    def converter(self):
        if self.converterdlg is not None:
            self.converterdlg.raise_()
            self.converterdlg.activateWindow()
            return
        self.converterdlg = ConverterDialog()
        self.converterdlg.open_sig.connect(self.open)
        self.converterdlg.show()
        # Run the dialog event loop
        self.converterdlg.exec_()
        self.converterdlg = None

    #return isValid, sh_dir, layer_name 
    def checkActiveLayerInfo(self):
        active_layer = self.iface.activeLayer()
        if active_layer is None:
            return False, "", ""
        uri = active_layer.dataProvider().dataSourceUri()
        sh_dir = path.dirname(uri)
        layer_name = path.basename(uri).split(".")[0]
        data_file = path.join(sh_dir, "data.xml")
        if path.isfile(data_file):
            return True, sh_dir, layer_name
        else:
            return False, sh_dir, layer_name

    def addFeature(self):
        # make our clickTool the tool that we'll use for now
        self.canvas.setMapTool(self.clickTool)
        isValidLayer, sh_dir, layer_name = self.checkActiveLayerInfo()
        if not isValidLayer:
            QMessageBox.critical(self.iface.mainWindow(),"iSim Error", "There is no active layer or the active layer is not iSim shapefile layer.")
            return

        '''
        #self.iface.messageBar().pushMessage("Info", "there is no active layer, so you can not add any feature!", level=QgsMessageBar.CRITICAL)
        uri = active_layer.dataProvider().dataSourceUri()
        sh_dir = path.dirname(uri)
        filename = path.basename(uri).split(".")[0]
        data_file = path.join(sh_dir, "data.xml")
        if path.isfile(data_file):
            QgsMessageLog.logMessage("find data file data.xml - %s" % filename)
        else:
            QgsMessageLog.logMessage("can not file data.xml")
        '''
        return

    def addNewFeature(self, point, button):
        QMessageBox.information(self.iface.mainWindow(),"Info", "X,Y = %s,%s" % (str(point.x()),str(point.y())))
        self.canvas.setMapTool(self.toolPan)

    def deleteFeature(self):
        # verify the current layer
        isValidLayer, sh_dir, active_layer_name = self.checkActiveLayerInfo()
        if not isValidLayer:
            QMessageBox.critical(self.iface.mainWindow(),"iSim Error", "The active layer is not iSim shapefile layer.")
            return

        # make sure there is a selected feature
        active_layer = self.iface.activeLayer()
        selected_features = active_layer.selectedFeatures()
        if len(selected_features) == 0:
            QMessageBox.critical(self.iface.mainWindow(),"iSim Error", "No feature is selected.")
            return

        # confirm message
        reply = QMessageBox.question(self.iface.mainWindow(), "Are you sure?", "Are you sure to delete the selected features ? It is NOT possible to undo this action.", 
            QMessageBox.Yes | QMessageBox.No, QMessageBox.No);
        if reply == QMessageBox.No:
            return

        handler = ActionHandler(sh_dir, self.canvas)
        # remove data dependency
        handler.delete(selected_features)
        handler.save()
            
        self.canvas.refresh()