当前位置: 首页>>代码示例>>Python>>正文


Python Util.check_api_url方法代码示例

本文整理汇总了Python中util.Util.check_api_url方法的典型用法代码示例。如果您正苦于以下问题:Python Util.check_api_url方法的具体用法?Python Util.check_api_url怎么用?Python Util.check_api_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在util.Util的用法示例。


在下文中一共展示了Util.check_api_url方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: CKANBrowserDialogSettings

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import check_api_url [as 别名]

#.........这里部分代码省略.........

    def test_ckan_url(self):
        """ Test if URL in LineEdit is a valid CKAN API URL """
        api_url = self.IDC_leCkanApi.text()
        self.util.msg_log('URL: {0}'.format(api_url))

        QApplication.setOverrideCursor(Qt.WaitCursor)
        ok, result = self.cc.test_groups(api_url)
        QApplication.restoreOverrideCursor()

        if ok is False:
            self.util.dlg_warning(result)
            return
        else:
            self.util.dlg_information(self.util.tr(u'py_dlg_set_info_conn_succs'))

#         for entry in result:
#             self.util.msg_log('Item: {0}'.format(entry))


    def pre_ckan_api(self):
        """select CKAN API from predefined file"""
        try:
            key = self.IDC_cbPreCkanApi.currentText()
            value = self.pre_ckan_apis[key]
            self.IDC_lblPreCkan.setText(value)
        except TypeError as err:
            self.util.msg_log('Error: No items in Preselected-Combo-Box: {0}'.format(err))
            pass


    def choose_pre_api(self):
        value = self.IDC_lblPreCkan.text()
        self.IDC_leCkanApi.setText(value)

    def cancel(self):
        QDialog.reject(self)

    def save(self):
        cache_dir = self.IDC_leCacheDir.text()
        if self.util.check_dir(cache_dir) is False:
            self.util.dlg_warning(
                self.util.tr(u'py_dlg_set_warn_cache_not_use').format(self.settings.cache_dir)
            )
            return

        # check URL - must not be empty
        api_url = self.IDC_leCkanApi.text()
        if self.util.check_api_url(api_url) is False:
            self.util.dlg_warning(self.util.tr(u'py_dlg_set_warn_ckan_url'))
            return

        self.settings.cache_dir = cache_dir
        self.settings.ckan_url = api_url

        authcfg = self.IDC_leAuthCfg.text()
        self.settings.authcfg = authcfg
        self.settings.auth_propagate = self.IDC_cbAuthPropagate.isChecked()

        self.settings.save()

        QDialog.accept(self)

    def help_cache_dir(self):
        self.util.dlg_information(self.util.tr(u'dlg_set_tool_cache'))

    def help_pre_urls(self):
        self.util.dlg_information(self.util.tr(u'dlg_set_tool_pre_urls'))

    def help_api_url(self):
        self.util.dlg_information(self.util.tr(u'dlg_set_tool_api_url'))

    def authcfg_clear(self):
         self.IDC_leAuthCfg.clear()

    def authcfg_edit(self):
        dlg = QDialog(None)
        dlg.setWindowTitle(self.util.tr("Select Authentication"))
        layout = QtGui.QVBoxLayout(dlg)

        acs = QgsAuthConfigSelect(dlg)
        if self.IDC_leAuthCfg.text():
            acs.setConfigId(self.IDC_leAuthCfg.text())
        layout.addWidget(acs)

        buttonbox = QtGui.QDialogButtonBox(
            QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel,
            Qt.Horizontal, dlg
        )

        layout.addWidget(buttonbox)
        buttonbox.accepted.connect(dlg.accept)
        buttonbox.rejected.connect(dlg.close)

        dlg.setLayout(layout)
        dlg.setWindowModality(Qt.WindowModal)

        if dlg.exec_():
            self.IDC_leAuthCfg.setText(acs.configId())
            self.cc.authcfg = acs.configId()
开发者ID:MonsantoCo,项目名称:QGIS-CKAN-Browser,代码行数:104,代码来源:ckan_browser_dialog_settings.py

示例2: __init__

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import check_api_url [as 别名]

#.........这里部分代码省略.........
        action.triggered.connect(callback)
        action.setEnabled(enabled_flag)

        if status_tip is not None:
            action.setStatusTip(status_tip)

        if whats_this is not None:
            action.setWhatsThis(whats_this)

        if add_to_toolbar:
            self.toolbar.addAction(action)

        if add_to_menu:
            self.iface.addPluginToMenu(
                self.menu,
                action)

        self.actions.append(action)

        return action

    def initGui(self):
        """Create the menu entries and toolbar icons inside the QGIS GUI."""

        icon_path = ':/plugins/CKANBrowser/icon.png'

        self.add_action(
            icon_path,
            text=self.util.tr(u'Open Data (CKAN) Browser'),
            callback=self.run,
            parent=self.iface.mainWindow()
        )
        
        icon_settings = ':/plugins/CKANBrowser/icon-settings.png'
        
        self.add_action(
            icon_settings,
            text=self.util.tr(u'ckan_browser_settings'),
            callback=self.open_settings,
            parent=self.iface.mainWindow()
        )

    def unload(self):
        """Removes the plugin menu item and icon from QGIS GUI."""
        for action in self.actions:
            self.iface.removePluginMenu(
                self.util.tr(u'&Open Data (CKAN) Browser'),
                action)
            self.iface.removeToolBarIcon(action)

    def run(self):
        """Run method that performs all the real work"""
        
        is_open = QSettings().value("ckan_browser/isopen", False)
        #Python treats almost everything as True````
        #is_open = bool(is_open)
        self.util.msg_log(u'isopen: {0}'.format(is_open))
        
        #!!!string comparison - Windows and Linux treat it as string, Mac as bool
        # so we convert string to bool
        if isinstance(is_open, basestring):
            is_open = self.util.str2bool(is_open)
        
        if is_open:
            self.util.msg_log(u'Dialog already opened')
            return
        
        # auf URL testen
        dir_check = self.util.check_dir(self.settings.cache_dir)
        api_url_check = self.util.check_api_url(self.settings.ckan_url)
        if dir_check is False or api_url_check is False:
            dlg = CKANBrowserDialogSettings(self.settings, self.iface, self.iface.mainWindow())
            dlg.show()
            result = dlg.exec_()
            if result != 1:
                return

#         self.util.msg_log('cache_dir: {0}'.format(self.settings.cache_dir))

        try: 
            QSettings().setValue("ckan_browser/isopen", True)
            self.dlg = CKANBrowserDialog(self.settings, self.iface, self.iface.mainWindow())
            
            # show the dialog
            self.dlg.show()
            #self.dlg.open()
            # Run the dialog event loop
            result = self.dlg.exec_()
            # See if OK was pressed
            if result:
                # Do something useful here - delete the line containing pass and
                # substitute with your code.
                pass
        finally: 
            QSettings().setValue("ckan_browser/isopen", False)

    def open_settings(self):
        dlg = CKANBrowserDialogSettings(self.settings, self.iface, self.iface.mainWindow())
        dlg.show()
        dlg.exec_()
开发者ID:BergWerkGIS,项目名称:QGIS-CKAN-Browser,代码行数:104,代码来源:ckan_browser.py


注:本文中的util.Util.check_api_url方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。