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


Python TextBox.addInputListener方法代码示例

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


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

示例1: __init__

# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addInputListener [as 别名]
class SongFrequency:

    def __init__(self):
        self.artist =''
        self.start_date = ''
        self.end_date = ''
        self.period_search =''
        self.search_option = 1
        #declare the general interface widgets
        self.panel = DockPanel(StyleName = 'background')
        self.ret_area = TextArea()
        self.ret_area.setWidth("350px")
        self.ret_area.setHeight("90px")
        self.options = ListBox()

        self.search_button = Button("Search", getattr(self, "get_result"), StyleName = 'button')

        #set up the date search panel; it has different text boxes for
        #to and from search dates
        self.date_search_panel = VerticalPanel()
        self.date_search_start = TextBox()
        self.date_search_start.addInputListener(self)
        self.date_search_end = TextBox()
        self.date_search_end.addInputListener(self)
        
        self.date_search_panel.add(HTML("Enter as month/day/year", True, StyleName = 'text'))
        self.date_search_panel.add(HTML("From:", True, StyleName = 'text'))
        self.date_search_panel.add(self.date_search_start)
        self.date_search_panel.add(HTML("To:", True, StyleName = 'text'))
        self.date_search_panel.add(self.date_search_end)
        #set up the artist search panel
        self.artist_search = TextBox()
        self.artist_search.addInputListener(self)
        self.artist_search_panel = VerticalPanel()
        self.artist_search_panel.add(HTML("Enter artist's name:",True,
                                          StyleName = 'text'))
        self.artist_search_panel.add(self.artist_search)

        #Put together the list timespan search options
        self.period_search_panel = VerticalPanel()
        self.period_search_panel.add(HTML("Select a seach period:",True,
                                          StyleName = 'text'))
        self.period_search = ListBox()
        self.period_search.setVisibleItemCount(1)
        self.period_search.addItem("last week")
        self.period_search.addItem("last month")
        self.period_search.addItem("last year")
        self.period_search.addItem("all time")
        self.period_search_panel.add(self.period_search)
        #add the listeners to the appropriate widgets
        self.options.addChangeListener(self)
        self.period_search.addChangeListener(self)
        self.ret_area_scroll = ScrollPanel()
        self.search_panel = HorizontalPanel()
        self.options_panel = VerticalPanel()

    # A change listener for the boxes
    def onChange(self, sender):
        #switch the list box options
        if sender == self.options:
            self.search_panel.remove(self.period_search_panel)
            self.search_panel.remove(self.date_search_panel)
            self.search_panel.remove(self.artist_search_panel)

            index = self.options.getSelectedIndex()

            if index == 0:
                self.search_panel.add(self.artist_search_panel)
                self.search_option = 1
            elif index == 1:
                self.search_panel.add(self.date_search_panel)
                self.search_option = 2
            elif index == 2:
                self.search_panel.add(self.period_search_panel)
                self.search_option = 3

        elif sender == self.period_search:
            index = self.period_search.getSelectedIndex()
            if index == 0:
                self.period_search = "last week"
            elif index == 1:
                self.period_search = "last month"
            elif index == 2:
                self.period_search = "last year"
            elif index == 3:
                self.period_search = "all time"

    #A listener for the text boxes            
    def onInput(self, sender):
        if sender == self.artist_search:
            self.artist = sender.getText()
        elif sender == self.date_search_end:
            self.end_date = sender.getText()
        elif sender == self.date_search_start:
            self.start_date = sender.getText()

    #A listener for the buttons that, when the button is clicked, looks up the results and outputs them
    def get_result(self):
        return_str = " "
        if self.search_option == 1:
#.........这里部分代码省略.........
开发者ID:jiangl,项目名称:WQHS-Web-Crawler,代码行数:103,代码来源:Widget.py

示例2: DateField

# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addInputListener [as 别名]
class DateField(Composite, DateSelectedHandler):

    img_base = None
    icon_img = None

    icon_style = "calendar-img"
    today_text = "Today"
    today_style = "calendar-today-link"

    def __init__(self, format='%d-%m-%Y'):
        DateSelectedHandler.__init__(self)
        if self.img_base is None:
            self.img_base = pygwt.getImageBaseURL(True)
        if self.icon_img is None:
            self.icon_img = self.img_base + 'icon_calendar.gif'
        self.format = format
        self.tbox = TextBox()
        self.tbox.setVisibleLength(10)
        # assume valid sep is - / . or nothing
        if format.find('-') >= 0:
            self.sep = '-'
        elif format.find('/') >= 0:
            self.sep = '/'
        elif format.find('.') >= 0:
            self.sep = '.'
        else:
            self.sep = ''
        # self.sep = format[2] # is this too presumptious?
        self.calendar = Calendar()
        self.img = Image(self.icon_img)
        self.img.addStyleName(self.icon_style)
        self.calendarLink = HyperlinkImage(self.img)
        self.todayLink = Hyperlink(self.today_text)
        self.todayLink.addStyleName(self.today_style)
        #
        # lay it out
        #
        hp = HorizontalPanel()
        hp.setSpacing(2)
        vp = VerticalPanel()
        hp.add(self.tbox)
        vp.add(self.calendarLink)
        vp.add(self.todayLink)
        #vp.add(self.calendar)
        hp.add(vp)

        Composite.__init__(self)
        self.initWidget(hp)
        #
        # done with layout, so now set up some listeners
        #
        self.tbox.addFocusListener(self) # hook to onLostFocus
        self.calendar.addSelectedDateListener(getattr(self, "onDateSelected"))
        self.todayLink.addClickListener(getattr(self, "onTodayClicked"))
        self.calendarLink.addClickListener(getattr(self, "onShowCalendar"))

        self.tbox.addChangeListener(getattr(self, "onFieldChanged"))
        self.tbox.addInputListener(getattr(self, "onFieldChanged"))

        self._last_date = None

    def emitSelectedDate(self):
        _d = self.getDate()
        if _d == self._last_date:
            return
        self._last_date = _d
        self.fireDateSelectedEvent(_d)

    def onFieldChanged(self, event):
        self.emitSelectedDate()

    def getTextBox(self):
        return self.tbox

    def getCalendar(self):
        return self.calendar

    def getDate(self):
        """ returns datetime.date object or None if empty/unparsable by current format"""
        _sdate = self.tbox.getText()
        try:
            return datetime.strptime(_sdate, self.format).date()
        except ValueError:
            return None

    def setID(self, id):
        self.tbox.setID(id)

    def onDateSelected(self, yyyy, mm, dd):
        secs = time.mktime((int(yyyy), int(mm), int(dd), 0, 0, 0, 0, 0, -1))
        d = time.strftime(self.format, time.localtime(secs))
        self.tbox.setText(d)
        self.emitSelectedDate()

    def onLostFocus(self, sender):
        #
        text = self.tbox.getText().strip()
        # if blank - leave it alone
        if text and len(text) == 8:
            # ok what format do we have? assume ddmmyyyy --> dd-mm-yyyy
#.........这里部分代码省略.........
开发者ID:Afey,项目名称:pyjs,代码行数:103,代码来源:Calendar.py

示例3: Spinner

# 需要导入模块: from pyjamas.ui.TextBox import TextBox [as 别名]
# 或者: from pyjamas.ui.TextBox.TextBox import addInputListener [as 别名]
class Spinner(HorizontalPanel):
    CHAR_WIDTH = 15
    def __init__(self, minvalue=0, maxvalue=100, startvalue=10, interval=1, buttonStyleName=None, decrText='<',
                 incrText='>', **kwargs):
        HorizontalPanel.__init__(self, **kwargs)
        self.minvalue = minvalue
        self.maxvalue = maxvalue
        self.interval = interval
        self.changeListeners = []

        self.lessButton = Button(decrText, listener=self._onArrowClick, StyleName=buttonStyleName)
        self.add(self.lessButton)
        self.textbox = TextBox()
        self.textbox.addInputListener(self._onTextboxInput)
        self.add(self.textbox)

        self.moreButton = Button(incrText, listener=self._onArrowClick, StyleName=buttonStyleName)
        self.add(self.moreButton)

        self.value = startvalue + 1
        self.setValue(startvalue)
        return
    def _resizeTextbox(self):
        width = max(2, len(self.textbox.getText())) * self.CHAR_WIDTH
        if self.textbox.getWidth() != width:
            self.textbox.setWidth(width)
    def _onArrowClick(self, sender):
        if sender == self.lessButton:
            incr = -1 * self.interval
        elif sender == self.moreButton:
            incr = self.interval
        else:
            raise NotImplementedError()
        val = self.getValue() + incr
        self.setValue(val)
    def _onTextboxInput(self, sender):
        text = sender.getText()
        try:
            val = int(text)
        except Exception:
            return
        self.setValue(val)
        return
    def addOnChangeListener(self, listener):
        self.changeListeners.append(listener)
    def removeOnChangeListener(self, listener):
        self.changeListeners.remove(listener)
    def getValue(self):
        return self.value
    def setValue(self, value):
        fixedval = min(self.maxvalue, value)
        fixedval = max(self.minvalue, fixedval)
        if fixedval == self.value:
            return
        self.value = fixedval
        self.textbox.setText(str(self.value))
        self._resizeTextbox()
        self.raiseOnChanged()
    def raiseOnChanged(self):
        for c in self.changeListeners:
            c(self.value)
开发者ID:satyam07,项目名称:taoggregator,代码行数:63,代码来源:commoncontrols.py


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