def update_text_buffer(self): if self.size_changed or not self.text_buffer: if self.text_buffer: self.text_buffer.destroy() self.text_buffer = yutani.GraphicsBuffer( self.width - self.decorator.width(), self.height - self.decorator.height() + 80 - self.menubar.height) surface = self.text_buffer.get_cairo_surface() ctx = cairo.Context(surface) ctx.rectangle(0, 0, surface.get_width(), surface.get_height()) ctx.set_source_rgb(1, 1, 1) ctx.fill() pad = 10 if not self.tr: self.tr = text_region.TextRegion(pad, 0, surface.get_width() - pad * 2, surface.get_height()) self.tr.set_line_height(18) self.tr.base_dir = '/usr/share/help/' self.tr.set_richtext(self.get_document_text()) elif self.size_changed: self.size_changed = False self.tr.resize(surface.get_width() - pad * 2, surface.get_height() - pad * 2) self.tr.scroll = self.scroll_offset self.tr.draw(self.text_buffer)
def load_wallpaper(self): tmp = cairo.ImageSurface.create_from_png('/usr/share/wallpapers/default') self.wallpaper = cairo.ImageSurface(cairo.FORMAT_ARGB32, self.width, self.height) x = self.width / tmp.get_width() y = self.height / tmp.get_height() nh = int(x * tmp.get_height()) nw = int(y * tmp.get_width()) ctx = cairo.Context(self.wallpaper) if (nw > self.width): ctx.translate((self.width - nw) / 2, 0) ctx.scale(y,y) else: ctx.translate(0,(self.height - nh) / 2) ctx.scale(x,x) ctx.set_source_surface(tmp,0,0) ctx.paint() buf = yutani.GraphicsBuffer(self.wallpaper.get_width(),self.wallpaper.get_height()) tmp = buf.get_cairo_surface() ctx = cairo.Context(tmp) ctx.set_source_surface(self.wallpaper) ctx.paint() yutani.yutani_gfx_lib.blur_context_box(buf._gfx, 20) yutani.yutani_gfx_lib.blur_context_box(buf._gfx, 20) yutani.yutani_gfx_lib.blur_context_box(buf._gfx, 20) ctx = cairo.Context(self.wallpaper) ctx.set_source_surface(tmp) ctx.paint() buf.destroy()
def update(self, width): needs_resize = False if width != self.width: needs_resize = True self.width = width self.tr.resize(self.width - self.pad * 2, self.tr.line_height) h = self.tr.line_height * len(self.tr.lines) + self.pad * 2 if h != self.height_int: needs_resize = True self.height_int = h if self.height_int - self.pad * 2 > 30000: # Shit... self.height_int = 30000 - self.pad * 2 self.tr.resize(self.width - self.pad * 2, self.height_int - self.pad * 2) self.tr.move(self.pad, self.pad) if needs_resize or not self.text_buffer: if self.text_buffer: self.text_buffer.destroy() self.text_buffer = yutani.GraphicsBuffer(self.width, self.height_int) surface = self.text_buffer.get_cairo_surface() ctx = cairo.Context(surface) ctx.rectangle(0, 0, surface.get_width(), surface.get_height()) ctx.set_source_rgb(*self.background) ctx.fill() self.tr.draw(self.text_buffer)
def init_buffer(self,w,h): self.modified = False self.buf = yutani.GraphicsBuffer(w,h) self.surface = self.buf.get_cairo_surface() self.draw_ctx = cairo.Context(self.surface) self.offset_x = int((self.width-self.decorator.width()-self.buf.width)/2) self.offset_y = int((self.height-self.decorator.height()-self.buf.height-self.menubar.height)/2)
def redraw_buf(self, clips=None): if self.buf: self.buf.destroy() w = 450 height = self.unit_height self.buf = yutani.GraphicsBuffer(w, len(self.files) * height) surface = self.buf.get_cairo_surface() ctx = cairo.Context(surface) if clips: for clip in clips: ctx.rectangle(clip.x, clip.y, w, height) ctx.clip() ctx.rectangle(0, 0, surface.get_width(), surface.get_height()) ctx.set_source_rgb(1, 1, 1) ctx.fill() offset_y = 0 i = 0 for f in self.files: f.y = offset_y if not clips or f in clips: tr = f.tr tr.move(26, offset_y + 2) if f.hilight: gradient = cairo.LinearGradient(0, 0, 0, height - 2) gradient.add_color_stop_rgba(0.0, *hilight_gradient_top, 1.0) gradient.add_color_stop_rgba(1.0, *hilight_gradient_bottom, 1.0) ctx.rectangle(0, offset_y, w, 1) ctx.set_source_rgb(*hilight_border_top) ctx.fill() ctx.rectangle(0, offset_y + height - 1, w, 1) ctx.set_source_rgb(*hilight_border_bottom) ctx.fill() ctx.save() ctx.translate(0, offset_y + 1) ctx.rectangle(0, 0, w, height - 2) ctx.set_source(gradient) ctx.fill() ctx.restore() tr.font.font_color = 0xFFFFFFFF else: ctx.rectangle(0, offset_y, w, height) if i % 2: ctx.set_source_rgb(0.9, 0.9, 0.9) else: ctx.set_source_rgb(1, 1, 1) ctx.fill() tr.font.font_color = 0xFF000000 ctx.set_source_surface(f.icon, 4, offset_y + 2) ctx.paint() tr.draw(self.buf) offset_y += height i += 1
def redraw_buf(self, clips=None): if self.buf: self.buf.destroy() w = self.width - self.decorator.width() self.buf = yutani.GraphicsBuffer(w, len(self.packages) * 24) surface = self.buf.get_cairo_surface() ctx = cairo.Context(surface) if clips: for clip in clips: ctx.rectangle(clip.x, clip.y, w, 24) ctx.clip() ctx.rectangle(0, 0, surface.get_width(), surface.get_height()) ctx.set_source_rgb(1, 1, 1) ctx.fill() offset_y = 0 for f in self.packages: f.y = offset_y if not clips or f in clips: tr = text_region.TextRegion(4, offset_y + 4, w - 4, 20) if f.hilight: gradient = cairo.LinearGradient(0, 0, 0, 18) gradient.add_color_stop_rgba(0.0, *hilight_gradient_top, 1.0) gradient.add_color_stop_rgba(1.0, *hilight_gradient_bottom, 1.0) ctx.rectangle(0, offset_y + 4, w, 1) ctx.set_source_rgb(*hilight_border_top) ctx.fill() ctx.rectangle(0, offset_y + 4 + 20 - 1, w, 1) ctx.set_source_rgb(*hilight_border_bottom) ctx.fill() ctx.save() ctx.translate(0, offset_y + 4 + 1) ctx.rectangle(0, 0, w, 20 - 2) ctx.set_source(gradient) ctx.fill() ctx.restore() tr.font.font_color = 0xFFFFFFFF else: ctx.rectangle(0, offset_y + 4, w, 20) ctx.set_source_rgb(1, 1, 1) ctx.fill() tr.font.font_color = 0xFF000000 tr.set_richtext(f.text) tr.set_one_line() tr.set_ellipsis() tr.draw(self.buf) offset_y += 24
def redraw_buf(self,size_changed=False): if size_changed: if self.buf: self.buf.destroy() w = self.width - self.decorator.width() h = self.height - self.decorator.height() self.buf = yutani.GraphicsBuffer(w,h) yutani.Window.fill(self.buf,0xFF777777) if self.document: self.fitz_lib.draw_page(self.fitz_ctx, self.document, self.page, self.buf._gfx) self.set_title(f"{self.path} - {self.page}/{self.page_count} - {app_name}","pdfviewer") else: self.set_title(app_name,"pdfviewer")
def redraw_buf(self, icons=None): if self.buf: self.buf.destroy() w = self.width - self.decorator.width() files_per_row = int(w / 100) self.buf = yutani.GraphicsBuffer( w, math.ceil(len(self.files) / files_per_row) * 100) surface = self.buf.get_cairo_surface() ctx = cairo.Context(surface) if icons: for icon in icons: ctx.rectangle(icon.x, icon.y, 100, 100) ctx.clip() ctx.rectangle(0, 0, surface.get_width(), surface.get_height()) ctx.set_source_rgb(1, 1, 1) ctx.fill() offset_x = 0 offset_y = 0 for f in self.files: if not icons or f in icons: x_, y_ = ctx.user_to_device(0, 0) f.tr.move(offset_x, offset_y + 60) f.tr.draw(self.buf) ctx.set_source_surface(f.icon, offset_x + 26, offset_y + 10) ctx.paint_with_alpha(1.0 if not f.hilight else 0.7) f.x = offset_x f.y = offset_y offset_x += 100 if offset_x + 100 > surface.get_width(): offset_x = 0 offset_y += 100
def redraw_buf(self,clips=None): if self.buf: self.buf.destroy() w = self.width - self.decorator.width() self.buf = yutani.GraphicsBuffer(w,len(self.packages)*package_height) surface = self.buf.get_cairo_surface() ctx = cairo.Context(surface) if clips: for clip in clips: ctx.rectangle(clip.x,clip.y,w,package_height) ctx.clip() ctx.rectangle(0,0,surface.get_width(),surface.get_height()) ctx.set_source_rgb(1,1,1) ctx.fill() offset_y = 0 button = Button('Install', None) for f in self.packages: f.y = offset_y if not clips or f in clips: tr = text_region.TextRegion(64,offset_y+4,w-64 - 120,package_height-4) tr.line_height = 19 if False and f.hilight: gradient = cairo.LinearGradient(0,0,0,18) gradient.add_color_stop_rgba(0.0,*hilight_gradient_top,1.0) gradient.add_color_stop_rgba(1.0,*hilight_gradient_bottom,1.0) ctx.rectangle(0,offset_y+4,w,1) ctx.set_source_rgb(*hilight_border_top) ctx.fill() ctx.rectangle(0,offset_y+package_height-1,w,1) ctx.set_source_rgb(*hilight_border_bottom) ctx.fill() ctx.save() ctx.translate(0,offset_y+4+1) ctx.rectangle(0,0,w,package_height-6) ctx.set_source(gradient) ctx.fill() ctx.restore() tr.font.font_color = 0xFFFFFFFF else: ctx.rectangle(0,offset_y+4,w,package_height-4) ctx.set_source_rgb(1,1,1) ctx.fill() tr.font.font_color = 0xFF000000 if f.installed: package_icon = get_icon(f.icon if f.icon else 'package',48,'package') else: if f.hilight: button.hilight = f.hilight else: button.hilight = 0 button.draw(self.buf,ctx,w-110,offset_y+11,100,32) package_icon = get_icon('package-uninstalled',48) ctx.set_source_surface(package_icon,8,11+offset_y) ctx.paint() tr.set_richtext(f.text) tr.set_ellipsis() tr.set_max_lines(3) tr.draw(self.buf) offset_y += package_height