~divmod-dev/divmod.org/dangling-1091

« back to all changes in this revision

Viewing changes to Reverend/reverend/ui/util.py

  • Committer: washort
  • Date: 2005-10-25 18:49:27 UTC
  • Revision ID: svn-v4:866e43f7-fbfc-0310-8f2a-ec88d1da2979:trunk:2573
import Reverend

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# This module is part of the Divmod project and is Copyright 2003 Amir Bakhtiar:
 
2
# amir@divmod.org.  This is free software; you can redistribute it and/or
 
3
# modify it under the terms of version 2.1 of the GNU Lesser General Public
 
4
# License as published by the Free Software Foundation.
 
5
#
 
6
 
 
7
from Tkinter import *
 
8
 
 
9
class StatusBar(Frame):
 
10
    """Courtesy of Fredrik Lundh.
 
11
    """
 
12
 
 
13
    def __init__(self, master):
 
14
        Frame.__init__(self, master)
 
15
        self.label = Label(self, bd=1, relief=SUNKEN, anchor=W)
 
16
        self.label.pack(fill=X)
 
17
 
 
18
    def set(self, format, *args):
 
19
        self.label.config(text=format % args)
 
20
        self.label.update_idletasks()
 
21
 
 
22
    def clear(self):
 
23
        self.label.config(text="")
 
24
        self.label.update_idletasks()
 
25
 
 
26
    def log(self, text, clear=0):
 
27
        # Clear after clear seconds
 
28
        self.set('%s', text)
 
29
        if clear:
 
30
            self.label.after(clear * 1000, self.clear)
 
31
 
 
32
    
 
33
class Command:
 
34
    """Courtesy of Danny Yoo
 
35
    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66521
 
36
    """
 
37
    def __init__(self, callback, *args, **kwargs):
 
38
        self.callback = callback
 
39
        self.args = args
 
40
        self.kwargs = kwargs
 
41
 
 
42
    def __call__(self):
 
43
        return apply(self.callback, self.args, self.kwargs)
 
44
    
 
45
class Notebook:
 
46
    """Courtesy of Iuri Wickert
 
47
    http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/188537
 
48
    """
 
49
    
 
50
    # initialization. receives the master widget
 
51
    # reference and the notebook orientation
 
52
    def __init__(self, master, side=LEFT):
 
53
        self.active_fr = None
 
54
        self.count = 0
 
55
        self.choice = IntVar(0)
 
56
 
 
57
        # allows the TOP and BOTTOM
 
58
        # radiobuttons' positioning.
 
59
        if side in (TOP, BOTTOM):
 
60
            self.side = LEFT
 
61
        else:
 
62
            self.side = TOP
 
63
 
 
64
        # creates notebook's frames structure
 
65
        self.rb_fr = Frame(master, borderwidth=2, relief=RIDGE)
 
66
        self.rb_fr.pack(side=side, fill=BOTH)
 
67
        self.screen_fr = Frame(master, borderwidth=2, relief=RIDGE)
 
68
        self.screen_fr.pack(fill=BOTH)
 
69
            
 
70
 
 
71
    # return a master frame reference for the external frames (screens)
 
72
    def __call__(self):
 
73
        return self.screen_fr
 
74
 
 
75
            
 
76
    # add a new frame (screen) to the (bottom/left of the) notebook
 
77
    def add_screen(self, fr, title):
 
78
        b = Radiobutton(self.rb_fr, text=title, indicatoron=0, \
 
79
            variable=self.choice, value=self.count, \
 
80
            command=lambda: self.display(fr))
 
81
        b.pack(fill=BOTH, side=self.side)
 
82
        
 
83
        # ensures the first frame will be
 
84
        # the first selected/enabled
 
85
        if not self.active_fr:
 
86
            fr.pack(fill=BOTH, expand=1)
 
87
            self.active_fr = fr
 
88
 
 
89
        self.count += 1
 
90
            
 
91
            
 
92
    # hides the former active frame and shows 
 
93
    # another one, keeping its reference
 
94
    def display(self, fr):
 
95
        self.active_fr.forget()
 
96
        fr.pack(fill=BOTH, expand=1)
 
97
        self.active_fr = fr
 
98