Hi,
As promised (long time ago), I have added monthfield into pyjamas. Also,
added basic locale (poor man's gettext) support.
But it will be my second push to pyjamas repository, I would like to
check first, if I won't break anything/introduce too bad code by it.
Attached a diff. Tell me, do the push or fix something?
--
pozdrawiam
Łukasz Mach
Pagema (http://www.pagema.net)
diff --git a/.gitignore b/.gitignore
index 1765976..b4f120b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -9,5 +9,6 @@ output
*.pyo
.*.sw?
*.py~
+*.komodoproject
/stdlib
diff --git a/library/gwt/ui/Calendar.py b/library/gwt/ui/Calendar.py
index a7de3e1..94699f2 100644
--- a/library/gwt/ui/Calendar.py
+++ b/library/gwt/ui/Calendar.py
@@ -21,7 +21,7 @@ from pyjamas.ui import HasAlignment
from pyjamas import DOM
import time
-from datetime import datetime
+from datetime import datetime,date
class Calendar(FocusPanel):
monthsOfYear = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
@@ -49,7 +49,6 @@ class Calendar(FocusPanel):
return
-
def setDate(self,_date):
""" _date - object of datetime.date class """
self.currentMonth = _date.month
@@ -101,7 +100,6 @@ class Calendar(FocusPanel):
self.setVisible(True)
def drawCurrent(self):
- #yr, mth, day = time.strftime("%Y-%m-%d").split("-")
yr, mth, day = self.currentYear, self.currentMonth, self.currentDay
self.draw(int(mth), int(yr))
@@ -201,6 +199,18 @@ class Calendar(FocusPanel):
self.middlePanel.setWidget(grid)
self.vp.add(self.middlePanel)
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
#
@@ -210,24 +220,23 @@ class Calendar(FocusPanel):
bh2.addClickListener(getattr(self, 'onToday'))
bh3 = Hyperlink(self.tomorrow)
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.add(bh1)
b.add(bh2)
b.add(bh3)
b.addStyleName("calendar-shortcuts")
self.vp.add(b)
+
+ def _gridCancelLink(self):
+ bh4 = Hyperlink(self.cancel)
+ bh4.addClickListener(getattr(self, 'onCancel'))
+
b2 = SimplePanel()
b2.add(bh4)
b2.addStyleName("calendar-cancel")
self.vp.add(b2)
-
- self.setVisible(True)
- return
+
def drawGrid(self, month, year):
# draw the grid in the middle of the calendar
@@ -353,8 +362,6 @@ class Calendar(FocusPanel):
self.setVisible(False)
def drawDate(self, month, year):
- # if year == self.currentYear and month == self.currentYear():
- # self.drawCurrent()
self.currentMonth = month
self.currentYear = year
self.draw(self.currentMonth, self.currentYear)
@@ -440,6 +447,14 @@ class DateField(Composite):
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)
diff --git a/library/pyjamas/locale.py b/library/pyjamas/locale.py
new file mode 100644
index 0000000..add6fc6
--- /dev/null
+++ b/library/pyjamas/locale.py
@@ -0,0 +1,28 @@
+#encoding: utf8
+"""
+ (C) 2012 by Maho (?ukasz Mach)
+
+ License: GPL
+
+
+ Poor man's i18n support for Pyjamas.
+
+ _("identifier") returns you translated version of "identifier". If you want
+ original (English) version, just do nothing. If you want other language
+ (eg. PL), please import translation_pl in your project, when it's content
+ is:
+
+ from pyjamas.locale import msgs
+
+ msgs["Week"] = "Tydzień"
+ msgs["Jan"] = "Sty"
+ msgs["January"] = "Styczeń"
+ msgs["Other eng identifier you'd like to translate"] = "Inny ang. identyfikator który chciałbyś przetłumaczyć"
+
+"""
+
+msgs = {}
+
+def _(identifier):
+ return msgs.get(identifier,identifier)
+
\ No newline at end of file
diff --git a/library/pyjamas/ui/MonthField.py b/library/pyjamas/ui/MonthField.py
new file mode 100644
index 0000000..d1b673d
--- /dev/null
+++ b/library/pyjamas/ui/MonthField.py
@@ -0,0 +1,52 @@
+from pyjamas.ui.Calendar import DateField,Calendar
+from pyjamas.ui.Button import Button
+from pyjamas.ui.HorizontalPanel import HorizontalPanel
+from pyjamas.ui.Hyperlink import Hyperlink
+from pyjamas.ui.SimplePanel import SimplePanel
+
+from pyjamas.locale import _
+
+class NoDaysCalendar(Calendar):
+
+ cancel = _("Cancel")
+ monthsOfYear = [_('Jan'), _('Feb'), _('Mar'), _('Apr'), _('May'), _('Jun'),
+ _('Jul'), _('Aug'), _('Sep'), _('Oct'), _('Nov'), _('Dec')]
+
+
+
+ def drawGrid(self,month,year):
+ empty = SimplePanel()
+ return empty
+
+ def _gridShortcutsLinks(self):
+ bh1 = Hyperlink(_("Current"))
+ bh1.addClickListener(getattr(self, 'onToday'))
+
+ b2 = Button(_("Choose"),self.onMonthSelected)
+
+ bh3 = Hyperlink(self.cancel)
+ bh3.addClickListener(getattr(self, 'onCancel'))
+
+
+ b = HorizontalPanel()
+ b.addStyleName("calendar-shortcuts")
+ b.add(bh1)
+ b.add(b2)
+ b.add(bh3)
+
+ self.vp.add(b)
+
+ def _gridCancelLink(self):pass
+
+
+ def onMonthSelected(self,event):
+ self.onDate(event,self.currentYear,self.currentMonth,1)
+
+class MonthField(DateField):
+ today_text = _("Current")
+
+ def __init__(self):
+ super(MonthField,self).__init__(format="%Y-%m")
+ self.calendar = NoDaysCalendar()
+ self.calendar.addSelectedDateListener(getattr(self,"onDateSelected"))
+
diff --git a/pyjamas.komodoproject b/pyjamas.komodoproject
new file mode 100644
index 0000000..063e5cb
--- /dev/null
+++ b/pyjamas.komodoproject
@@ -0,0 +1,4 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Komodo Project File - DO NOT EDIT -->
+<project id="cd05bf7c-7f2d-4729-b437-45fc14e9420b" kpf_version="5" name="pyjamas.komodoproject">
+</project>