def setup_images(self): """Create image structures for each icon files.""" for img_name, iconfile in self.icons_files.items(): if iconfile is None: logger.warning( 'No icon found for application "%s" (%s) switch to text mode', img_name, iconfile, ) # if no icon is found and no default icon was set, we just # print the name, based on a textbox. textbox = base._TextBox() textbox._configure(self.qtile, self.bar) textbox.layout = self.drawer.textlayout( textbox.text, self.foreground, self.font, self.fontsize, self.fontshadow, markup=textbox.markup, ) # the name will be displayed textbox.text = img_name textbox.calculate_length() self.icons_widths[img_name] = textbox.width self.surfaces[img_name] = textbox continue else: try: img = cairocffi.ImageSurface.create_from_png(iconfile) except cairocffi.Error: logger.exception( 'Error loading icon for application "%s" (%s)', img_name, iconfile) return input_width = img.get_width() input_height = img.get_height() sp = input_height / (self.bar.height - 4) width = int(input_width / sp) imgpat = cairocffi.SurfacePattern(img) scaler = cairocffi.Matrix() scaler.scale(sp, sp) scaler.translate(self.padding * -1, -2) imgpat.set_matrix(scaler) imgpat.set_filter(cairocffi.FILTER_BEST) self.surfaces[img_name] = imgpat self.icons_widths[img_name] = width
def setup_images(self): """ Create image structures for each icon files. """ for img_name, iconfile in self.icons_files.items(): if iconfile is None: self.qtile.log.warning('No icon found for application "' + img_name + '" (' + str(iconfile) + ')' + ' switch to text mode') # if no icon is found and no default icon was set, we just # print the name, based on a textbox. textbox = base._TextBox() textbox._configure(self.qtile, self.bar) textbox.layout = self.drawer.textlayout( textbox.text, textbox.foreground, textbox.font, textbox.fontsize, textbox.fontshadow, markup=textbox.markup, ) # the name will be displayed textbox.text = img_name textbox.calculate_width() self.icons_widths[img_name] = textbox.width self.surfaces[img_name] = textbox continue else: try: img = cairocffi.ImageSurface.create_from_png(iconfile) except cairocffi.Error: self.qtile.log.exception('Error loading icon for ' + 'application "' + img_name + '" (' + iconfile + ')') return input_width = img.get_width() input_height = img.get_height() sp = input_height / float(self.bar.height - 4) width = input_width / sp imgpat = cairocffi.SurfacePattern(img) scaler = cairocffi.Matrix() scaler.scale(sp, sp) scaler.translate(self.padding * -1, -2) imgpat.set_matrix(scaler) imgpat.set_filter(cairocffi.FILTER_BEST) self.surfaces[img_name] = imgpat self.icons_widths[img_name] = width
from libqtile import hook from libqtile.widget import Chord, base RED = "#FF0000" BLUE = "#00FF00" textbox = base._TextBox("") BASE_BACKGROUND = textbox.background BASE_FOREGROUND = textbox.foreground def test_chord_widget(fake_bar): chord = Chord(chords_colors={"testcolor": (RED, BLUE)}) chord.bar = fake_bar chord._setup_hooks() assert chord.text == "" hook.fire("enter_chord", "test") assert chord.text == "test" assert chord.background == BASE_BACKGROUND assert chord.foreground == BASE_FOREGROUND hook.fire("enter_chord", True) assert chord.text == "" hook.fire("leave_chord") assert chord.text == "" hook.fire("enter_chord", "testcolor") assert chord.background == RED assert chord.foreground == BLUE