Skip to content

Commit

Permalink
- added missing changes to Calendar
Browse files Browse the repository at this point in the history
- added example which shows DateField usage
  • Loading branch information
maho committed Jul 22, 2012
1 parent 9ec8e81 commit 078e5a6
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 10 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -20,3 +20,6 @@ __output__


.lock* .lock*
.waf* .waf*
/.project
/.pydevproject
/.settings
3 changes: 3 additions & 0 deletions examples/datefield/DateField.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pyjamas.ui.TextBox import TextBox from pyjamas.ui.TextBox import TextBox
from pyjamas.ui.Button import Button from pyjamas.ui.Button import Button
from pyjamas.ui.Calendar import DateField, Calendar, CalendarPopup from pyjamas.ui.Calendar import DateField, Calendar, CalendarPopup
from pyjamas.ui.MonthField import MonthField


class App: class App:
def onModuleLoad(self): def onModuleLoad(self):
Expand All @@ -17,12 +18,14 @@ def onModuleLoad(self):
df2 = DateField(format='%Y/%m/%d') df2 = DateField(format='%Y/%m/%d')
b = Button("Show Calendar", self) b = Button("Show Calendar", self)
self.cal = Calendar() self.cal = Calendar()
df3 = MonthField()


vp = VerticalPanel() vp = VerticalPanel()
vp.setSpacing(10) vp.setSpacing(10)
vp.add(df1) vp.add(df1)
vp.add(b) vp.add(b)
vp.add(df2) vp.add(df2)
vp.add(df3)


RootPanel().add(vp) RootPanel().add(vp)


Expand Down
2 changes: 1 addition & 1 deletion examples/datefield/public/DateField.html
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<head> <head>
<meta name="pygwt:module" content="DateField"> <meta name="pygwt:module" content="DateField">
<link rel='stylesheet' href='DateField.css'> <link rel='stylesheet' href='DateField.css'>
<title>Calendar Example</title> <title>Calendar and Monthfield Example</title>
</head> </head>
<body bgcolor="white"> <body bgcolor="white">
<script language="javascript" src="bootstrap.js"></script> <script language="javascript" src="bootstrap.js"></script>
Expand Down
35 changes: 26 additions & 9 deletions library/pyjamas/ui/Calendar.py
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from pyjamas import DOM from pyjamas import DOM


import time import time
from datetime import datetime from datetime import datetime, date


class Calendar(FocusPanel): class Calendar(FocusPanel):
monthsOfYear = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', monthsOfYear = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
Expand Down Expand Up @@ -200,6 +200,17 @@ def drawFull(self, month, year):
self.middlePanel.setWidget(grid) self.middlePanel.setWidget(grid)
self.vp.add(self.middlePanel) self.vp.add(self.middlePanel)
self.defaultGrid = grid self.defaultGrid = grid

self._gridShortcutsLinks()
self._gridCancelLink()
#
# add code to test another way of doing the layout
#
self.setVisible(True)
return

def _gridShortcutsLinks(self):

# #
# some links & handlers # some links & handlers
# #
Expand All @@ -209,25 +220,23 @@ def drawFull(self, month, year):
bh2.addClickListener(getattr(self, 'onToday')) bh2.addClickListener(getattr(self, 'onToday'))
bh3 = Hyperlink(self.tomorrow) bh3 = Hyperlink(self.tomorrow)
bh3.addClickListener(getattr(self, 'onTomorrow')) bh3.addClickListener(getattr(self, 'onTomorrow'))
bh4 = Hyperlink(self.cancel)
bh4.addClickListener(getattr(self, 'onCancel'))
#
# add code to test another way of doing the layout
#
b = HorizontalPanel() b = HorizontalPanel()
b.add(bh1) b.add(bh1)
b.add(bh2) b.add(bh2)
b.add(bh3) b.add(bh3)
b.addStyleName("calendar-shortcuts") b.addStyleName("calendar-shortcuts")
self.vp.add(b) self.vp.add(b)

def _gridCancelLink(self):
bh4 = Hyperlink(self.cancel)
bh4.addClickListener(getattr(self, 'onCancel'))

b2 = SimplePanel() b2 = SimplePanel()
b2.add(bh4) b2.add(bh4)
b2.addStyleName("calendar-cancel") b2.addStyleName("calendar-cancel")
self.vp.add(b2) self.vp.add(b2)


self.setVisible(True)
return

def drawGrid(self, month, year): def drawGrid(self, month, year):
# draw the grid in the middle of the calendar # draw the grid in the middle of the calendar


Expand Down Expand Up @@ -438,6 +447,14 @@ def getTextBox(self):
def getCalendar(self): def getCalendar(self):
return self.calendar 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): def setID(self, id):
self.tbox.setID(id) self.tbox.setID(id)


Expand Down

0 comments on commit 078e5a6

Please sign in to comment.