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


Python Util.tr方法代码示例

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


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

示例1: CKANBrowserDialogDisclaimer

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import tr [as 别名]
class CKANBrowserDialogDisclaimer(QtGui.QDialog, FORM_CLASS):
    def __init__(self, settings, parent=None):
        """Constructor."""
        super(CKANBrowserDialogDisclaimer, self).__init__(parent)
        # Set up the user interface from Designer.
        # After setupUI you can access any designer object by doing
        # self.<objectname>, and you can use autoconnect slots - see
        # http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
        # #widgets-and-dialogs-with-auto-connect
        self.setModal(True)
        self.setupUi(self)
        self.main_win = parent
        self.settings = settings
        self.util = Util(self.settings, self.main_win)
        
        logo_path = self.util.resolve(u'ckan_logo_big.png')
        self.IDC_lblLogo.setPixmap(QtGui.QPixmap(logo_path))
        self.IDC_brInfo.setOpenExternalLinks(True)
        self.IDC_brInfo.setHtml(self.util.tr('py_disc_info_html'))
开发者ID:BergWerkGIS,项目名称:QGIS-CKAN-Browser,代码行数:21,代码来源:ckan_browser_dialog_disclaimer.py

示例2: CKANBrowserDialog

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import tr [as 别名]
class CKANBrowserDialog(QtGui.QDialog, FORM_CLASS):

    def __init__(self, settings, iface, parent=None):
        """Constructor."""
        super(CKANBrowserDialog, self).__init__(parent)
        # Set up the user interface from Designer.
        # After setupUI you can access any designer object by doing
        # self.<objectname>, and you can use autoconnect slots - see
        # http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
        # #widgets-and-dialogs-with-auto-connect
        self.setupUi(self)
        self.iface = iface
        self.main_win = parent
        self.search_txt = ''
        self.cur_package = None
        self.result_count = 0
        self.current_page = 1
        self.page_count = 0
        self.current_group = None
        # TODO:
        # * create settings dialog
        # * read SETTINGS

        self.settings = settings
        self.util = Util(self.settings, self.main_win)

        self.IDC_lblApiUrl.setText(self.util.tr('py_dlg_base_server') + self.settings.ckan_url)
        self.IDC_lblCacheDir.setText(self.util.tr('py_dlg_base_cache_path') + self.settings.cache_dir)
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
        # TODO: automatically populate version
        # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!111
        self.IDC_lblVersion.setText(self.util.tr('py_dlg_base_version').format(self.settings.version))
        self.IDC_lblSuchergebnisse.setText(self.util.tr('py_dlg_base_search_result'))
        self.IDC_lblPage.setText(self.util.tr('py_dlg_base_page_1_1'))

        icon_path = self.util.resolve(u'icon-copy.png')
        self.IDC_bCopy.setIcon(QtGui.QIcon(icon_path))

        self.cc = CkanConnector(self.settings, self.util)

        self.timer = QTimer()
        self.timer.setSingleShot(True)
        self.timer.timeout.connect(self.window_loaded)
        QApplication.setOverrideCursor(Qt.WaitCursor)

    def showEvent(self, event):
        self.util.msg_log('showevent')
        QDialog.showEvent(self, event)
        if self.timer is not None:
            self.timer.start(500)
        self.util.msg_log('showevent finished')

    def window_loaded(self):
        try:
            self.util.msg_log('window_loaded')
            self.util.msg_log('before stop')
            self.timer.stop()
            self.timer = None
            self.util.msg_log('before get_groupds')
            ok, result = self.cc.get_groups()
            if ok is False:
                QApplication.restoreOverrideCursor()
                self.util.dlg_warning(result)
                return

            if not result:
                self.list_all_clicked()
            else:
                for entry in result:
                    item = QListWidgetItem(entry['display_name'])
                    item.setData(Qt.UserRole, entry)
                    #item.setCheckState(Qt.Checked)
                    item.setCheckState(Qt.Unchecked)
                    self.IDC_listGroup.addItem(item)
        finally:
            QApplication.restoreOverrideCursor()


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


    def show_disclaimer(self):
        self.dlg_disclaimer = CKANBrowserDialogDisclaimer(self.settings)
        self.dlg_disclaimer.show()

    def searchtextchanged(self, search_txt):
        self.search_txt = search_txt

    def suchen(self):
        self.current_page = 1
        self.current_group = None
        self.__search_package()

    def list_all_clicked(self):
        self.current_page = 1
        self.current_group = None
        # don't hint on wildcards, empty text works as well, as CKAN uses *:* as
        # default when ?q= has not text
        # self.IDC_lineSearch.setText('*:*')
#.........这里部分代码省略.........
开发者ID:MonsantoCo,项目名称:QGIS-CKAN-Browser,代码行数:103,代码来源:ckan_browser_dialog.py

示例3: CKANBrowserDialogSettings

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import tr [as 别名]
class CKANBrowserDialogSettings(QtGui.QDialog, FORM_CLASS):
    def __init__(self, settings, iface, parent=None):
        """Constructor."""
        super(CKANBrowserDialogSettings, self).__init__(parent)
        # Set up the user interface from Designer.
        # After setupUI you can access any designer object by doing
        # self.<objectname>, and you can use autoconnect slots - see
        # http://qt-project.org/doc/qt-4.8/designer-using-a-ui-file.html
        # #widgets-and-dialogs-with-auto-connect
        self.setupUi(self)
        self.iface = iface
        self.main_win = parent
        self.settings = settings
        self.util = Util(self.settings, self.main_win)

        self.IDC_leCacheDir.setText(self.settings.cache_dir)
        self.IDC_leCkanApi.setText(self.settings.ckan_url)
        if QgsAuthConfigSelect is None:
            self.IDC_leAuthCfg.hide()
            self.IDC_bAuthCfgClear.hide()
            self.IDC_bAuthCfgEdit.hide()
            self.IDC_lblAuthCfg.hide()
            self.IDC_cbAuthPropagate.hide()
        else:
            if self.settings.authcfg:
                self.IDC_leAuthCfg.setText(self.settings.authcfg)
                self.IDC_cbAuthPropagate.setChecked(self.settings.auth_propagate)
            else:
                self.IDC_cbAuthPropagate.setChecked(False)

        self.cc = CkanConnector(self.settings, self.util)

        self.pre_ckan_apis = None
        self.fill_combobox();

    def fill_combobox(self):
        """ Fill Combobox with predefined CKAN API Urls """
        try:
            json_path = self.util.resolve(u'CKAN_APIs.json')
            with open(json_path) as json_file:
                self.pre_ckan_apis = json.load(json_file, object_pairs_hook=OrderedDict)

            for key in self.pre_ckan_apis.keys():
                self.IDC_cbPreCkanApi.addItem(key)

            value = self.pre_ckan_apis.itervalues().next()
            self.IDC_lblPreCkan.setText(value)

        except IOError as err:
            self.util.dlg_warning(self.util.tr(u"py_dlg_set_warn_urls_not_load").format(err))


    def select_cache_dir(self):
        cache_dir = QFileDialog.getExistingDirectory(
            self.main_win,
            self.settings.DLG_CAPTION,
            self.settings.cache_dir,
            QFileDialog.ShowDirsOnly | QFileDialog.DontResolveSymlinks
        )
        if '' == cache_dir:
            self.util.msg_log('no cachedir selected')
        else:
            self.IDC_leCacheDir.setText(cache_dir)


    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):
#.........这里部分代码省略.........
开发者ID:MonsantoCo,项目名称:QGIS-CKAN-Browser,代码行数:103,代码来源:ckan_browser_dialog_settings.py

示例4: __init__

# 需要导入模块: from util import Util [as 别名]
# 或者: from util.Util import tr [as 别名]
class CKANBrowser:
    """QGIS Plugin Implementation."""

    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
        """
        QSettings().setValue("ckan_browser/isopen", False)
        # Save reference to the QGIS interface
        self.iface = iface
        # initialize plugin directory
        self.plugin_dir = os.path.dirname(__file__)
        # initialize locale
        locale = QSettings().value('locale/userLocale')[0:2]
        locale_path = os.path.join(
            self.plugin_dir,
            'i18n',
            'CKANBrowser_{}.qm'.format(locale))
        
        # load english file for testing
#         locale_path = os.path.join(
#             self.plugin_dir,
#             'i18n',
#             'CKANBrowser_en.qm')
        
        if not os.path.exists(locale_path):
            locale_path = os.path.join(
                self.plugin_dir,
                'i18n',
                'CKANBrowser_en.qm')
        
        if os.path.exists(locale_path):
            self.translator = QTranslator()
            self.translator.load(locale_path)

            if qVersion() > '4.3.3':
                QCoreApplication.installTranslator(self.translator)

        self.settings = Settings()
        self.settings.load()
        self.util = Util(self.settings, self.iface.mainWindow())

        # TODO ping API

        # Create the dialog (after translation) and keep reference
#         self.dlg = CKANBrowserDialog(self.settings, self.iface, self.iface.mainWindow())

        # Declare instance attributes
        self.actions = []
        self.menu = self.util.tr(u'&Open Data (CKAN) Browser')
        # TODO: We are going to let the user set this up in a future iteration
        self.toolbar = self.iface.addToolBar(u'Open Data (CKAN) Browser')
        self.toolbar.setObjectName(u'Open Data (CKAN) Browser')


    def add_action(
        self,
        icon_path,
        text,
        callback,
        enabled_flag=True,
        add_to_menu=True,
        add_to_toolbar=True,
        status_tip=None,
        whats_this=None,
        parent=None):
        """Add a toolbar icon to the InaSAFE toolbar.

        :param icon_path: Path to the icon for this action. Can be a resource
            path (e.g. ':/plugins/foo/bar.png') or a normal file system path.
        :type icon_path: str

        :param text: Text that should be shown in menu items for this action.
        :type text: str

        :param callback: Function to be called when the action is triggered.
        :type callback: function

        :param enabled_flag: A flag indicating if the action should be enabled
            by default. Defaults to True.
        :type enabled_flag: bool

        :param add_to_menu: Flag indicating whether the action should also
            be added to the menu. Defaults to True.
        :type add_to_menu: bool

        :param add_to_toolbar: Flag indicating whether the action should also
            be added to the toolbar. Defaults to True.
        :type add_to_toolbar: bool

        :param status_tip: Optional text to show in a popup when mouse pointer
            hovers over the action.
        :type status_tip: str

        :param parent: Parent widget for the new action. Defaults None.
        :type parent: QWidget
#.........这里部分代码省略.........
开发者ID:BergWerkGIS,项目名称:QGIS-CKAN-Browser,代码行数:103,代码来源:ckan_browser.py


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