예제 #1
0
    def init_config(self):

        # initialize plugin directory
        user_folder = os.path.expanduser("~")
        self.plugin_name = 'giswater'
        self.plugin_dir = os.path.join(
            user_folder, '.qgis2/python/plugins/' + self.plugin_name)

        # Get config file
        setting_file = os.path.join(self.plugin_dir, 'config',
                                    self.plugin_name + '.config')
        if not os.path.isfile(setting_file):
            message = "Config file not found at: " + setting_file
            self.iface.messageBar().pushMessage(message, QgsMessageBar.WARNING,
                                                5)
            self.close()
            return

        self.settings = QSettings(setting_file, QSettings.IniFormat)
        self.settings.setIniCodec(sys.getfilesystemencoding())

        # Set controller to handle settings and database connection
        # TODO: Try to make only one connection
        self.controller = DaoController(self.settings, self.plugin_name)
        status = self.controller.set_database_connection()
        if not status:
            message = self.controller.getLastError()
            self.iface.messageBar().pushMessage(message, QgsMessageBar.WARNING,
                                                5)
            return

        self.schema_name = self.controller.getSchemaName()
        self.dao = self.controller.getDao()
예제 #2
0
    def initConfig(self):

        self.node_id = utils_giswater.getStringValue2("node_id")
        self.epa_type = utils_giswater.getSelectedItem("epa_type")

        # initialize plugin directory
        user_folder = os.path.expanduser("~")
        self.plugin_name = 'giswater'
        self.plugin_dir = os.path.join(
            user_folder, '.qgis2/python/plugins/' + self.plugin_name)

        # Get config file
        setting_file = os.path.join(self.plugin_dir, 'config',
                                    self.plugin_name + '.config')
        if not os.path.isfile(setting_file):
            message = "Config file not found at: " + setting_file
            self.iface.messageBar().pushMessage(message, QgsMessageBar.WARNING,
                                                5)
            self.close()
            return

        self.settings = QSettings(setting_file, QSettings.IniFormat)
        self.settings.setIniCodec(sys.getfilesystemencoding())

        # Get widget controls
        self.cbo_cat_nodetype_id = self.dialog.findChild(
            QComboBox, "cat_nodetype_iddd")
        self.cbo_nodecat_id = self.dialog.findChild(QComboBox, "nodecat_id")
        self.tab_analysis = self.dialog.findChild(QTabWidget, "tab_analysis")
        self.tab_event = self.dialog.findChild(QTabWidget, "tab_event")

        # Set controller to handle settings and database connection
        # TODO: Try to make only one connection
        self.controller = DaoController(self.settings, self.plugin_name)
        status = self.controller.set_database_connection()
        if not status:
            message = self.controller.getLastError()
            self.iface.messageBar().pushMessage(message, QgsMessageBar.WARNING,
                                                5)
            return

        self.schema_name = self.controller.getSchemaName()
        self.dao = self.controller.getDao()

        # Manage tab visibility
        self.setTabsVisibility()

        # Manage i18n
        self.translateForm()

        # Fill combo 'node type' from 'epa_type'
        self.fillNodeType()

        # Load data from related tables
        self.loadData()

        # Set layer in editing mode
        self.layer.startEditing()
예제 #3
0
    def __init__(self, iface):
        ''' Constructor 
        :param iface: An interface instance that will be passed to this class
            which provides the hook by which you can manipulate the QGIS
            application at run time.
        :type iface: QgsInterface
        '''
        super(Giswater, self).__init__()

        # Save reference to the QGIS interface
        self.iface = iface
        self.legend = iface.legendInterface()

        # initialize plugin directory
        self.plugin_dir = os.path.dirname(__file__)
        self.plugin_name = os.path.basename(self.plugin_dir)

        # initialize locale
        locale = QSettings().value('locale/userLocale')
        locale_path = os.path.join(self.plugin_dir, 'i18n',
                                   self.plugin_name + '_{}.qm'.format(locale))
        if os.path.exists(locale_path):
            self.translator = QTranslator()
            self.translator.load(locale_path)
            if qVersion() > '4.3.3':
                QCoreApplication.installTranslator(self.translator)

        # Load local settings of the plugin
        setting_file = os.path.join(self.plugin_dir, 'config',
                                    self.plugin_name + '.config')
        self.settings = QSettings(setting_file, QSettings.IniFormat)
        self.settings.setIniCodec(sys.getfilesystemencoding())

        # Set controller to handle settings and database
        self.controller = DaoController(self.settings, self.plugin_name)
        self.controller.set_database_connection()
        self.dao = self.controller.getDao()
        self.schema_name = self.controller.getSchemaName()

        # Declare instance attributes
        self.icon_folder = self.plugin_dir + '/icons/'
        self.actions = {}
        self.search_plus = None

        # {function_name, map_tool}
        self.map_tools = {}

        # Define signals
        self.set_signals()