/usr/lib/gdesklets/display/TargetFrame.py is in gdesklets 0.36.1-7.
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 | from ContainerTarget import ContainerTarget
from utils.datatypes import *
from layout import Unit
from utils import vfs
import utils
import os
import gtk
try:
from utils.tiling import Tiling
except ImportError:
import sys
log("Could not import tiling module!")
sys.exit(1)
#
# Class for putting frames around targets.
#
class TargetFrame(ContainerTarget):
def __init__(self, name, parent):
self.__frame_widths = [Unit.ZERO] * 4
self.__images = []
ContainerTarget.__init__(self, name, parent)
self.__table = gtk.Table(3, 3)
self.__table.set_direction(gtk.TEXT_DIR_LTR)
self.__table.show()
r, g, b, a = utils.parse_color("black")
for x, y in ((0, 1), (1, 0), (2, 1), (1, 2),
(0, 0), (2, 0), (2, 2), (0, 2)):
img = Tiling()
img.set_from_color(r, g, b, a)
img.show()
self.__table.attach(img, x, x + 1, y, y + 1)
self.__images.append(img)
self.__box = gtk.HBox()
self.__box.show()
self.__table.attach(self.__box, 1, 2, 1, 2)
self._register_property("border-uris", TYPE_LIST,
self._setp_border_uris, self._getp)
self._register_property("border-width", TYPE_UNIT_LIST,
self._setp_border_width, self._getp)
self._register_property("color", TYPE_STRING,
self._setp_border_color, self._getp)
self.set_prop("border-width",
[Unit.Unit(2, Unit.UNIT_PX), Unit.Unit(2, Unit.UNIT_PX),
Unit.Unit(2, Unit.UNIT_PX), Unit.Unit(2, Unit.UNIT_PX)])
self._setp("color", "black")
# watch for geometry changes
self.add_observer(self.__on_observe_size)
def get_widget(self): return self.__table
def new_child(self, childtype, settings, children):
child = ContainerTarget.new_child(self, childtype, settings, children)
self.__box.add(child.get_widget())
self.__redraw_frame()
#
# Observer for size changes.
#
def __on_observe_size(self, src, cmd, *args):
x, y, w, h = src.get_geometry()
if (cmd == src.OBS_GEOMETRY and
(w.as_px() != 0) and (h.as_px() != 0)):
self.__redraw_frame()
def __redraw_frame(self, src = None, event = None):
x, y, w, h = self.get_geometry()
w1, h1, w2, h2 = self.__frame_widths
iw = max(Unit.ZERO, w - w1 - w2)
ih = max(Unit.ZERO, h - h1 - h2)
self.__box.set_size_request(iw.as_px(), ih.as_px())
cnt = 0
for bw, bh in ((w1, ih), (iw, h1),
(w2, ih), (iw, h2),
(w1, h1), (w2, h1),
(w2, h2), (w1, h2)):
img = self.__images[cnt]
cnt += 1
if (bw.as_px() == 0 or bh.as_px() == 0):
img.hide()
else:
img.show()
img.tile(bw.as_px(), bh.as_px())
img.set_size_request(bw.as_px(), bh.as_px())
#end for
def __set_border_width(self, args):
for i in xrange(len(args)):
self.__frame_widths[i] = args[i]
self.get_layout_object().set_border_width(*args)
def __set_border(self, args):
cnt = 0
for uri in args:
uri = self._get_display().get_full_path(uri)
if (vfs.exists(uri)):
try:
data = vfs.read_entire_file(uri)
except:
return
self.__images[cnt].set_from_data(data)
cnt += 1
self.__redraw_frame()
def __set_border_color(self, color):
r, g, b, a = utils.parse_color(color)
for cnt in range(8):
self.__images[cnt].set_from_color(r, g, b, a)
self.__redraw_frame()
def get_border_size(self):
w1, h1, w2, h2 = self.__frame_widths
return (w1, h1, w2, h2)
def _setp_border_uris(self, key, value):
self.__set_border(value)
self._setp(key, value)
def _setp_border_color(self, key, value):
self.__set_border_color(value)
self._setp(key, value)
def _setp_border_width(self, key, value):
self.__set_border_width(value)
self._setp(key, value)
|