PageRenderTime 43ms CodeModel.GetById 35ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/mail/Mail.py

http://pyjamas.googlecode.com/
Python | 90 lines | 50 code | 17 blank | 23 comment | 1 complexity | 33c0b92bb884da35fafb37b59103fa35 MD5 | raw file
 1# import com.google.gwt.core.client.EntryPoint;
 2# import com.google.gwt.user.client.Command;
 3# import com.google.gwt.user.client.DeferredCommand;
 4import Window
 5# import com.google.gwt.user.client.WindowResizeListener;
 6from DeferredCommand import DeferredCommand
 7from ui import DockPanel, RootPanel, VerticalPanel
 8from MailDetail import MailDetail
 9from Shortcuts import Shortcuts
10from MailList import MailList
11from TopPanel import TopPanel
12from Logger import Logger
13
14class Mail:
15
16    def get(self):
17        return self.singleton
18
19    def onModuleLoad(self):
20        self.singleton = self
21
22        topPanel = TopPanel()
23        rightPanel = VerticalPanel()
24        self.mailDetail = MailDetail()
25        self.shortcuts = Shortcuts()
26
27        topPanel.setWidth("100%")
28
29        # MailList uses Mail.get() in its constructor, so initialize it after
30        # 'singleton'.
31        mailList = MailList(self.singleton)
32        mailList.setWidth("100%")
33        
34        # Create the right panel, containing the email list & details.
35        rightPanel.add(mailList)
36        rightPanel.add(self.mailDetail)
37        mailList.setWidth("100%")
38        self.mailDetail.setWidth("100%")
39
40        # Create a dock panel that will contain the menu bar at the top,
41        # the shortcuts to the left, and the mail list & details taking the rest.
42        outer = DockPanel()
43        outer.add(topPanel, DockPanel.NORTH)
44        outer.add(self.shortcuts, DockPanel.WEST)
45        outer.add(rightPanel, DockPanel.CENTER)
46        outer.setWidth("100%")
47
48        outer.setSpacing(4)
49        outer.setCellWidth(rightPanel, "100%")
50
51        # Hook the window resize event, so that we can adjust the UI.
52        #FIXME need implementation # Window.addWindowResizeListener(this)
53        #Window.addWindowResizeListener(self)
54
55        # Get rid of scrollbars, and clear out the window's built-in margin,
56        # because we want to take advantage of the entire client area.
57        Window.enableScrolling(False)
58        Window.setMargin("0px")
59        
60        # Finally, add the outer panel to the RootPanel, so that it will be
61        # displayed.
62        #RootPanel.get().add(outer) # FIXME get#
63        RootPanel().add(outer)
64        RootPanel().add(Logger())
65        
66        # Call the window resized handler to get the initial sizes setup. Doing
67        # this in a deferred command causes it to occur after all widgets' sizes
68        # have been computed by the browser.
69
70        DeferredCommand().add(self)
71
72    def execute(self):
73        self.onWindowResized(Window.getClientWidth(), Window.getClientHeight())
74
75    def onWindowResized(self, width, height):
76        # Adjust the shortcut panel and detail area to take up the available room
77        # in the window.
78        #Logger("Window resized", "width: " + width+ ", height: " + height)
79
80        shortcutHeight = height - self.shortcuts.getAbsoluteTop() - 8
81        if (shortcutHeight < 1):
82            shortcutHeight = 1
83        self.shortcuts.setHeight("" + shortcutHeight)
84
85        # Give the mail detail widget a chance to resize itself as well.
86        self.mailDetail.adjustSize(width, height)
87
88    def displayItem(self, item):
89        self.mailDetail.setItem(item)
90