當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。