Screen.py :  » Ajax » pyjamas » src » examples » shell » 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 » shell » Screen.py
from Popups import DialogBoxModal
from pyjamas.ui.AbsolutePanel import AbsolutePanel
from pyjamas import Window
from pyjamas import log

class Application(DialogBoxModal):
    def __init__(self, screen, title, width, height):
        DialogBoxModal.__init__(self, title, None, False, screen)
        self.screen = screen
        self.setText(title)
        self.dragged = False
        #self.setWidth(width)
        #self.setHeight(height)

    def onMouseDown(self, sender, x, y):
        #log.writebr("down %d %d" % (x, y))
        DialogBoxModal.onMouseDown(self, sender, x, y)
        self.dragged = False
        
    def onMouseMove(self, sender, x, y):
        #log.writebr("move %d %d" % (x, y))
        if self.dragStartX != x or self.dragStartY != y:
            if not self.dragged:
                self.screen.raise_app(self)
            self.dragged = True
        DialogBoxModal.onMouseMove(self, sender, x, y)

    def onMouseUp(self, sender, x, y):
        #log.writebr("up %d %d" % (x, y))
        DialogBoxModal.onMouseUp(self, sender, x, y)
        if not self.dragged:
            self.screen.raise_or_lower(self)

    def onClick(self, sender):
        if sender == self.closeButton:
            self.screen.close_app(self)

class Screen(AbsolutePanel):

    def __init__(self, width, height):

        AbsolutePanel.__init__(self)
        self.setWidth(width)
        self.setHeight(height)

        self.window = {}
        self.window_zindex = {}

    def add_app(self, app, title, width, height):

        sa = Application(self, title, width, height)
        sa.setWidget(app)
        self.window[title] = sa
        self.window_zindex[title] = len(self.window)-1

        return sa

    def set_app_zindex(self, title, zi):
        w = self.window[title]
        self.window_zindex[title] = zi
        w.setzIndex(zi)

    def lower_app(self, app):
        app_zi = self.window_zindex[app.identifier]
        for t in self.window_zindex.keys():
            w = self.window[t]
            zi = self.window_zindex[t]
            if zi < app_zi:
                self.set_app_zindex(t, zi+1)

        self.set_app_zindex(app.identifier, 0)

    def raise_app(self, app):
        app_zi = self.window_zindex[app.identifier]
        for t in self.window_zindex.keys():
            w = self.window[t]
            zi = self.window_zindex[t]
            if zi > app_zi:
                self.set_app_zindex(t, zi-1)

        app_zi = len(self.window)-1
        self.set_app_zindex(app.identifier, app_zi)

    def raise_or_lower(self, app):
        
        app_zi = self.window_zindex[app.identifier]
        if app_zi != len(self.window)-1:
            self.raise_app(app)
        else:
            self.lower_app(app)

    def close_app(self, app):
        
        app_zi = self.window_zindex[app.identifier]
        for t in self.window_zindex.keys():
            w = self.window[t]
            zi = self.window_zindex[t]
            if zi > app_zi:
                self.set_app_zindex(t, zi-1)

        t = self.window[app.identifier]
        if not self.remove(t):
            Window.alert("%s not in app" % app.identifier)
        t.hide()
        del self.window[app.identifier]
        del self.window_zindex[app.identifier]

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.