Esempio n. 1
0
 def openSettings(self):
     """Open settings dialog and reload settings"""
     settingsDialog = SettingsDialog(self.settings)
     settingsDialog.exec_()
     if self.settings["theme"] == "dark":
         self.dark_theme = True
         self.darkstyle = self.genDarkStyle()
         self.style = self.darkstyle
     else:
         self.dark_theme = False
         self.style = self.def_style
     #self.app.setStyleSheet("")
     self.app.setStyleSheet(self.style)
     self.resizeElements()
    def settings(self):
        oldMoveToLayer = QSettings().value("/TileLayerPlugin/moveToLayer",
                                           0,
                                           type=int)

        from settingsdialog import SettingsDialog
        dialog = SettingsDialog(self.iface)
        accepted = dialog.exec_()
        if not accepted:
            return False
        self.downloadTimeout = dialog.ui.spinBox_downloadTimeout.value()
        self.navigationMessagesEnabled = dialog.ui.checkBox_NavigationMessages.checkState(
        )

        moveToLayer = dialog.ui.checkBox_MoveToLayer.checkState()
        if moveToLayer != oldMoveToLayer:
            if oldMoveToLayer:
                self.iface.layerToolBar().removeAction(self.action)
                self.iface.removeAddLayerAction(self.action)
            else:
                self.iface.removePluginWebMenu(self.pluginName, self.action)

            if moveToLayer:
                self.iface.insertAddLayerAction(self.action)
                self.iface.layerToolBar().addAction(self.action)
            else:
                self.iface.addPluginToWebMenu(self.pluginName, self.action)
        return True
Esempio n. 3
0
 def setting(self):
     from settingsdialog import SettingsDialog
     dialog = SettingsDialog(self.iface.mainWindow())
     dialog.show()
     if dialog.exec_():
         from pluginmanager import PluginManager
         self.pluginManager = PluginManager()
Esempio n. 4
0
    def settings(self):
      oldMoveToLayer = QSettings().value("/TileLayerPlugin/moveToLayer", 0, type=int)

      from settingsdialog import SettingsDialog
      dialog = SettingsDialog(self.iface)
      accepted = dialog.exec_()
      if not accepted:
        return False
      self.downloadTimeout = dialog.ui.spinBox_downloadTimeout.value()
      self.navigationMessagesEnabled = dialog.ui.checkBox_NavigationMessages.checkState()

      moveToLayer = dialog.ui.checkBox_MoveToLayer.checkState()
      if moveToLayer != oldMoveToLayer:
        if oldMoveToLayer:
          self.iface.layerToolBar().removeAction(self.action)
          self.iface.removeAddLayerAction(self.action)
        else:
          self.iface.removePluginWebMenu(self.pluginName, self.action)

        if moveToLayer:
          self.iface.insertAddLayerAction(self.action)
          self.iface.layerToolBar().addAction(self.action)
        else:
          self.iface.addPluginToWebMenu(self.pluginName, self.action)
      return True
    def pluginSettings(self):
        from settingsdialog import SettingsDialog

        dialog = SettingsDialog(self)
        if dialog.exec_():
            self.pluginManager.reloadPlugins()
            self.pages[ppages.PAGE_DEM].initLayerComboBox()
Esempio n. 6
0
 def setting(self):
   from settingsdialog import SettingsDialog
   dialog = SettingsDialog(self.iface.mainWindow())
   dialog.show()
   if dialog.exec_():
     from pluginmanager import PluginManager
     self.pluginManager = PluginManager()
Esempio n. 7
0
 def settings(self):
     from settingsdialog import SettingsDialog
     dialog = SettingsDialog(self.iface)
     dialog.show()
     accepted = dialog.exec_()
     if accepted:
         self.downloadTimeout = dialog.ui.spinBox_downloadTimeout.value()
         self.navigationMessagesEnabled = dialog.ui.checkBox_NavigationMessages.checkState(
         )
Esempio n. 8
0
    def settings_button_clicked(self):
        s = SettingsDialog(self)

        ret = s.exec_()

        if ret == 1:
            Settings.save(s.settings)

            self.settings = Settings.read()

            self.refresh_shortcuts()
Esempio n. 9
0
    def settings_button_clicked(self):
        s = SettingsDialog(self)
        
        ret = s.exec_()
    
        if ret == 1:
            Settings.save(s.settings)

            self.settings = Settings.read()
            
            self.refresh_shortcuts()
Esempio n. 10
0
 def on_actionConfigure_triggered(self):
     dialog = SettingsDialog(self.programSettings, self)
     dialog.exec_()
Esempio n. 11
0
 def openSettings(self):
     """Open settings dialog and reload settings"""
     settingsDialog = SettingsDialog(self.settings)
     settingsDialog.exec_()
Esempio n. 12
0
class MainWindow(QtGui.QMainWindow, Ui_MainWindow):
    """Main Window for MOOSE GUI"""
    def __init__(self, loadFile=None, fileType=None):
	QtGui.QMainWindow.__init__(self)
	self.setupUi(self)
        self.setWindowIcon(QtGui.QIcon(':moose_thumbnail.png'))
        self.settingsDialog = SettingsDialog()
        self.settingsDialog.hide()
        layout = QtGui.QVBoxLayout(self.modelTreeTab)
        self.modelTreeTab.setLayout(layout)
        layout.addWidget(self.modelTreeContainerWidget)
        self.modelTreeWidget.headerItem().setHidden(True)
        self.plotUpdateIntervalLabel.setText(self.tr('<br>Plot update interval (<b>steps</b>)'))
        self.runTimeLabel.setText(self.tr('<br>Run for (<b>seconds</b>)'))
#         self.modelTreeWidget.show()
#         self.mooseClassToolBox.show()
###################
#         self.plotsLayout = QtGui.QHBoxLayout(self.plotsGroupBox)
#         self.plotsGroupBox.setLayout(self.plotsLayout)
#         self.plotsScrollArea = QtGui.QScrollArea(self.plotsGroupBox)
#         self.plotsLayout.addWidget(self.plotsScrollArea)
#         self.plots = MoosePlots(self.plotsScrollArea)
#         self.plotsScrollArea.setWidget(self.plots)
#         self.plots.show()
##################
        self.plots = MoosePlots(self.plotsGroupBox)
        self.plotsLayout = QtGui.QHBoxLayout(self.plotsGroupBox)
        self.plotsGroupBox.setLayout(self.plotsLayout)
        self.plotsLayout.addWidget(self.plots)
        
######################
        self.plots.show()
        self.isModelLoaded = False
        self.stopFlag = False
	self.mooseHandler = MHandler()
        self.runTimeLineEdit.setText(self.tr(str(self.mooseHandler.runTime)))
        self.plotUpdateIntervalLineEdit.setText(self.tr(str(self.mooseHandler.updateInterval)))
	self.currentDirectory = '.'
	self.fileType = fileType
	self.fileTypes = MHandler.file_types
	self.filter = ''
	self.setupActions()
        if loadFile is not None and fileType is not None:
            self.load(loadFile, fileType)


    def setupActions(self):
	self.connect(self.actionQuit,
		     QtCore.SIGNAL('triggered()'), 
		     QtGui.qApp, 
		     QtCore.SLOT('closeAllWindows()'))		     
	self.connect(self.actionLoad, 
		     QtCore.SIGNAL('triggered()'),		   
		     self.loadFileDialog)
	self.connect(self.actionSquid_Axon,
		     QtCore.SIGNAL('triggered()'),
		     self.loadSquid_Axon_Tutorial)
	self.connect(self.actionIzhikevich_Neurons,
		     QtCore.SIGNAL('triggered()'),
		     self.loadIzhikevich_Neurons_Tutorial)
        self.connect(self.actionGLCell,
                     QtCore.SIGNAL('triggered()'),
                     self.loadGLCellDemo)
        self.connect(self.actionGLView,
                     QtCore.SIGNAL('triggered()'),
                     self.loadGLViewDemo)
	self.connect(self.actionAbout_MOOSE,
		     QtCore.SIGNAL('triggered()'),
		     self.showAbout_MOOSE)
	self.connect(self.actionReset,
		     QtCore.SIGNAL('triggered()'),
		     self.reset)
	self.connect(self.actionStart,
		     QtCore.SIGNAL('triggered()'),
		     self.run)
        self.connect(self.actionStop,
                     QtCore.SIGNAL('triggered()'),
                     self.stop)
        self.connect(self.runPushButton,
                     QtCore.SIGNAL('clicked()'),
                     self.run)
        self.connect(self.resetPushButton,
                     QtCore.SIGNAL('clicked()'),
                     self.reset)
#         self.connect(self.stopPushButton,
#                      QtCore.SIGNAL('clicked()'),
#                      self.mooseHandler.stop)
        self.connect(self.plotUpdateIntervalLineEdit,
                     QtCore.SIGNAL('editingFinished()'),
                     self.plotUpdateIntervalSlot)
        self.connect(self.modelTreeWidget, 
                     QtCore.SIGNAL('itemDoubleClicked(QTreeWidgetItem *, int)'),
                     self.popupPropertyEditor)
        self.connect(self.mooseHandler, 
                     QtCore.SIGNAL('updated()'), 
                     self.updatePlots)
        self.connect(self.runTimeLineEdit, 
                     QtCore.SIGNAL('editingFinished()'),
                     self.runTimeSlot)
        self.connect(self.rescalePlotsPushButton,
                     QtCore.SIGNAL('clicked()'),
                     self.plots.rescalePlots)

        self.connect(self.actionSettings,
                     QtCore.SIGNAL('triggered()'),
                     self.popupSettings)
        for listWidget in self.mooseClassToolBox.listWidgets:
            self.connect(listWidget, 
                         QtCore.SIGNAL('itemDoubleClicked(QListWidgetItem*)'), 
                         self.insertMooseObjectSlot)
        

    def popupPropertyEditor(self, item, column):
        """Pop-up a property editor to edit the Moose object in the item"""
        obj = item.getMooseObject()
        self.propertyModel = PropertyModel(obj)
        self.connect(self.propertyModel, 
                     QtCore.SIGNAL('objectNameChanged(const QString&)'),
                     item.updateSlot)
        self.propertyEditor = QtGui.QTableView()
        self.propertyEditor.setModel(self.propertyModel)
        self.propertyEditor.setContextMenuPolicy(Qt.CustomContextMenu)
        self.connect(self.propertyEditor, QtCore.SIGNAL('customContextMenuRequested ( const QPoint&)'), self.popupFieldMenu)
        self.propertyEditor.show()

    def loadFileDialog(self):
	fileDialog = QtGui.QFileDialog(self)
	fileDialog.setFileMode(QtGui.QFileDialog.ExistingFile)
	ffilter = ''
	for key in self.fileTypes.keys():
	    ffilter = ffilter + key + ';;'
	ffilter = ffilter[:-2]
	fileDialog.setFilter(self.tr(ffilter))
        # The following version gymnastic is because QFileDialog.selectNameFilter() was introduced in Qt 4.4
        qtVersion = str(QtCore.QT_VERSION_STR).split('.')
        major = int(qtVersion[0])
        minor = int(qtVersion[1])
        if (major > 4)or ((major == 4) and (minor >= 4)):
            for key, value in self.fileTypes.items():
                if value == FileTypeChecker.type_genesis:
                    fileDialog.selectNameFilter(key)
                    break
	if fileDialog.exec_():
	    fileNames = fileDialog.selectedFiles()
	    fileFilter = fileDialog.selectedFilter()
	    fileType = self.fileTypes[str(fileFilter)]
# 	    print 'file type:', fileType
	    directory = fileDialog.directory() # Potential bug: if user types the whole file path, does it work? - no but gives error message
	    for fileName in fileNames: 
# 		print fileName
		self.load(fileName, fileType)


    def loadIzhikevich_Neurons_Tutorial(self):
#     self.mooseHandler.load('../../DEMOS/pymoose/izhikevich/Izhikevich.py', 'MOOSE')
        spath = sys.path[0] + '/../../DEMOS/pymoose/izhikevich/demogui_qt.py'
        self.mooseHandler.load(spath, 'MOOSE')
        
    def loadGLCellDemo(self):
        spath = sys.path[0] + '/demo/glcelldemo.py'
        self.mooseHandler.load(spath, 'MOOSE')

    def loadGLViewDemo(self):
        spath = sys.path[0] + '/demo/glviewdemo.py'
        self.mooseHandler.load(spath, 'MOOSE')
        


    def loadSquid_Axon_Tutorial(self):
#     self.mooseHandler.load('../../DEMOS/pymoose/squid/qtSquid.py', 'MOOSE')
       spath = sys.path[0] + '/../../DEMOS/pymoose/squid/qtSquid.py'
       self.mooseHandler.load(spath, 'MOOSE')
       
	


    def showAbout_MOOSE(self):
	about = QtCore.QT_TR_NOOP('<p>MOOSE is the Multi-scale Object Oriented Simulation Environment.</p>'
				  '<p>It is a general purpose simulation environment for computational neuroscience and chemical kinetics.</p>'
				  '<p>Copyright (C) 2003-2009 Upinder S. Bhalla. and NCBS</p>'
				  '<p>It is made available under the terms of the GNU Lesser General Public License version 2.1. See the file COPYING.LIB for the full notice.</p>'
                  '<p>homepage: <a href="http://moose.ncbs.res.in">http://moose.ncbs.res.in</a></p>')
	aboutDialog = QtGui.QMessageBox.information(self, self.tr('About MOOSE'), about)

    def plotUpdateIntervalSlot(self):
        try:
            new_interval = int(str(self.plotUpdateIntervalLineEdit.text()))
            self.plotUpdateInterval = new_interval
        except ValueError:
            print 'Update steps must be whole number.'
            self.plotUpdateIntervalLineEdit.setText(self.tr(str(self.plotUpdateInterval)))
    
    def runTimeSlot(self):
        try:
            runtime = float(str(self.runTimeLineEdit.text()))
            self.mooseHandler.runTime = runtime
        except ValueError:
            print 'Error in converting runtime to float'
            self.runTimeLineEdit.setText(self.tr(str(self.mooseHandler.updateInterval)))
        
            
    def run(self):
        #print 'Going to run'
        if not self.isModelLoaded:
            errorDialog = QtGui.QErrorMessage(self)
            errorDialog.setModal(True)
            errorDialog.showMessage('<p>You must load a model first.</p>')
            return
        # The run for update interval and replot data until the full runtime has been executed
        # But this too is unresponsive
        self.mooseHandler.run()

    def updatePlots(self):        
        """Update the plots"""
        if self.plots is not None:
            self.plots.updatePlots(self.mooseHandler)
            self.update()
        self.currentTimeLabel.setText(self.tr('Current time (seconds): %g' %  self.mooseHandler.currentTime()))

    def reset(self):
        if not self.isModelLoaded:
            QtGui.QErrorMessage.showMessage('<p>You must load a model first.</p>')
        else:
            self.mooseHandler.reset()
            self.plots.resetPlots()
        self.currentTimeLabel.setText(self.tr('Current time (seconds): %g' % self.mooseHandler.currentTime()))
                
    
    def load(self, fileName, fileType):
 #      if self.isModelLoaded:            
#            import subprocess
#            subprocess.call(['python', 'main.py', fileName, fileType])
        fileType = FileTypeChecker(str(fileName)).fileType()
        print 'File is of type:', fileType
        self.mooseHandler.context.setCwe(self.modelTreeWidget.currentItem().getMooseObject().path)
        self.mooseHandler.load(fileName, fileType)
        self.isModelLoaded = True
        self.modelTreeWidget.recreateTree()
        if fileType is FileTypeChecker.type_sbml:
            self.moleculeListWidget = QtGui.QListWidget(self)
            self.moleculeItems = []
            for molecule in self.mooseHandler.moleculeList:
                item = QtGui.QListWidgetItem(self.moleculeListWidget)
                item.setText(molecule.name)
                item.setData(QtCore.Qt.UserRole, QtCore.QVariant(self.tr(molecule.path)))
                self.moleculeItems.append(item)
            self.simulationWidget.layout().addWidget(self.moleculeListWidget)
            self.connect(self.moleculeListWidget, 
                         QtCore.SIGNAL('itemDoubleClicked(QListWidgetItem*)'),
                         self.addMoleculeInPlot)
            
            self.moleculeListWidget.show()

        self.plots.loadPlots(self.mooseHandler, fileType)
        self.currentTimeLabel.setText(self.tr('Current time (seonds): %g' % self.mooseHandler.currentTime()))
#         self.update()

    def addMoleculeInPlot(self, item):
        self.mooseHandler.createTableForMolecule(str(item.text()))
        self.plots.loadPlots(self.mooseHandler, FileTypeChecker.type_sbml)
        self.plots.setVisible(True)
        self.modelTreeWidget.recreateTree()
        self.update()

    # Until MOOSE has a way of getting stop command from outside
    def stop(self):
        self.mooseHandler.stop()

    def insertMooseObjectSlot(self, item):
        self.modelTreeWidget.insertMooseObjectSlot(item.text())

    def popupSettings(self):
        self.settingsDialog.show()
        result = self.settingsDialog.exec_()
        if result == self.settingsDialog.Accepted:
            self.mooseHandler.addSimPathList(self.settingsDialog.simPathList())

    def popupFieldMenu(self, clickpoint):
        print 'PopupFieldMenu'
        index = self.propertyEditor.indexAt(clickpoint)
        data = self.propertyModel.data(self.propertyModel.createIndex(index.row(), 0))
        print data
        menu = QtGui.QMenu(self.propertyEditor)
        self.actionPlotField = menu.addAction('Plot this field')
        self.connect(self.actionPlotField, QtCore.SIGNAL('triggered()'), self.plotThisFieldSlot)
        menu.popup(clickpoint)

    def plotThisFieldSlot(self):
        print 'plotThisFieldSlot'
        moose_object = self.modelTreeWidget.currentItem().getMooseObject()
        row = self.propertyEditor.currentIndex().row()
        index = self.propertyModel.createIndex(row, 0)
        print index.row(), index.column()
        field_name = self.propertyModel.data(index)        
        table = self.mooseHandler.createTableForMolecule(moose_object, field_name)
        print table.path
Esempio n. 13
0
 def setting(self):
   from settingsdialog import SettingsDialog
   dialog = SettingsDialog(self.iface)
   dialog.show()
   dialog.exec_()
Esempio n. 14
0
 def openSettings(self):
     """Open settings dialog and reload settings"""
     settingsDialog = SettingsDialog(self.settings)
     settingsDialog.exec_()
Esempio n. 15
0
class GVDigitizingTools:
    def __init__(self, iface):
        self.iface = iface
        self.plugin_dir = os.path.dirname(__file__)

        self.dlgSettings = SettingsDialog()

        self.digitizingSetup = DigitizingSetup(self.iface)
        self.currentMode = None
        self.currentLayer = None
        self.isBackgroundSnapping = False

        self.initSettings()

    def initSettings(self):
        # set default if first time this ie executed
        settings = QSettings()
        method = settings.value(constants.ARC_METHOD,
                                constants.ARC_METHOD_ANGLE)
        settings.setValue(constants.ARC_METHOD, method)
        angle = settings.value(constants.ARC_ANGLE, 3.0, type=float)
        settings.setValue(constants.ARC_ANGLE, angle)
        numberOfPoints = settings.value(constants.ARC_NUMBEROFPOINTS,
                                        10,
                                        type=int)
        settings.setValue(constants.ARC_NUMBEROFPOINTS, numberOfPoints)

        enablePreview = settings.value(constants.PREVIEW_ENABLED, True)
        settings.setValue(constants.PREVIEW_ENABLED, enablePreview)
        enablePreviewLimit = settings.value(constants.PREVIEW_LIMIT_ENABLED,
                                            False)
        settings.setValue(constants.PREVIEW_LIMIT_ENABLED, enablePreviewLimit)
        maxLimitPreview = settings.value(constants.PREVIEW_LIMIT_MAX, 1000)
        settings.setValue(constants.PREVIEW_LIMIT_MAX, maxLimitPreview)

    def initGui(self):
        self.actions = []
        self.createAction("actionSettings",
                          "icons/iconSettings.png",
                          u"Settings",
                          self.doShowSettings,
                          checkable=False)
        self.createAction("action", "icon.png", u"Digitizing tools",
                          self.doSetupDigitizing)
        self.createAction("actionBackgroundSnapping", "icons/iconSnap.png",
                          u"Snap to background layers",
                          self.doSetupBackgroundSnapping)

        self.createAction("actionDrawArc", "icons/iconDrawArc.png", u"Add arc",
                          self.doDrawArc, "Alt+Ctrl+S")
        self.createAction("actionExtend", "icons/iconExtend.png", u"Extend",
                          self.doExtend, "Alt+Ctrl+E")
        self.createAction("actionFillet", "icons/iconFillet.png", u"Fillet",
                          self.doFillet, "Alt+Ctrl+F")
        self.createAction("actionTrim", "icons/iconTrim.png", u"Trim",
                          self.doTrim, "Alt+Ctrl+C")
        self.createAction("actionMirror", "icons/iconMirror.png", u"Mirror",
                          self.doMirror, "Alt+Ctrl+W")
        self.createAction("actionScale", "icons/iconScale.png", u"Scale",
                          self.doScale, "Alt+Ctrl+Z")
        self.createAction("actionMove", "icons/iconMove.png", u"Move",
                          self.doMove, "Alt+Ctrl+D")
        self.createAction("actionCopy", "icons/iconCopy.png", u"Copy",
                          self.doCopy, "Alt+Ctrl+X")
        self.createAction("actionMoveMultipleLayers",
                          "icons/iconMoveMultipleLayers.png",
                          u"Move from multiple layers",
                          self.doMoveMultipleLayers, "Alt+Ctrl+Q")
        self.createAction("actionCopyMultipleLayers",
                          "icons/iconCopyMultipleLayers.png",
                          u"Copy from multiple layers",
                          self.doCopyMultipleLayers, "Alt+Ctrl+R")
        self.createAction("actionParallel", "icons/iconParallel.png",
                          u"Parallel", self.doParallel, "Alt+Ctrl+P")
        self.createAction("actionSplit", "icons/iconSplit.png", u"Split",
                          self.doSplit, "Alt+Ctrl+H")
        self.createAction("actionCenterline", "icons/iconCenterline.png",
                          u"Centerline", self.doCenterline, "Alt+Ctrl+J")
        self.createAction("actionCenterlineAdvanced",
                          "icons/iconCenterlineAdvanced.png",
                          u"Centerline Advanced", self.doCenterlineAdvanced,
                          "Alt+Ctrl+K")

        self.createAction("actionPolygonize",
                          "icons/iconPolygonize.png",
                          u"Polygonize",
                          self.doPolygonize,
                          checkable=False)
        self.createAction("actionIntersect",
                          "icons/iconIntersect.png",
                          u"Create node at intersections",
                          self.doIntersect,
                          checkable=False)
        self.createAction("actionExplode",
                          "icons/iconExplode.png",
                          u"Explode multipart to single parts",
                          self.doExplode,
                          checkable=False)

        # Add toolbar button and menu item
        self.iface.addPluginToMenu(u"&GV Digitizing Tools",
                                   self.actionSettings)

        self.toolbar = self.iface.addToolBar("GV Digitizing Tools")
        self.toolbar.addAction(self.action)
        self.toolbar.addAction(self.actionBackgroundSnapping)
        self.toolbar.addSeparator()
        self.addActionGroup([
            self.actionDrawArc, self.actionExtend, self.actionFillet,
            self.actionTrim, self.actionMirror, self.actionScale,
            self.actionParallel, self.actionSplit, self.actionCenterline,
            self.actionCenterlineAdvanced
        ])
        self.toolbar.addSeparator()
        self.addActionGroup([
            self.actionMove, self.actionCopy, self.actionMoveMultipleLayers,
            self.actionCopyMultipleLayers
        ])
        self.toolbar.addSeparator()
        self.addActionGroup(
            [self.actionPolygonize, self.actionIntersect, self.actionExplode])

        self.ignoreActions = set([
            self.action, self.actionSettings, self.actionBackgroundSnapping,
            self.actionMoveMultipleLayers, self.actionCopyMultipleLayers,
            self.actionMove, self.actionCopy, self.actionParallel
        ])
        self.action.setEnabled(True)
        self.actionMoveMultipleLayers.setEnabled(True)
        self.actionCopyMultipleLayers.setEnabled(True)
        self.actionParallel.setEnabled(False)
        self.actionBackgroundSnapping.setEnabled(True)

        self.extendMode = ExtendDigitizingMode(self.iface)
        self.extendMode.setAction(self.actionExtend)
        self.trimMode = TrimDigitizingMode(self.iface)
        self.trimMode.setAction(self.actionTrim)
        self.drawArcMode = DrawArcDigitizingMode(self.iface)
        self.drawArcMode.setAction(self.actionDrawArc)
        self.filletMode = FilletDigitizingMode(self.iface)
        self.filletMode.setAction(self.actionFillet)
        self.mirrorMode = MirrorDigitizingMode(self.iface, self)
        self.mirrorMode.setAction(self.actionMirror)
        self.scaleMode = ScaleDigitizingMode(self.iface, self)
        self.scaleMode.setAction(self.actionScale)
        self.moveMode = MoveDigitizingMode(self.iface, self)
        self.moveMode.setAction(self.actionMove)
        self.copyMode = CopyDigitizingMode(self.iface, self)
        self.copyMode.setAction(self.actionCopy)
        self.moveMultipleLayersMode = MoveMultipleLayersDigitizingMode(
            self.iface, self)
        self.moveMultipleLayersMode.setAction(self.actionMoveMultipleLayers)
        self.copyMultipleLayersMode = CopyMultipleLayersDigitizingMode(
            self.iface, self)
        self.copyMultipleLayersMode.setAction(self.actionCopyMultipleLayers)
        self.parallelConstraintMode = ParallelConstraintMode(self.iface)
        self.parallelConstraintMode.setAction(self.actionParallel)
        self.splitMode = SplitDigitizingMode(self.iface)
        self.splitMode.setAction(self.actionSplit)
        self.centerlineMode = CenterlineDigitizingMode(self.iface)
        self.centerlineMode.setAction(self.actionCenterline)
        self.centerlineAdvancedMode = CenterlineAdvancedDigitizingMode(
            self.iface)
        self.centerlineAdvancedMode.setAction(self.actionCenterlineAdvanced)

        self.explodeCommand = ExplodeCommand(self.iface)
        self.polygonizeCommand = PolygonizeCommand(self.iface)
        self.intersectCommand = IntersectCommand(self.iface)

        self.cadPointList = CadPointList(self.checkIsParallelEnabled)
        self.eventFilter = ConstraintEventFilter(self.iface, self,
                                                 self.cadPointList)
        # to track the mouse for mouseMoveEvents to happen
        self.iface.mapCanvas().viewport().setMouseTracking(True)
        # to get the mouse events
        self.iface.mapCanvas().viewport().installEventFilter(self.eventFilter)

        self.iface.legendInterface().currentLayerChanged.connect(
            self.currentLayerChanged)
        self.currentLayer = self.iface.legendInterface().currentLayer()
        if self.currentLayer and self.currentLayer.type(
        ) == QgsMapLayer.VectorLayer:
            self.currentLayer.editingStopped.connect(self.editingStopped)
            self.currentLayer.editingStarted.connect(self.editingStarted)
            self.currentLayer.selectionChanged.connect(self.selectionChanged)
        self.iface.mapCanvas().mapToolSet.connect(self.maptoolChanged)

        self.maptoolChanged()
        self.checkCurrentLayerIsEditableLineLayer()
        self.checkIsMoveOrCopyEnabled()
        self.checkIsParallelEnabled()

    def unload(self):
        # Remove the plugin menu item and icon
        self.iface.removePluginMenu(u"&GV Digitizing Tools",
                                    self.actionSettings)

        self.iface.legendInterface().currentLayerChanged.disconnect(
            self.currentLayerChanged)
        self.currentLayer = self.iface.legendInterface().currentLayer()
        if self.currentLayer:
            try:
                self.currentLayer.editingStarted.disconnect(
                    self.editingStarted)
            except Exception:
                pass
            try:
                self.currentLayer.editingStopped.disconnect(
                    self.editingStopped)
            except Exception:
                pass
            try:
                self.currentLayer.selectionChanged.disconnect(
                    self.selectionChanged)
            except:
                pass
        self.iface.mapCanvas().mapToolSet.disconnect(self.maptoolChanged)

        self.iface.mapCanvas().viewport().setMouseTracking(False)
        self.eventFilter.close()
        self.iface.mapCanvas().viewport().removeEventFilter(self.eventFilter)

        del self.toolbar

    def createAction(self,
                     name,
                     icon,
                     tip,
                     callback,
                     shortcut=None,
                     checkable=True):

        action = QAction(QIcon(":/plugins/gvdigitizingtools/" + icon), tip,
                         self.iface.mainWindow())
        # connect the action to the run method
        action.triggered.connect(callback)
        action.setCheckable(checkable)

        if shortcut:
            action.setShortcut(shortcut)

        self.__dict__[name] = action
        self.actions.append(action)

    def addActionGroup(self, actions):
        for action in actions:
            self.toolbar.addAction(action)

    def currentLayerChanged(self):
        # first cleanup events for previous layer
        if self.currentLayer:
            try:
                self.currentLayer.editingStarted.disconnect(
                    self.editingStarted)
            except Exception:
                pass
            try:
                self.currentLayer.editingStopped.disconnect(
                    self.editingStopped)
            except Exception:
                pass
            try:
                self.currentLayer.selectionChanged.disconnect(
                    self.selectionChanged)
            except:
                pass
        self.currentLayer = self.iface.legendInterface().currentLayer()
        if self.currentLayer and self.currentLayer.type(
        ) == QgsMapLayer.VectorLayer:
            self.currentLayer.editingStopped.connect(self.editingStopped)
            self.currentLayer.editingStarted.connect(self.editingStarted)
            self.currentLayer.selectionChanged.connect(self.selectionChanged)

        self.checkCurrentLayerIsEditableLineLayer()
        self.checkIsParallelEnabled()

        # selectedLayers not yet updated and no event for this (have to use
        # currentLAyer change event)
        # get stuck when going from multiple to one selection
        QTimer.singleShot(1, self.checkIsMoveOrCopyEnabled)

    def editingStarted(self):
        self.checkCurrentLayerIsEditableLineLayer()
        self.checkIsParallelEnabled()
        self.checkIsMoveOrCopyEnabled()

    def editingStopped(self):
        self.checkCurrentLayerIsEditableLineLayer()
        self.checkIsParallelEnabled()
        self.checkIsMoveOrCopyEnabled()

    def selectionChanged(self):
        self.checkIsMoveOrCopyEnabled()

    def maptoolChanged(self):
        self.parallelConstraintMode.isRelevant = (
            self.iface.mapCanvas().mapTool() is not None
            and self.iface.mapCanvas().mapTool().isEditTool())

    def checkCurrentLayerIsEditableLineLayer(self):
        if self.currentLayer and self.currentLayer.type(
        ) == QgsMapLayer.VectorLayer and self.currentLayer.geometryType(
        ) == QGis.Line and self.currentLayer.isEditable():
            for action in self.actions:
                # special processing for some actions (irrelevant or some custom processing)
                if action not in self.ignoreActions:
                    action.setEnabled(True)

            if self.currentMode and self.currentMode != self.moveMultipleLayersMode:
                self.currentMode.reset()
                self.currentMode.setLayer(self.currentLayer)

        else:
            for action in self.actions:
                if action not in self.ignoreActions:
                    action.setEnabled(False)

            if self.currentMode and self.currentMode != self.moveMultipleLayersMode:
                self.currentMode.reset()
                self.iface.mapCanvas().unsetMapTool(self.currentMode)
                self.currentMode = None

    def checkIsParallelEnabled(self):
        if (self.currentLayer
                and self.currentLayer.type() == QgsMapLayer.VectorLayer
                and self.currentLayer.geometryType() == QGis.Line
                and self.currentLayer.isEditable()
                and len(self.cadPointList) > 1
                and self.digitizingSetup.enableEventFilter):
            self.actionParallel.setEnabled(True)
        else:
            self.actionParallel.setEnabled(False)

    def checkIsMoveOrCopyEnabled(self):
        """
        Any type of geometry
        For Multiple... modes, no need to be editable but needs to have selection
        """
        layers = self.iface.legendInterface().selectedLayers()
        isSingleEnabled = False
        isMultipleEnabled = False
        for layer in layers:
            if layer.type() == QgsMapLayer.VectorLayer:
                if layer.isEditable():
                    self.actionMove.setEnabled(True)
                    self.actionCopy.setEnabled(True)
                    isSingleEnabled = True
                if layer.selectedFeatureCount() > 0:
                    self.actionMoveMultipleLayers.setEnabled(True)
                    self.actionCopyMultipleLayers.setEnabled(True)
                    isMultipleEnabled = True
                    break

        if not isSingleEnabled:
            self.moveMode.reset()
            self.copyMode.reset()
            self.actionMove.setChecked(False)
            self.actionMove.setEnabled(False)
            self.actionCopy.setChecked(False)
            self.actionCopy.setEnabled(False)

        if not isMultipleEnabled:
            self.moveMultipleLayersMode.reset()
            self.copyMultipleLayersMode.reset()
            self.actionMoveMultipleLayers.setChecked(False)
            self.actionMoveMultipleLayers.setEnabled(False)
            self.actionCopyMultipleLayers.setChecked(False)
            self.actionCopyMultipleLayers.setEnabled(False)

    def setupMode(self):
        layer = self.iface.legendInterface().currentLayer()
        self.currentMode.setLayer(layer)
        self.iface.mapCanvas().setMapTool(self.currentMode)

        self.currentMode.reset()
        self.currentMode.next()

    def doSetupDigitizing(self):
        if self.action.isChecked():
            self.digitizingSetup.activate()
            self.checkIsParallelEnabled()
        else:
            self.digitizingSetup.deactivate()
            self.checkIsParallelEnabled()

    def doSetupBackgroundSnapping(self):
        self.isBackgroundSnapping = self.actionBackgroundSnapping.isChecked()

    def doShowSettings(self):
        self.dlgSettings.clear()
        self.dlgSettings.show()
        result = self.dlgSettings.exec_()

    def doDrawArc(self):
        self.currentMode = self.drawArcMode
        self.setupMode()

    def doExtend(self):
        self.currentMode = self.extendMode
        self.setupMode()

    def doFillet(self):
        self.currentMode = self.filletMode
        self.setupMode()

    def doTrim(self):
        self.currentMode = self.trimMode
        self.setupMode()

    def doMirror(self):
        self.currentMode = self.mirrorMode
        self.setupMode()

    def doScale(self):
        self.currentMode = self.scaleMode
        self.setupMode()

    def doMove(self):
        self.currentMode = self.moveMode
        self.setupMode()

    def doCopy(self):
        self.currentMode = self.copyMode
        self.setupMode()

    def doMoveMultipleLayers(self):
        self.currentMode = self.moveMultipleLayersMode
        self.setupMode()

    def doCopyMultipleLayers(self):
        self.currentMode = self.copyMultipleLayersMode
        self.setupMode()

    def doParallel(self):
        if self.actionParallel.isChecked():
            self.parallelConstraintMode.activate()
        else:
            self.parallelConstraintMode.deactivate()

    def doSplit(self):
        self.currentMode = self.splitMode
        self.setupMode()

    def doCenterline(self):
        self.currentMode = self.centerlineMode
        self.setupMode()

    def doCenterlineAdvanced(self):
        self.currentMode = self.centerlineAdvancedMode
        self.setupMode()

    def doPolygonize(self):
        self.polygonizeCommand.run()

    def doIntersect(self):
        self.intersectCommand.run()

    def doExplode(self):
        self.explodeCommand.run()
Esempio n. 16
0
 def showSettings(self):
     dlg = SettingsDialog(self)
     dlg.exec_()
Esempio n. 17
0
 def setting(self):
     from settingsdialog import SettingsDialog
     dialog = SettingsDialog(self.iface)
     dialog.show()
     dialog.exec_()
Esempio n. 18
0
 def on_actionConfigure_triggered(self):
     dialog = SettingsDialog(self.programSettings, self)
     dialog.rowHeightChanged.connect(self.setRowHeight)
     dialog.exec_()
Esempio n. 19
0
class DateControl:
 
    def __init__(self, iface):
        # Save reference to the QGIS interface
        self.iface = iface
        # initialize plugin directory
        self.plugin_dir = os.path.dirname(__file__)
        # initialize locale
        locale = QSettings().value("locale/userLocale")[0:2]
        localePath = os.path.join(self.plugin_dir, 'i18n', 'datecontrol_{}.qm'.format(locale))
        
        self.proj = QgsProject.instance()
        UriFile = str(self.proj.fileName())
        self.Path = str(os.path.dirname(UriFile))
#        QMessageBox.warning(None, "Path",self.Path)
        self.projName = UriFile[len(self.Path)+1:]

        if os.path.exists(localePath):
            self.translator = QTranslator()
            self.translator.load(localePath)

            if qVersion() > '4.3.3':
                QCoreApplication.installTranslator(self.translator)

        # Create the dialog (after translation) and keep reference
        self.setGetSaveSettings()            
        self.dock = DateControlDock(self.iface, self.pluginSettingsDic)
 
    def initGui(self):
        # Create action that will start plugin configuration
        self.action = QAction(QIcon(":/plugins/datecontrol/DateControlControl.png"), u"Date control", self.iface.mainWindow())
        # connect the action to the run method
        self.action.triggered.connect(self.run)
        self.settingsAction = QAction(QIcon(":/plugins/datecontrol/DateControlSettings.png"), u"Settings", self.iface.mainWindow())
        self.settingsAction.triggered.connect(self.showSettings)
        self.convertDatesAction = QAction(QIcon(":/plugins/datecontrol/DateControlCheckDates.png"), u"Convert dates", self.iface.mainWindow())
        self.convertDatesAction.triggered.connect(self.showConvertDates)
#        self.iface.mapCanvas().layersChanged.connect(self.layersChanged)
        self.iface.projectRead.connect(self.changeProject)

        # Add toolbar button and menu item
        self.iface.addToolBarIcon(self.action)
        self.iface.addToolBarIcon(self.settingsAction)
        self.iface.addToolBarIcon(self.convertDatesAction)
        self.iface.addPluginToMenu(u"&DateControl", self.action)
        self.iface.addPluginToMenu(u"&DateControl", self.settingsAction)     
        self.iface.addPluginToMenu(u"&DateControl", self.convertDatesAction)     

    def changeProject(self):
        if not QgsProject is None:
            self.proj = QgsProject.instance()
            UriFile = str(self.proj.fileName())
            self.Path = str(os.path.dirname(UriFile))
            self.projName = UriFile[len(self.Path)+1:]
        else:
            self.projName = ""

        self.setGetSaveSettings()
        settingsKeys = self.pluginSettingsDic.keys()
        self.dock = DateControlDock(self.iface, self.pluginSettingsDic)
        self.convertDatesDialog = convertDatesDialog(self.iface)

    def setGetSaveSettings(self):
        self.pluginSettingsDic = {}
        try:
            self.getSaveSettings = GetSaveSettings(self.pluginSettingsDic, self.iface, self.projName, self.Path)
            self.pluginSettingsDic = self.getSaveSettings.getSettings(self.pluginSettingsDic)
        except:
            pass
        self.settingsDialog = SettingsDialog(self.iface, self.pluginSettingsDic, self.projName, self.Path)

# run method that performs all the real work
    def run(self):
        # show the dialog
        self.openDateControlDock()
#        try:
#            self.openDateControlDock()
#        except:
#            pass
 
    def showConvertDates(self):
        self.convertDatesDialog = convertDatesDialog(self.iface)
        self.convertDatesDialog.show()
        # Run the dialog event loop
        self.convertDatesDialog.exec_()
 
    def showSettings(self):
        self.settingsDialog.show()
        # Run the dialog event loop
        if self.settingsDialog.exec_():
            self.pluginSettingsDic = self.settingsDialog.pluginSettingsDic
            self.dock = DateControlDock(self.iface, self.pluginSettingsDic)
 
    def openDateControlDock(self):
        self.dock.getLayersData()
        self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.dock)

    def unload(self):
       # Remove the plugin menu item and icon
        self.dock.resetLayerQueries()
        self.iface.removePluginMenu(u"&DateControl", self.action)
        self.iface.removeToolBarIcon(self.action)
        self.iface.removePluginMenu(u"&DateControl", self.settingsAction)
        self.iface.removeToolBarIcon(self.settingsAction)
        self.iface.removePluginMenu(u"&DateControl", self.convertDatesAction)
        self.iface.removeToolBarIcon(self.convertDatesAction)
Esempio n. 20
0
 def pluginSettings(self):
     from settingsdialog import SettingsDialog
     dialog = SettingsDialog(self)
     if dialog.exec_():
         self.pluginManager.reloadPlugins()
         self.pages[ppages.PAGE_DEM].initLayerComboBox()
Esempio n. 21
0
 def on_actionConfigure_triggered(self):
     dialog = SettingsDialog(self.programSettings, self)
     dialog.rowHeightChanged.connect(self.setRowHeight)
     dialog.exec_()
Esempio n. 22
0
 def showSettings(self):
     dlg = SettingsDialog(self)
     dlg.exec_()
 def initParameters(self):
     from settingsdialog import SettingsDialog
     dialog = SettingsDialog(self.iface)
     accepted = dialog.exec_()
     if not accepted:
         return False