MenuMediator.py :  » Ajax » pyjamas » src » examples » timesheet » view » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Ajax » pyjamas 
pyjamas » src » examples » timesheet » view » MenuMediator.py

# vim: set ts=4 sw=4 expandtab:

from puremvc.patterns.mediator import Mediator

from ApplicationConstants import Notification

from pyjamas.Window import alert
from model.TimeProxy import TimeProxy
from view.components.FileOpenDlg import FileOpenDlg
from view.components.PreferencesDlg import PreferencesDlg
from view.components.HelpContentsDlg import HelpContentsDlg
from view.components.HelpAboutDlg import HelpAboutDlg
from pyjamas.Cookies import getCookie

import sys
from pyjamas.Window import alert
from __pyjamas__ import wnd

import base64

class MenuMediator(Mediator):

    NAME = 'MenuMediator'
    fileLocation = None

    def __init__(self, viewComponent):
        Mediator.__init__(self, MenuMediator.NAME, viewComponent)
        viewComponent.mFileOpen.setHandler(self.onFileOpen)
        viewComponent.mFileSaveAs.setHandler(self.onFileSaveAs)
        viewComponent.mFilePreferences.setHandler(self.onFilePreferences)
        viewComponent.mViewEdit.setHandler(self.onViewEdit)
        viewComponent.mViewSummary.setHandler(self.onViewSummary)
        viewComponent.mHelpContents.setHandler(self.onHelpContents)
        viewComponent.mHelpAbout.setHandler(self.onHelpAbout)
        self.timeProxy = self.facade.retrieveProxy(TimeProxy.NAME)
        try:
            fileLocation = getCookie("fileLocation")
        except:
            fileLocation = None
        self.fileLocation = self.checkFileLocation(fileLocation)
        self.onFileOpen(self.fileLocation)

    def listNotificationInterests(self):
        return []

    def handleNotification(self, note):
        pass

    def checkFileLocation(self, fileLocation):
        if fileLocation is None \
           or fileLocation is "null":
            fileLocation = "timesheet.txt"
        return fileLocation

    def onFileOpen(self, fileLocation = None):
        try:
            dlg = None

            def onOpen(sender):
                self.sendNotification(Notification.FILE_LOADED, 
                                      (dlg.filename, dlg.data))

            fileLocation = self.checkFileLocation(fileLocation)
            dlg = FileOpenDlg(fileLocation = fileLocation)
            dlg.openBtn.addClickListener(onOpen)
            dlg.show()
        except:
            raise

    def onFileSaveAs(self):
        data = self.timeProxy.exportData()
        data_uri = 'data:text/plain;base64,%s' % base64.encodestring(data)
        wnd = wnd().open('','_blank','scrollbars=yes,width=300,height=300')
        wnd.document.open("text/html")
        wnd.document.write("""<a href="%s">Right click here</a> if your browser supports data uri<br />Otherwise, you'll have to copy and paste this output to a text file<br />\n""" % data_uri)
        wnd.document.write("<pre>")
        wnd.document.write(data)
        wnd.document.write("</pre>")
        wnd.document.close()

    def onFilePreferences(self):
        dlg = PreferencesDlg()
        dlg.mediator = self
        dlg.show()

    def onViewEdit(self):
        self.sendNotification(Notification.EDIT_SELECTED)

    def onViewSummary(self):
        self.sendNotification(Notification.SUM_SELECTED)

    def onHelpContents(self):
        dlg = HelpContentsDlg()
        dlg.mediator = self
        dlg.show()

    def onHelpAbout(self):
        dlg = HelpAboutDlg()
        dlg.mediator = self
        dlg.show()
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.