IOStatusPanel.py :  » Network » Grail-Internet-Browser » grail-0.6 » ancillary » 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 » Network » Grail Internet Browser 
Grail Internet Browser » grail 0.6 » ancillary » IOStatusPanel.py
from Tkinter import *
import tktools

class IOStatusPanel:

    def __init__(self, app):
        self.app = app
        self.id = None
        self.create_widgets()
        self.update()

    def create_widgets(self):
        self.top = tktools.make_toplevel(self.app.root,
                                         title="Grail: I/O Status",
                                         class_="IOStatusPanel")
        self.closebutton = Button(self.top, name="close", command=self.close,
                                  default="active")
        self.closebutton.pack(side=BOTTOM, pady='1m', padx='1m', anchor=E)
        self.closebutton.focus_set()
        self.infobox, self.frame = tktools.make_list_box(self.top, width=40)
        self.infobox.pack(expand=1, fill=BOTH, side=TOP)
        self.top.protocol('WM_DELETE_WINDOW', self.close)
        self.top.bind("<Alt-w>", self.close)
        self.top.bind("<Alt-W>", self.close)

    def close(self, event=None):
        self.cancel_update()
        top = self.top
        self.top = self.closebutton = self.infobox = None
        if top:
            top.destroy()

    def reopen(self):
        if self.top:
            self.top.deiconify()
            self.top.tkraise()
        else:
            self.create_widgets()
            self.update()

    def schedule_update(self):
        self.cancel_update()
        self.id = self.top.after(1000, self.call_update)

    def call_update(self):
        self.id = None
        self.update()

    def cancel_update(self):
        id = self.id
        self.id = None
        if id:
            if self.top:
                self.top.after_cancel(id)

    def update(self):
        if self.top:
            self.fill_info()
            self.schedule_update()

    def fill_info(self):
        count = 0
        self.infobox.delete(0, END)
        for browser in self.app.browsers:
            count = count+1
            headline = "<Browser %d>" % count
            self.infobox.insert(END, headline)
            self.add_context_info(browser.context)

    def add_context_info(self, context, level=1):
        indent = "   " * level
        headline = context.get_url() or "<no document>"
        if context.viewer.name:
            headline = "%s: %s" % (context.viewer.name, headline)
        self.infobox.insert(END, indent + headline)
        for reader in context.readers:
            self.add_reader_info(reader, level+1)
        for viewer in context.viewer.subviewers:
            subcontext = viewer.context
            if subcontext is not context:
                self.add_context_info(subcontext, level+1)

    def add_reader_info(self, reader, level):
        indent = "   " * level
        headline = str(reader)
        self.infobox.insert(END, indent + headline)
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.