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


Python HTML.javascript方法代码示例

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


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

示例1: __init__

# 需要导入模块: from HTML import HTML [as 别名]
# 或者: from HTML.HTML import javascript [as 别名]

#.........这里部分代码省略.........
                    res += '&{0};'.format(K[V.index(char)])
                else:
                    res += char
            
        else:
            res = tmp
        
        # --- Convert newlines
        if newlines:
            res = str.replace(res, '\n', '<br>')
        
        # --- Return
        return res
      
    # ----------------------------------------------------------------------
    def truncate(self, s, limit=100, suffix='...'):
        '''
        Smart truncate
        
        Inputs:
            M (tuple) The text in many languages
        
        Output:
            The text in the current language
        '''
        if len(s) <= limit:
            return s
        else:
            return ' '.join(s[:limit+1].split(' ')[0:-1]) + suffix
    
    # ----------------------------------------------------------------------
    def redirect(self, location):
        '''
        Redirection (javascript based)
        
        Inputs:
            location (str) The new spot location
            
        Output
            None
        '''

        self.html.javascript('document.location.href="{0}"'.format(location))
        
    # ----------------------------------------------------------------------
    def language_chooser(self):
        '''
        Language chooser
        
        Inputs:
            -
            
        Output
            None
        '''
        
        # --- Store reference
        ref = self.html.ref
            
        # Language container
        self.html.div(0, id='language')
        
        if self.session.language != 'en':
            self.html.a(0, "?spot={0}&lang=en".format(self.settings.get('spot')))
            self.html.img(0, 'Core/Style/Icons/Flags/English.png')
        
开发者ID:LaboJeanPerrin,项目名称:Data.Manager,代码行数:69,代码来源:Spot.py

示例2: __init__

# 需要导入模块: from HTML import HTML [as 别名]
# 或者: from HTML.HTML import javascript [as 别名]

#.........这里部分代码省略.........
                    res += "&{0};".format(K[V.index(char)])
                else:
                    res += char

        else:
            res = tmp

        # --- Convert newlines
        if newlines:
            res = str.replace(res, "\n", "<br>")

        # --- Return
        return res

    # ----------------------------------------------------------------------
    def truncate(self, s, limit=100, suffix="..."):
        """
        Smart truncate
        
        Inputs:
            M (tuple) The text in many languages
        
        Output:
            The text in the current language
        """
        if len(s) <= limit:
            return s
        else:
            return " ".join(s[: limit + 1].split(" ")[0:-1]) + suffix

    # ----------------------------------------------------------------------
    def redirect(self, location):
        """
        Redirection (javascript based)
        
        Inputs:
            location (str) The new spot location
            
        Output
            None
        """

        self.html.javascript('document.location.href="{0}"'.format(location))

    # ----------------------------------------------------------------------
    def language_chooser(self):
        """
        Language chooser
        
        Inputs:
            -
            
        Output
            None
        """

        # --- Store reference
        ref = self.html.ref

        # Language container
        self.html.div(0, id="language")

        if self.session.language != "en":
            self.html.a(0, "?spot={0}&lang=en".format(self.settings.get("spot")))
            self.html.img(0, "Core/Style/Icons/Flags/English.png")
开发者ID:LaboJeanPerrin,项目名称:Lab.notes,代码行数:69,代码来源:Spot.py


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