Пример #1
0
 def __init__(self, img, **kwargs):
     self.mouseListeners = []
     if not kwargs.has_key('StyleName'):
         kwargs['StyleName'] = 'gwt-HyperlinkImage'
     Hyperlink.__init__(self, **kwargs)
     DOM.appendChild(DOM.getFirstChild(self.getElement()), img.getElement())
     img.unsinkEvents(Event.ONCLICK | Event.MOUSEEVENTS)
     self.sinkEvents(Event.ONCLICK | Event.MOUSEEVENTS)
Пример #2
0
    def onBrowserEvent(self, event):
        type = DOM.eventGetType(event)
        if type == 'mousedown' or type == 'mouseup' or type == 'mousemove' or type == 'mouseover' or type == 'mouseout':
            MouseListener.fireMouseEvent(self.mouseListeners, self, event)
            # stop event falling through esp. for drag on image
            DOM.eventPreventDefault(event)

        else:
            Hyperlink.onBrowserEvent(self, event)
Пример #3
0
    def __init__(self,format='%d-%m-%Y'):
        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()
        img = Image("icon_calendar.gif")
        img.addStyleName("calendar-img")
        self.calendarLink = HyperlinkImage(img)
        self.todayLink = Hyperlink('Today')
        self.todayLink.addStyleName("calendar-today-link")
        #
        # 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"))
Пример #4
0
    def __init__(self, format="%d-%m-%Y"):
        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, targetHistoryToken=History.getToken())
        self.todayLink = Hyperlink(self.today_text, targetHistoryToken=History.getToken())
        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"))
Пример #5
0
class DateField(Composite):

    def __init__(self,format='%d-%m-%Y'):
        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()
        img = Image("icon_calendar.gif")
        img.addStyleName("calendar-img")
        self.calendarLink = HyperlinkImage(img)
        self.todayLink = Hyperlink('Today')
        self.todayLink.addStyleName("calendar-today-link")
        #
        # 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"))

    def getTextBox(self):
        return self.tbox

    def getCalendar(self):
        return self.calendar

    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)

    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
            self.tbox.setText( text[0:2] + self.sep + text[2:4] + self.sep + text[4:8] )

    def onFocus(self, sender):
        pass

    def onTodayClicked(self, event):
        today = time.strftime(self.format)
        self.tbox.setText( today )

    def onShowCalendar(self, sender):
        p = CalendarPopup(self.calendar)
        x = self.tbox.getAbsoluteLeft() + 10
        y = self.tbox.getAbsoluteTop() + 10
        p.setPopupPosition(x,y)
        p.show()
Пример #6
0
    def drawFull(self, month, year):
        # should be called only once when we draw the calendar for the first time
        #
        self.vp = VerticalPanel()
        self.vp.setSpacing(2)
        self.vp.addStyleName("calendarbox calendar-module calendar")
        self.setWidget(self.vp)
        self.setVisible(False)
        #
        mth = int(month)
        yr = int(year)

        tp = HorizontalPanel()
        tp.addStyleName("calendar-top-panel")
        tp.setSpacing(5)

        h1 = Hyperlink('<<')
        h1.addClickListener( getattr(self,'onPreviousYear') )
        h2 = Hyperlink('<')
        h2.addClickListener( getattr(self,'onPreviousMonth') )
        h4 = Hyperlink('>')
        h4.addClickListener( getattr(self,'onNextMonth') )
        h5 = Hyperlink('>>')
        h5.addClickListener( getattr(self,'onNextYear') )

        tp.add(h1)
        tp.add(h2)

        # titlePanel can be changed, whenever we draw, so keep the reference

        self.titlePanel = SimplePanel()
        self.titlePanel.setWidget(HTML("<b>" + self.monthsOfYear[mth-1] + " " + str(yr) + "</b>" ) )
        self.titlePanel.setStyleName("calendar-center")

        tp.add( self.titlePanel )
        tp.add(h4)
        tp.add(h5)
        tvp = VerticalPanel()
        tvp.setSpacing(10)
        tvp.add(tp)

        self.vp.add(tvp)

        # done with top panel

        self.middlePanel = SimplePanel()
        grid = self.drawGrid(mth,yr)
        self.middlePanel.setWidget(grid)
        self.vp.add(self.middlePanel)
        self.defaultGrid = grid
        #
        # some links & handlers
        #
        bh1 = Hyperlink('Yesterday')
        bh1.addClickListener( getattr(self,'onYesterday') )
        bh2 = Hyperlink('Today')
        bh2.addClickListener( getattr(self,'onToday') )
        bh3 = Hyperlink('Tomorrow')
        bh3.addClickListener( getattr(self,'onTomorrow') )
        bh4 = Hyperlink('Cancel')
        bh4.addClickListener( getattr(self,'onCancel') )
        #
        # add code to test another way of doing the layout
        #
        b = HorizontalPanel()
        b.add(bh1)
        b.add(bh2)
        b.add(bh3)
        b.addStyleName("calendar-shortcuts")
        self.vp.add(b)
        b2 = SimplePanel()
        b2.add(bh4)
        b2.addStyleName("calendar-cancel")
        self.vp.add(b2)

        self.setVisible(True)
        return