/usr/share/pyshared/plwm/modewindow.py is in python-plwm 2.6a+20080530-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | #
# modewindow.py -- manage a mode window within PLWM
#
# Copyright (C) 2001 Peter Liljenberg <petli@ctrl-c.liu.se>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
from Xlib import X
import wmanager
TOP = 0
BOTTOM = 1
LEFT = 0
CENTER = 1
RIGHT = 2
# Screen mixin
class ModeWindowScreen:
modewindow_pos = TOP
def __screen_client_init__(self):
fg = self.get_color_res('.modewindow.foreground',
'.ModeWindow.Foreground',
'#ffffff')
bg = self.get_color_res('.modewindow.background',
'.ModeWindow.Background',
'#000000')
self.modewindow_mw = ModeWindow(self, fg, bg,
self.wm.get_font_res('.modewindow.font',
'.ModeWindow.Font',
'fixed'),
self.modewindow_pos)
def modewindow_add_message(self, message):
self.modewindow_mw.add_message(message)
def modewindow_remove_message(self, message):
self.modewindow_mw.remove_message(message)
class ModeWindow:
def __init__(self, screen, fg, bg, font, pos):
self.messages = []
fq = font.query()
font_center = (fq.font_ascent + fq.font_descent) / 2 - fq.font_descent
height = fq.font_ascent + fq.font_descent + 6
if pos == TOP:
c = screen.alloc_border('top', height)
else:
c = screen.alloc_border('bottom', height)
self.x, self.y, self.width, self.height = c
self.base = self.height / 2 + font_center
window = screen.root.create_window(
self.x, self.y, self.width, self.height, 0,
X.CopyFromParent, X.InputOutput, X.CopyFromParent,
background_pixel = bg,
event_mask = X.ExposureMask
)
self.gc = window.create_gc(foreground = fg, font = font)
self.window = screen.add_internal_window(window)
self.window.dispatch.add_handler(X.Expose, self.redraw)
window.map()
def add_message(self, message):
try:
self.messages.index(message)
except ValueError:
self.messages.append(message)
message.add_to_mw(self)
def remove_message(self, message):
try:
message.remove_from_mw(self)
self.messages.remove(message)
except ValueError:
pass
def redraw(self, event):
for m in self.messages:
m.draw(self)
class Message:
def __init__(self, position, justification = CENTER, nice = 0, text = None):
if position < 0 or position > 1:
raise ValueError('position should be in the interval [0.0, 1.0], was %s'
% position)
self.position = position
self.justification = justification
self.nice = nice
self.text = text
# Mapping of modewins to text widths
self.modewins = {}
def add_to_mw(self, mw):
self.modewins[mw] = None
self.draw(mw)
def remove_from_mw(self, mw):
self.undraw(mw)
del self.modewins[mw]
def set_text(self, text):
if text == self.text:
return
self.text = text
for mw in self.modewins.keys():
self.undraw(mw)
self.modewins[mw] = None
self.draw(mw)
def draw(self, mw):
if not self.text:
return
pos = self.modewins[mw]
if pos is None:
# Get width
if self.text:
f = mw.gc.query_text_extents(self.text)
width = f.overall_width + 4
else:
width = 0
# Get x pos
x = (mw.width * self.position)
if self.justification == CENTER:
x = x - width / 2
elif self.justification == RIGHT:
x = x - width
self.modewins[mw] = (width, x)
else:
width, x = pos
mw.window.draw_text(mw.gc, x + 2, mw.base, self.text)
def undraw(self, mw):
pos = self.modewins[mw]
if pos is not None:
width, x = pos
mw.window.clear_area(x = x, width = width)
|