Hi,

I made my first pyjamas widget, based on DateField (attached), for selecting month instead of full date.

All PyJS guru - please look at it, and tell me:
- what did I do wrong/against pyj(ama)s philosophy there,
- what to do with it? should such widget go into pyj(ama)s code, or rather keep it somewhere available outside the pyjs?

--
pozdrawiam

Ɓukasz Mach
Pagema (http://www.pagema.net)

from pyjamas import Window
from pyjamas.ui.Calendar import DateField,Calendar
from pyjamas.ui.Button import Button

try:
    from locale import _
except ImportError:
    _ = lambda x:x

class NoDaysCalendar(Calendar):
    
    cancel = _("Cancel")
    monthsOfYear = [_('Jan'), _('Feb'), _('Mar'), _('Apr'), _('May'), _('Jun'), 
                    _('Jul'), _('Aug'), _('Sep'), _('Oct'), _('Nov'), _('Dec')]
    
    yesterday = ""
    tomorrow = ""
    today = _("Current")
    
    
    def drawGrid(self,month,year):
        button = Button(_("Choose"),self.onMonthSelected)
        self.middlePanel.setWidget(button)
        return button
        
    def onMonthSelected(self,event):
        self.onDate(event,self.currentYear,self.currentMonth,1)

class MonthField(DateField):
    icon_img = "gfx/ts_picker/cal.gif"
    today_text = _("Current")
    
    def __init__(self):
        super(MonthField,self).__init__(format="%Y-%m")
        self.calendar = NoDaysCalendar()
        self.calendar.addSelectedDateListener(getattr(self,"onDateSelected"))

Reply via email to