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) self.todayLink = Hyperlink(today_text) self.todayLink.addStyleName(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"))
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 __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"))
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()
class DateField(Composite): icon_img = "icon_calendar.gif" icon_style = "calendar-img" today_text = "Today" today_style = "calendar-today-link" 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) self.todayLink = Hyperlink(today_text) self.todayLink.addStyleName(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")) 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()