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


Python Button.setText方法代码示例

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


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

示例1: GettextExample

# 需要导入模块: from pyjamas.ui.Button import Button [as 别名]
# 或者: from pyjamas.ui.Button.Button import setText [as 别名]
class GettextExample(object):

    def __init__(self):
        self.b = Button(_("Click me"), self.greet, StyleName='teststyle')
        self.h = HTML(_("<b>Hello World</b> (html)"), StyleName='teststyle')
        self.l = Label(_("Hello World (label)"), StyleName='teststyle')
        self.base = HTML(_("Hello from %s") % pygwt.getModuleBaseURL(),
                         StyleName='teststyle')
        RootPanel().add(self.b)
        RootPanel().add(self.h)
        RootPanel().add(self.l)
        RootPanel().add(self.base)

    def change_texts(self, text):
        self.b.setText(_("Click me"))
        self.h.setHTML(_("<b>Hello World</b> (html)"))
        self.l.setText(_("Hello World (label)"))
        text = [_("Hello from %s") % pygwt.getModuleBaseURL()]
        for i in range(4):
            text.append(ngettext('%(num)d single', '%(num)d plural', i) % dict(num=i))
        text = '<br />'.join(text)
        self.base.setHTML(text)

    def greet(self, fred):
        fred.setText(_("No, really click me!"))
        Window.alert(_("Hello, there!"))
        i18n.load(lang=lang[0], onCompletion=self.change_texts)
        lang.append(lang.pop(0))
开发者ID:Afey,项目名称:pyjs,代码行数:30,代码来源:Gettext.py

示例2: __init__

# 需要导入模块: from pyjamas.ui.Button import Button [as 别名]
# 或者: from pyjamas.ui.Button.Button import setText [as 别名]
class pjBallot:
    
    def __init__(self):
        self.mainPanel = VerticalPanel()
        self.contest = HorizontalPanel()
        self.contest.setStyleName('words')
        self.selection = HorizontalPanel()
        self.selection.setStyleName('words')
        self.button = Button('test', self.test)
        self.x = 1
    
    def test(self):
        self.button.setText("No, really click me!")
#        Window.alert("Hello, AJAAAX!")
        self.contest.add(HTML('yay'))

    def nextContest(self):
        self.x += 1
        self.contest.clear()
        self.contest.add(HTML('<b /> Contest: %d' % self.x))

    def nextSelection(self):
        self.x += 1
        self.selection.clear()
        self.selection.add(HTML('<b /> Selection: %d' % self.x))
    
    def onKeyDown(self, sender, keycode, modifiers):
        pass

    def onKeyUp(self, sender, keycode, modifiers):
        pass

    def onKeyPress(self, sender, keycode, modifiers):
        DOM.eventPreventDefault(DOM.eventGetCurrentEvent()) #not needed
        if keycode == KeyboardListener.KEY_UP:
            self.nextContest()
        if keycode == KeyboardListener.KEY_DOWN:
            self.nextContest()
        if keycode == KeyboardListener.KEY_LEFT:
            self.nextSelection()
        if keycode == KeyboardListener.KEY_RIGHT:
            self.nextSelection()

    def onModuleLoad(self):
        h = HTML("<b />Contest: ")
        self.contest.add(h)
        l = HTML("<b />Selection: ")
        self.selection.add(l)
#        self.mainPanel.add(self.button)
        self.mainPanel.add(self.contest)
        self.mainPanel.add(self.selection)
        
        panel = FocusPanel(Widget=self.mainPanel)
        gp = RootPanelListener(panel)
        manageRootPanel(gp)
        RootPanel().add(panel)
        panel.setFocus(True)
开发者ID:kurifu,项目名称:Old-CMUSV-Voting,代码行数:59,代码来源:pjBallot.py

示例3: Timer

# 需要导入模块: from pyjamas.ui.Button import Button [as 别名]
# 或者: from pyjamas.ui.Button.Button import setText [as 别名]
class Clock:

    # pyjamas doesn't generate __doc__
    __doc__ = '''This demonstrates using Timer instantiated with the
    notify keyword, as in:<pre> timer = Timer(notify=func) </pre>When
    the timer fires it will call func() with no arguments (or
    <code>self</code> if it is a bound method as in this example).
    This timer is scheduled with the <code>scheduleRepeating()</code>
    method, so after func() is called, it is automatically rescheduled
    to fire again after the specified period.  The timer can be
    cancelled by calling the <code>cancel()</code> method; this
    happens when you click on the button.
    '''

    
    start_txt = 'Click to start the clock'
    stop_txt = 'Click to stop the clock'
    
    def __init__(self):

        # the button
        self.button = Button(listener=self)
        # set an attr on the button to keep track of its state
        self.button.stop = False
        # date label
        self.datelabel = Label(StyleName='clock')
        # the timer
        self.timer = Timer(notify=self.updateclock)
        # kick start
        self.onClick(self.button)

    def onClick(self, button):
        if self.button.stop:
            # we're stopping the clock
            self.button.stop = False
            self.timer.cancel()
            self.button.setText(self.start_txt)
        else:
            # we're starting the clock
            self.button.stop = True
            self.timer.scheduleRepeating(1000)
            self.button.setText(self.stop_txt)

    def updateclock(self, timer):

        # the callable attached to the timer with notify
        dt = datetime.now().replace(microsecond=0)
        self.datelabel.setText(dt.isoformat(' '))
开发者ID:anandology,项目名称:pyjamas,代码行数:50,代码来源:timerdemo.py

示例4: ContentItemToolbar

# 需要导入模块: from pyjamas.ui.Button import Button [as 别名]
# 或者: from pyjamas.ui.Button.Button import setText [as 别名]
class ContentItemToolbar(HorizontalPanel):
    def __init__(self, contentitem, onPublish, onLike, onDislike):
        """Create a ContentItemToolbar.

        Event handlers should be methods that take: sender
        """
        HorizontalPanel.__init__(self)
        self.contentitem = contentitem
        self.publishBtn = Button('Publish', listener=onPublish, StyleName=Styles.TOOLBAR_BUTTON)
        self.add(self.publishBtn)
        self.likeBtn = Button('FOO', listener=onLike, StyleName=Styles.TOOLBAR_BUTTON)
        self.add(self.likeBtn)
        self.dislikeBtn = Button('Dislike', listener=onDislike, StyleName=Styles.TOOLBAR_BUTTON)
        self.add(self.dislikeBtn)
        self.updateStatusFromItem()
        return
    def updateStatusFromItem(self, updatedItem=None):
        if updatedItem:
            self.contentitem = updatedItem
        likes = self.contentitem['metadata']['likes']
        self.likeBtn.setText('Like (%s)' % likes)
        isPublished = self.contentitem['metadata']['is_published']
        self.publishBtn.setStyleName(Styles.TOOLBAR_BUTTON_PUBLISHED if isPublished else Styles.TOOLBAR_BUTTON)
开发者ID:satyam07,项目名称:taoggregator,代码行数:25,代码来源:feedpublisherwebui.py

示例5: makeLink

# 需要导入模块: from pyjamas.ui.Button import Button [as 别名]
# 或者: from pyjamas.ui.Button.Button import setText [as 别名]
 def makeLink(self):
     link = Button()
     link.setText("+ Add another")
     return link
开发者ID:anandology,项目名称:pyjamas,代码行数:6,代码来源:DNDTest.py

示例6: UserForm

# 需要导入模块: from pyjamas.ui.Button import Button [as 别名]
# 或者: from pyjamas.ui.Button.Button import setText [as 别名]
class UserForm(AbsolutePanel):

    MODE_ADD    = "modeAdd";
    MODE_EDIT   = "modeEdit";

    user = None
    mode = None

    usernameInput = None
    firstInput = None
    lastInput = None
    emailInput = None
    passwordInput = None
    confirmInput = None
    departmentCombo = None
    addBtn = None
    cancelBtn = None

    def __init__(self,parent):
        AbsolutePanel.__init__(self)
        ftable = FlexTable()

        ftable.setWidget(0, 0, Label("First Name", wordWrap=False))
        ftableFormatter = ftable.getFlexCellFormatter()
        self.firstInput = TextBox()
        self.firstInput.addChangeListener(self.checkValid)
        self.firstInput.addKeyboardListener(self)
        ftable.setWidget(0, 1, self.firstInput)

        ftable.setWidget(1, 0, Label("Last Name", wordWrap=False))
        self.lastInput = TextBox()
        self.lastInput.addChangeListener(self.checkValid)
        self.lastInput.addKeyboardListener(self)
        ftable.setWidget(1, 1, self.lastInput)

        ftable.setWidget(2, 0, Label("Email", wordWrap=False))
        self.emailInput = TextBox()
        self.emailInput.addChangeListener(self.checkValid)
        self.emailInput.addKeyboardListener(self)
        ftable.setWidget(2, 1, self.emailInput)

        w = Label("* Username", wordWrap=False)
        w.addMouseListener(TooltipListener("Required, not changable"))
        ftable.setWidget(3, 0, w)
        self.usernameInput = TextBox()
        self.usernameInput.addChangeListener(self.checkValid)
        self.usernameInput.addKeyboardListener(self)
        ftable.setWidget(3, 1, self.usernameInput)

        w = Label("* Password", wordWrap=False)
        w.addMouseListener(TooltipListener("Required"))
        ftable.setWidget(4, 0, w)
        self.passwordInput = PasswordTextBox()
        self.passwordInput.addChangeListener(self.checkValid)
        self.passwordInput.addKeyboardListener(self)
        ftable.setWidget(4, 1, self.passwordInput)

        w = Label("* Confirm", wordWrap=False)
        w.addMouseListener(TooltipListener("Required"))
        ftable.setWidget(5, 0, w)
        self.confirmInput = PasswordTextBox()
        self.confirmInput.addChangeListener(self.checkValid)
        self.confirmInput.addKeyboardListener(self)
        ftable.setWidget(5, 1, self.confirmInput)

        w = Label("* Department", wordWrap=False)
        w.addMouseListener(TooltipListener("Required"))
        ftable.setWidget(6, 0, w)
        self.departmentCombo = ListBox()
        self.departmentCombo.addChangeListener(self.checkValid)
        self.departmentCombo.addKeyboardListener(self)
        ftable.setWidget(6, 1, self.departmentCombo)

        hpanel = HorizontalPanel()
        self.addBtn = Button("Add User")
        self.addBtn.setEnabled(False)
        hpanel.add(self.addBtn)
        self.cancelBtn = Button("Cancel")
        hpanel.add(self.cancelBtn)
        ftable.setWidget(7, 0, hpanel)
        ftableFormatter.setColSpan(7, 0, 2)

        self.add(ftable)
        self.clearForm()
        return

    def clearForm(self):
        self.user = None
        self.usernameInput.setText('')
        self.firstInput.setText('')
        self.lastInput.setText('')
        self.emailInput.setText('')
        self.passwordInput.setText('')
        self.confirmInput.setText('')
        self.departmentCombo.setItemTextSelection(None)
        self.updateMode(self.MODE_ADD)
        self.checkValid()

    def updateUser(self, user):
        def setText(elem, value):
#.........这里部分代码省略.........
开发者ID:Afey,项目名称:pyjs,代码行数:103,代码来源:components.py

示例7: __init__

# 需要导入模块: from pyjamas.ui.Button import Button [as 别名]
# 或者: from pyjamas.ui.Button.Button import setText [as 别名]
class PjBallot:
    def __init__(self):
        self.mainPanel = VerticalPanel()      
        self.button = Button('test', self.test)
        self.status = Label('hi')
        self.x = 1
        self.srace = Race('', '', [], '')
    
    def test(self):
        self.button.setText("No, really click me!")
        self.contest.add(HTML('yay'))

    def onKeyDown(self, sender, keycode, modifiers):
        #print "inside onKeyDown, self is", self, "sender is", sender, "keycode is", keycode
        #self.mainPanel.add(keycode)
        pass

    def onKeyUp(self, sender, keycode, modifiers):
        pass

    def onModuleLoad(self):
        print "inside onModuleLoad"
        self.remote_py = JSONService()
        self.mainPanel.add(sampleBallot.title)
        self.mainPanel.add(sampleBallot.instructions)
        self.mainPanel.add(sampleBallot.contest)
        self.mainPanel.add(sampleBallot.candidate)
        self.mainPanel.add(sampleBallot.selection)
        self.mainPanel.add(sampleBallot.status)
        panel = FocusPanel(Widget=self.mainPanel)
        gp = RootPanelListener(panel)
        manageRootPanel(gp)
        RootPanel().add(panel)
        panel.setFocus(True)
        self.remote_py.passBallot(self)
            
    def onRemoteResponse(self, response, request_info):     
        print "inside onRemoteResponse"
        print response  
        self.srace = response  
        sampleBallot.sendRace(self.srace)
        #sampleBallot.instructions.clear()
        #sampleBallot.title.add(HTML('Name: %s' % self.srace.name))
        #sampleBallot.instructions.add(HTML('Instruction: %s' %  self.srace.instructions))
        #inst = sampleBallot.getInstruction()
        #self.mainPanel.add(HTML()
        sampleBallot.fsm.startVoting()
        sampleBallot.currObj = sampleBallot.race.selectionList[0]
        #sampleBallot.playAudio()
        sampleBallot.setContest()

    def onRemoteError(self, code, errobj, request_info):
        # onRemoteError gets the HTTP error code or 0 and
        # errobj is an jsonrpc 2.0 error dict:
        #     {
        #       'code': jsonrpc-error-code (integer) ,
        #       'message': jsonrpc-error-message (string) ,
        #       'data' : extra-error-data
        #     }
        message = errobj['message']
        if code != 0:
            self.status.setText("HTTP error %d: %s" % (code, message))
            print "HTTP error %d: %s" % (code, message)
        else:
            code = errobj['code']
            self.status.setText("JSONRPC Error %s: %s" % (code, message))
            print "JSONRPC Error %s: %s: %s" % (code, message, data)
开发者ID:simbara,项目名称:Voting,代码行数:69,代码来源:pjBallot.py

示例8: __init__

# 需要导入模块: from pyjamas.ui.Button import Button [as 别名]
# 或者: from pyjamas.ui.Button.Button import setText [as 别名]
class pjBallot:
    
    def __init__(self):
        self.mainPanel = VerticalPanel()
        self.contest = HorizontalPanel()
        self.contest.setStyleName('words')
        self.selection = HorizontalPanel()
        self.selection.setStyleName('words')
        self.button = Button('test', self.test)
        self.status = Label('hi')
        self.x = 1
    
    def test(self):
        self.button.setText("No, really click me!")
#        Window.alert("Hello, AJAAAX!")
        self.contest.add(HTML('yay'))

    def nextContest(self):
        self.x += 1
        self.contest.clear()
        self.contest.add(HTML('<b /> Contest: %d' % self.x))

    def nextSelection(self):
        self.x += 1
        self.selection.clear()
        self.selection.add(HTML('<b /> Selection: %d' % self.x))
    
    def onKeyDown(self, sender, keycode, modifiers):
        pass

    def onKeyUp(self, sender, keycode, modifiers):
        pass

    def onKeyPress(self, sender, keycode, modifiers):
        DOM.eventPreventDefault(DOM.eventGetCurrentEvent()) #not needed
        if keycode == KeyboardListener.KEY_UP:
            self.nextContest()
        if keycode == KeyboardListener.KEY_DOWN:
            self.nextContest()
        if keycode == KeyboardListener.KEY_LEFT:
            self.nextSelection()
        if keycode == KeyboardListener.KEY_RIGHT:
            self.nextSelection()


    def onModuleLoad(self):
        self.remote_py = JSONService()
        h = HTML("<b />Contest: ")
        self.contest.add(h)
        l = HTML("<b />Selection: ")
        self.selection.add(l)
#        self.mainPanel.add(self.button)
        self.mainPanel.add(self.contest)
        self.mainPanel.add(self.selection)
        self.mainPanel.add(self.status)
        panel = FocusPanel(Widget=self.mainPanel)
        gp = RootPanelListener(panel)
        manageRootPanel(gp)
        RootPanel().add(panel)
        panel.setFocus(True)
#        self.remote_py.uppercase('yay', self)
        self.remote_py.passBallot(self)
        
#        encoded_object = '[{"__jsonclass__": "Candidate.Candidate", "name": "Barack Obama"}]'
##        test = json2.loads(encoded_object)
##        self.mainPanel.add(HTML("%s" % test))#json.loads(encoded_object)))#, object_hook=self.dict_to_object)))
#        foo = '["foo", {"bar":["baz", null, 1.0, 2]}]'
#        bar = loads(foo, object_hook=tester)
#        self.mainPanel.add(HTML(bar))

 
    def dict_to_object(self,d):
        Window.alert("Hello, AJAAAX!")
        self.mainPanel.add(HTML('whatevs: %s' % 12))
        if '__class__' in d:
            # import pdb
            # pdb.set_trace()
            class_name = d.pop('__class__')
            module_name = d.pop('__module__')
            module = __import__(module_name)
            print 'MODULE:', module
            class_ = getattr(module.ballotTree, class_name) #because module was just audioBallot
            print 'CLASS:', class_
            args = dict( (key.encode('ascii'), value) for key, value in d.items())
            print 'INSTANCE ARGS:', args
            inst = class_(**args)
        else:
            inst = d
        return inst       
    

    
    def onRemoteResponse(self, response, request_info): 
        race = response  
        name = race.works
        self.mainPanel.add(HTML('pleasework %s' % name))
#        self.mainPanel.add(HTML('pleasework2 %s' % JSONResponseTextHandler(response)))
#        test = JSONResponseTextHandler(response)
#        test.request
#        self.mainPanel.add(HTML('pleasework3 %s' % test.name))
#.........这里部分代码省略.........
开发者ID:simbara,项目名称:Old-Voting,代码行数:103,代码来源:pjBallot.py


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