Permalink
Browse files

Added PureMVC example: timesheet

git-svn-id: https://pyjamas.svn.sourceforge.net/svnroot/pyjamas/trunk@1147 7a2bd370-bda8-463c-979e-2900ccfb811e
  • Loading branch information...
keesbos
keesbos committed Aug 11, 2009
1 parent 9861f26 commit f1571272bc927869721ec4276c60057bf5e0054d
@@ -0,0 +1,34 @@
+
+# vim: set ts=4 sw=4 expandtab:
+
+class Notification(object):
+
+ STARTUP = "startup"
+ SHOW_DIALOG = "showDialog"
+ HELLO = "hello"
+
+ # Menu
+ MENU_FILE_OPEN = "menuFileOpen"
+ MENU_FILE_SAVEAS = "menuFileSaveAs"
+ MENU_FILE_PREFS = "menuFilePreferences"
+ MENU_VIEW_EDIT = "menuViewEdit"
+ MENU_VIEW_SUM = "menuViewSummary"
+ MENU_HELP_CONTENTS = "menuHelpContents"
+ MENU_HELP_ABOUT = "menuHelpAbout"
+
+ FILE_LOADED = "fileLoaded"
+ EDIT_SELECTED = "editMode"
+ SUM_SELECTED = "summaryMode"
+
+ # Date picker
+ DISPLAY_DAY = "displayDay"
+ PREV_DAY = "previousDay"
+ NEXT_DAY = "nextDay"
+ PREV_WEEK = "previousWeek"
+ NEXT_WEEK = "nextWeek"
+ DATE_SELECTED = "dateSelected"
+
+ # Time Grid
+ CELL_SELECTED = "cellSelected"
+ CELL_UPDATED = "cellUpdated"
+
@@ -0,0 +1,39 @@
+try:
+ import puremvc.patterns.facade
+except:
+ from pyjamas.Window import alert
+ alert("""\
+This application depends on puremvc for python,\n\
+which doesn't seem to be available.\n\
+See README.
+""")
+
+from ApplicationConstants import Notification
+from controller.StartupCommand import StartupCommand
+from components.AppFrame import AppFrame
+
+class AppFacade(puremvc.patterns.facade.Facade):
+
+ def __init__(self):
+ self.initializeFacade()
+
+ @staticmethod
+ def getInstance():
+ return AppFacade()
+
+ def initializeFacade(self):
+ super(AppFacade, self).initializeFacade()
+ self.initializeController()
+
+ def initializeController(self):
+ super(AppFacade, self).initializeController()
+ super(AppFacade, self).registerCommand(Notification.STARTUP, StartupCommand)
+
+def main():
+ app = AppFacade.getInstance()
+ appFrame = AppFrame()
+ app.sendNotification(Notification.STARTUP, appFrame)
+
+if __name__ == '__main__':
+ main()
+
@@ -0,0 +1,19 @@
+#!/bin/sh
+options="$@"
+
+if [ -z "$DOWNLOADS" ] ; then
+ if echo $options |grep -- '--downloads-yes'>/dev/null ; then
+ DOWNLOADS=yes
+ export DOWNLOADS
+ options=`echo "$options"|sed 's/--downloads-yes//g'`
+ fi
+ if echo $options |grep -- '--downloads-no'>/dev/null ; then
+ DOWNLOADS=no
+ export DOWNLOADS
+ options=`echo "$options"|sed 's/--downloads-no//g'`
+ fi
+fi
+
+if (cd ../employeeadmin;./download.sh) ; then
+../../bin/pyjsbuild --library_dir "`pwd`/../employeeadmin/PureMVC_Python_1_0/src" $options TimeSheet
+fi
@@ -0,0 +1,56 @@
+
+# vim: set ts=4 sw=4 expandtab:
+
+from ApplicationConstants import Notification
+
+from pyjamas.ui.DockPanel import DockPanel
+from pyjamas.ui.RootPanel import RootPanelCls
+from pyjamas.ui.MenuBar import MenuBar
+from pyjamas.ui.MenuItem import MenuItem
+from pyjamas.ui.VerticalPanel import VerticalPanel
+
+from pyjamas.ui.Button import Button
+
+from components.Menu import Menu
+from components.DatePicker import DatePicker
+from components.TimeGrid import TimeGrid
+from components.Summary import Summary
+
+
+class AppFrame(RootPanelCls):
+
+ menuBar = None
+ datePicker = None
+ timeGrid = None
+ summary = None
+
+ def __init__(self):
+ try:
+ RootPanelCls.__init__(self)
+
+ vpanel = VerticalPanel()
+ self.menuBar = Menu()
+ vpanel.add(self.menuBar)
+
+ self.datePicker = DatePicker()
+ vpanel.add(self.datePicker)
+
+ self.timeGrid = TimeGrid()
+ vpanel.add(self.timeGrid)
+
+ self.summary = Summary()
+ vpanel.add(self.summary)
+
+ self.add(vpanel)
+ except:
+ raise
+
+ def onHello(self, sender):
+ self.mediator.sendNotification(Notification.HELLO)
+
+ def onOpen(self, sender):
+ self.mediator.sendNotification(Notification.MENU_FILE_OPEN)
+
+ def onSaveAs(self, sender):
+ self.mediator.sendNotification(Notification.MENU_FILE_SAVEAS)
+
@@ -0,0 +1,70 @@
+
+# vim: set ts=4 sw=4 expandtab:
+
+from ApplicationConstants import Notification
+
+from pyjamas.ui.HorizontalPanel import HorizontalPanel
+from pyjamas.ui.Button import Button
+from pyjamas.ui.TextBox import TextBox
+
+import time
+
+class DatePicker(HorizontalPanel):
+
+ time = None
+ dateBox = None
+
+ def __init__(self):
+ try:
+ HorizontalPanel.__init__(self)
+ self.time = time.time()
+
+ prevDayBtn = Button(" < ", self.onPrevDay)
+ nextDayBtn = Button(" > ", self.onNextDay)
+ prevWeekBtn = Button(" << ", self.onPrevWeek)
+ nextWeekBtn = Button(" >> ", self.onNextWeek)
+ self.dateBox = TextBox()
+ self.dateBox.setMaxLength(10)
+ self.dateBox.setVisibleLength(10)
+
+ self.add(prevWeekBtn)
+ self.add(prevDayBtn)
+ self.add(self.dateBox)
+ self.add(nextDayBtn)
+ self.add(nextWeekBtn)
+ except:
+ raise
+
+ def onPrevDay(self, sender):
+ self.mediator.sendNotification(Notification.PREV_DAY)
+
+ def onNextDay(self, sender):
+ self.mediator.sendNotification(Notification.NEXT_DAY)
+
+ def onPrevWeek(self, sender):
+ self.mediator.sendNotification(Notification.PREV_WEEK)
+
+ def onNextWeek(self, sender):
+ self.mediator.sendNotification(Notification.NEXT_WEEK)
+
+ def displayDay(self):
+ self.dateBox.setText(time.strftime("%d/%m/%Y", time.localtime(self.time)))
+ date = time.strftime("%Y%m%d", time.localtime(self.time))
+ self.mediator.sendNotification(Notification.DATE_SELECTED, date)
+
+ def prevDay(self):
+ self.time -= 86400
+ self.displayDay()
+
+ def nextDay(self):
+ self.time += 86400
+ self.displayDay()
+
+ def prevWeek(self):
+ self.time -= 7*86400
+ self.displayDay()
+
+ def nextWeek(self):
+ self.time += 7*86400
+ self.displayDay()
+
@@ -0,0 +1,127 @@
+
+# vim: set ts=4 sw=4 expandtab:
+
+from ApplicationConstants import Notification
+
+from pyjamas.ui.HorizontalPanel import HorizontalPanel
+from pyjamas.ui.VerticalPanel import VerticalPanel
+from pyjamas.ui.Label import Label
+from pyjamas.ui.Button import Button
+from pyjamas.ui.DialogBox import DialogBox
+from pyjamas.ui.FormPanel import FormPanel
+from pyjamas.ui.FileUpload import FileUpload
+from pyjamas.ui.HTML import HTML
+from pyjamas.ui.DockPanel import DockPanel
+from pyjamas.ui.Frame import Frame
+import pyjamas.DOM as DOM
+
+
+from pyjamas.Window import alert
+import sys
+
+has_getAsText = True
+
+class FileOpenDlg(DialogBox):
+
+ files = None
+
+ def __init__(self, left = 50, top = 50, fileLocation = None):
+ global has_getAsText
+ try:
+ DialogBox.__init__(self, modal = False)
+
+ self.setPopupPosition(left, top)
+ self.dockPanel = DockPanel()
+ self.dockPanel.setSpacing(4)
+ self.setText("File Open")
+
+ if not fileLocation is None:
+ msg = HTML("Loading file...", True)
+ self.dockPanel.add(msg, DockPanel.NORTH)
+ location = fileLocation
+ if fileLocation.find("://") < 0:
+ base = '' + doc().location
+ if base.find('/') >= 0:
+ sep = '/'
+ else:
+ sep = '\\'
+ base = sep.join(base.split(sep)[:-1]) + sep
+ location = base + fileLocation
+ self.iframe = Frame(location)
+ self.dockPanel.add(self.iframe, DockPanel.CENTER)
+ else:
+ msg = HTML("Choose a file", True)
+
+ self.browseFile = FileUpload()
+ elem = self.browseFile.getElement()
+ if False and has_getAsText and hasattr(elem, 'files'):
+ self.iframe = None
+ self.files = elem.files
+ self.dockPanel.add(self.browseFile, DockPanel.CENTER)
+ else:
+ self.browseFile = None
+ self.files = None
+ base = '' + doc().location
+ if base.find('/') >= 0:
+ sep = '/'
+ else:
+ sep = '\\'
+ if not base.lower()[:5] == "file:":
+ base = "file:///C:/"
+ msg = HTML("You'll have to place the application on a local file system, otherwise the browser forbids access.", True)
+ else:
+ base = sep.join(base.split(sep)[:-1]) + sep
+ self.iframe = Frame(base)
+ self.dockPanel.add(self.iframe, DockPanel.CENTER)
+ self.dockPanel.add(msg, DockPanel.NORTH)
+
+ if self.iframe:
+ self.iframe.setWidth("36em")
+ hpanel = HorizontalPanel()
+ self.openBtn = Button("Open", self)
+ hpanel.add(self.openBtn)
+ self.cancelBtn = Button("Cancel", self)
+ hpanel.add(self.cancelBtn)
+ self.dockPanel.add(hpanel, DockPanel.SOUTH)
+
+ self.setWidget(self.dockPanel)
+ except:
+ raise
+
+ def onClick(self, sender):
+ global has_getAsText
+ if sender == self.cancelBtn:
+ self.hide()
+ elif sender == self.openBtn:
+ data = None
+ filename = None
+ if self.files:
+ if self.files.length == 0:
+ return
+ if self.files.length > 1:
+ alert("Cannot open more than one file")
+ return
+ file = self.files.item(0)
+ filename = file.fileName
+ try:
+ data = file.getAsText("")
+ except AttributeError, e:
+ has_getAsText = False
+ alert("Sorry. cannot retrieve file in this browser.\nTry again.")
+ else:
+ elem = self.iframe.getElement()
+ # On firefox, this runs into:
+ # Permission denied to get property Window.document
+ # when the file is not in the current domain
+ body = elem.contentWindow.document.body
+ try:
+ filename = '' + elem.contentWindow.location
+ except:
+ filename = None
+ if body.childNodes.length == 1:
+ data = '' + body.childNodes.item(0).innerHTML
+ else:
+ data = '' + body.innerHTML
+ self.hide()
+ if data:
+ self.mediator.sendNotification(Notification.FILE_LOADED, (filename, data))
Oops, something went wrong.

0 comments on commit f157127

Please sign in to comment.