Пример #1
0
    def initGui(self):
        self.settingsDialog = SettingsWidget(self.iface,
                                             self.iface.mainWindow())
        self.mapTool = CopyLatLonTool(self.settingsDialog, self.iface)

        icon = QIcon(":/plugins/latlontools/copyicon.png")
        self.copyAction = QAction(icon, "Copy Latitude, Longitude",
                                  self.iface.mainWindow())
        self.copyAction.triggered.connect(self.setTool)
        self.copyAction.setCheckable(True)
        self.iface.addToolBarIcon(self.copyAction)
        self.iface.addPluginToMenu("Lat Lon Tools", self.copyAction)

        zoomicon = QIcon(':/plugins/latlontools/zoomicon.png')
        self.zoomToAction = QAction(zoomicon, "Zoom To Latitude, Longitude",
                                    self.iface.mainWindow())
        self.zoomToAction.triggered.connect(self.zoomTo)
        self.iface.addPluginToMenu('Lat Lon Tools', self.zoomToAction)

        self.iface.mapCanvas().mapToolSet.connect(self.unsetTool)

        self.dockwidget = ZoomToLatLon(self.iface, self.iface.mainWindow())
        self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.dockwidget)
        self.dockwidget.hide()

        # Initialize the Settings Dialog Box
        settingsicon = QIcon(':/plugins/latlontools/settings.png')
        self.settingsAction = QAction(settingsicon, "Settings",
                                      self.iface.mainWindow())
        self.settingsAction.triggered.connect(self.settings)
        self.iface.addPluginToMenu('Lat Lon Tools', self.settingsAction)
    def initGui(self):
        '''Initialize Lot Lon Tools GUI.'''
        # Initialize the Settings Dialog box
        self.settingsDialog = SettingsWidget(self, self.iface,
                                             self.iface.mainWindow())
        self.multiZoomDialog = MultiZoomWidget(self, self.settingsDialog,
                                               self.iface.mainWindow())
        self.mapTool = CopyLatLonTool(self.settingsDialog, self.iface)

        # Add Interface for Coordinate Capturing
        icon = QIcon(os.path.dirname(__file__) + "/images/copyicon.png")
        self.copyAction = QAction(icon, "Copy Latitude, Longitude",
                                  self.iface.mainWindow())
        self.copyAction.triggered.connect(self.setTool)
        self.copyAction.setCheckable(True)
        self.iface.addToolBarIcon(self.copyAction)
        self.iface.addPluginToMenu("Lat Lon Tools", self.copyAction)

        # Add Interface for Zoom to Coordinate
        zoomicon = QIcon(os.path.dirname(__file__) + "/images/zoomicon.png")
        self.zoomToAction = QAction(zoomicon, "Zoom To Latitude, Longitude",
                                    self.iface.mainWindow())
        self.zoomToAction.triggered.connect(self.zoomTo)
        self.iface.addPluginToMenu('Lat Lon Tools', self.zoomToAction)
        self.canvas.mapToolSet.connect(self.unsetTool)
        self.zoomToDialog = ZoomToLatLon(self, self.iface,
                                         self.iface.mainWindow())
        self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.zoomToDialog)
        self.zoomToDialog.hide()

        # Add Interface for Multi point zoom
        zoomicon = QIcon(os.path.dirname(__file__) + '/images/multizoom.png')
        self.multiZoomToAction = QAction(zoomicon, "Multi-location Zoom",
                                         self.iface.mainWindow())
        self.multiZoomToAction.triggered.connect(self.multiZoomTo)
        self.iface.addPluginToMenu('Lat Lon Tools', self.multiZoomToAction)

        # Initialize the Settings Dialog Box
        settingsicon = QIcon(
            os.path.dirname(__file__) + '/images/settings.png')
        self.settingsAction = QAction(settingsicon, "Settings",
                                      self.iface.mainWindow())
        self.settingsAction.triggered.connect(self.settings)
        self.iface.addPluginToMenu('Lat Lon Tools', self.settingsAction)

        # Help
        helpicon = QIcon(os.path.dirname(__file__) + '/images/help.png')
        self.helpAction = QAction(helpicon, "Lat Lon Tools Help",
                                  self.iface.mainWindow())
        self.helpAction.triggered.connect(self.help)
        self.iface.addPluginToMenu('Lat Lon Tools', self.helpAction)
    def initGui(self):
        self.settingsDialog = SettingsWidget(self.iface, self.iface.mainWindow())
        self.mapTool = CopyLatLonTool(self.settingsDialog, self.iface)

        icon = QIcon(":/plugins/latlontools/copyicon.png")
        self.copyAction = QAction(icon, "Copy Latitude, Longitude",
            self.iface.mainWindow())
        self.copyAction.triggered.connect(self.setTool)
        self.copyAction.setCheckable(True)
        self.iface.addToolBarIcon(self.copyAction)
        self.iface.addPluginToMenu("Lat Lon Tools", self.copyAction)

        zoomicon = QIcon(':/plugins/latlontools/zoomicon.png')
        self.zoomToAction = QAction(zoomicon, "Zoom To Latitude, Longitude", 
                    self.iface.mainWindow())
        self.zoomToAction.triggered.connect(self.zoomTo)
        self.iface.addPluginToMenu('Lat Lon Tools', self.zoomToAction)
        
        
        self.iface.mapCanvas().mapToolSet.connect(self.unsetTool)

        
        self.dockwidget = ZoomToLatLon(self.iface,
                    self.iface.mainWindow())
        self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.dockwidget)
        self.dockwidget.hide()
        
        # Initialize the Settings Dialog Box
        settingsicon = QIcon(':/plugins/latlontools/settings.png')
        self.settingsAction = QAction(settingsicon, "Settings", 
                    self.iface.mainWindow())
        self.settingsAction.triggered.connect(self.settings)
        self.iface.addPluginToMenu('Lat Lon Tools', self.settingsAction)
Пример #4
0
    def __init__(self, debug = False):       
        # Logger
        self.logger = Logger(debug)

        # Setup data handler and config helper
        self.datahandler = MaemoDataHandler(self, self.logger)
        self.config_helper = ConfigHelper(self.datahandler, self.logger)
        
        # Setup ui
        self.ui = UiController(self, debug, self.logger)
        self.logger.set_ui(self.ui)
        self.settings_widget = SettingsWidget(self.ui, self.config_helper, self.logger)

        # Setup connection
        self.connection = ConnectionManager(self, self.ui, self.logger)
        
        # Create transfer managers and widget
        self.sync_manager = SyncManager(self)
        self.transfer_manager = TransferManager(self)
        self.transfer_widget = TransferWidget(self.transfer_manager)

        # Pass objects around
        self.ui.tree_controller.setup(self.connection)
        self.settings_widget.setup(self.connection, self.sync_manager)
        self.ui.set_settings_widget(self.settings_widget)
        self.ui.set_transfer_widget(self.transfer_widget)
        self.transfer_manager.set_transfer_widget(self.transfer_widget)
Пример #5
0
    def initGui(self):
        self.settingsDialog = SettingsWidget(self.iface,
                                             self.iface.mainWindow())
        self.shapeDialog = Vector2ShapeWidget(self.iface,
                                              self.iface.mainWindow(),
                                              self.settingsDialog)
        self.xyLineDialog = XYToLineWidget(self.iface, self.iface.mainWindow(),
                                           self.settingsDialog)

        # Initialize the create shape Dialog Box
        icon = QIcon(os.path.dirname(__file__) + '/images/shapes.png')
        self.shapeAction = QAction(icon, u'Create Shapes',
                                   self.iface.mainWindow())
        self.shapeAction.triggered.connect(self.shapeTool)
        self.iface.addPluginToVectorMenu(u'Shape Tools', self.shapeAction)

        # Initialize the XY to Line Dialog Box
        icon = QIcon(os.path.dirname(__file__) + '/images/xyline.png')
        self.xyLineAction = QAction(icon, u'XY to Line',
                                    self.iface.mainWindow())
        self.xyLineAction.triggered.connect(self.xyLineTool)
        self.iface.addPluginToVectorMenu(u'Shape Tools', self.xyLineAction)

        # Settings
        icon = QIcon(os.path.dirname(__file__) + '/images/settings.png')
        self.settingsAction = QAction(icon, u'Settings',
                                      self.iface.mainWindow())
        self.settingsAction.triggered.connect(self.settings)
        self.iface.addPluginToVectorMenu(u'Shape Tools', self.settingsAction)

        # Help
        icon = QIcon(os.path.dirname(__file__) + '/images/help.png')
        self.helpAction = QAction(icon, u'Shape Tools Help',
                                  self.iface.mainWindow())
        self.helpAction.triggered.connect(self.help)
        self.iface.addPluginToVectorMenu(u'Shape Tools', self.helpAction)
    def initGui(self):
        '''Initialize Lot Lon Tools GUI.'''
        # Initialize the Settings Dialog box
        self.settingsDialog = SettingsWidget(self.iface, self.iface.mainWindow())
        self.multiZoomDialog = MultiZoomWidget(self, self.settingsDialog, self.iface.mainWindow())
        self.mapTool = CopyLatLonTool(self.settingsDialog, self.iface)
        
        # Add Interface for Coordinate Capturing
        icon = QIcon(":/plugins/latlontools/copyicon.png")
        self.copyAction = QAction(icon, "Copy Latitude, Longitude",
            self.iface.mainWindow())
        self.copyAction.triggered.connect(self.setTool)
        self.copyAction.setCheckable(True)
        self.iface.addToolBarIcon(self.copyAction)
        self.iface.addPluginToMenu("Lat Lon Tools", self.copyAction)

        # Add Interface for Zoom to Coordinate
        zoomicon = QIcon(':/plugins/latlontools/zoomicon.png')
        self.zoomToAction = QAction(zoomicon, "Zoom To Latitude, Longitude", 
                    self.iface.mainWindow())
        self.zoomToAction.triggered.connect(self.zoomTo)
        self.iface.addPluginToMenu('Lat Lon Tools', self.zoomToAction)
        self.canvas.mapToolSet.connect(self.unsetTool)

        self.zoomToDialog = ZoomToLatLon(self, self.iface,
                    self.iface.mainWindow())
        self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.zoomToDialog)
        self.zoomToDialog.hide()
        
        # Add Interface for Multi point zoom
        zoomicon = QIcon(':/plugins/latlontools/multizoom.png')
        self.multiZoomToAction = QAction(zoomicon, "Multi-location Zoom", 
                    self.iface.mainWindow())
        self.multiZoomToAction.triggered.connect(self.multiZoomTo)
        self.iface.addPluginToMenu('Lat Lon Tools', self.multiZoomToAction)
        
        
        # Initialize the Settings Dialog Box
        settingsicon = QIcon(':/plugins/latlontools/settings.png')
        self.settingsAction = QAction(settingsicon, "Settings", 
                    self.iface.mainWindow())
        self.settingsAction.triggered.connect(self.settings)
        self.iface.addPluginToMenu('Lat Lon Tools', self.settingsAction)
class LatLonTools:
    def __init__(self, iface):
        self.iface = iface

    def initGui(self):
        self.settingsDialog = SettingsWidget(self.iface, self.iface.mainWindow())
        self.mapTool = CopyLatLonTool(self.settingsDialog, self.iface)

        icon = QIcon(":/plugins/latlontools/copyicon.png")
        self.copyAction = QAction(icon, "Copy Latitude, Longitude",
            self.iface.mainWindow())
        self.copyAction.triggered.connect(self.setTool)
        self.copyAction.setCheckable(True)
        self.iface.addToolBarIcon(self.copyAction)
        self.iface.addPluginToMenu("Lat Lon Tools", self.copyAction)

        zoomicon = QIcon(':/plugins/latlontools/zoomicon.png')
        self.zoomToAction = QAction(zoomicon, "Zoom To Latitude, Longitude", 
                    self.iface.mainWindow())
        self.zoomToAction.triggered.connect(self.zoomTo)
        self.iface.addPluginToMenu('Lat Lon Tools', self.zoomToAction)
        
        
        self.iface.mapCanvas().mapToolSet.connect(self.unsetTool)

        
        self.dockwidget = ZoomToLatLon(self.iface,
                    self.iface.mainWindow())
        self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.dockwidget)
        self.dockwidget.hide()
        
        # Initialize the Settings Dialog Box
        settingsicon = QIcon(':/plugins/latlontools/settings.png')
        self.settingsAction = QAction(settingsicon, "Settings", 
                    self.iface.mainWindow())
        self.settingsAction.triggered.connect(self.settings)
        self.iface.addPluginToMenu('Lat Lon Tools', self.settingsAction)
        
    def unsetTool(self, tool):
        try:
            if not isinstance(tool, CopyLatLonTool):
                self.copyAction.setChecked(False)
        except:
            pass
 

    def unload(self):
        self.iface.mapCanvas().unsetMapTool(self.mapTool)
        self.iface.removePluginMenu('Lat Lon Tools', self.copyAction)
        self.iface.removeToolBarIcon(self.copyAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.zoomToAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.settingsAction)
        self.iface.removeDockWidget(self.dockwidget)
        self.dockwidget = None

    def setTool(self):
        self.copyAction.setChecked(True)
        self.iface.mapCanvas().setMapTool(self.mapTool)

    def zoomTo(self):
        self.dockwidget.show()
    
    def settings(self):
        self.settingsDialog.show()
class LatLonTools:
    def __init__(self, iface):
        self.iface = iface
        self.canvas = iface.mapCanvas()
        self.crossRb = QgsRubberBand(self.canvas, QGis.Line)
        self.crossRb.setColor(Qt.red)

    def initGui(self):
        '''Initialize Lot Lon Tools GUI.'''
        # Initialize the Settings Dialog box
        self.settingsDialog = SettingsWidget(self.iface, self.iface.mainWindow())
        self.multiZoomDialog = MultiZoomWidget(self, self.settingsDialog, self.iface.mainWindow())
        self.mapTool = CopyLatLonTool(self.settingsDialog, self.iface)
        
        # Add Interface for Coordinate Capturing
        icon = QIcon(":/plugins/latlontools/copyicon.png")
        self.copyAction = QAction(icon, "Copy Latitude, Longitude",
            self.iface.mainWindow())
        self.copyAction.triggered.connect(self.setTool)
        self.copyAction.setCheckable(True)
        self.iface.addToolBarIcon(self.copyAction)
        self.iface.addPluginToMenu("Lat Lon Tools", self.copyAction)

        # Add Interface for Zoom to Coordinate
        zoomicon = QIcon(':/plugins/latlontools/zoomicon.png')
        self.zoomToAction = QAction(zoomicon, "Zoom To Latitude, Longitude", 
                    self.iface.mainWindow())
        self.zoomToAction.triggered.connect(self.zoomTo)
        self.iface.addPluginToMenu('Lat Lon Tools', self.zoomToAction)
        self.canvas.mapToolSet.connect(self.unsetTool)

        self.zoomToDialog = ZoomToLatLon(self, self.iface,
                    self.iface.mainWindow())
        self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.zoomToDialog)
        self.zoomToDialog.hide()
        
        # Add Interface for Multi point zoom
        zoomicon = QIcon(':/plugins/latlontools/multizoom.png')
        self.multiZoomToAction = QAction(zoomicon, "Multi-location Zoom", 
                    self.iface.mainWindow())
        self.multiZoomToAction.triggered.connect(self.multiZoomTo)
        self.iface.addPluginToMenu('Lat Lon Tools', self.multiZoomToAction)
        
        
        # Initialize the Settings Dialog Box
        settingsicon = QIcon(':/plugins/latlontools/settings.png')
        self.settingsAction = QAction(settingsicon, "Settings", 
                    self.iface.mainWindow())
        self.settingsAction.triggered.connect(self.settings)
        self.iface.addPluginToMenu('Lat Lon Tools', self.settingsAction)
        
    def unsetTool(self, tool):
        '''Uncheck the Copy Lat Lon tool'''
        try:
            if not isinstance(tool, CopyLatLonTool):
                self.copyAction.setChecked(False)
        except:
            pass

    def unload(self):
        '''Unload LatLonTools from the QGIS interface'''
        self.canvas.unsetMapTool(self.mapTool)
        self.iface.removePluginMenu('Lat Lon Tools', self.copyAction)
        self.iface.removeToolBarIcon(self.copyAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.zoomToAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.multiZoomToAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.settingsAction)
        self.iface.removeDockWidget(self.zoomToDialog)
        self.zoomToDialog = None

    def setTool(self):
        '''Set the focus of the copy coordinate tool and check it'''
        self.copyAction.setChecked(True)
        self.canvas.setMapTool(self.mapTool)

    def zoomTo(self):
        '''Show the zoom to docked widget.'''
        self.zoomToDialog.show()

    def multiZoomTo(self):
        '''Display the Multi-zoom to dialog box'''
        self.multiZoomDialog.show()
    
    def settings(self):
        '''Show the settings dialog box'''
        self.settingsDialog.show()
 
    def zoomToLatLon(self, lat, lon):
        canvasCrs = self.canvas.mapRenderer().destinationCrs()
        epsg4326 = QgsCoordinateReferenceSystem("EPSG:4326")
        transform4326 = QgsCoordinateTransform(epsg4326, canvasCrs)
        x, y = transform4326.transform(float(lon), float(lat))
            
        rect = QgsRectangle(x,y,x,y)
        self.canvas.setExtent(rect)

        pt = QgsPoint(x,y)
        self.highlight(pt)
        self.canvas.refresh()
        
    def highlight(self, point):
        currExt = self.canvas.extent()
        
        leftPt = QgsPoint(currExt.xMinimum(),point.y())
        rightPt = QgsPoint(currExt.xMaximum(),point.y())
        
        topPt = QgsPoint(point.x(),currExt.yMaximum())
        bottomPt = QgsPoint(point.x(),currExt.yMinimum())
        
        horizLine = QgsGeometry.fromPolyline( [ leftPt , rightPt ] )
        vertLine = QgsGeometry.fromPolyline( [ topPt , bottomPt ] )
        
        self.crossRb.reset(QGis.Line)
        self.crossRb.addGeometry(horizLine, None)
        self.crossRb.addGeometry(vertLine, None)
        
        QTimer.singleShot(700, self.resetRubberbands)
        
    def resetRubberbands(self):
        self.crossRb.reset()
class LatLonTools:
    def __init__(self, iface):
        self.iface = iface
        self.canvas = iface.mapCanvas()
        self.crossRb = QgsRubberBand(self.canvas, QGis.Line)
        self.crossRb.setColor(Qt.red)

    def initGui(self):
        '''Initialize Lot Lon Tools GUI.'''
        # Initialize the Settings Dialog box
        self.settingsDialog = SettingsWidget(self.iface,
                                             self.iface.mainWindow())
        self.multiZoomDialog = MultiZoomWidget(self, self.settingsDialog,
                                               self.iface.mainWindow())
        self.mapTool = CopyLatLonTool(self.settingsDialog, self.iface)

        # Add Interface for Coordinate Capturing
        icon = QIcon(":/plugins/latlontools/copyicon.png")
        self.copyAction = QAction(icon, "Copy Latitude, Longitude",
                                  self.iface.mainWindow())
        self.copyAction.triggered.connect(self.setTool)
        self.copyAction.setCheckable(True)
        self.iface.addToolBarIcon(self.copyAction)
        self.iface.addPluginToMenu("Lat Lon Tools", self.copyAction)

        # Add Interface for Zoom to Coordinate
        zoomicon = QIcon(':/plugins/latlontools/zoomicon.png')
        self.zoomToAction = QAction(zoomicon, "Zoom To Latitude, Longitude",
                                    self.iface.mainWindow())
        self.zoomToAction.triggered.connect(self.zoomTo)
        self.iface.addPluginToMenu('Lat Lon Tools', self.zoomToAction)
        self.canvas.mapToolSet.connect(self.unsetTool)

        self.zoomToDialog = ZoomToLatLon(self, self.iface,
                                         self.iface.mainWindow())
        self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.zoomToDialog)
        self.zoomToDialog.hide()

        # Add Interface for Multi point zoom
        zoomicon = QIcon(':/plugins/latlontools/multizoom.png')
        self.multiZoomToAction = QAction(zoomicon, "Multi-location Zoom",
                                         self.iface.mainWindow())
        self.multiZoomToAction.triggered.connect(self.multiZoomTo)
        self.iface.addPluginToMenu('Lat Lon Tools', self.multiZoomToAction)

        # Initialize the Settings Dialog Box
        settingsicon = QIcon(':/plugins/latlontools/settings.png')
        self.settingsAction = QAction(settingsicon, "Settings",
                                      self.iface.mainWindow())
        self.settingsAction.triggered.connect(self.settings)
        self.iface.addPluginToMenu('Lat Lon Tools', self.settingsAction)

    def unsetTool(self, tool):
        '''Uncheck the Copy Lat Lon tool'''
        try:
            if not isinstance(tool, CopyLatLonTool):
                self.copyAction.setChecked(False)
        except:
            pass

    def unload(self):
        '''Unload LatLonTools from the QGIS interface'''
        self.canvas.unsetMapTool(self.mapTool)
        self.iface.removePluginMenu('Lat Lon Tools', self.copyAction)
        self.iface.removeToolBarIcon(self.copyAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.zoomToAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.multiZoomToAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.settingsAction)
        self.iface.removeDockWidget(self.zoomToDialog)
        self.zoomToDialog = None

    def setTool(self):
        '''Set the focus of the copy coordinate tool and check it'''
        self.copyAction.setChecked(True)
        self.canvas.setMapTool(self.mapTool)

    def zoomTo(self):
        '''Show the zoom to docked widget.'''
        self.zoomToDialog.show()

    def multiZoomTo(self):
        '''Display the Multi-zoom to dialog box'''
        self.multiZoomDialog.show()

    def settings(self):
        '''Show the settings dialog box'''
        self.settingsDialog.show()

    def zoomToLatLon(self, lat, lon):
        canvasCrs = self.canvas.mapRenderer().destinationCrs()
        epsg4326 = QgsCoordinateReferenceSystem("EPSG:4326")
        transform4326 = QgsCoordinateTransform(epsg4326, canvasCrs)
        x, y = transform4326.transform(float(lon), float(lat))

        rect = QgsRectangle(x, y, x, y)
        self.canvas.setExtent(rect)

        pt = QgsPoint(x, y)
        self.highlight(pt)
        self.canvas.refresh()

    def highlight(self, point):
        currExt = self.canvas.extent()

        leftPt = QgsPoint(currExt.xMinimum(), point.y())
        rightPt = QgsPoint(currExt.xMaximum(), point.y())

        topPt = QgsPoint(point.x(), currExt.yMaximum())
        bottomPt = QgsPoint(point.x(), currExt.yMinimum())

        horizLine = QgsGeometry.fromPolyline([leftPt, rightPt])
        vertLine = QgsGeometry.fromPolyline([topPt, bottomPt])

        self.crossRb.reset(QGis.Line)
        self.crossRb.addGeometry(horizLine, None)
        self.crossRb.addGeometry(vertLine, None)

        QTimer.singleShot(700, self.resetRubberbands)

    def resetRubberbands(self):
        self.crossRb.reset()
Пример #10
0
class LatLonTools:
    def __init__(self, iface):
        self.iface = iface

    def initGui(self):
        self.settingsDialog = SettingsWidget(self.iface,
                                             self.iface.mainWindow())
        self.mapTool = CopyLatLonTool(self.settingsDialog, self.iface)

        icon = QIcon(":/plugins/latlontools/copyicon.png")
        self.copyAction = QAction(icon, "Copy Latitude, Longitude",
                                  self.iface.mainWindow())
        self.copyAction.triggered.connect(self.setTool)
        self.copyAction.setCheckable(True)
        self.iface.addToolBarIcon(self.copyAction)
        self.iface.addPluginToMenu("Lat Lon Tools", self.copyAction)

        zoomicon = QIcon(':/plugins/latlontools/zoomicon.png')
        self.zoomToAction = QAction(zoomicon, "Zoom To Latitude, Longitude",
                                    self.iface.mainWindow())
        self.zoomToAction.triggered.connect(self.zoomTo)
        self.iface.addPluginToMenu('Lat Lon Tools', self.zoomToAction)

        self.iface.mapCanvas().mapToolSet.connect(self.unsetTool)

        self.dockwidget = ZoomToLatLon(self.iface, self.iface.mainWindow())
        self.iface.addDockWidget(Qt.LeftDockWidgetArea, self.dockwidget)
        self.dockwidget.hide()

        # Initialize the Settings Dialog Box
        settingsicon = QIcon(':/plugins/latlontools/settings.png')
        self.settingsAction = QAction(settingsicon, "Settings",
                                      self.iface.mainWindow())
        self.settingsAction.triggered.connect(self.settings)
        self.iface.addPluginToMenu('Lat Lon Tools', self.settingsAction)

    def unsetTool(self, tool):
        try:
            if not isinstance(tool, CopyLatLonTool):
                self.copyAction.setChecked(False)
        except:
            pass

    def unload(self):
        self.iface.mapCanvas().unsetMapTool(self.mapTool)
        self.iface.removePluginMenu('Lat Lon Tools', self.copyAction)
        self.iface.removeToolBarIcon(self.copyAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.zoomToAction)
        self.iface.removePluginMenu('Lat Lon Tools', self.settingsAction)
        self.iface.removeDockWidget(self.dockwidget)
        self.dockwidget = None

    def setTool(self):
        self.copyAction.setChecked(True)
        self.iface.mapCanvas().setMapTool(self.mapTool)

    def zoomTo(self):
        self.dockwidget.show()

    def settings(self):
        self.settingsDialog.show()
Пример #11
0
class DropN900():

    def __init__(self, debug = False):       
        # Logger
        self.logger = Logger(debug)

        # Setup data handler and config helper
        self.datahandler = MaemoDataHandler(self, self.logger)
        self.config_helper = ConfigHelper(self.datahandler, self.logger)
        
        # Setup ui
        self.ui = UiController(self, debug, self.logger)
        self.logger.set_ui(self.ui)
        self.settings_widget = SettingsWidget(self.ui, self.config_helper, self.logger)

        # Setup connection
        self.connection = ConnectionManager(self, self.ui, self.logger)
        
        # Create transfer managers and widget
        self.sync_manager = SyncManager(self)
        self.transfer_manager = TransferManager(self)
        self.transfer_widget = TransferWidget(self.transfer_manager)

        # Pass objects around
        self.ui.tree_controller.setup(self.connection)
        self.settings_widget.setup(self.connection, self.sync_manager)
        self.ui.set_settings_widget(self.settings_widget)
        self.ui.set_transfer_widget(self.transfer_widget)
        self.transfer_manager.set_transfer_widget(self.transfer_widget)
                
    def start(self):
        # Show ui
        self.ui.show()
        # Some validations
        self.authenticator = None
        self.request_token = None
        self.login_done = False
        self.connected = False
        # Start by checking existing auth
        self.check_for_auth(self.datahandler.configpath("token.ini"))
        # Exec QApplication
        os._exit(singleton_app.exec_())
                
    def check_for_auth(self, filename):
        token_config = SafeConfigParser()
        if isinstance(filename, unicode):
            filename = filename.encode("utf-8")
        token_config.read(filename)
        try:
            access_key = token_config.get("token", "key")
            access_secret = token_config.get("token", "secret")
            if access_key != "" and access_secret != "":
                self.logger.config("Found existing access token")
                self.login_done = True
                self.init_dropbox_client(oauth.OAuthToken(access_key, access_secret))
            else:
                self.logger.error("Parsing access token from file failed")
                self.datahandler.reset_auth()
        except NoSectionError:
            self.logger.config("No stored access token found")
            self.start_trusted_auth()
    
    def start_trusted_auth(self):
        self.login_done = False
        self.ui.switch_context("trustedlogin")
    
    def end_trusted_auth(self, email, password):
        self.login_done = False
        if self.connection.connection_available():
            if self.authenticator:
                del self.authenticator
            self.authenticator = auth.Authenticator(self.get_config())
            try:
                access_token = self.authenticator.obtain_trusted_access_token(email, password)
            except AssertionError:
                self.ui.set_trusted_login_error("Email and/or password invalid")
                return
            except socket.gaierror:
                self.ui.set_trusted_login_info("Requesting a network connection...")
                self.connection.request_connection()
                return
            self.login_done = True
            self.datahandler.store_auth(access_token)
            self.init_dropbox_client(access_token)
        else:
            self.ui.set_trusted_login_info("Requesting a network connection...")
            self.connection.request_connection()
    
    def init_dropbox_client(self, access_token):
        dropbox_config = self.get_config()
        server = dropbox_config["server"]
        content_server = dropbox_config["content_server"]
        if not self.authenticator:
            self.authenticator = auth.Authenticator(dropbox_config)
        dropbox_client = client.DropboxClient(server, content_server, 80, self.authenticator, access_token)
        self.connection.set_client(dropbox_client)
        self.ui.switch_context("manager")
        self.connected = True

    def get_config(self):
        return auth.Authenticator.load_config(self.datahandler.datapath(".config"))
Пример #12
0
class ShapeTools:
    def __init__(self, iface):
        self.iface = iface

    def initGui(self):
        self.settingsDialog = SettingsWidget(self.iface,
                                             self.iface.mainWindow())
        self.shapeDialog = Vector2ShapeWidget(self.iface,
                                              self.iface.mainWindow(),
                                              self.settingsDialog)
        self.xyLineDialog = XYToLineWidget(self.iface, self.iface.mainWindow(),
                                           self.settingsDialog)

        # Initialize the create shape Dialog Box
        icon = QIcon(os.path.dirname(__file__) + '/images/shapes.png')
        self.shapeAction = QAction(icon, u'Create Shapes',
                                   self.iface.mainWindow())
        self.shapeAction.triggered.connect(self.shapeTool)
        self.iface.addPluginToVectorMenu(u'Shape Tools', self.shapeAction)

        # Initialize the XY to Line Dialog Box
        icon = QIcon(os.path.dirname(__file__) + '/images/xyline.png')
        self.xyLineAction = QAction(icon, u'XY to Line',
                                    self.iface.mainWindow())
        self.xyLineAction.triggered.connect(self.xyLineTool)
        self.iface.addPluginToVectorMenu(u'Shape Tools', self.xyLineAction)

        # Settings
        icon = QIcon(os.path.dirname(__file__) + '/images/settings.png')
        self.settingsAction = QAction(icon, u'Settings',
                                      self.iface.mainWindow())
        self.settingsAction.triggered.connect(self.settings)
        self.iface.addPluginToVectorMenu(u'Shape Tools', self.settingsAction)

        # Help
        icon = QIcon(os.path.dirname(__file__) + '/images/help.png')
        self.helpAction = QAction(icon, u'Shape Tools Help',
                                  self.iface.mainWindow())
        self.helpAction.triggered.connect(self.help)
        self.iface.addPluginToVectorMenu(u'Shape Tools', self.helpAction)

    def unload(self):
        self.iface.removePluginVectorMenu(u'Shape Tools', self.shapeAction)
        self.iface.removePluginVectorMenu(u'Shape Tools', self.xyLineAction)
        self.iface.removePluginVectorMenu(u'Shape Tools', self.settingsAction)
        self.iface.removePluginVectorMenu(u'Shape Tools', self.helpAction)

    def shapeTool(self):
        self.shapeDialog.show()

    def xyLineTool(self):
        self.xyLineDialog.show()

    def settings(self):
        self.settingsDialog.show()

    def help(self):
        '''Display a help page'''
        url = QUrl.fromLocalFile(os.path.dirname(__file__) +
                                 '/index.html').toString()
        webbrowser.open(url, new=2)