def setup(self): for st in self._imgs: w, h = self.pos['width'], self.pos['height'] x = (w - self._img_source.size[0]) / 2 y = (h - self._img_source.size[1]) / 2 buttonbg = image.hex_to_rgb(self.frame.colors[st]['buttonbg']) buttonfg = image.hex_to_rgb(self.frame.colors[st]['buttonfg']) # Create the "base" image normal = Image.new('RGBA', (w, h), color=buttonbg) normal.paste(self._img_source, box=(x, y), mask=self._img_source) imgd = ImageDraw.Draw(normal) imgd.bitmap((x, y), self._img_source, fill=buttonfg) # Make other two states before beveling hover = normal.copy() click = normal.copy() # Now add effects that differentiate the states rendering.bevel_up(normal) bright = ImageEnhance.Brightness(click) click = bright.enhance(1.2) rendering.bevel_down(click) bright = ImageEnhance.Brightness(hover) hover = bright.enhance(1.2) rendering.bevel_up(hover) self._imgs[st]['normal'] = image.get_data(normal) self._imgs[st]['click'] = image.get_data(click) self._imgs[st]['hover'] = image.get_data(hover)
def setup(self): icon = self.frame.client.win.get_icon(self.pos['width'], self.pos['height']) # If for some reason we couldn't get an icon... if icon is None or not icon['width'] or not icon['height']: for st in self._imgs: self._imgs[st] = rendering.box(self.frame.colors[st]['bg'], self.pos['width'], self.pos['height']) return # Blending time... yuck im = image.get_image(icon['width'], icon['height'], icon['data']) im = im.resize((self.pos['width'], self.pos['height'])) if 'mask' in icon and icon['mask'] and icon['mask'] != icon['data']: immask = image.get_bitmap(icon['width'], icon['height'], icon['mask']) immask = immask.resize((self.pos['width'], self.pos['height'])) else: immask = im.copy() for st in self._imgs: im = rendering.blend(im, immask, self.frame.colors[st]['bg'], self.pos['width'], self.pos['height']) self._imgs[st] = image.get_data(im)
def setup(self): self._img_w = self.pos['width'] self._img_h = self.pos['height'] for st in self._imgs: self._imgs[st] = image.get_data( rendering.corner(self.frame.colors[st]['thinborder'], self.frame.colors[st]['bg'], self._img_w, self._img_h, 'right_bottom'))
def setup(self): self._img_w = 1 self._img_h = self.pos['height'] for st in self._imgs: self._imgs[st] = image.get_data( rendering.border(self.frame.colors[st]['thinborder'], self.frame.colors[st]['bottomborder'], self._img_w, self._img_h, 'bottom'))
def setup(self): self._img_w = self.pos['width'] self._img_h = 1 for st in self._imgs: self._imgs[st] = image.get_data( rendering.border(self.frame.colors[st]['thinborder'], self.frame.colors[st]['bg'], self._img_w, self._img_h, 'left'))
def setup(self): self._img_w = 1 self._img_h = self.pos['height'] for st in self._imgs: self._imgs[st] = image.get_data(rendering.border( self.frame.colors[st]['thinborder'], self.frame.colors[st]['bg'], self._img_w, self._img_h, 'top'))
def setup(self): self._img_w = self.pos['width'] self._img_h = self.pos['height'] for st in self._imgs: self._imgs[st] = image.get_data(rendering.corner( self.frame.colors[st]['thinborder'], self.frame.colors[st]['bg'], self._img_w, self._img_h, 'right_bottom'))
def setup(self): self._img_w = self.pos['width'] self._img_h = 1 for st in self._imgs: self._imgs[st] = image.get_data(rendering.border( self.frame.colors[st]['thinborder'], self.frame.colors[st]['bg'], self._img_w, self._img_h, 'left'))
def __init__(self, *_): _PopupWindow.__init__(self) self.width = self.height = c_icn_sz + (2 * c_brdr_sz) self.configure(width=self.width, height=self.height) icon = self.client.win.get_icon(c_icn_sz, c_icn_sz) im = image.get_image(icon['width'], icon['height'], icon['data']) im = im.resize((c_icn_sz, c_icn_sz)) if 'mask' in icon and icon['mask'] and icon['mask'] != icon['data']: immask = image.get_bitmap(icon['width'], icon['height'], icon['mask']) immask = immask.resize((c_icn_sz, c_icn_sz)) else: immask = im.copy() alpha = 1 if not self.client.mapped: alpha = 0.3 icon_im = rendering.blend(im, immask, c_bg, c_icn_sz, c_icn_sz, alpha) im_inactive = rendering.box(c_bg, self.width, self.height) im_inactive.paste(icon_im, box=(c_brdr_sz, c_brdr_sz)) im_active = rendering.box(c_brdr_clr, self.width, self.height) im_active.paste(icon_im, box=(c_brdr_sz, c_brdr_sz)) self.inactive = image.get_data(im_inactive) self.active = image.get_data(im_active) self.render_inactive() self.map()
def set_text(self, txt): if not len(txt): txt = ' ' # Dirty hack. I guess PIL can't handle empty strings font_file = '/usr/share/fonts/TTF/DejaVuSans-Bold.ttf' font = rendering.create_font(font_file, 15) for st in self._imgs: im = rendering.draw_text_bgcolor(font, txt, self.frame.colors[st]['bg'], self.frame.colors[st]['title'], self.pos['width'], self.pos['height']) width, height = im.size self._imgs[st] = image.get_data(im) self._fwidth, self._fheight = width, height self.configure(width=self._fwidth)
def get_icon(self, width, height): def icon_diff(icn_w, icn_h): return abs(width - icn_w) + abs(height - icn_h) def icon_size(icn_w, icn_h): return icn_w * icn_h try: icons = ewmh.get_wm_icon(conn, self.id).reply() except xproto.BadWindow: return { 'data': image.get_data(rendering.openbox), 'mask': image.get_data(rendering.openbox), 'width': rendering.openbox.size[0], 'height': rendering.openbox.size[1] } # Find a valid icon... icon = None # The EWMH way... find an icon closest to our desired size # Bigger is better! if icons: size = icon_size(width, height) for icn in icons: if icon is None: icon = icn else: old = icon_diff(icon['width'], icon['height']) new = icon_diff(icn['width'], icn['height']) old_size = icon_size(icon['width'], icon['height']) new_size = icon_size(icn['width'], icn['height']) if ((new < old and new_size > old_size) or (size > old_size and size < new_size)): icon = icn if icon is not None: icon['data'] = image.net_wm_icon_to_bgra(icon['data']) icon['mask'] = icon['data'] # The ICCCM way... if (icon is None and self.hints['flags']['IconPixmap'] and self.hints['icon_pixmap'] is not None and self.hints['icon_mask'] is not None): pixid = self.hints['icon_pixmap'] maskid = self.hints['icon_mask'] w, h, d = image.get_image_from_pixmap(conn, pixid) icon = {'width': w, 'height': h, 'data': d} _, _, icon['mask'] = image.get_image_from_pixmap(conn, maskid) # Default icon... # Stealing from Openbox for now... I swear I'll make my own soon :P if icon is None: icon = { 'data': image.get_data(rendering.openbox), 'mask': image.get_data(rendering.openbox), 'width': rendering.openbox.size[0], 'height': rendering.openbox.size[1] } return icon