Exemplo n.º 1
0
 def _updateRecentsMenu(self):
     # Ensures the recent files menu matches the recent file names
     # into the recent_file_names attribute.
     # This shoud be called each time the recent_file_names is modified.
     
     self.ui.menuRecent_Files.clear()
     for recent_file_name in self.recent_file_names:
         recent_file_info = QFileInfo(recent_file_name)
         action_text = recent_file_info.baseName() + " ["
         action_text += recent_file_info.canonicalFilePath() + "]"
         file_action = self.ui.menuRecent_Files.addAction(action_text)
         file_name = recent_file_info.canonicalFilePath()
         file_action.triggered.connect(self._genRecentOpenSlot(file_name))
     
     self.ui.menuRecent_Files.addSeparator()
     self.ui.menuRecent_Files.addAction(self.ui.actionClear_All)
Exemplo n.º 2
0
    def createDb(self, fileName):
        '''Create a new spatialite database file
        :param fileName: the filename of the database file
        :returns: True if the file could be created
        :rtype: bool
        '''
        try:
            db = sqlite.connect(fileName)
            cur = db.cursor()
        except OperationalError:
            self.bar.pushMessage(self.tr("SpatiaLite Database"), self.tr("Unable to create database file!"),
                                 level=QgsMessageBar.CRITICAL)
            return False

        try:
            db.enable_load_extension(True)
        except OperationalError:
            self.bar.pushMessage(self.tr("SpatiaLite Database"), self.tr("SQLITE Load_extension off!"),
                                 level=QgsMessageBar.INFO)

        cur.execute("Select initspatialmetadata(1)")
        db.commit()
        db.close

        fi = QFileInfo(fileName)
        if not fi.exists():
            return False

        key = u'/SpatiaLite/connections/' + fi.fileName() + u'/sqlitepath'

        settings = QSettings()
        if not settings.contains(key):
            settings.setValue('/SpatiaLite/connections/selected', fi.fileName() + self.tr('@') + fi.canonicalFilePath())
            settings.setValue(key, fi.canonicalFilePath())
            self.bar.pushMessage(self.tr("SpatiaLite Database"), self.tr("Registered new database!"),
                                 level=QgsMessageBar.SUCCESS)
        return True