def _get_bpej_code_prices(self):
     """Returns BPEJ code prices.
     
     Returns:
         dict: A dictionary with BPEJ codes as keys (int)
             and prices as values (float).
     
     """
     
     formatTimeStr = '%d.%m.%Y'
     
     bpejDir = QDir(self.pluginDir.path() + u'/data/bpej')
     
     bpejBaseName = u'SC_BPEJ'
     
     bpejZipFileName = bpejBaseName + u'.zip'
     
     bpejZipFilePath = bpejDir.filePath(bpejZipFileName)
     
     bpejCsvFileName = bpejBaseName + u'.csv'
     
     bpejCsvFilePath = bpejDir.filePath(bpejCsvFileName)
     
     upToDate = self._check_bpej_csv(bpejCsvFilePath, formatTimeStr)
     
     if not upToDate:
         testInternetUrl, bpejZipUrl = self._get_url()
         
         self._download_bpej_csv(
             testInternetUrl, bpejZipUrl, bpejZipFilePath, bpejCsvFileName)
     
     bpejCodePrices = self._read_bpej_csv(bpejCsvFilePath, formatTimeStr)
     
     return bpejCodePrices
    def initTemplateList(self):
        cbox = self.ui.comboBox_Template
        cbox.clear()
        templateDir = QDir(tools.templateDir())
        for i, entry in enumerate(templateDir.entryList(["*.html", "*.htm"])):
            cbox.addItem(entry)

            config = tools.getTemplateConfig(templateDir.filePath(entry))
            # get template type
            templateType = config.get("type", "plain")
            cbox.setItemData(i, templateType, Qt.UserRole)

            # set tool tip text
            desc = config.get("description", "")
            if desc:
                cbox.setItemData(i, desc, Qt.ToolTipRole)

        # select the last used template
        templateName = QSettings().value("/Qgis2threejs/lastTemplate", "", type=unicode)
        if templateName:
            index = cbox.findText(templateName)
            if index != -1:
                cbox.setCurrentIndex(index)
            return index
        return -1
 def _unzip_bpej_zip(self, bpejZipFilePath, bpejCsvFileName):
     """Unzips BPEJ ZIP file into the same directory.
     
     Args:
         bpejZipFilePath (str): A full path to the BPEJ ZIP file.
         bpejCsvFileName (str): A name of the BPEJ CSV file.
     
     """
     
     fileInfo = QFileInfo(bpejZipFilePath)
     
     bpejDir = fileInfo.absolutePath()
     
     bpejZip = zipfile.ZipFile(bpejZipFilePath, 'r')
     
     bpejZipContent = bpejZip.namelist()
     
     if len(bpejZipContent) != 1:
         bpejZip.close()
         
         raise self.dW.puError(
             self.dW, self.pW,
             u'The structure of the BPEJ ZIP file has changed. '
             u'The BPEJ ZIP file contains more than one file.',
             u'Struktura stahovaného BPEJ ZIP souboru se změnila.')
     
     bpejZipFirstMember = bpejZipContent[0]
     
     bpejZip.extract(bpejZipFirstMember, bpejDir)
     bpejZip.close()
     
     if bpejZipFirstMember != bpejCsvFileName:
         bpejDir = QDir(bpejDir)
         
         bpejZipFirstMemberFilePath = bpejDir.filePath(bpejZipFirstMember)
         
         bpejCsvFilePath = bpejDir.filePath(bpejCsvFileName)
         
         os.rename(bpejZipFirstMemberFilePath, bpejCsvFilePath)
 def set_layer_style(self, layer, qmlFileBaseName):
     """Sets layer style according to the given QML file base name.
     
     Args:
         layer (QgsVectorLayer): A reference to the layer.
         qmlFileBaseName (str): A QML file base name.
     
     """
     
     qmlDir = QDir(self.pluginDir.path() + u'/data/qml')
     style = qmlDir.filePath(qmlFileBaseName + u'.qml')
     
     layer.loadNamedStyle(style)
class puPlugin(object):
    """The main class of the PU Plugin."""

    def __init__(self, iface):
        """Constructor.
        
        Args:
            iface (QgisInterface): A reference to the QgisInterface.
        
        """
        
        self.iface = iface
        
        self.name = u'PU Plugin'

        self.pluginDir = QDir(os.path.dirname(__file__))
    
    def initGui(self):
        """Initializes GUI."""
        
        self.puAction = QAction(self.iface.mainWindow())
        self.puAction.setText(self.name)
        puIcon = QIcon(self.pluginDir.filePath(u'puplugin.svg'))
        self.puAction.setIcon(puIcon)
        self.puAction.triggered.connect(self.run)

        self.iface.addToolBarIcon(self.puAction)
        self.iface.addPluginToMenu(self.name, self.puAction)
        
        self.dockWidget = dockwidget.DockWidget(
            self.iface, self.pluginDir, self.name)
        
        self.iface.addDockWidget(Qt.TopDockWidgetArea, self.dockWidget)
    
    def unload(self):
        """Removes the plugin menu and icon."""
        
        self.dockWidget.disconnect_from_iface()
        
        self.iface.removePluginMenu(self.name, self.puAction)
        self.iface.removeToolBarIcon(self.puAction)
        
        self.iface.removeDockWidget(self.dockWidget)
    
    def run(self):
        """Shows the dockWidget if not visible, otherwise hides it."""
        
        if not self.dockWidget.isVisible():
            self.dockWidget.show()
        else:
            self.dockWidget.hide()
    def _build_widgets(self):
        """Builds own widgets."""

        self.iface.initializationCompleted.connect(self._set_icon_size)

        iconsDir = QDir(self.pluginDir.path() + u'/data/icons')

        self.openTabActionGroup = QActionGroup(self)

        self.loadVfkAction = QAction(self)
        self.loadVfkAction.setObjectName(u'loadVfkAction')
        self.loadVfkAction.setToolTip(u'Načtení VFK souboru')
        self.loadVfkAction.setCheckable(True)
        loadVfkIcon = QIcon()
        loadVfkIcon.addPixmap(QPixmap(iconsDir.filePath(u'loadvfk.png')))
        self.loadVfkAction.setIcon(loadVfkIcon)
        self.openTabActionGroup.addAction(self.loadVfkAction)
        self.addAction(self.loadVfkAction)
        self.loadVfkAction.trigger()

        self.editAction = QAction(self)
        self.editAction.setObjectName(u'editAction')
        self.editAction.setToolTip(u'Editace')
        self.editAction.setCheckable(True)
        editIcon = QIcon()
        editIcon.addPixmap(QPixmap(iconsDir.filePath(u'edit.png')))
        self.editAction.setIcon(editIcon)
        self.openTabActionGroup.addAction(self.editAction)
        self.addAction(self.editAction)

        self.checkAnalysisAction = QAction(self)
        self.checkAnalysisAction.setObjectName(u'checkAnalysisAction')
        self.checkAnalysisAction.setToolTip(u'Kontroly a analýzy')
        self.checkAnalysisAction.setCheckable(True)
        checkIcon = QIcon()
        checkIcon.addPixmap(QPixmap(iconsDir.filePath(u'checkanalysis.png')))
        self.checkAnalysisAction.setIcon(checkIcon)
        self.openTabActionGroup.addAction(self.checkAnalysisAction)
        self.addAction(self.checkAnalysisAction)

        self.addSeparator()

        self.zoomFullExtentAction = self.iface.actionZoomFullExtent()
        self.addAction(self.zoomFullExtentAction)

        self.zoomToSelectedAction = self.iface.actionZoomToSelected()
        self.addAction(self.zoomToSelectedAction)

        self.selectToolButton = QToolButton(self)
        self.selectToolButton.setObjectName(u'selectToolButton')
        self.selectToolButton.setPopupMode(1)

        self.selectRectangleAction = self.iface.actionSelectRectangle()
        self.selectToolButton.addAction(self.selectRectangleAction)

        self.selectPolygonAction = self.iface.actionSelectPolygon()
        self.selectToolButton.addAction(self.selectPolygonAction)

        self.selectFreehandAction = self.iface.actionSelectFreehand()
        self.selectToolButton.addAction(self.selectFreehandAction)

        self.selectRadiusAction = self.iface.actionSelectRadius()
        self.selectToolButton.addAction(self.selectRadiusAction)

        for action in self.iface.attributesToolBar().actions():
            if action.objectName() == 'ActionSelect':
                self.qgisSelectToolButton = action.defaultWidget()
                break

        self.qgisSelectToolButton.toggled.connect(
            self._set_default_action_selectToolButton)

        self._set_default_action_selectToolButton()

        self.addWidget(self.selectToolButton)

        self.selectionToolButton = QToolButton(self)
        self.selectionToolButton.setObjectName(u'selectionToolButton')
        self.selectionToolButton.setPopupMode(1)

        for action in self.iface.attributesToolBar().actions():
            if action.objectName() == 'ActionSelection':
                self.qgisSelectionToolButton = action.defaultWidget()
                break

        self.selectionToolButton.addActions(
            self.qgisSelectionToolButton.actions())

        self.selectionToolButton.setDefaultAction(
            self.qgisSelectionToolButton.defaultAction())

        self.addWidget(self.selectionToolButton)

        for action in self.iface.attributesToolBar().actions():
            if action.objectName() == 'mActionDeselectAll':
                self.deselectAllAction = action
                break

        self.addAction(self.deselectAllAction)

        self.openTableAction = self.iface.actionOpenTable()
        self.addAction(self.openTableAction)
Exemple #7
0
    def populateUi(self):
        """
		Die Graphische Oberfläche wird bevölkert.
		"""

        ## Die Icons werden hier definiert, da der Pfad zur ressourcen-DAtei nicht stimmt, wenn pyside-uic über die ui-Datei marschiert ist.
        self.ui.pushButton_previous.setIcon(
            QIcon(":/icons/images/actions/1leftarrow.png"))
        self.ui.pushButton_next.setIcon(
            QIcon(":/icons/images/actions/1rightarrow.png"))
        self.ui.actionNew.setIcon(QIcon(":/icons/images/actions/filenew.png"))
        self.ui.actionOpen.setIcon(
            QIcon(":/icons/images/actions/fileopen.png"))
        self.ui.actionSave.setIcon(
            QIcon(":/icons/images/actions/filesave.png"))
        self.ui.actionExport.setIcon(
            QIcon(":/icons/images/actions/fileexport.png"))
        self.ui.actionPrint.setIcon(
            QIcon(":/icons/images/actions/agt_print.png"))
        self.ui.actionSettings.setIcon(
            QIcon(":/icons/images/actions/exec.png"))
        self.ui.actionQuit.setIcon(QIcon(":/icons/images/actions/exit.png"))

        self.info = InfoWidget(self.__storage, self.__character, self)
        self.ui.layout_info.addWidget(self.info)

        attributes = AttributeWidget(self.__storage, self.__character, self)
        self.ui.layout_attributes.addWidget(attributes)

        skills = SkillWidget(self.__storage, self.__character, self)
        self.ui.layout_skills.addWidget(skills)

        #specialties = Specialties( self.__storage.traits["Skill"], self )
        specialties = SpecialtiesWidget(self.__storage.traits["Skill"], self)
        self.ui.layout_specialties.addWidget(specialties)

        merits = MeritWidget(self.__storage, self.__character, self)
        self.ui.layout_merits.addWidget(merits)

        morality = MoralityWidget(self.__storage, self.__character, self)
        self.ui.layout_morality.addWidget(morality)

        self.template = TemplateWidget(self.__storage, self.__character, self)
        self.ui.layout_template.addWidget(self.template)

        if "Power" in self.__storage.traits.keys():
            powers = PowerWidget(self.__storage, self.__character, self)
            self.ui.layout_powers.addWidget(powers)

            subPowers = SubPowerWidget(self.__storage, self.__character, self)
            self.ui.layout_subPowers.addWidget(subPowers)

        flaws = FlawWidget(self.__storage, self.__character, self)
        self.ui.layout_flaws.addWidget(flaws)

        self.__advantages = AdvantagesWidget(self.__storage, self.__character,
                                             self)
        self.ui.layout_advantages.addWidget(self.__advantages)

        items = ItemWidget(self.__storage, self.__character, self)
        self.ui.layout_items.addWidget(items)

        speciesSpecials = SpecialsWidget(self.__storage, self.__character,
                                         self)
        self.ui.layout_specials.addWidget(speciesSpecials)

        ## Wenn sich der Name im InfoWidget ändert, soll sich auch die Titelzeile des Programms ändern
        self.info.nameChanged.connect(self.setTitle)

        ### Wird eine neue Seite angewählt, muß das Info-Widget den Beschreibungstext speichern.
        #self.pageChanged.connect(self.info.saveDescription)

        # Die Spezialisierungen einer Fertigkeit sollen angezeigt werden.
        skills.specialtiesActivated.connect(specialties.showSpecialties)

        # Menschen haben keine übernatürlichen Kräfte, also zeige ich sie auch nicht an.
        self.__character.speciesChanged.connect(
            self.ui.selectWidget_select.disableItems)

        # Hintergrundbild ändert sich je nach Spezies
        self.__character.speciesChanged.connect(self.showBackround)

        ## Sämtliche Schriften in das System laden, damit ich sie auch benutzen kann.
        resourceFontDir = QDir(":/fonts/fonts")
        fontsList = resourceFontDir.entryList()
        for font in fontsList:
            QFontDatabase.addApplicationFont(resourceFontDir.filePath(font))
	def populateUi(self):
		"""
		Die Graphische Oberfläche wird bevölkert.
		"""

		## Die Icons werden hier definiert, da der Pfad zur ressourcen-DAtei nicht stimmt, wenn pyside-uic über die ui-Datei marschiert ist.
		self.ui.pushButton_previous.setIcon(QIcon(":/icons/images/actions/1leftarrow.png"))
		self.ui.pushButton_next.setIcon(QIcon(":/icons/images/actions/1rightarrow.png"))
		self.ui.actionNew.setIcon(QIcon(":/icons/images/actions/filenew.png"))
		self.ui.actionOpen.setIcon(QIcon(":/icons/images/actions/fileopen.png"))
		self.ui.actionSave.setIcon(QIcon(":/icons/images/actions/filesave.png"))
		self.ui.actionExport.setIcon(QIcon(":/icons/images/actions/fileexport.png"))
		self.ui.actionPrint.setIcon(QIcon(":/icons/images/actions/agt_print.png"))
		self.ui.actionSettings.setIcon(QIcon(":/icons/images/actions/exec.png"))
		self.ui.actionQuit.setIcon(QIcon(":/icons/images/actions/exit.png"))

		self.info = InfoWidget(self.__storage, self.__character, self)
		self.ui.layout_info.addWidget( self.info )

		attributes = AttributeWidget( self.__storage, self.__character, self )
		self.ui.layout_attributes.addWidget( attributes )

		skills = SkillWidget( self.__storage, self.__character, self )
		self.ui.layout_skills.addWidget( skills )

		#specialties = Specialties( self.__storage.traits["Skill"], self )
		specialties = SpecialtiesWidget( self.__storage.traits["Skill"], self )
		self.ui.layout_specialties.addWidget( specialties )

		merits = MeritWidget( self.__storage, self.__character, self )
		self.ui.layout_merits.addWidget( merits )

		morality = MoralityWidget( self.__storage, self.__character, self )
		self.ui.layout_morality.addWidget( morality )

		self.template = TemplateWidget(self.__storage, self.__character, self)
		self.ui.layout_template.addWidget( self.template )

		if "Power" in self.__storage.traits.keys():
			powers = PowerWidget( self.__storage, self.__character, self )
			self.ui.layout_powers.addWidget( powers )

			subPowers = SubPowerWidget( self.__storage, self.__character, self )
			self.ui.layout_subPowers.addWidget( subPowers )

		flaws = FlawWidget( self.__storage, self.__character, self )
		self.ui.layout_flaws.addWidget( flaws )

		self.__advantages = AdvantagesWidget( self.__storage, self.__character, self )
		self.ui.layout_advantages.addWidget( self.__advantages )

		items = ItemWidget( self.__storage, self.__character, self )
		self.ui.layout_items.addWidget( items )

		speciesSpecials = SpecialsWidget(self.__storage, self.__character, self)
		self.ui.layout_specials.addWidget( speciesSpecials )

		## Wenn sich der Name im InfoWidget ändert, soll sich auch die Titelzeile des Programms ändern
		self.info.nameChanged.connect(self.setTitle)

		### Wird eine neue Seite angewählt, muß das Info-Widget den Beschreibungstext speichern.
		#self.pageChanged.connect(self.info.saveDescription)

		# Die Spezialisierungen einer Fertigkeit sollen angezeigt werden.
		skills.specialtiesActivated.connect(specialties.showSpecialties)

		# Menschen haben keine übernatürlichen Kräfte, also zeige ich sie auch nicht an.
		self.__character.speciesChanged.connect(self.ui.selectWidget_select.disableItems)

		# Hintergrundbild ändert sich je nach Spezies
		self.__character.speciesChanged.connect(self.showBackround)

		## Sämtliche Schriften in das System laden, damit ich sie auch benutzen kann.
		resourceFontDir = QDir(":/fonts/fonts")
		fontsList = resourceFontDir.entryList()
		for font in fontsList:
			QFontDatabase.addApplicationFont(resourceFontDir.filePath(font))
Exemple #9
0
    def _open_database(self, dbPath):
        """Opens a database.
        
        Checks if there are geometry_columns and spatial_ref_sys
        tables in the database, if not it creates and fills those tables.
        
        Checks if there are all PU columns in PAR table,
        if it it creates and fills those columns.
        
        Args:
            dbPath (str): A full path to the database.
        
        Raises:
            dw.puError: When SQLITE database driver is not available
                or when database connection fails.
        
        """

        if not QSqlDatabase.isDriverAvailable('QSQLITE'):
            raise self.dW.puError(
                self.dW, self, u'SQLITE database driver is not available.',
                u'Databázový ovladač QSQLITE není dostupný.',
                u'Databázový ovladač QSQLITE není dostupný.')

        connectionName = QUuid.createUuid().toString()
        db = QSqlDatabase.addDatabase('QSQLITE', connectionName)
        db.setDatabaseName(dbPath)
        db.open()

        if not db.open():
            raise self.dW.puError(self.dW, self,
                                  u'Database connection failed.',
                                  u'Nepodařilo se připojit k databázi.',
                                  u'Nepodařilo se připojit k databázi.')

        self.set_text_statusbar.emit(u'Kontroluji tabulky a sloupce...', 0,
                                     False)

        QgsApplication.processEvents()

        sqlQuery = QSqlQuery(db)

        sqlDir = QDir(self.pluginDir.path() + u'/data/sql')

        query = self._read_text_from_file(sqlDir.filePath(u'check_gc_srs.sql'))

        sqlQuery.exec_(query)

        QgsApplication.processEvents()

        checkGcSrsSize = 0

        while sqlQuery.next():
            checkGcSrsSize += 1

        if checkGcSrsSize < 2:
            queries = self._read_text_from_file(
                sqlDir.filePath(u'create_fill_gc_srs.sql')).split(';')

            for query in queries:
                sqlQuery.exec_(query)

                QgsApplication.processEvents()

        query = self._read_text_from_file(
            sqlDir.filePath(u'check_pu_columns_PAR.sql'))

        sqlQuery.exec_(query)

        QgsApplication.processEvents()

        columns = []

        while sqlQuery.next():
            record = sqlQuery.record()
            name = str(record.value('name'))
            columns.append(name)

        if not all(column in columns for column in self.dW.allPuColumns):
            queries = self._read_text_from_file(
                sqlDir.filePath(u'add_pu_columns_PAR.sql')).split(';')

            for query in queries:
                sqlQuery.exec_(query)

                QgsApplication.processEvents()

        queries = self._read_text_from_file(
            sqlDir.filePath(u'create_sobr_spol.sql')).split(';')

        for query in queries:
            sqlQuery.exec_(query)

        db.close()
Exemple #10
0
class NodeLibrary ( QtCore.QObject ) : # QtCore.QObject
  #
  # __init__
  #
  def __init__ ( self, dirName ) :
    #
    self.dirName = dirName
    self.libdir = QDir ( dirName );
    self.model = 	QStandardItemModel ()
    self.parentItem = self.model.invisibleRootItem ()
    
    print '>> NodeLibrary: libdir = %s' % dirName 
    
    self.liblevel = ''
    self.scanLibDir ()
  #    
  # scanLibDir
  #
  def scanLibDir ( self ) :
    # process directories
    sortFlags = QDir.Name
    filterFlags = ( QDir.AllDirs | QDir.NoDotAndDotDot )
    fileList = self.libdir.entryInfoList ( filterFlags, sortFlags ) 
    
    for f in fileList :
      item = QStandardItem ( f.fileName () )
      item.setEditable ( False )
      item.setDragEnabled ( False )
      
      # set bold font for folders
      font = item.font()
      font.setBold ( True )
      item.setFont ( font )
      
      item.setWhatsThis ( 'folder' )
      
      currparent = self.parentItem
      self.parentItem.appendRow ( item )
      self.parentItem = item
      
      currlevel = self.liblevel # store current level
      self.liblevel = self.liblevel + f.fileName () + '/' 
      self.libdir.cd ( f.fileName () )
      
      self.scanLibDir () # recurcive call itself
      
      self.liblevel = currlevel # restore current level
      self.libdir.cdUp ()
      
      self.parentItem = currparent
        
    # process XML files
    filterFlags = QDir.Files    
    fileList = self.libdir.entryInfoList ( [ '*.xml' ], filterFlags, sortFlags ) 
    for f in fileList :
      self.scanXmlNodes ( f.fileName () )
  #
  # scanXmlNodes
  #
  def scanXmlNodes ( self, filename ) :      
    #
    dom = QtXml.QDomDocument ( '' )
    nodeFilename = self.dirName + '/' + self.liblevel + filename
    
    file = QFile ( self.libdir.filePath ( filename )  )
    
    if file.open ( QtCore.QIODevice.ReadOnly ) :
      if dom.setContent ( file ) :
        node = dom.documentElement () 
        if node.nodeName () == 'nodenet' or node.nodeName () == 'node' :
          nodeName   = node.attributes ().namedItem ( 'name' ).nodeValue ()
          nodeType   = node.attributes ().namedItem ( 'type' ).nodeValue ()
          nodeAuthor = node.attributes ().namedItem ( 'author' ).nodeValue ()
          nodeIcon   = node.attributes ().namedItem ( 'icon' ).nodeValue ()
          nodeHelp   = ''
          help_tag   = node.namedItem ('help')
          
          if not help_tag.isNull() : nodeHelp = help_tag.toElement ().text ()
          
          item = QStandardItem ( nodeName )
          item.setEditable ( False )
          
          item.setData ( QVariant ( nodeAuthor ),   QtCore.Qt.UserRole + 1 )
          item.setData ( QVariant ( nodeType ),     QtCore.Qt.UserRole + 2 )
          item.setData ( QVariant ( nodeHelp ),     QtCore.Qt.UserRole + 3 )
          item.setData ( QVariant ( nodeFilename ), QtCore.Qt.UserRole + 4 )
          item.setData ( QVariant ( nodeIcon ),     QtCore.Qt.UserRole + 5 )
          
          if node.nodeName () == 'nodenet' :
            # set Blue color for nodenet items
            brush = QtGui.QBrush ()
            brush.setColor ( QtCore.Qt.blue )
            item.setForeground ( brush )
            item.setWhatsThis ( 'nodenet' )
          else:
            item.setWhatsThis ( 'node' )
          
          self.parentItem.appendRow ( item )
    file.close ()