1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
<!DOCTYPE HTML PUBLIC "-//Netscape_Microsoft//DTD HTML 3.0//EN">
<HTML>
<!-- This file generated using the Python HTMLgen module. -->
<HEAD>
<META NAME="GENERATOR" CONTENT="HTMLgen 1.1">
<TITLE>PmwMessageBar.py</TITLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF">
<PRE>
<FONT COLOR="#DD0000"># Class to display messages in an information line.</FONT>
import Tkinter
import Pmw
<STRONG><FONT COLOR="#CC6600">class MessageBar</FONT></STRONG>(Pmw.MegaWidget):
<STRONG> def __init__</STRONG>(self, parent = None, **kw):
<FONT COLOR="#DD0000"># Define the megawidget options.</FONT>
INITOPT = Pmw.INITOPT
defaultMessageTypes = {
<FONT COLOR="#DD0000"># (priority, showtime, bells, logmessage)</FONT>
<FONT COLOR="#009900">'systemerror'</FONT> : (5, 10, 2, 1),
<FONT COLOR="#009900">'usererror'</FONT> : (4, 5, 1, 0),
<FONT COLOR="#009900">'busy'</FONT> : (3, 0, 0, 0),
<FONT COLOR="#009900">'systemevent'</FONT> : (2, 5, 0, 0),
<FONT COLOR="#009900">'userevent'</FONT> : (2, 5, 0, 0),
<FONT COLOR="#009900">'help'</FONT> : (1, 5, 0, 0),
<FONT COLOR="#009900">'state'</FONT> : (0, 0, 0, 0),
}
optiondefs = (
(<FONT COLOR="#009900">'labelmargin'</FONT>, 0, INITOPT),
(<FONT COLOR="#009900">'labelpos'</FONT>, None, INITOPT),
(<FONT COLOR="#009900">'messagetypes'</FONT>, defaultMessageTypes, INITOPT),
(<FONT COLOR="#009900">'silent'</FONT>, 0, None),
)
self.defineoptions(kw, optiondefs)
<FONT COLOR="#DD0000"># Initialise the base class (after defining the options).</FONT>
Pmw.MegaWidget.__init__(self, parent)
<FONT COLOR="#DD0000"># Create the components.</FONT>
interior = self.interior()
self._messageBarEntry = self.createcomponent(<FONT COLOR="#009900">'entry'</FONT>,
(), None,
Tkinter.Entry, (interior,), state = <FONT COLOR="#009900">'disabled'</FONT>)
self._messageBarEntry.grid(column=2, row=2, sticky=<FONT COLOR="#009900">'nsew'</FONT>)
interior.grid_columnconfigure(2, weight=1)
interior.grid_rowconfigure(2, weight=1)
self.createlabel(interior)
<FONT COLOR="#DD0000"># Initialise instance variables.</FONT>
self._numPriorities = 0
self._busyPriority = None
for messagetype, info in self[<FONT COLOR="#009900">'messagetypes'</FONT>].items():
if messagetype == <FONT COLOR="#009900">'busy'</FONT>:
self._busyPriority = info[0]
if self._numPriorities < info[0]:
self._numPriorities = info[0]
self._numPriorities = self._numPriorities + 1
self._timer = [None] * self._numPriorities
self._messagetext = [<FONT COLOR="#009900">''</FONT>] * self._numPriorities
self._activemessage = [0] * self._numPriorities
<FONT COLOR="#DD0000"># Check keywords and initialise options.</FONT>
self.initialiseoptions(MessageBar)
<STRONG> def destroy</STRONG>(self):
for timerId in self._timer:
if timerId is not None:
self.after_cancel(timerId)
self._timer = [None] * self._numPriorities
Pmw.MegaWidget.destroy(self)
<STRONG> def message</STRONG>(self, type, text):
<FONT COLOR="#DD0000"># Display a message in the message bar.</FONT>
(priority, showtime, bells, logmessage) = self[<FONT COLOR="#009900">'messagetypes'</FONT>][type]
if not self[<FONT COLOR="#009900">'silent'</FONT>]:
for i in range(bells):
self.bell()
self._activemessage[priority] = 1
if text is None:
text = <FONT COLOR="#009900">''</FONT>
self._messagetext[priority] = text
self._redisplayInfoMessage()
if logmessage:
<FONT COLOR="#DD0000"># Should log this text to a text widget.</FONT>
pass
if showtime > 0:
if self._timer[priority] is not None:
self.after_cancel(self._timer[priority])
<FONT COLOR="#DD0000"># Define a callback to clear this message after a time.</FONT>
<STRONG> def _clearmessage</STRONG>(self=self, priority=priority):
self._clearActivemessage(priority)
mseconds = int(showtime * 1000)
self._timer[priority] = self.after(mseconds, _clearmessage)
<STRONG> def helpmessage</STRONG>(self, text):
self.message(<FONT COLOR="#009900">'help'</FONT>, text)
<STRONG> def resetmessages</STRONG>(self, type):
priority = self[<FONT COLOR="#009900">'messagetypes'</FONT>][type][0]
self._clearActivemessage(priority)
for messagetype, info in self[<FONT COLOR="#009900">'messagetypes'</FONT>].items():
thisPriority = info[0]
showtime = info[1]
if thisPriority < priority and showtime != 0:
self._clearActivemessage(thisPriority)
<STRONG> def _clearActivemessage</STRONG>(self, priority):
self._activemessage[priority] = 0
if self._timer[priority] is not None:
self.after_cancel(self._timer[priority])
self._timer[priority] = None
self._redisplayInfoMessage()
<STRONG> def _redisplayInfoMessage</STRONG>(self):
text = <FONT COLOR="#009900">''</FONT>
for priority in range(self._numPriorities - 1, -1, -1):
if self._activemessage[priority]:
text = self._messagetext[priority]
break
self._messageBarEntry.configure(state = <FONT COLOR="#009900">'normal'</FONT>)
self._messageBarEntry.delete(0, <FONT COLOR="#009900">'end'</FONT>)
self._messageBarEntry.insert(<FONT COLOR="#009900">'end'</FONT>, text)
self._messageBarEntry.configure(state = <FONT COLOR="#009900">'disabled'</FONT>)
Pmw.forwardmethods(MessageBar, Tkinter.Entry, <FONT COLOR="#009900">'_messageBarEntry'</FONT>)
</PRE>
</BODY> </HTML>
|